Debian – How to Reinstall Packages After File Corruption

debianpackage-management

After an unclean shutdown, fsck reported corruption in several parts of the filesystem, apparently affecting installed packages (luckily no user data was affected).

Is there an easy way how I can reinstall these packages from scratch, e.g. tell apt or dpkg to install the same package again, without changing its flags (especially preserving the auto-installed flag)?

I have a list of the affected files and, with some effort, could figure out which packages I would need to reinstall. Alternative is to reinstall everything installed on the system.

Best Answer

For each of your corrupted file, the package that installed your file can be obtained with:

dpkg -S /full/path/of/the/corrupted/file

You can then reinstall it with the command:

apt-get --reinstall install package

If all your corrupted files are in a single file list.txt, then you can obtain all the associated packages with:

dpkg -S $(cat list.txt) | cut -d: -f1 | sort -u

And of course install all those packages with that single command:

apt-get --reinstall install $(dpkg -S $(cat list.txt) | cut -d: -f1 | sort -u)
Related Question