24

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

sudo apt-get remove openoffice*.*
0

3 Answers 3

16

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.

3
  • -P is meant for never following symbolic links, not prompt
    – rancho
    Jun 19, 2016 at 20:27
  • Also using ~nredshift will not search for redshift, but ~nredshift. Also ~n is not any argument by default
    – rancho
    Jun 19, 2016 at 20:39
  • Answer given by NorticUs is paartly correct. The correct syntax here would be ~n^redshift
    – rancho
    Jun 19, 2016 at 20:44
7

You just put it in quotes:

sudo apt-get remove "openoffice*"

Otherwise the shell would try to match this to the files of your current working directory.

6
  • 6
    The question is about aptitude and not apt-get. This solution does not work with aptitude.
    – N.N.
    Sep 23, 2011 at 10:39
  • @MichałŠrajer: no pathname expansion occur in quotes, both single and double
    – enzotib
    Sep 23, 2011 at 12:01
  • @enzotib: My mistake. Thanks for pointing it out. Removed comment. Sep 23, 2011 at 14:07
  • ok, I don't get ... so can be done with aptitude or work in that way... sudo aptitude remove "openoffice*" Sep 23, 2011 at 14:40
  • @raulricardo21 A similar thing can be done with aptitude, see my answer.
    – N.N.
    Sep 23, 2011 at 15:11
5

To match strings starting with a package name, prepend a ^ in front of it.
e.g: aptitude search ~n^openoffice

1
  • I does just the search portion, you should also mention how to get the search result
    – rancho
    Jun 19, 2016 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .