I accidentally deleted all .desktop
files from /usr/share/applications
directory.
Is there any way to restore/recover/regenerate it back for all the applications that I have currently installed in my Ubuntu 16.04 LTS laptop?
I accidentally deleted all .desktop
files from /usr/share/applications
directory.
Is there any way to restore/recover/regenerate it back for all the applications that I have currently installed in my Ubuntu 16.04 LTS laptop?
Since only files extracted from packages are supposed be stored in /usr
(but not /usr/local
) you can use the package manager to recover all those files:
dpkg-query -S [PATH]
lists all currently installed packages that (used to) have files in [PATH]
.
With a bit of mangling we can pass the package names to apt-get
to reinstall them:
xargs -r -d '\n' -a <(
dpkg-query -S /usr/share/applications/ <&- |
gawk -F '[,:][ \t]' '{ for (i=1; i<NF; i++) if (!a[$i]++) print $i; }'
) -- sudo apt-get install --reinstall --
If there are packages among them that weren't installed from a package repository but manually from a Deb package file, apt-get
will complain that it can't find those particular packages and you'll have to install them anew.