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.

  • 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. – Faheem Mitha Mar 28 '12 at 5:20
  • @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 Mar 28 '12 at 18:19

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.

  • Sorry, it's not working line 1> # sudo aptitude purge '-c' line 2> aptitude: invalid option -- 'c' – Alexandre Martins Mar 27 '12 at 15:10
  • 4
    @AlexandreMartins The first character in the quotes is a tilde, not a hyphen. – Chris Down Mar 27 '12 at 15:11
  • aptitude purge ~c works as well – Ortomala Lokni Feb 21 '15 at 14:11
  • @OrtomalaLokni Not reliably. ~[user] is a valid POSIX tilde expansion. – Chris Down Feb 21 '15 at 17:32
  • @Chris Down Ok, in the case you have a user named c – Ortomala Lokni Feb 21 '15 at 17:38

For those who don't want to install aptitude:

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

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)
  • 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? – Alexandre Martins Mar 28 '12 at 17:51
  • 1
    @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. – Faheem Mitha Mar 28 '12 at 21:33
aptitude --clean-on-startup

That should clear the package cache.

  • 3
    Following the manuale page: "Cleans the package cache when the program starts". This is not what the OP asked. – enzotib Mar 27 '12 at 16:39

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.