{"id":44920,"date":"2023-12-15T15:19:11","date_gmt":"2023-12-15T15:19:11","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=44920"},"modified":"2023-12-15T15:19:11","modified_gmt":"2023-12-15T15:19:11","slug":"command-edit-desktop-file-linux","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2023\/12\/command-edit-desktop-file-linux\/","title":{"rendered":"Single Command to Edit .desktop file in Ubuntu &#038; other Linux"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/x-exe-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-44921\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/x-exe-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/x-exe-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/x-exe-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/x-exe-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/x-exe-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/x-exe-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>This simple tutorial shows how to edit <code>.desktop<\/code> files, the config files for your apps shown in start menu (app launcher), in Linux via single command.<\/p>\n<p>In most Linux, the app icons (and their names) you see in dock &amp; launcher are handled by <code>.desktop<\/code> files. If need, user can edit them by using either text editor or even third-party apps.<\/p>\n<p>For software developing, scripting, or editing multiple <code>.desktop<\/code> files at the same time, there&#8217;s a command line tool that can help!<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/startmenu-entries.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-44922\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/startmenu-entries-600x406.webp\" alt=\"\" width=\"600\" height=\"406\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/startmenu-entries-600x406.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/startmenu-entries-300x203.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/startmenu-entries-768x520.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/startmenu-entries.webp 956w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>What you can do by editing .desktop file for your app:<\/h3>\n<p>The <code>.desktop<\/code> files are usually stored in following locations:<\/p>\n<ul>\n<li><u>\/usr\/share\/applications<\/u> &#8211; for system wide.<\/li>\n<li><u>$HOME\/.local\/share\/applications<\/u> &#8211; for current user only.<\/li>\n<li><u>\/var\/lib\/flatpak\/exports\/share\/applications<\/u> &#8211; for Flatpak apps (system wide).<\/li>\n<li><u>$HOME\/.local\/share\/flatpak\/exports\/share\/applications<\/u> &#8211; for Flatpak apps (current user).<\/li>\n<li><u>\/var\/lib\/snapd\/desktop\/applications\/<\/u> &#8211; for Snap apps.<\/li>\n<\/ul>\n<p>By editing a .desktop file that is associated with your app can do following things:<\/p>\n<ul>\n<li><b>Change app icon<\/b><\/li>\n<li><b>Change the app name<\/b> in start menu.<\/li>\n<li><b>Hide app<\/b><\/li>\n<li>Group app icon in different categories.<\/li>\n<li>Associate with different file types.<\/li>\n<li>And more.<\/li>\n<\/ul>\n<h3>Find out the .desktop file for your app<\/h3>\n<p>If you don&#8217;t know where is the .desktop file, then try following steps to find it out.<\/p>\n<p>First, open terminal (Ctrl+Alt+T) and run command to install <code>plocate<\/code> (or mlocate for old Ubuntu):<\/p>\n<pre>sudo apt install plocate<\/pre>\n<p>Then, update the database by running command:<\/p>\n<pre>sudo updatedb<\/pre>\n<p>Finally, try searching the desktop file for your apps (<i>Firefox for example<\/i>):<\/p>\n<pre>locate \"*firefox*desktop\"<\/pre>\n<p><i>In last command replace <code>firefox<\/code> with the keyword for yours (case sensitive). And, copy the path-to-file for the one in the location mentioned above.<\/i><\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/plocate-firefox.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-44923\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/plocate-firefox-600x398.webp\" alt=\"\" width=\"600\" height=\"398\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/plocate-firefox-600x398.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/plocate-firefox-300x199.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/plocate-firefox-768x509.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/plocate-firefox.webp 804w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>Single command to edit the .desktop file<\/h3>\n<p>As far as I know, Debian, Ubuntu, Fedora, Manjaro, and their based systems have <code>desktop-file-edit<\/code> tool out-of-the-box for edit .desktop entries.<\/p>\n<p><b>Option 1: To change app name<\/b>, use command:<\/p>\n<pre>desktop-file-edit --set-name=NEW_NAME \/path\/to\/file.desktop<\/pre>\n<p>In command, <code>sudo<\/code> is required for .desktop file in system directories.<\/p>\n<p>For example, change the pre-installed Firefox (Snap version) in Ubuntu to &#8220;My Web Browser&#8221;:<\/p>\n<pre>sudo desktop-file-edit --set-name=\"My Web Browser\" \/var\/lib\/snapd\/desktop\/applications\/firefox_firefox.desktop\r\n<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-name.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-44924\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-name-600x382.webp\" alt=\"\" width=\"600\" height=\"382\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-name-600x382.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-name-300x191.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-name-768x489.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-name.webp 979w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><b>Option 2: To change app icon<\/b>, use command:<\/p>\n<pre>desktop-file-edit --set-icon=\/path\/to\/icon \/path\/to\/file.desktop<\/pre>\n<p><i>For icon file under \/usr\/share\/icons, or .local\/share\/icons, just replace <code>\/path\/to\/icon-file<\/code> with file-name without extension (e.g., .png, .svg).<\/i><\/p>\n<p>For example, change the icon for my Firefox browser:<\/p>\n<pre>sudo desktop-file-edit --set-icon='\/home\/ji\/Pictures\/icons\/myfirefoxicon.png' \/var\/lib\/snapd\/desktop\/applications\/firefox_firefox.desktop<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-44925\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-icon-600x343.webp\" alt=\"\" width=\"600\" height=\"343\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-icon-600x343.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-icon-300x172.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-icon-768x439.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/12\/change-firefox-icon.webp 1233w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><b>Option 3: To add\/remove category or mime type<\/b>, use command:<\/p>\n<pre>desktop-file-edit --add-category=VALUE_HERE \/path\/to\/file.desktop<\/pre>\n<p><i>Replace <code>--add-category<\/code> with one of the options below depends on which action you want to do:<\/i><\/p>\n<ul>\n<li><code>--remove-category<\/code><\/li>\n<li><code>--add-mime-type<\/code><\/li>\n<li><code>--remove-mime-type<\/code><\/li>\n<\/ul>\n<p>See <a href=\"https:\/\/specifications.freedesktop.org\/menu-spec\/latest\/apa.html\" target=\"_blank\" rel=\"noopener\">list of well known categories<\/a>.. And, right-click on a file and go to its &#8216;Properties&#8217; to check &#8220;Type&#8221;.<\/p>\n<p><b>Option 4: To add\/edit other keys<\/b>.<\/p>\n<p>Use &#8220;&#8211;set-key=KEY_NAME &#8211;set-value=KEY_VALUE&#8221; option. You can add more than one pair of the options in single command.<\/p>\n<p>For example, hide Firefox from app launcher by setting &#8220;<i>NoDisplay=true<\/i>&#8220;. It will add the key &#8216;NoDisplay&#8217;, if not exist.<\/p>\n<pre>sudo desktop-file-edit --set-key=NoDisplay --set-value=true \/var\/lib\/snapd\/desktop\/applications\/firefox_firefox.desktop<\/pre>\n<p><b>Option 5: To remove a key<\/b>, use &#8220;&#8211;remove-key=KEY_NAME&#8221; option.<\/p>\n<p>For example, un-hide Firefox by deleting &#8220;<i>NoDisplay=true<\/i>&#8221; from the .desktop file:<\/p>\n<pre>sudo desktop-file-edit --remove-key=NoDisplay \/var\/lib\/snapd\/desktop\/applications\/firefox_firefox.desktop<\/pre>\n<p><b>Option 6: Edit multiple desktop files<\/b><\/p>\n<p>You can edit more than one files using for loop.<\/p>\n<p>For example, hide all the Waydroid Android app icons associated with the <code>.desktop<\/code> files under .local\/share\/applications directory.<\/p>\n<pre>for file in $Home\/.local\/share\/applications\/waydroid.*.desktop; do desktop-file-edit --set-key=NoDisplay --set-value=true $file; done<\/pre>\n<p><b>In addition,<\/b> the <code>desktop-file-edit<\/code> command will automatically <b>validate<\/b> the .desktop file after <b>done<\/b> editing it. It will output errors if validation not passed. For more, see its man page.<\/p>","protected":false},"excerpt":{"rendered":"<p>&nbsp; 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 &amp; launcher are handled by .desktop files. If need, user can edit them by using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":44921,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[890],"class_list":["post-44920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-app-launcher"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/44920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=44920"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/44920\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/44921"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=44920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=44920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=44920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}