What is the difference between the ?narrow
and ?and
options of aptitude search? For example, why would aptitude search "?and(?installed,?origin(backports))"
return results on my system, but aptitude search "?narrow(?installed,?origin(backports))"
return nothing?
Note that running apt-cache policy
on the packages returned by the ?and
version shows that versions installed are not from backports, so the ?narrow
result is the correct one. But I've run into similar unintuitive results before which have been solved by using ?narrow
after some googling, but have never understood why.
Best Answer
Short answer
The first command
finds packages that are installed and have a backport available, but the backport is not necessarily installed. (Maybe the backport is installed, maybe it isn't.)
By contrast, the second command
finds package that are installed, and the currently installed version is from a backport, i.e. the backports that are actually installed. This is a more restrictive search, because the set of installed backports is a subset of available backports. You can think of it like this:
all packages
installed packages
installed packages with a backport available (first command)
On your system, the first command returns results but the second returns nothing. This means that you have installed packages with backports available, but evidently none of those backports are currently installed.
Long answer
It has to do with aptitude's distinction between matching the package and matching the package version. From the documentation:
The documentation for
?and
reads:Note that this matches packages, not single versions. So this query:
gets a list of all the package versions that are installed, then a list of all the package versions with an origin matching the regular expression
backports
, and then returns the packages that appear in both lists.On the other hand, the documentation for
?narrow
reads:So that's why this query only shows packages where the single installed version has an origin that matches
backports
:There is a related discussion for the
?any-version
function:By running
aptitude versions
instead ofaptitude search
, we find that these queries all give the same result:Whew! If you find the query language for
aptitude
confusing (as I do), you may prefer to use a different approach, such as Python's bindings tolibapt
. Rather than matching on version strings, you can check the origin string directly, like this: