27

I want to uninstall libreoffice. This program consists of about three dozen modules. Ideally, they could be removed with:

aptitude remove libreoffice3.6* libreoffice-debian-menus libobasis3.6-*

but that fails with

Couldn't find any package whose name or description matched "libreoffice3.6*"

etc.

How do I delete a set of packages by pattern?

PS: I'm happy about answers with use dpkg or apt, too

  • Are you trying to know the answer about certain pattern or happy with the removal of LibreOffice components? – Anwar Apr 4 '13 at 7:39
  • 1
    possible duplicate of How to uninstall LibreOffice? The answer is probabaly: this only works for 3.6 and you are not using 3.6 :-) – Rinzwind Apr 4 '13 at 7:44
  • I'm using libreoffice as an example because it contains so many parts. But I had the same problem with the kernel (cleaning up old versions) – Aaron Digulla Apr 4 '13 at 12:12
28
  1. Use apt-get, not aptitude, and use regular expressions.

  2. In a regular expression, . mean any character, and * means zero or more times. So the expression libreoffice.* matches any package name containing the string libreoffice, followed by any number of characters.

  3. Surround the regular expression with single quotes to avoid the shell interpreting the asterisk. (If you had a file named libreoffice.example for example in your current directory, the shell would replace libreoffice.* with libreoffice.example, so you have to use single quotes to stop this behaviour.)

Result:

sudo apt-get remove 'libreoffice.*'
| improve this answer | |
  • Thanks, this works. Interestingly enough, it also works with the pattern libreoffice* (i.e. glob style patterns) which confuses me a bit because either of them shouldn't work :-) – Aaron Digulla Apr 4 '13 at 12:09
  • 3
    For those who want to test this, use the option --dry-run to see what would be deleted without any changes to the system. – Aaron Digulla Apr 4 '13 at 12:11
  • @AaronDigulla Didn't know about --dry-run yet. That will come in handy! Thanks! – Glutanimate Apr 4 '13 at 14:33
  • apt-get is pretty bad handling regular expressions too, compare both solutions in this answer. – Braiam Mar 31 '14 at 2:42
  • To make it clear, apt uses POSIX regular expressions. From man apt-get (Debian Jessie): "If no package matches the given expression and the expression contains one of '.', '?' or '*' then it is assumed to be a POSIX regular expression..." – x-yuri Nov 20 '17 at 16:07
7

An alternative is:

dpkg -l | grep libreoffice | awk '{print $2}' | xargs -n1 echo

This will list out all the packages matching libreoffice. When you've confirmed that they're all the ones you wish to get rid of, run the following command... with caution:

dpkg -l | grep libreoffice | awk '{print $2}' | xargs -n1 sudo apt-get purge -y

The idea:

  1. Get the system to list out all installed packages
  2. Filter to show only the ones matching libreoffice
  3. Filter to show only the column with the package name
  4. Run the purge command on each of those packages
| improve this answer | |
  • 1
    maybe you could suggest adding the -p option so that xargs will prompt for confirmation before executing each command constructed, or first checking with echo instead of sudo apt-get purge – Zanna Oct 18 '16 at 6:11
  • 1
    @Zanna -p would help, but it wouldn't be a one-shot command. I did use echos to test what I was getting before running the command, so that's worth recommending. – aalaap Oct 18 '16 at 6:21
  • 2
    I can give you +1 now you made it safer :) – Zanna Oct 18 '16 at 6:31
  • I think the -n1 is good for the echo but you have to remove it from the purge; otherwise, dependency order (a depends on b, tries to delete b first) might break the purge. – Aaron Digulla Nov 9 '16 at 13:01
  • Your solution is the best I've found until now, thank you. – João Pedro Nov 3 '17 at 13:39
5

Aptitude has support for global patterns, and another pretty cool matches like this:

aptitude remove '?and(?name(libreoffice), name(3.6), ~i)' libreoffice-debian-menus

This will match any package that has in it's name libreoffice and 3.6 and also it's installed (that's what the ~i stands for.

| improve this answer | |

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.