11 December 2009

Cleaning up old removed Debian packages

When using Debian there are two ways to remove packages:
The first: $ apt-get remove packagename
The second: $ dpkg --purge packagename
The former removes packages but leaves the configuration files. The latter purges the package as well as the configuration files. But what if you have been using apt-get remove or apt-get autoremove to get rid of packages and now you want to go back and remove all the configuration files for all those packages? Here are some very useful utilities that you can use to automate this process
dpkg --get-selections will give you a list of all installed packages followed by their installation status
grep deinstall will show the lines that are packages that were removed using remove instead of purge
cut -f 1 will grab just the column containing the package names excluding their status
xargs dpkg --purge will take the column of packages and run dpkg --purge on it
dpkg --get-selections | grep deinstall | cut -f 1 | xargs dpkg -P
Warning: Make sure to run the command without the last portion to see what will be removed. It can be very easy to accidentally remove packages by accident if you make a mistake.

No comments:

Post a Comment