![](/style/images/good.png)
![](/style/images/bad.png)
How to install and edit desktop files on Linux (Desktop entries)
source link: https://www.cyberciti.biz/howto/how-to-install-and-edit-desktop-files-on-linux-desktop-entries/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Linux comes with three commands for developers, sysadmins and users to set up a hierarchy of applications, typically displayed as a menu. In other words, these commands allow third-party software to add menu items that work for all desktops. In addition, it allows Linux system administrators to edit menus in a way that affects all desktops using the following commands to install and edit desktop files on Linux to make Desktop entries:
- desktop-file-edit command is a tool for editing desktop files.
- Use the desktop-file-install command to install .desktop files.
- Update database of desktop entries cache using the update-desktop-database command.
- Validate desktop entry files using desktop-file-validate command.
What is desktop entry?
Popular desktop environments like KDE and GNOME follow desktop entry standards. It defines config file syntax about a particular program launched and how it appears in menus. For example, say I compiled and installed an app called foo. Then I can define desktop entry about it.
Location of .desktop file
All such config files have a .desktop extension, and you can find them in the following location:
- The default Linux distro specific applications – /usr/share/applications/
- Third party specific applications – /usr/local/share/applications/
- User specific applications – ~/.local/share/applications/
Use the ls command to list those file:$ ls -l /usr/share/applications/
# Count ALL .desktop files using the wc command #
$ ls -l /usr/share/applications/ | wc -l
Sample .desktop file
Here is an example of .desktop file structure for “Startup Disk Creator” app displayed using the cat command or more command on my Ubuntu Linux desktop:$ cat /usr/share/applications/usb-creator-gtk.desktop
Sample outputs (I added comments for ease of understanding):
[Desktop Entry] ## The name of the application ## Name=Startup Disk Creator GenericName=Startup Disk Creator ## A comment which act as a tooltip ## Comment=Create a startup disk using a CD or disc image ## The executable of the application with optional args ## ## You can state full path too ## Exec=usb-creator-gtk ## State the name of the icon that will be used to display this entry ## Icon=usb-creator-gtk ## Is it a terminal app? For example htop will be set as Terminal=True ## ## Then default terminal app will be used to open the 'htop' ## Terminal=false ## The type as listed ## Type=Application ## States the categories in which this entry should be shown menu ## Categories=System;Settings;GTK;HardwareSettings; X-Ubuntu-Gettext-Domain=usbcreator
Creating desktop file on Linux
For demo purpose I am going to create a new file called gpass.desktop as follows in the current directory called “$HOME”/desktop-entries using a text editor. Here is my sample file displayed using the cat command:cat ~/desktop-entries/gpass.desktop
Sample outputs:
[Desktop Entry] # App name Name=gpass in LXD # Comment Comment=Old password manager # Is it terminal or GUI app? Terminal=false # Command to run Exec=/snap/bin/lxc exec gui-1804-gimp -- sudo --login --user vivek /usr/local/bin/gpass # Icon file Icon=/home/vivek/desktop-entries/gpass-icon.png # Categories Categories=Utility;Security; # The type as listed Type=Application
Using desktop-file-edit command
Instead of a text editor, one can use desktop-file-edit as follows to build entries. First, create an empty file named gimp-2.8.desktop using the touch command:touch gimp-2.8.desktop
Then, run desktop-file-edit:
desktop-file-edit \ --set-name="GIMP on LXD" \ --set-comment="GIMP 2.8 with custom plugins" \ --set-icon="/home/vivek/backups/desktop-entries/gimp.png" \ --add-category="Graphics;2DGraphics;RasterGraphics;GTK;" \ --set-key="Exec" --set-value="/snap/bin/lxc exec gui-1804-gimp -- sudo --login --user vivek /usr/bin/gimp-2.8 %U" \ --set-key="Type" --set-value="Application" \ gimp-2.8.desktop
desktop-file-edit example
Understanding desktop-file-edit options
Table 1: The desktop-file-edit program is a tool to edit a desktop file
Command option Description
--set-key=KEY Set the KEY key to the value passed to the next –set-value option. A matching –set-value option is mandatory.
--set-value=VALUE Set the key specified with the previous –set-key option to VALUE. A matching –set-key option is mandatory.
--set-key="Exec" --set-value="/snap/bin/lxc exec gui-1804-gimp -- sudo --login --user vivek /usr/bin/gimp-2.8 %U" Set an exec path
--set-key="Type" --set-value="Application" Set app type to “Application”
--set-name="GIMP on LXD" Set the tool tip
--set-comment="GIMP 2.8 with custom plugins" Set the comment
--set-icon="/home/vivek/backups/desktop-entries/gimp.png" Set the ICON path
--add-category="Graphics;2DGraphics;RasterGraphics;GTK;" Set the app category
How to install and edit desktop files on Linux (Desktop entries)
First, validate your desktop entries using the desktop-file-validate command. For example:desktop-file-validate ~/desktop-entries/gpass.desktop
Then install the file using the desktop-file-install command, run:desktop-file-install --dir=~/.local/share/applications ~/desktop-entries/gpass.desktop
Finally, update the database, run:update-desktop-database ~/.local/share/applications
To access the overview at any time, click the Activities button, or just move your mouse pointer to the top-left hot corner. You can also press the Super key on your keyboard and typegpass
Summing up
And that is how we set up desktop entries, and it will work with KDE, GNOME and other desktops as long as your environment is following XDG Desktop Entry specification. Try it out. Do check the following manual pages for more info using the man command:
man desktop-file-validate man desktop-file-install man update-desktop-database man desktop-file-edit
🥺 Was this helpful? Please add your comment below ↓
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
RSS feed ➔
Weekly email newsletter ➔
ADVERTISEMENT Category List of Unix and Linux commandsDownload managerswgetDriver ManagementLinux Nvidia driver • lsmodDocumentationhelp • mandb • man • pinfoDisk space analyzersdf • duf • ncdu • pydfFile Managementcat • cp • less • mkdir • more • treeFirewallAlpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04Linux Desktop appsGIMP • Skype • Spotify • VLC 3Modern utilitiesbat • exaNetwork UtilitiesNetHogs • dig • host • ip • nmap • pingOpenVPNCentOS 7 • CentOS 8 • Debian 10 • Debian 11 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04Power ManagementupowerPackage Managerapk • apt-get • apt • yumProcesses Managementbg • chroot • cron • disown • fg • glances • gtop • iotop • jobs • killall • kill • pidof • pstree • pwdx • time • vtopSearchingag • egrep • grep • whereis • whichShell builtinscompgen • echo • printfSystem Managementreboot • shutdownTerminal/sshttyText processingcut • revUser Environmentexit • whoUser Informationgroups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • wWireGuard VPNAlpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 • qrencode
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK