Monday, July 23, 2012

Removing all residual config packages in Ubuntu

In Ubuntu/Debian based operating systems, when a program is uninstalled in Ubuntu Software Center or by using apt-get, the configuration files are not removed if you do not explicitly say so. Usually after several install/uninstalls, there will be a lot of left over configuration files that is never needed anymore.

To remove these configuration files, Synaptic Package Manager have a status filter "Not Installed (residual config)" that can let you easily find these packages. But if you do not have Synaptic installed, a good way to remove all these packages is by using the line below:
$ sudo apt-get remove --purge `dpkg -l | grep '^rc' | awk '{print $2}'`
This line of command is explained:

  • dpkg -l will list all packages installed in your system.
  • grep '^rc' will search for "rc" in the start of each line, which is the status printed out by dpkg meaning "residual config".
  • awk '{print $2}' will print out only the second column of the above output. The second column is the name of the packages that should be purged.
  • sudo apt-get remove --purge explicitly removes both the packages themselves and the residual configurations of the packages.