How do I delete all packages which match a certain pattern?
Use
apt-get
, notaptitude
, and use regular expressions.In a regular expression,
.
mean any character, and*
means zero or more times. So the expressionlibreoffice.*
matches any package name containing the stringlibreoffice
, followed by any number of characters.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 replacelibreoffice.*
withlibreoffice.example
, so you have to use single quotes to stop this behaviour.)
Result:
sudo apt-get remove 'libreoffice.*'
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:
- Get the system to list out all installed packages
- Filter to show only the ones matching
libreoffice
- Filter to show only the column with the package name
- Run the purge command on each of those packages