Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I want do is to purge (via aptitude purge) every package installed with a given string in its name.

E.g. apache2. I've got several packages with the string apache2 in their name installed on a system. Now I want to aptitude purge apache2 (like apache2, apache2.2-bin, libapache2-mod-ruby, etc.). But I do not find a way to do this.

Thanks for your answers in advance.

share|improve this question
up vote 2 down vote accepted

A quick troll through the Aptitude Reference Manual on patterns I found this entry.

Working from that, aptitude purge ?name('apache2') will do what you want, but if you're wise you'll run it with -s the first time so you can see what all it'll remove before committing to the task.

share|improve this answer
Thanks, that's what I was looking for. – Ulf Klose Oct 31 '11 at 12:30
Meanwhile I had the opportunity to try this. Unfortunately, it doesn't work :(. -bash: Syntaxfehler beim unerwarteten Wort (' (Syntax error on unexpected word (') – Ulf Klose Nov 10 '11 at 13:34
You may need to escape the ()s from your shell. – Shadur Nov 10 '11 at 14:34
This works brilliantly and as mentioned by @Shadur it has to be escaped as sudo aptitude purge ?name\('apache2'\) – kontinuity Dec 12 '12 at 10:21

I would parse the output of dpkg --get-selections, doing something along the following.

$ dpkg --get-selections | cut -f 1 | grep apache | sudo xargs aptitude purge -y

(For better understanding, feel free to try the pipe out one step at a time.)

share|improve this answer
That was what I feared first, that I had to use the xargs command. But I hoped that there would be a built-in solution as Shadur pointed out. Thanks for your answer. – Ulf Klose Oct 31 '11 at 12:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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