Loading...
X

How to find out which package contains a file

How to find out which package a file is in

Sometimes the name of the required utility does not coincide with the name of the package - this is especially the case when one package contains several programs. As a result, a problem arises - to find a package in which the required executable file or header file is present (if you received an error during compilation due to the absence of a specific file).

This article will help you by showing you how to search packages by filename. Moreover, for all packages at once - regardless of whether they are installed or not.

The pkgfile utility looks in the .files metadata generated by repo-add to get information about the files in the packages. By default, the specified target is assumed to be the filename and pkgfile will return packages containing that file. The repositories that pkgfile looks for are determined by those included in /etc/pacman.conf.

To install the program, run the command:

sudo pacman -S pkgfile

Update the saved metadata files.

sudo pkgfile --update

For example, I need to find out which package contains the file finger. Then I run the following command:

pkgfile finger

As you can see, pkgfile did a great job - the finger executable is in the netkit-bsd-finger package in the blackarch repository.

Using the -l, --list option, you can view the contents of any package:

pkgfile -l netkit-bsd-finger

The target is the package name, not the file name, and the contents of the specified package are returned. This allows the use of repo/package style syntax (eg, “core/pacman”) to limit the search range, but only when --list is used without the --glob or --regex options.

Matching heuristic

In --search mode and without the --regex or --glob option, pkgfile will try to match the supplied target as the exact filename. If the target contains a '/' character, then an attempt will be made to match the full path. With --regex and --glob search enabled, pkgfile will always match the full path.

In --list mode and without the --regex or --glob option, pkgfile will try to match the supplied target as the exact package name. If the target contains a '/' character, the text before the forward slash will be considered a repository and searches will be limited to that repository only.

All pkgfile options

Usage:

pkgfile [options] target

Options:

 Operations:
  -l, --list              list contents of a package
  -s, --search            search for packages containing the target (default)
  -u, --update            update repo files lists

 Matching:
  -b, --binaries          return only files contained in a bin dir
  -d, --directories       match directories in searches
  -g, --glob              enable matching with glob characters
  -i, --ignorecase        use case insensitive matching
  -R, --repo <repo>       search a singular repo
  -r, --regex             enable matching with regular expressions

 Output:
  -q, --quiet             output less when listing
  -v, --verbose           output more
  -w, --raw               disable output justification
  -0, --null              null terminate output

 Downloading:
  -z, --compress[=type]   compress downloaded repos

 General:
  -C, --config <file>     use an alternate config (default: /etc/pacman.conf)
  -D, --cachedir <dir>    use an alternate cachedir (default: /var/cache/pkgfile)
  -h, --help              display this help and exit
  -V, --version           display the version and exit

See also How to view package information in Arch Linux (BlackArch, Manjaro).


Leave Your Observation

Your email address will not be published.