Ubuntu – Recreate the *.desktop files at /usr/share/applications/

desktoplauncherunityunity-dash

Is it possible to regenerate those files somehow for every app that should be in Dash (Ubuntu 16.04)? I got them all deleted with rm command. Don't ask, my stupidity (I was following suggestions here: Applications don't appear in the Dash (14.04) and my problem was actually because I simply disabled the applications plugin in Dash itself, but while getting those files back I managed to delete them along the way).
Launching an app through terminal works, and when secondary-clicked on the icon in Launcher it even gives an option to add to Dash, but that doesn't add the lists where with the secondary click you get options like "Launch in Private Mode" (firefox) or bookmarks for Nautilus (nautilus was actually re-added with a link to one of my folders, rather than the home folder). Reinstalling would probably solve it for each app, but that seems too nightmarish and besides I can't even find a list with all my gui apps that should be there (including the ones in System Settings and possibly somewhere else).
Is it possible to restore it somehow or would reinstalling the OS be a more sensible solution?

Best Answer

You can obtain a list of packages that think they own files in the directory using dpkg -S e.g.:

dpkg -S /usr/share/applications

Then re-install each one:

sudo apt install --reinstall <package>

There are ways to automate that by processing the dpkg output - but doing it by hand will be a reminder to be more careful.

Related Question