brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: apt purge '~c' removes the config leftovers of packages you already removed

Apt
~/tips/tip-apt-purge-config-files

apt list '~c'

Cleans out packages that are gone but still left their configuration behind.

apt remove keeps a package’s config files, in case you install it again. Over the years these leftovers pile up, and dpkg -l marks them with rc.

See them first:

dpkg -l | grep '^rc'
apt list '~c'

Both show packages that are removed but still have config files. ~c is the short form of the apt pattern ?config-files, which matches exactly that state.

Then purge them all in one go:

sudo apt -s purge '~c'
sudo apt purge '~c'

Quote the pattern so your shell leaves the tilde alone. This is different from apt autoremove --purge, which deals with unused dependencies that are still installed. The ~c pattern only looks at packages that are already gone.

I like doing this before reinstalling a service from scratch, so the new install doesn’t pick up an old config I forgot about.

Purging deletes your changes to those files for good, and sometimes more: some packages remove their data folders on purge too, like a database package deleting its data directory. Read the list from the simulation and keep a copy of anything in /etc you might want later. There’s no undo apart from your backups.

Further reading: apt-patterns(7) manual page, apt(8) manual page

More Apt tips sudo apt-mark minimize-manual grep -E ' (install|upgrade|remove) ' /var/log/dpkg.log | tail -o Dpkg::Options::="–force-confold" upgrade sudo apt-get -d -y full-upgrade apt show nginx All Apt tips (42) All topics

Link