In Debian based systems, how do we purge configuration files of packages that have already been uninstalled?

5,592

Solution 1

The following should do what you want:

aptitude purge \~c

This purges all packages with the c (package removed, configuration files still present) state flag. Flag documentation is here.

Solution 2

For those who don't want to install aptitude:

sudo dpkg -P $(dpkg -l | awk '/^rc/ { print($2) }')

Solution 3

The --purge flag removes configuration files for packages that are no longer installed. I don't recommend blindly removing configuration files for all uninstalled packages. You might want to keep some of them. For an individual package, dpkg -P will work (-P stands for --purge). Here alacarte only has its configuration files installed, hence the rc flags. E.g.

orwell:/home/faheem# dpkg -l alacarte
[...]
rc  alacarte                           0.11.5-1                           easy GNOME menu editing tool
orwell:/home/faheem# dpkg -P alacarte
(Reading database ... 345418 files and directories currently installed.)
Removing alacarte ...
Purging configuration files for alacarte ...
orwell:/home/faheem# dpkg -l alacarte
[...]
un  alacarte                           <none>                             (no description available)
Share:
5,592

Related videos on Youtube

Alexandre Martins
Author by

Alexandre Martins

Updated on September 18, 2022

Comments

  • Alexandre Martins
    Alexandre Martins over 1 year

    To be more specific, I would like to do the equivalent of adding the --purge flag to the following command

    sudo apt-get autoremove --purge [package name]
    

    to packages that are no longer on the system.

    Preferably, I would like to know how to do it to specific packages and to every uninstalled package in the system.

    • Alen Milakovic
      Alen Milakovic about 12 years
      The question is not clearly worded. I assume you mean - "how does one remove configuration files from packages that have been removed from the system, but still have configuration files installed". Bringing in autoremove is just confusing, imo.
    • Alexandre Martins
      Alexandre Martins about 12 years
      @FaheemMitha Changed the title according to your suggestions. But I think the autoremove only would make things confusing if I didn't write anything else. But the sentence "I would like to do the equivalent of adding the --purge flag to the following command" makes things clear.
  • Alexandre Martins
    Alexandre Martins about 12 years
    Sorry, it's not working line 1> # sudo aptitude purge '-c' line 2> aptitude: invalid option -- 'c'
  • clerksx
    clerksx about 12 years
    @AlexandreMartins The first character in the quotes is a tilde, not a hyphen.
  • enzotib
    enzotib about 12 years
    Following the manuale page: "Cleans the package cache when the program starts". This is not what the OP asked.
  • Alexandre Martins
    Alexandre Martins about 12 years
    Usually, I keep the important configurations in my own home folder. This means the --purge flag does not do anything problematic to me. And it actually helps me not having any problems later on. Is there any good reason you say I shouldn't use --purge that I'm missing?
  • Alen Milakovic
    Alen Milakovic about 12 years
    @AlexandreMartins: If you are sure you don't have any configuration in any of the system config files, that is fine, I guess. That is definitely not the case for me though.
  • clerksx
    clerksx over 9 years
    @OrtomalaLokni Not reliably. ~[user] is a valid POSIX tilde expansion.
  • Ortomala Lokni
    Ortomala Lokni over 9 years
    @Chris Down Ok, in the case you have a user named c