39

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

Braiam
  • 69,112

5 Answers5

51
  1. Use apt-get or apt, (not aptitude), and use anchored 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. You must anchor the regular expression with ^ (to match the beginning of the string) or $ (to match the end of the string) or both, otherwise, the regular expression will not be recognised by APT.

  3. Surround the regular expression with single quotes to avoid the shell interpreting the asterisk.

Example:

To remove all packages with a name that starts with libreoffice, run:

sudo apt remove '^libreoffice.*$'
Flimm
  • 44,031
12

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
aalaap
  • 418
6

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.

Braiam
  • 69,112
5

2023 solution

sudo apt remove 'libreoffice*' -y

(The -y flag skips the "are you sure?" prompt)

birgersp
  • 531
  • 1
  • 10
  • 21
1

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.

funder7
  • 196