29 April 2014

Purge deinstalled packages from apt database

My understatement of the day: "I've had a bit of a hiatus from blogging!"

Nothing fancy today as I haven't time and it is better to restart with something small, tweet-long, than not at all.

On a Linux distribution which uses apt for package management you may, through the years, get plenty of packages which are still in the database as deinstalled. This means that the program or library binaries are long gone but what remains is their configuration files. This usually happend when you use remove or autoremove commands without the --purge argument.

You can consider this one-liner as a bit of good housekeeping.

 dpkg --get-selections|grep deinstall| xargs | sed s/\ deinstall//g |xargs sudo apt-get purge
Run this command as root or, if your user a sudoer, use the sudo su hack:
sudo su -c "dpkg --get-selections|grep deinstall| xargs | sed s/\ deinstall//g |xargs sudo apt-get purge"
An explanation:
Using dpkg list all selected packages, with grep choose those which are deinstalled. With xargs linearise the lines into a single line, delete all occurrences of the word deinstall with sed and then use xargs to supply the list to apt's purge command.

No comments:

Post a Comment

Yin & Yang!