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*"


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) Apr 4 '13 at 12:12
  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.)


sudo apt-get remove 'libreoffice.*'
  • 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 :-) Apr 4 '13 at 12:09
  • 4
    For those who want to test this, use the option --dry-run to see what would be deleted without any changes to the system. Apr 4 '13 at 12:11
  • 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

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
  • 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. Nov 9 '16 at 13:01
  • Your solution is the best I've found until now, thank you. Nov 3 '17 at 13:39

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.


When you need to remove many files having the same prefix, I find brace expansion very handy:

sudo apt remove libreoffice-l10n-{bg,ca,cs,da,de,en-za,es,fr,hu,id,ja,ko,nb,nl,pl,pt,ru,sv,th,tr,uk,vi,zh-cn,zh-tw}

I used this command to remove all the language packs that I never use. Yes, with a regex you can tell which one to keep, and delete the others. Anyway I like this because it's easy to remember, and it works also with many bash commands.

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.