This simple tutorial shows how to edit .desktop files, the config files for your apps shown in start menu (app launcher), in Linux via single command.
In most Linux, the app icons (and their names) you see in dock & launcher are handled by .desktop files. If need, user can edit them by using either text editor or even third-party apps.
For software developing, scripting, or editing multiple .desktop files at the same time, there’s a command line tool that can help!
The .desktop files are usually stored in following locations:
By editing a .desktop file that is associated with your app can do following things:
If you don’t know where is the .desktop file, then try following steps to find it out.
First, open terminal (Ctrl+Alt+T) and run command to install plocate (or mlocate for old Ubuntu):
sudo apt install plocate
Then, update the database by running command:
sudo updatedb
Finally, try searching the desktop file for your apps (Firefox for example):
locate "*firefox*desktop"
In last command replace firefox with the keyword for yours (case sensitive). And, copy the path-to-file for the one in the location mentioned above.
As far as I know, Debian, Ubuntu, Fedora, Manjaro, and their based systems have desktop-file-edit tool out-of-the-box for edit .desktop entries.
Option 1: To change app name, use command:
desktop-file-edit --set-name=NEW_NAME /path/to/file.desktop
In command, sudo is required for .desktop file in system directories.
For example, change the pre-installed Firefox (Snap version) in Ubuntu to “My Web Browser”:
sudo desktop-file-edit --set-name="My Web Browser" /var/lib/snapd/desktop/applications/firefox_firefox.desktop
Option 2: To change app icon, use command:
desktop-file-edit --set-icon=/path/to/icon /path/to/file.desktop
For icon file under /usr/share/icons, or .local/share/icons, just replace /path/to/icon-file with file-name without extension (e.g., .png, .svg).
For example, change the icon for my Firefox browser:
sudo desktop-file-edit --set-icon='/home/ji/Pictures/icons/myfirefoxicon.png' /var/lib/snapd/desktop/applications/firefox_firefox.desktop
Option 3: To add/remove category or mime type, use command:
desktop-file-edit --add-category=VALUE_HERE /path/to/file.desktop
Replace --add-category with one of the options below depends on which action you want to do:
--remove-category--add-mime-type--remove-mime-typeSee list of well known categories.. And, right-click on a file and go to its ‘Properties’ to check “Type”.
Option 4: To add/edit other keys.
Use “–set-key=KEY_NAME –set-value=KEY_VALUE” option. You can add more than one pair of the options in single command.
For example, hide Firefox from app launcher by setting “NoDisplay=true“. It will add the key ‘NoDisplay’, if not exist.
sudo desktop-file-edit --set-key=NoDisplay --set-value=true /var/lib/snapd/desktop/applications/firefox_firefox.desktop
Option 5: To remove a key, use “–remove-key=KEY_NAME” option.
For example, un-hide Firefox by deleting “NoDisplay=true” from the .desktop file:
sudo desktop-file-edit --remove-key=NoDisplay /var/lib/snapd/desktop/applications/firefox_firefox.desktop
Option 6: Edit multiple desktop files
You can edit more than one files using for loop.
For example, hide all the Waydroid Android app icons associated with the .desktop files under .local/share/applications directory.
for file in $Home/.local/share/applications/waydroid.*.desktop; do desktop-file-edit --set-key=NoDisplay --set-value=true $file; done
In addition, the desktop-file-edit command will automatically validate the .desktop file after done editing it. It will output errors if validation not passed. For more, see its man page.
The post Single Command to Edit .desktop file in Ubuntu & other Linux appeared first on Osgrove.
Previously I have written about how useful public cloud storage can be when starting a…
This is Part 2 of the "Karafka to Async Journey" series. Part 1 covered WaterDrop's…
For many software teams, documentation is written after features are built and design decisions have…
With the release of the FIPS 140-3 certified cryptographic modules for Ubuntu 22.04 LTS, Canonical…
Open source libraries are repositories of code that developers can use and, depending on the…
Last year, we had the opportunity to speak at Regent’s UX Conference (Regent’s University London’s…