How can I use logical operators when searching for packages in Aptitude?

161 Views Asked by At

1) How to search for packages matching "word1 or word2" with aptitude?

2) How to search for packages matching "word1 and word2" with aptitude?

2

There are 2 best solutions below

0
SpoonMeiser On BEST ANSWER

This wasn't clear to me from the documentation initially either. In my case, I wanted to search for packages that matched a name and were installed.

Anyway, the key is that each argument is a space separated list of conditions that are AND'd, and each argument is OR'd. So:

$ aptitude search "foo bar"

Will search for all packages that contain the string foo and the string bar

Where as:

$ aptitude search foo bar

Will search for all packages which contain either foo or bar

You can then combine this with other conditions that aptitude accepts to do things like:

$ aptitude search "~i python"

Will list all installed packages that contain the string python in their name

There are also other ways of doing this. For example:

$ aptitude search "?and(foo, bar)"
$ aptitude search "?or(foo, bar)"
0
David Ehrmann On

Take a look at the aptitude search pattern quick reference.

pattern1 | pattern2: Select packages that match pattern1, pattern2, or both.

pattern1 pattern2: Select any package that matches both pattern1 and pattern2.

Since that's a pipe, make sure it's escaped or in a string if you're running aptitude from a shell; it has a special meaning for shells.