Remove residual config files in Ubuntu – A one liner

I have spent literally hours over the last year or two searching for an elegant way to remove configuration files left over from package installs, in a command line environment, with Ubuntu.

Googling would provide a frustrating list of solutions that would either involve installing extra packages, using a complicated command line, or script, solutions that I would never be happy with and would “redo” the search again, each time I wanted to perform the same task, in the hope of finding something better.

In the end Aptitude and Xargs were my friends. Without further ado ….

aptitude -F %p search '~c' | xargs dpkg -P

Please note this command is meant for server/cli environments only. Desktop users should use Synaptics and the “Not Installed (residual config)” status. Nanny out.

21 thoughts on “Remove residual config files in Ubuntu – A one liner”

  1. 1. The “-F %p” customises the output of the aptitude command to remove the first column so we only get package names in the output. This makes the output suitable for passing on to dpkg.

    2. According to http://ubuntu-virginia.ubuntuforums.org/showthread.php?p=7897462 the ā€˜~cā€™ displays packages that are uninstalled and still have configuration files lying around.

    3. xargs takes the output of aptitude and passes it to dpkg.

    4. The “-P” stands for purge and “purges” the packages provided by xargs removing any config files left behind.

    Is it dangerous? The 64k question. Well I suppose if you have some uninstalled app that you still want to keep the config for in case you reinstall and don’t want to setup the config again then yes, but otherwise no.

  2. Well I’m not exactly familiar with bzr but assuming it is a version control system and that it has nothing to do with the apt cache then yes, also assuming that none of the bzr files have config files in the same place apt is expecting.

  3. Gosh, what a rush, I deleted about 1.5gb of fluff out of my system, and the system came back up. Just a complaint about my gdm settings but nothing serious. Wooosh.

  4. Maybe I shouldn’t have done a sudo -i, Rebooted this is the gdm error I get:

    Could not update ICEauthority file /.ICEauthority
    configuration server. (/usr/lib/libgconf2-4/gconf-sanity-check-2 exited with status 256

    I googled around and it has something to do with ownership and permissions.

  5. Either chmod 777 just to see if it helps or rename the file.

    I’ve had errors like that before with Gentoo but I can’t remember what I did to sort it out beyond that.

    That was xauthority though I think.

  6. Doesn’t seem to affect anything that much, but I guess one needs a sanity check before running this commmand. :)

    I see its failing to update /var/lib/gdm/.ICEauthority which doesn’t exist.

    I only have an .ICEauthority in my home folder, so I suspect there is something wrong with the configuration of the
    configuration server. (/usr/lib/libgconf2-4/gconf-sanity-check-2 which exits with status 256)

    Changing ownership and permissions of my home folder hasn’t worked.

    Changing permissions of my tmp folder hasn’t worked.

    Need to reconfigure something. An interesting crossword puzzle.

  7. -rw-r–r– 1 afrodeity afrodeity 209184 2010-07-15 15:29 .ICEauthority

    chmod 644 and chown to my user doesn’t seem to work.

    I’ve tried chmod my home directory to 775 and root, doesn’t work either.

    Sigh.

  8. My /var/lib/gdm looks like this:-

    drwxr-x— 11 gdm gdm 4.0K 2010-07-15 13:17 gdm

    My /var/lib/gdm/.ICEauthority looks like this:-

    -rw——- 1 gdm gdm 82K 2010-07-15 13:17 .ICEauthority

    Perhaps you could check the permissions of /var/lib/gdm are the same and log in again.

    Failing that touch /var/lib/gdm/.ICEauthority and match the permissions for that.

  9. Thanks John, but solved it like this:

    sudo chmod 755 /etc/gconf*

    then sudo apt-get install –reinstall gdm

    (I reinstalled gdm just to be safe. I see now there is a gdm folder where it is supposed to be with nothing in it, so I guess I could have recreated the folder manually)

    Problem was probably due to a bum record somewhere caused by an upgrade either/or running sudo -i.

    Nice one liner all the same, but you should probably edit the page for a sanity check with sudo first. Been destroying Linux since 2007. BTW we share the same last names :)

  10. Having the same last name is nice, although Lewis would be one of the more common ones so the odds are it would happen sooner or later!

    I doubt very much that running sudo -i would delete the entire /var/lib/gdm directory, that would be a bug and a half!

    More likely that you have a hard disk problem or deleted by accident (I mean you did delete 1.5G of stuff).

    On the sanity check and sudo thing I would disagree. It is already pretty easy to remove leftover config files running the GUI with Synaptics and that is how I would recommend any desktop user do it. If I had realised earlier on you were running a GUI I would’ve said that.

    The command is really meant for server maintenance. Generally speaking people don’t bother running non root in server environments since sys admins like myself won’t be logged in unless we are doing stuff that requires elevated privileges. Anyone maintaining a server should know their beans enough to be sure of what they’re doing or suffer the consequences!

    I will add a note that it is meant for server/cli environments only.

    Cheers,

    John.

  11. My Ubuntu desktop is really just a GUI banged on to bits of the server, the machine has Apache and a whole bunch of things which tend to grow and grow and you know the problem — 100gb+ software stack. Interesting ride nevertheless. Perhaps there’s a better way to accomplish all of this in a GUI environment? Thanks for pointing us in an interesting direction.

  12. Yeah as I said the best way in the GUI is to go into Synaptics and click on “not installed (residual config)” (in status). You can then select all the packages and choose “completely remove”.

    Though I suppose the one liner would be quicker than that.

    1. Well. I’ve just tried it on my laptop, which has the latest release of Ubuntu and it worked. Did you copy and paste the command or try to type it in?

Leave a Reply