1

There are a number of pkgs that weren't removed with "apt-get purge" and I would like to automate cleaning them up.

You can't apt-get purge apache2.2-common because the pkg is already removed.

You can still list the files that are in the pkg with dpkg -L apache2.2-common.

This means I could just remove the list of files in the pkg, but how would dpkg know this? How do I remove the config files left behind AND remove it from the following report?

Example output:

$ dpkg -l | grep ^rc
rc  apache2.2-common                  2.2.14-5ubuntu8.10                Apache HTTP Server common files
rc  libapache2-mod-php5filter         5.3.10-1ubuntu2ppa6~lucid         server-side, HTML-embedded scripting languag
rc  libapr1                           1.3.8-1ubuntu0.3                  The Apache Portable Runtime Library
rc  libaprutil1                       1.3.9+dfsg-3ubuntu0.10.04.1       The Apache Portable Runtime Utility Library
rc  libgd2-xpm                        2.0.36~rc1~dfsg-3.1ubuntu1        GD Graphics Library version 2
rc  libt1-5                           5.1.2-3ubuntu0.10.04.2            Type 1 font rasterizer library - runtime
rc  php5-gd                           5.3.10-1ubuntu2ppa6~lucid         GD module for php5
rc  ssl-cert                          1.0.23ubuntu2                     simple debconf wrapper for OpenSSL
  • I probably do /not/ want to remove ssl-cert. It is just an example. – Dan Garthwaite Apr 16 '14 at 16:06
2

Something like this will find the package names:

dpkg --list | grep ^rc | awk '{print $2}'

Or to remove the number of pipes you can use this:

dpkg --list | awk '/^rc/ {print $2}'

So the next step is to feed one of those lists into dpkg --purge. Using a subshell you can do that easily:

dpkg --purge $(dpkg --list | grep ^rc | awk '{print $2}')

Simple!

  • 1
    Ah, I tried various iterations of dpkg | awk | xargs apt-get purge which was failing because the pkg was not installed. I never tried dpkg | awk | xargs dpkg --purge. To be honest, I didn't know it had a purge option. Thank you! – Dan Garthwaite May 17 '14 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.