2

I'd like to query the pacman database for the package that satisfies a requirement: essentially the package that would get installed if I were to run pacman -S <requirement>.

It appears there are three cases:

  • The requirement is the name of a package.
  • The requirement is the name of a file or library.
  • The requirement appears in the provides field of another package.

The first two cases are pretty straightforward, but the third one is causing me trouble.

For example, the requirement apache-ant is provided by package ant.
pacman -S apache-ant correctly identifies and installs ant.
pacman -Q apache-ant returns the information I want, but only if the package is already installed.

Is there a command that works similarly to pacman -Q, but does not fail if the package isn't locally installed?

4 Answers4

3

There's no built-in method for the third case, but I've used this:

pacprovides(){
    pacman -Si | sed -n '/^Name.*: /{s///;h}; /^Provides.*'"$1"'/{g; p}'
}

hold the package name, get and print it when you find a matching line.

1

--print shows the targets of a transaction:

$ pacman --sync --print libtagparser.so

file:///var/cache/pacman/pkg/cpp-utilities-5.20.0-100-x86_64.pkg.tar.zst

file:///var/cache/pacman/pkg/tagparser-11.5.0-100-x86_64.pkg.tar.zst

The package is the last target, trimmed:

$ pacman --sync --print libtagparser.so | tail -n1 | rev | cut --delimiter='/' --fields=1 | cut --delimiter='-' --fields=4- | rev

tagparser

0

This should work

pacman -Ss "^<requirement>$"

It gives all packages which provide the requirement.

It wont tell which woud be installed, but is faster than pacman -Sp

nadapez
  • 250
-1

Try pacman -F string1 string2 ...

Refer to : Querying package databases