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.

13 Responses to APT Tip: Purge Removed Packages

  1. […] 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. […] 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. […] APT Tip: Purge Removed Packages « exit’s /dev/urandom blog a few seconds ago from Adium […]

  6. aaa says:

    thanks dude

  7. drm says:

    Another way of handling this is using just aptitude.

    aptitude purge $(aptitude search ~c -F %p)

    purge all packages with the ‘c’ flag (“the package was removed, but its configuration files are still present.” [1]) by printing only the package name

    [1] http://algebraicthunk.net/~dburrows/projects/aptitude/doc/en/ch02s02s02.html,

  8. Constantin says:

    Very cool! Didn’t know about that form of invoking aptitude.

  9. dmit10 says:

    Thank you! Very helpful.

  10. drm says:

    I found out later that it could be done even simpler:

    aptitude purge ~c

    This simply purges all packages with the c flag.

  11. […] purge を使わずに削除したパッケージは設定ファイルだけが残ってしまう。この設定ファイルのみを削除する方法もあるようだ。こちらで紹介されている。APT Tip: Purge Removed Packages « exit’s /dev/urandom blog こいつは便利! […]

  12. […] Original article here: https://ascending.wordpress.com/2007/04/10/apt-tip-purge-removed-packages/ […]

%d bloggers like this: