Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given the path to an executable (say /usr/bin/gvim), how can I find the Gnome .desktop file for that application?

I'm futzing around in python, so a python-specific answer would be most helpful.

share|improve this question
I've poked around with the Gnome docs, but I haven't found anything for querying the existing set of desktop entries. – Erigami Feb 12 '11 at 17:36
up vote 3 down vote accepted

If you want to do it programmatically, use python-gmenu. It wraps the libgnome-menu2 API for Python.

That API lets you iterate over all the desktop directories that are currently configured and includes any overrides or modifications the user has customized. Then you just query each file to see if it's Exec line matches what you expect.

I couldn't find any documentation for either library, but liberal use of "import gmenu; dir(gmenu)" and looking over /usr/include/gnome-menus/gmenu-tree.h should help.

share|improve this answer
Excellent! That's exactly what I was looking for! Thanks! – Erigami Feb 13 '11 at 21:58

If your package is installed from package (not from source), you can use (in Bash):

dpkg -L $(dpkg -S /usr/bin/pidgin | cut -f1 -d: ) | grep \.desktop$

In the case of gvim, it outputs nothing. You have another problem, in fact, gvim is an alternative. The "true" gvim can be multiple programs. On my computer it is /usr/bin/vim.gnome. Let's try with it. This doesn't work either... because there is no .desktop in the same package that vim.gnome. In fact, in this complicated case, the .desktop is in another package common to all graphical interfaces of Vim: vim-gui-common

share|improve this answer

The .desktop files for most applications are stored in:


some .desktop files may also be stored in:


or (for per user settings) in:

share|improve this answer
Can't .desktop also be installed in the user's home directory? I'd rather not walk every file in every possible install location to track down a path if it's available from some service. – Erigami Feb 12 '11 at 18:28
See edit. The location of .desktop files cannot be extracted from the installation path, I'm afraid (but should be defined in the .deb package). – Takkat Feb 12 '11 at 18:43

You can search through all desktop files. For example, to find the desktop file related to gedit:

grep -li exec=gedit $(locate -r '\.desktop$')
share|improve this answer

You can execut 1.sudo find /path_to_folder/ -iname *.desktop in general. And 2.sudo find / -iname *.desktop in your case.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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