Remove all packages marked as “rc” on Debian / Ubuntu

debian linux remove packages marked rc

I often run into the problem of having to clean up on a system. Because we use Debian / Ubuntu-based systems in many places, we update these systems with the apt package manager. After a while, if I do autoremove, packages that are in the “rc” state will accumulate, i.e. the package manager has already removed them, but the configuration files are still there on the system. For kernel headers and kernel packages, especially for systems having smaller root and / or boot partitions, you can gain tens of megabytes of free space by clearing these residual packages up.

The remnant data can be completely purged from the affected systems by utilizing the following command:

~# dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge