Ubuntu: Why do we have .desktop files?



Question:

I wonder why do we have .desktop files, I downloaded a trivial .jpg picture from internet (yes, I'm a newbie, currently learning command line), and saw that when I list the file, I saw .desktop extension even if I move that file to the documents etc.

How necessary are they? What functionality do they constitute? How to remove them?


Solution:1

.desktop files are very important. When you search the Dash for programs, or click a program in the Launcher at the side, you are using a .desktop file.

In Ubuntu, most programs can be launched with a command from terminal - for example firefox can be opened with the command firefox in terminal, and Chrome is google-chrome.

A .desktop launcher does this for you. When you click, it runs the command - so you don't have to interact with the terminal at all.

This is a basic .desktop file. The # signs are comments that I've added.

[Desktop Entry]    # Tell the computer what file this is (a launcher)   Encoding=UTF-8   Version=1.0   Type=Application  # Specifies what to do when clicked (there is also Link and Directory).   Terminal=false    # Whether to open a terminal and run the command, or just run without   Exec=firefox      # The command to run   Name=Firefox      # A name to display   Icon=/usr/share/icons/firefox.png  # Location of the icon  

These files are clearly important - and you can create them yourself to run custom commands.

You can put one of these files (from /usr/share/applications) onto the "Desktop" and then use that to launch the program. It sounds like what you did was the following:

  1. There is already a .desktop file, unrelated to the following download.
  2. You download a file - and then list the files and see something like this:

    firefox.desktop  trivial.jpg  My Document.odt  

    That .desktop file is unrelated to the download.

  3. Moving the .jpg understandably does nothing - the files are unrelated. If you post a screenshot of your Desktop and also the output of the command ls Desktop, we can have a look and compare the two.

    Note that the name of the .desktop file when you look with the terminal can be completely different from the displayed name of the .desktop launcher. For example, Google Chrome extensions will show as their name, for example "Chrome Remote Desktop", but the file name will be gbchcmhmhahfdphkhkmpfmihenigjmpp.desktop. This could be happening here - a weird saved name that doesn't seem to link to the launcher you would recognise.


Solution:2

.desktop files have two functions:

  1. They inform the desktop environment how the file is to be handled by the desktop environment with regard to menu placement, display, environmental variables, and similar. They are located in /usr/share/applications/.

  2. They provide direct shortcuts on the desktop.

Hope this helped you out :)


Solution:3

The main function is the direct shortcut

So if you want to have an application both in the menu and on your desktop, you’ll need to put the .desktop file

As @blade19899 commented .desktop files are Progam Launchers.

For location of .desktop files refer here

refer here


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »