Purge configuration from removed packages

apt-get remove allows to uninstall software packages for Debian and Ubuntu. Some software may still have configuration stored on your system. If you don’t have used apt-get purge, the config files still resides on your Debian installation. This post illustrates how to remove these packages.

Show all removed debian packages with configuration files:

dpkg --list | grep ^rc

Example output

tan@cinhtau:~$ dpkg --list | grep ^rc
rc  libcouchdb-glib-1.0-2                      0.6.3-0ubuntu2                                  GLib-based API for CouchDB
rc  libdesktopcouch-glib-1.0-2                 0.6.3-0ubuntu2                                  Glib-based API for Desktopcouch
rc  libgtkhtml-editor0                         1:3.29.6.is.3.28.3-0ubuntu2                     HTML rendering/editing library - editor widget
rc  libpst4                                    0.6.41-0ubuntu4                                 Shared library needed by the readpst utilities, and

Use awk to get the package name and use it as input for the purge command.

sudo dpkg --purge $(dpkg --list | grep ^rc | awk '{ print $2; }')

Another way to achieve the same goal. xargs has the advantage, that it can batch up the arguments to allow one command to process lots of items.

dpkg --list | grep '^rc\b' | awk '{ print $2 }'\
 | xargs sudo dpkg -P