0

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.

Ulf Klose
  • 387
  • 1
  • 5
  • 18

2 Answers2

2

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.)

andol
  • 6,848
  • 28
  • 43
  • 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
2

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.

Shadur
  • 1,297
  • 1
  • 10
  • 20
  • 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