2

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?

  • 3
    .desktop files are Progam Launchers – blade19899 Oct 19 '15 at 9:22
  • Burak, I'd be interested to see the output of ls Desktop and if possible a desktop screenshot! It would be nice to see if there is an issue and something odd downloaded. – Tim Oct 19 '15 at 13:31
  • What probably happened is actually that you created a .desktop format shortcut on your Desktop, to that picture's original URL online. – underscore_d Oct 19 '15 at 16:32
  • @Tim Here, I took a screenshot of what you might probably wanted(i58.tinypic.com/epg66x.png). In the original form, instead of rabbit.jpg, its format was, <some-gibberish-words>.jpg.desktop, however, before asking the question I removed it unconsciously because I didn't know what was that :) – Burak. Oct 19 '15 at 16:48
9

.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.

My pronouns are He / Him

| improve this answer | |
  • 1
    very nice =)....@Tim – Ravan Oct 19 '15 at 9:48
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 :)

| improve this answer | |
0

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

| improve this answer | |
0

Desktop files are a FreeDesktop standard. There are currently three types: Application, Link, and Directory.

This specification defines 3 types of desktop entries: Application (type 1), Link (type 2) and Directory (type 3). To allow the addition of new types in the future, implementations should ignore desktop entries with an unknown type.

https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

Application-type desktop files

This is an example Application-type desktop file:

[Desktop Entry]
Name=Calculator
Comment=Perform arithmetic, scientific or financial calculations
Keywords=calculation;arithmetic;scientific;financial;
Exec=gnome-calculator
Icon=gnome-calculator
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Utility;Calculator;

When you do a search for "calculator" in a menu, the name matches, so it shows this result and icon. When you click on it, it runs the gnome-calculator application. There are more examples of this kind of desktop file in /usr/share/applications/.

Directory-type desktop files

This is an example Directory-type desktop file from /usr/share/desktop-directories/Utility.directory:

[Desktop Entry]
Name=Accessories
Comment=Desktop accessories
Icon=applications-utilities
Type=Directory
X-Ubuntu-Gettext-Domain=gnome-menus-3.0

This means that there will be an "Accessories" entry in a hierarchical menu, and because e.g. the calculator example above has Utility in the Categories field, the calculator will show up as a sub-entry of "Accessories". The FreeDesktop spec also mentions that these can include localized names in other languages:

Directory entry

A directory entry is a file with a name ending in the ".directory" extension which conforms to the desktop entry specification with Type=Directory. It provides a localized name and an icon for a submenu. Directory entries are also known as ".directory files."

https://specifications.freedesktop.org/menu-spec/latest/go01.html

for example:

[Desktop Entry]
Type=Directory
Verson=1.0
Name=Electronics
Name[ca]=Electrònica
Name[cs]=Elektronika
Name[de]=Elektronik
Name[el]=Ηλεκτρονικά
Name[es]=Electrónica
Name[eu]=Elektronika
Name[fi]=Elektroniikka
Name[fr]=Electronique
Name[hu]=Elektronika
Name[it]=Elettronica
Name[ja]=電子工学
Name[nb_NO]=Elektronikk
Name[nl]=Electro
Name[pl]=Elektronika
Name[pt_BR]=Eletrônica
Name[pt_PT]=Eletrónica
Name[ro]=Electronică
Name[ru]=Электроника
Name[sv]=Elektronik
Name[tr]=Elektronik
Name[zh_CN]=电子
Name[zh_TW]=電子學
Icon=applications-electronics

(Hierarchical menus for listing applications aren't supported by the GNOME 3 desktop anymore, but other desktops like XFCE4, KDE Plasma, and LXDE still have them.)

There are more examples here:

/usr/share/desktop-directories/

Link-type desktop files

This is an example Link-type desktop file:

[Desktop Entry]
Type=Link
Name=Examples
Comment=Example content for Ubuntu
URL=file:///usr/share/example-content/
Icon=folder

This is a simplified version of the desktop file provided from the example-content package. When you click this in a file manager, it navigates to this directory:

/usr/share/example-content/

In this case the URL field is a file:// URL, but it could be any other kind of URL, such as an https:// URL:

[Desktop Entry]
Name=AskUbuntu.com
Type=Link
URL=https://askubuntu.com/
Icon=text-html

or a mailto: URL:

[Desktop Entry]
Name=Email someone
Type=Link
URL=mailto:example@ubuntu.com

or an smb:// URL:

[Desktop Entry]
Name=My Samba share
Type=Link
URL=smb://username@server/my-samba-share

or a special file-manager URL like this:

[Desktop Entry]
Name=Trash
Type=Link
Icon=user-trash-full
EmptyIcon=user-trash
URL=trash:///

or this:

[Desktop Entry]
Name=Recent documents
Type=Link
Icon=document-open-recent
URL=recent:///

Related:

| 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.