How to purge residual config packages on Debian and Ubuntu

The apt package management system often ends up uninstalling packages but leaving behind their configuration files. For many years it’s been easy to find them using the command dpkg -l | grep --perl-regexp '^rc', but it required fiddling around with shell commands to purge the packages (remove the leftover configuration files) because apt didn't support a way of filtering them by installation state. Since apt version 2.0 this is no longer the case, but I always forget the command and searching online usually turns up the old and overly complicated way of doing it.

To list packages that have been removed but still have configuration files left behind:

apt list '~c'

To remove the configuration files for packages that are no longer installed:

apt purge '~c'

Add new comment

CAPTCHA