APT Tip: Purge Removed Packages

Many times I find the command-line utilities for package management faster and more convenient than GUI tools like Synaptic or Adept. Yet learning how to use them efficiently takes time. Here’s a trick you can use to purge packages that have already been removed with apt-get remove or aptitude remove. When a package is uninstalled, its configuration files are left on the system, in case you’ll want to install it again. Purging a package gets rid of these configuration files. This not only frees disk space, but also helps maintain the system clean. It’s easy to forget to add --purge to each apt-get remove command you run, but there’s an easy way to purge packages after you’ve removed them:

dpkg -l |awk ‘/^rc/ {print $2}’ |xargs sudo dpkg --purge

What this does is run a dpkg -l to list packages, select all lines that begin with “rc” (which means the package is removed, but its config files are still on the system), and pass them to dpkg --purge to get rid of them. Neat, huh?

NOTE: If you don’t use sudo, remove it from the command above and run the whole line as root.

5 Responses to “APT Tip: Purge Removed Packages”

  1. Purgar paquetes eliminados « Ubuntu Life Says:

    [...] by superpiwi in Tips, Linux, Ubuntu. trackback Un truco interesante que me encuentro en esta pagina y que aparte de hacernos ganar algo de espacio en disco, tambien ayuda a mantener el sistema mas [...]

  2. Rimuovere i file di configurazione di pacchetti rimossi « The Kiwi Project Says:

    [...] i file di configurazione di pacchetti rimossi 9 10 2008 Ho appena scoperto un piccolo trucchetto che permetti di rimuovere tutti i file di configurazione di pacchetti [...]

  3. Spinus Says:

    Nice tips!!

  4. Super Jamie Says:

    Thanks very much for this, extremely useful!

  5. Graham Freeman (gjmf) 's status on Thursday, 10-Sep-09 18:45:24 UTC - Identi.ca Says:

    [...] APT Tip: Purge Removed Packages « exit’s /dev/urandom blog a few seconds ago from Adium [...]

Leave a Reply