One of the beautiful things about Linux is that developers tend to be conscientious about the use of technical standards. Freedesktop.org maintains a wide series of standards for X Window System desktops, which apply to Gnome, KDE, LXDE and XFCE (I’m not sure whether Fluxbox implements these standards.) The standard for “desktop entries” is still technically a draft, but is generally accepted by the larger X community.
The .desktop file fills two primary functions: first, it informs the desktop environment how the file is to be handled by the desktop environment with regard to menu placement, display, environmental variables, and similar. In this function, it resides globally in /usr/share/applications/ and for specific users in $HOME/.local/applications. The second function is the direct shortcut on the desktop itself. In this function, it resides in $HOME/Desktop. The same file fills both functions, so if you want to have an application both in the menu and on your desktop, you’ll need to put the .desktop file in two places. Let’s take a closer look, shall we?
The .desktop file is generally in a key,value pair format. This means that, generally speaking, each line will look like this:
key=value
Required Elements
Type – specifies the type of desktop entry. Currently, there are three valid types: Application, Link and Directory.
Name – The name of the specific application or directory. This determines the actual display name for the menu/desktop entry.
Exec – provides the actual command to execute, with associated arguments (if necessary.)
Optional Elements
Version – specifies the version of the Desktop Entry Specification to which the .desktop file conforms (currently 1.0).
Encoding – The encoding for the .desktop file. The standard calls for UTF-8.
GenericName – specifies the generic name of the application.
NoDisplay – This is a boolean (i.e. true/false) element. If set to “true”, it means “this application exists but should not appear in menus.” This is most frequently used to associate an application with MIME types so file managers know how to handle things.
Comment – specifies tooltip entries for the file.
Icon – specifies the icon to be used. This entry supports both icons supported under the FreeDesktop Icon Theme Specification (which I haven’t yet fully grokked) as well as absolute paths.
Hidden – another boolean entry which, if true, essentially treats the application as having been deleted.
OnlyShowIn – If you use multiple desktop environments (say, for instance, you use both Gnome and LXDE) and only want the .desktop entry to apply to a few of the environments, this line specifies the environments in which the entry should apply. This entry is mutually exclusive with NotShowIn.
NotShowIn – As above, but instead of specifying where to display the entry, it displays where NOT to display the entry. This is more useful if you have numerous environments but only want to exclude one or two.
Path – specifies the working directory for an application to run in.
Terminal – a boolean entry which specifies whether or not the application requires a terminal to run.
MimeType – specifies any associated MIME types with this application.
Categories – Categories in which this application should appear in menus. Supported categories vary from system to system, but there is an emerging standard for categories.
Finally, any line beginning with an octothorpe (“#”) is considered a comment.
Putting It All Together
Now that we have all the elements, we can open up any text editor and create a .desktop entry. Here’s a very simple sample:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=$HOME/MyApp
Name=My Application
Icon=$HOME/Icons/MyIcon.png
Save your entry (as filename.desktop), then put a copy in $HOME/.local/applications and (if you want) another in $HOME/Desktop. If you did it right (and if you’re running Gnome, KDE or LXDE), your new application should show up in your menu and (possibly) on your desktop.

Thank you for this. Not for me personally, but I can point people to this who want a simple explanation of how this works.
Also, Fluxbox is not standards compliant, but the fm2 menu system is pretty darn close. Openbox is standards compliant from the get go.
By: Kendall on April 7, 2010
at 07:58
Very helpful and well written. Bite sized and complete. Thank you.
By: Rick on April 8, 2010
at 04:30
[...] Anatomy of a .desktop File [...]
By: Links 8/4/2010: Linux Probably Back to the PS3, Ubuntu GNU/Linux Users @ ~12 Million | Techrights on April 8, 2010
at 05:20
This info will help greatly, thank you much!
By: lefty.crupps on April 8, 2010
at 06:23
Great little article, Joe!
By: Algol on April 8, 2010
at 13:01
Thanks for the kind words, everyone!
By: Joe on April 8, 2010
at 13:49
[...] http://linuxcritic.wordpress.com/2010/04/07/anatomy-of-a-desktop-file/ [...]
By: GoblinX Project » GoblinX Newsletter, Issue 245 (04/11/2010) on April 11, 2010
at 07:40
[...] Anatomy of a .desktop File « The Linux Critic [...]
By: Installattion Thunderbird 3 Ubuntu 9.10 | PSchwan on April 12, 2010
at 12:00
[...] Anatomy of a .desktop File « The Linux Critic [...]
By: Installation Thunderbird 3 Ubuntu 9.10 | PSchwan on April 13, 2010
at 15:31
This is good info about .desktop files, but it’s missing some important general info. Here’s what I learned trying to create a “start” menu item for a beta build of Mozilla’s SeaMonkey browser.
a) One of the value-added things a Linux distribution usually does when it packages an app is provide a .desktop file and icons. E.g. look at http://packages.ubuntu.com/maverick/amd64/seamonkey-browser/filelist , you can see a .desktop file and some icon pixmaps. You can extract these files from the package (a separate topic in itself!) and modify them to suit or use them for inspiration, e.g. whether the Exec= line should use %u or %f or something else for the file name to open. (Of course if you installed the package using the distribution’s package manager in the first place, you shouldn’t need to do any of this!)
b) If you want to create an icon on your desktop for an app, I believe both Gnome and KDE let you do it by dragging a program from their file browser to the desktop or a KDE panel.
c) If you need to create a start menu item for an app, there’s often a GUI to do it. In KDE run the program `kmenuedit` (“KDE Menu Editor”).
d) If you create a .desktop file by hand, you’ll have to get your desktop environment to notice your change. The brute-force way to do this is logout and back in, or even restart Linux, but there’s probably a program to rebuild the desktop information. For example, in KDE run the command-line program `kbuildsycoca4`.
e) I think the desktop looks for the icon file in the Icon= line in $HOME/.local/share/icons , /usr/share/pixmaps, and /usr/share/icons.
f) Note that if you try to put the .desktop file and icons in their system locations in /usr/share, you’ll need to be the super-user “root”.
g) This could be Ubuntu-specific, but it seems to have .desktop files and icons in /usr/share/app-install for programs that you *might* install; the distribution uses these in its “Get/Install new software/applications” utility.
I hope this helps someone!
By: skierpage on November 14, 2010
at 20:34
[...] Shortcut Written by: Vhati Aside: Linux GUIs have shortcuts too (text .desktop files). A few lines of echo and the google-resistant specs will create one. Shortcut is a [...]
By: RancidMeat: Shortcut « Misanthropic Geek Dot Net on January 28, 2011
at 15:23
“specific users in $HOME/.local/applications” : this is actually $HOME/.local/share/applications (“share” is missing). By the way, there seems to be many similarities between $HOME/.local/share and /usr/share. May be $HOME/.local is a kind of /usr.
By: Yannick Duchêne (Hibou57) on March 9, 2011
at 17:41
nice article! anyways, i need to put in an extra command on my skype launcher to make my webcam work properly, however when i add the ff to the Exec line:
export LIBV4LCONTROL_FLAGS=3 && LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so skype
the launcher doesn’t work. any thoughts on this? thanks!
By: Paulo on May 19, 2011
at 02:02
To be honest, I’m not entirely sure how you’d go about embedding that in a .desktop file. Personally, I’d write a quick and dirty shell script to handle that, then point the .desktop file at the script.
By: Joe on May 19, 2011
at 06:44
you have to use the _env_ command from coreutils.
In example:
Exec=env LIBV4LCONTROL_FLAGS=3 LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so skype
HTH
By: diega on August 29, 2011
at 23:43
[...] I think I remember running into this once. I had the options when I had a Home and Trash folder, but then I deleted them, and was presented with a different right-click menu. When you say just menu options, do you mean just like the menu you see when you click the launcher on the panel? Or something else? I would go ahead and create a Desktop directory in /home, then you just need generic .desktop files, I think they all follow the same freedesktop.org standards. http://linuxcritic.wordpress.com/201…-desktop-file/ [...]
By: How can I get files and folders on CrunchBang 10 Xfce desktop? on June 29, 2011
at 20:30
[...] a script to be able to do something new. To make it more useful, I would recommend creating a .desktop file in /usr/share/applications that launches your script in a terminal. As is, the user would have to [...]
By: openSUSE CLI updater on August 26, 2011
at 13:18
[...] more info on .desktop files see this page. [...]
By: TechnoStripe – Auto run a command on startup on August 31, 2011
at 09:24
[...] http://linuxcritic.wordpress.com/2010/04/07/anatomy-of-a-desktop-file/ Like this:LikeBe the first to like this post. [...]
By: GNU/Linux .desktop files « Giovanni’s Blog on December 28, 2011
at 06:31
[...] The Free Desktop Project has created a standard for desktop entry files. You may also find this summary of the standard to be helpful. To add Paraview to the menu, you simply need to create a new file in the standard [...]
By: Paraview 3.12 on 64-bit CentOS 5.7 | shocksolution.com on January 19, 2012
at 14:23
[...] menu. Solution: I used to just delete them from /usr/share/applications, but apparently there was a smarter way. Just open the .desktop file, e.g. /usr/share/applications/DMake.desktop and add the following: [...]
By: Hiding unwanted .desktop entries from the menu | slackalaxy on June 24, 2012
at 05:43
[...] 3. Add a desktop entry to /home/user/.config/autostart with the contents below. Desktop entry has a .desktop [...]
By: » Changing wallpaper using keyboard shortcut in XFCE. on October 26, 2012
at 23:56
[...] used this guide (http://linuxcritic.wordpress.com/201…-desktop-file/) and I have created a desktop file with file execution path and icon inside, but I still don't see [...]
By: Gnome3 and application shortcuts on November 18, 2012
at 21:51
Are you sure you can use $HOME in the Desktop entry file? Have you tried it to run desktop launcher on nautilus?
By: nobody on January 17, 2013
at 22:58
[...] are interpreted by your system, as Joe over at the Linux Critic blog has a great post titled the Anatomy of a .desktop File that does just that and I encourage you to go and read his [...]
By: Adding a printer to Linux Mint, LMDE or Ubuntu: an Encore | /pseudomorph on March 16, 2013
at 01:01
[...] e criar todos os fabulosos atalhos para meus programas no Gnome Shell! Foi somente criar arquivos .desktop [...]
By: Ubuntu, Gnome Shell e Atalhos - Randômio e Aleatórico on April 4, 2013
at 22:26