1

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?

3 Answers3

1

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.

0

Try pacman -F string1 string2 ...

Refer to : Querying package databases

  • 1
    `pacman -F` works in second the case, where I'm looking for the package that provides a file, but fails in the third: `pacman -F apache-ant` returns no results, while I want a command that returns `ant`. – qwertyzzz18 Sep 02 '20 at 22:34
0

--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