15

For some reason I have a bunch of left-over start menu entries from applications (e.g, Gnome Do, Synapse, Leafpad.) and was wondering if there's a way to remove all orphaned entries for applications that are no longer installed?

34
+50

You can use the following command to list application icons that link to nonexistent programs:

for i in {/usr,~/.local}/share/applications/*.desktop; do which $(grep -Poh '(?<=Exec=).*?( |$)' $i) > /dev/null || echo $i; done

I suspect you'll find that most of yours are customized icons in your home folder, since these are not automatically cleaned up by the package manager. If this is the case and you'd like to trash Install trash-cli them all at once, you can use a modification of the previous command:

for i in ~/.local/share/applications/*.desktop; do which $(grep -Poh '(?<=Exec=).*?( |$)' $i) > /dev/null || trash $i; done

Or, of course, browse to ~/.local/share/applications/ in Nautilus and trash them via the graphical interface.

| improve this answer | |
  • That did the trick! Is there anyway I can turn that into a shortcut that I can run when such a thing happens again? – Alan May 21 '11 at 18:13
3

If by start menu you mean the 'Applications' menu, you can edit it by going to: System -> Preferences -> Main Menu.

You can add, rearrange, edit and delete entries at will.

| improve this answer | |
  • Hi Eugenio. That's correct, but I have to go through each one, confirm if it really is orphaned or not, and then delete it. I'm looking for a way that would do all of this for me, as I have about 40+ entries that I want to remove. – Alan May 7 '11 at 2:58
  • Probably the most noob-friendly answer. +1 – tir38 Dec 27 '13 at 7:53
3

When an application is uninstalled it should remove menu items it installed. And it work this way on my machine.

If it works differently, it is a bug of a particular package or a problem on your system. I cannot believe that you have more than 40 entry orphaned. It would be the symptom of a problem.

| improve this answer | |
  • It's very strange, I've never had this problem until my upgrade to Natty Narwhal. I may downgrade to 10.04LTS, and wait a short while until 11.04 is a little more bug-free. – Alan May 21 '11 at 18:15
  • There are programs that actively install themselves but which don't have an actual installer per se. They get orphaned if the binary is moved. – Pointy Feb 5 '19 at 23:38
2

Well, this one is hard but i want, at least, to tell you what's the problem.

Gnome stores the installed applications in /usr/share/applications with files ended in .desktop (so vlc program is launchad by vlc.desktop)

Inside each one, there's a "Category" section in which you can set in what part of the Applications menu that program you want it to be. The thing is: the only way i think it can be done what you are asking for is using a bash script that ask if the package related to that .desktop is installed or not. if it's not, delete that .desktop file. When you delete the file, it will be out of the menu, and when you app is in a category, that one isn't shown.

That one is a bit out of my scope because every command (dpkg, apt-get, etc..) always return a good exit when they say the package isn't installed, so we have to read the exit from that app searching for a String (f.i. "not installed"), check it, and if the String exists, it means the application isn't installed and the .desktop can be deleted.

So, if you want, you could just enter the folder (/usr/share/applications) and click on files that correspond to the programs. They'll dissappear from the Applications menu. To do it automatically, i guess we need a good bash script on the track i said.

I hope this helps in some way.

| improve this answer | |
  • Hi David, thanks for your help! That tip about going into /usr/share/applications is certainly a time saver compared to deleting the broken links one-by-one in the menu editor. – Alan May 21 '11 at 18:23
0

Alternative:

Following @ændrük answer, here is a similar solution that support spaces in path and subfolders, this can be used on a specific folder or the the entire disk to look for broken .desktop files (shortcut)

find {/usr,~/.local,/usr/local,}/share/applications/ -name '*.desktop' | while read -r line; do which $(grep -Poh '(?<=Exec=).*?( |$)' $line) > /dev/null || echo $line;  done

For the entire disk

find / -name '*.desktop' | while read -r line; do which $(grep -Poh '(?<=Exec=).*?( |$)' $line) > /dev/null || echo $line;  done

Note: that any method can show false positive check twice found files before deleting them

| improve this answer | |
0

This may be an old posted question but I thought I should chime in anyway since I had the same problem however none of these suggestions worked but I found on the internet a very smart person who knew of a program called Alacarte (easy GNOME menu editing) program it installed using the software manager and I'm thrilled it's still available because it used the be installed by default but isn't now and is not a well known program but I'm so glad it It's still available via software manager and it's so easy to use just click on to highlight the uninstalled program entry you want to get rid of and click delete on the right and it's done. maybe this will help if these other suggestions don't work for you

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.