Weblog entry #4 for fsateler

Purging configuration files
Posted by fsateler on Sun 20 Nov 2005 at 02:34
Tags:
I have always wondered why the apt default remove action doesn't purge configuration files. Of course, one could use the --purge option (or command, whether you are using aptitude or other front end), but then any automatically removed package would still not be purged. And today I found out how to purge all those files easily:
dpkg --list | grep '^rc\b' | awk '{ print $2 }'\
| xargs sudo dpkg -P
The explanation: dpkg --list lists all the installed packages. Then we pipe it through grep to select only the lines that start with 'rc' (I guess for Remaining Configuration or somthing like that). Then awk will print the second word of each line (the package name), and finally xargs receives all those packages and passes them as the comand line to dpkg.

 

Comments on this Entry

Posted by emeitner (69.21.xx.xx) on Sun 20 Nov 2005 at 05:04
[ View emeitner's Scratchpad | View Weblogs ]
"rc" stands for "removed" and "config files".
I think the config line you are looking for is:
Apt::Get::Purge;

See the apt-get man page where it discusses the --purge option.

[ Parent | Reply to this comment ]

Posted by Anonymous (84.45.xx.xx) on Mon 21 Nov 2005 at 02:41
"I have always wondered why the apt default remove action doesn't purge configuration files"

Debian values user data.

More specifically it is useful to uninstall and reinstall without losing configuration information.

Note some applications may lose serious user data on a purge, check the options for Postgres installs for one

Now if you'd asked why it doesn't clean up /etc/init.d and friends when removing a package I'd have said you might have a point, although without the files the start-up scripts don't do much, but it does seem untidy.

[ Parent | Reply to this comment ]

Posted by fsateler (201.214.xx.xx) on Mon 21 Nov 2005 at 05:34
[ View Weblogs ]
Well, it is useful to uninstall and reinstall... although why do you usually reinstall software? I mostly reinstall software after purging every configuration file (or copying somewhere just in case), just to make sure it starts in a clean state. However for those specific cases where I don't want to purge files, I could choose not to purge the application via a command line option, and keep the default as purge.
--------
Felipe Sateler

[ Parent | Reply to this comment ]

Posted by simonw (84.45.xx.xx) on Wed 23 Nov 2005 at 18:26
[ View Weblogs ]
I usually reinstall software when I upgrade it.

I very rarely reinstall software because it is misconfigured, although later this week I have to figure out where CPAN perl lives, and downgrade one of our boxes from "CPAN" to "sarge" versions of key Perl code - hohum. Blimin mod_perl 1.999.21 to 1.999.22 upgrade.... Steve was right about packaging perl, but making packages of it all that is needed will take a long time, even with the tools available.

As discussed, you can make "apt" always purge.

Just don't expect smooth upgrades of operational systems. If a simple upgrade works, all is fine, if it fails and you need to then purge, and reinstall, all is fine, if you start by purging the customisation and then reinstall, and it doesn't work.... back to backups you go.

Whoever put "diff" for config files in the dpkg tools earns my undying thanks.

[ Parent | Reply to this comment ]

Posted by Anonymous (80.104.xx.xx) on Sun 24 Jun 2007 at 08:42
# aptitude search ~c
# aptitude purge ~c

[ Parent | Reply to this comment ]

Posted by Anonymous (200.169.xx.xx) on Sat 11 Aug 2007 at 03:07
What about deborphan?

deborphan --find-config | xargs dpkg --purge

[ Parent | Reply to this comment ]

Posted by Anonymous (62.41.xx.xx) on Wed 14 Nov 2007 at 14:38
Or ...

dpkg --purge `dpkg --get-selections | grep deinstall`

or

apt-get remove --purge package
or
in case of postfix exim change

apt-get install --purge postfix ( removes + purges exim and installs postfix )

or

dpkg --purge package remove the configuration files.

Greetz,

Louis

[ Parent | Reply to this comment ]

Posted by Anonymous (80.59.xx.xx) on Thu 20 May 2010 at 16:56
Still running ;) Thank you very much, 48 deinstalled pkgs purged = 38mb freed within 50 seconds, in P4 C.Flash 820Mb debian i686 server (Apache2 , Ftp, Telnet, MySql5 , php5 , Drupal6 - 7 , Cake, SMF1, PhpMyadmin2).

[ Parent | Reply to this comment ]