Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

sudo apt-get remove openoffice*.*
share|improve this question
up vote 14 down vote accepted

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.

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

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.

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

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

share|improve this answer
    
I does just the search portion, you should also mention how to get the search result – rancho Jun 19 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.