Ubuntu – How to use wildcards with aptitude

aptitudecommand line

Is there a way to use wildcards with aptitude such as in the following:

sudo apt-get remove openoffice*.*

Best Answer

http://ubuntuforums.org/showthread.php?t=228309 indicates that it's possible via constructs such as ~n<package name> and this is confirmed by the user manual http://algebraicthunk.net/~dburrows/projects/aptitude/doc/en/ch02s03s02.html.

~n in ~n<package name> is a search pattern for matching package names. It's also possible to match other fields than packages' names, see http://algebraicthunk.net/~dburrows/projects/aptitude/doc/en/ch02s03s05.html#tableSearchTermQuickGuide.

Here's an example. Say that you want aptitude to show every package with "redshift" in its name, then you issue

aptitude show ~nredshift

It should be combinable with other aptitude options, such as install and remove, too, e.g. to remove all installed packages with openoffice in their name you issue

sudo aptitude -P remove ~nopenoffice

Make sure to use the -P option when using search patterns to force aptitude to display a prompt before downloading, installing or removing packages (the search pattern might have many matches and you'll want to be prompted before carrying out an action).

One thing that I haven't worked out is how to get the exact functionality of wildcards, e.g. that openoffice* matches every string starting with "openoffice" (~nopenoffice matches any string containing "openoffice"). Maybe a workaround is possible, e.g. to search for installed packages with a certain string in their names and then feed aptitude with their names.

Related Question