Home Linux Commands How To Find Which Package Provides A Command In Linux

How To Find Which Package Provides A Command In Linux

Track Down Package for a Specific Command in Various Linux Distributions

By sk
Published: Updated: 2.9K views

On Linux systems, commands are typically provided by packages installed from distribution repositories. To identify which package provides a particular command, you can use package management tools specific to your Linux distribution. This can be useful for installing missing commands or troubleshooting package dependencies.

Find Which Package Provides a Specific Command in Linux

To find out which package provides a certain command on various Linux distributions, you generally use the package management system (E.g. Apk, Apt, DNF, Pacman, Zypper etc.,) specific to your distribution.

Here's how you can do it for some of the most common Linux distributions:

1. Identify the Package Owning a Linux Command in Alpine Linux

In Alpine Linux, you can use the apk package manager to find out which package provides a specific command.

# apk search -e pstree
pstree-2.40-r1
Find Which Package Provides the Given Command in Alpine Linux
Find Which Package Provides the Given Command in Alpine Linux

This command searches for packages in the Alpine Linux package repository that are related to the pstree command.

Here's a breakdown of the command:

  • apk is the package management utility for Alpine Linux, similar to apt for Debian-based distributions or yum for Red Hat-based distributions.
  • search is the command to search for packages in the repositories.
  • -e or --exact is an option that tells apk to search for an exact package name, rather than performing a substring search.
  • pstree is the package name or command name you're searching for.

By running apk search -e pstree, Alpine Linux will search its package repositories for any packages that provide the pstree command or are named exactly "pstree".

This can help you find and install the package containing the pstree utility if it's not already installed on your Alpine Linux system.

2. Find the Package Source of a Linux Command in Arch Linux, EndeavourOS, and Manjaro Linux

On Arch Linux and its variants like EndeavourOS and Manjaro Linux, you can use the pacman command with -F or -Qo flags to search for the file (or command) in packages.

For instance, the following command will display the packages that contains the command grep:

$ pacman -F grep

The command pacman -F grep is used to find which package(s) provide a specific file or command.

Here's what the different parts of the command mean:

  • pacman: This is the package manager for Arch Linux.
  • -F (or --files): This option tells pacman to search for packages that contain a specific file.
  • grep: This is the file or command you're searching for. In this case, it's the grep command.

When you run pacman -F grep, the package manager searches through its package databases and lists all the installed packages that contain a file or executable named grep.

The output of this command will typically show the package name(s) and the full path(s) of the file(s) matching grep. For example, the output might look something like this:

core/grep 3.11-1
    usr/bin/grep
[...]

This indicates that the grep command is provided by the grep package from the core repository, and the executable file is located at /usr/bin/grep.

If multiple packages provide files matching grep, they will all be listed. Conversely, if no package provides a file named grep, the command will return no output.

You can also use the pacman -Qo command to find which package owns or provides a specific file or command.

$ pacman -Qo grep

Here's what the different parts of the command mean:

  • pacman: This is the package manager for Arch Linux.
  • -Q: This option tells pacman to query the local package database.
  • -o (or --owns): This option specifies that you want to search for the package that owns a particular file.
  • grep: This is the file or command you're searching for. In this case, it's the grep command.

When you run pacman -Qo grep, pacman will search through all the installed packages on your system and find the package(s) that contain or provide the file or executable named grep.

The output of this command will typically show the package name(s) that own the file(s) matching grep. For example, the output might look something like this:

/usr/bin/grep is owned by grep 3.11-1

This indicates that the grep command (located at /usr/bin/grep) is provided by the grep package.

If multiple packages provide files matching grep, they will all be listed. If no package owns a file named grep, the command will return no output.

This command is useful when you need to find out which package a specific file or command belongs to on your Arch Linux system. It can help you troubleshoot missing files or dependencies, or assist in selectively reinstalling packages that provide specific components.

The main difference between pacman -F grep and pacman -Qo grep is that -F searches the package databases for packages that contain a specific file, while -Qo searches the files that are already installed on your system and finds which packages own them.

3. Locate the Package for a Linux Command in Debian, Ubuntu and derivatives

On Debian-based systems (like Ubuntu), you can use the dpkg command with the -S option to search for the package that installed a specific file.

However, if the file is not already installed, you'll want to use the apt-file command. First, ensure apt-file is installed and its database is updated:

$ sudo apt update
$ sudo apt install apt-file
$ sudo apt-file update

Then, search for the package that provides a specific command, for example pstree command, using the following command:

$ apt-file search pstree

Sample Output:

criu: /usr/lib/python3/dist-packages/pycriu/images/pstree_pb2.py
manpages-ja: /usr/share/man/ja/man1/pstree.1.gz
psmisc: /usr/bin/pstree
psmisc: /usr/bin/pstree.x11
psmisc: /usr/share/man/de/man1/pstree.1.gz
psmisc: /usr/share/man/fr/man1/pstree.1.gz
psmisc: /usr/share/man/man1/pstree.1.gz
psmisc: /usr/share/man/man1/pstree.x11.1.gz
psmisc: /usr/share/man/pt_BR/man1/pstree.1.gz
psmisc: /usr/share/man/ru/man1/pstree.1.gz
psmisc: /usr/share/man/uk/man1/pstree.1.gz
psmisc: /usr/share/pixmaps/pstree16.xpm
psmisc: /usr/share/pixmaps/pstree32.xpm
python-psutil-doc: /usr/share/doc/python-psutil-doc/examples/pstree.py
recap: /usr/lib/recap/core/pstree
systemtap-doc: /usr/share/systemtap/examples/process/pstree.meta
systemtap-doc: /usr/share/systemtap/examples/process/pstree.stp
tomoyo-tools: /usr/sbin/tomoyo-pstree
tomoyo-tools: /usr/share/man/man8/tomoyo-pstree.8.gz
Find Which Package Provides a Specific Command in Linux
Find Which Package Provides a Specific Command in Linux

As you noticed in the output above, the psmisc package provides the pstree command. This approach allows you to identify the package necessary to install or ensure that pstree is available on your system.

Or, if you already have pstree installed and just want to confirm that pstree comes from this package, you could use:

$ dpkg -S pstree

4. Discovering the Package for a Specific Command in Fedora, CentOS, RHEL, and derivatives

On Fedora and other RPM-based systems (like AlmaLinux, CentOS, RHEL and Rocky Linux), you can use the dnf command. On older systems, you might need to use yum.

For example, to search for packages that provide files matching the pattern */pstree, you would run:

$ dnf provides */pstree

Here's a breakdown of what the command does:

  • dnf: This is the DNF package manager command.
  • provides: This subcommand tells DNF to search for packages that provide a specific file or capability.
  • */pstree: This is a glob pattern that matches any file named pstree. The * part means "any characters" before the filename.

When you run this command, DNF will search through its package databases and list all the available packages that contain a file named pstree. This file is typically the executable for the pstree utility, which displays a process tree.

The output of this command will display the package names and version numbers that provide the pstree file. For example, the output might look like this:

psmisc-23.6-4.fc39.x86_64 : Utilities for managing processes on your system
Repo        : fedora
Matched from:
Provide    : /usr/bin/pstree

This indicates that the pstree file (located at /usr/bin/pstree) is primarily provided by the psmisc package, version 23.6-4, from the Fedora repository.

By using the dnf provides command, you can find which package(s) you need to install to get a specific file or utility on your system.

5. Identifying the Package Associated with a Linux Command in SUSE, openSUSE

On SUSE and openSUSE, you can use the zypper se --provides command to search for packages that provide the specified file or executable.

$ zypper se --provides '/usr/bin/grep'

Here's a breakdown of the command:

  • zypper: This is the command-line interface for the ZYpp package manager.
  • se: This is a shorthand for the search subcommand, which searches for packages.
  • --provides: This option tells zypper to search for packages that provide a specific file or capability.
  • '/usr/bin/grep': This is the file or executable path that you're searching for. In this case, it's the path for the grep command, which is typically located at /usr/bin/grep.

When you run this command, zypper will search through its package databases and list all the available packages that contain or provide the file /usr/bin/grep.

The output of this command will display the package names, versions, and repository information for the packages that provide the specified file. For example, the output might look like this:

Loading repository data...
Reading installed packages...

S | Name                    | Summary                                 | Type
--+-------------------------+------------------------------------------+-------
  | grep-3.11-3          | Pattern matching utilities               | package
[...]

This output indicates that the file /usr/bin/grep is primarily provided by the grep package (version 3.11-3).

6. Finding the Package Behind a Linux Command in NixOS

In NixOS Linux, you can find which package provides a specific command using the nix-env utility.

For example, to find which package provides the pstree command, you would run:

$ nix-env -qaP pstree

This will search all installed packages and print out the package name and path if a match is found.

Sample Output:

nixpkgs.pstree  pstree-2.39

Indicating that the pstree command is provided by the pstree-2.39 package.

You can also use the nix search Command to find the name of the package that provides a certain command. While this command is still experimental, you can use it to search for a package.

It may be slow the first time, but subsequent runs will use cached results.

For example, to find the package containing the pstree command, run:

$ nix --extra-experimental-features "nix-command flakes" search nixpkgs pstree

Sample Output:

* legacyPackages.x86_64-linux.psmisc (23.6)
  A set of small useful utilities that use the proc filesystem (such as fuser, killall and pstree)

* legacyPackages.x86_64-linux.pstree (2.39)
  Show the set of running processes as a tree

7. Revealing Command Origins in Gentoo

We can find which package provides a specific command using the equery tool from the app-portage/gentoolkit package in Gentoo Linux.

Make sure you have app-portage/gentoolkit installed:

# emerge --ask app-portage/gentoolkit

To search for a package that provides a specific command, use equery with the belongs option:

equery belongs /path/to/command

Replace /path/to/command with the full path to the command you're looking for.

If you don't know the path of the command, you can use whereis command to find it.

# whereis pstree

Sample Output:

# whereis pstree
pstree: /usr/bin/pstree /usr/share/man/man1/pstree.1.bz2

Now let us find out which package provides the pstree command using command:

# equery belongs /usr/bin/pstree

This will output the package name and category that provides the grep command, e.g.:

 * Searching for /usr/bin/pstree ... 
sys-process/psmisc-23.6 (/usr/bin/pstree)

Indicating that the pstree command is provided by the sys-apps/psmisc package.

Identify Which Package Provides a Command in Gentoo
Identify Which Package Provides a Command in Gentoo

If you just want to search for a command name without specifying the full path, you can use the hasuse option instead:

# equery hasuse search-term

This will search for packages that have a specific USE flag or provide a specific executable.

Conclusion

The package managers of most major Linux distributions provide built-in options to identify the package that provides a particular command or file. They allow you to search the package databases and locate the source package for any given command or file.

This capability is often helpful for troubleshooting missing dependencies, selectively reinstalling packages, and ensuring your system has the necessary components installed.

Related Read: How To Find The Package That Provides A Specific File In Linux

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More