4

When we want to add a shortcut to menu. We can do that by creating filename.desktop and copy that file to /usr/share/applications. And there is another way to, that is doing desktop-file-install filename.desktop. What is difference between those two?

Until now, I still use copy method because if I want to remove it, i just delete it. And desktop-file-install seems like doesn't have desktop-file-uninstall.

Mas Bagol
  • 1,341

2 Answers2

7

To quote man desktop-file-install:

desktop-file-install will always try to validate the resulting desktop file. A failure to validate might lead to the abortion of the installation of the desktop files.

In contrast, cp will copy anything.

So there is no desktop-file-uninstall since there is no need to validate files you are deleting.

2

I know this is an old question, but the answer was either incomplete or has changed over time.

desktop-file-install causes a database update, and to be precise, it updates the cache by rebuild_cache().
More details can be found in the source, in the official repository "desktop-file-utils":
https://gitlab.freedesktop.org/xdg/desktop-file-utils/-/blob/master/src/install.c#L291

Just copying with cp does not cause the mime base to be updated, which is important - it does not update its cache.
This is important for file updating - you may notice that if you change the text of the *.desktop on path /usr/share/xfce4/helpers/ file itself, the changes will not be accepted immediately.

The install call will do:

  • First validation of the *.desktop file by desktop-file-validate
  • Further, if the file is valid, it will update the database by calling the update-desktop-database command
linxuil
  • 21