Commands in Linux systems are usually provided by software packages installed in the distribution repository. To determine which package provides specific commands , you can use a package management tool specific to Linux distributions. This is useful for installing missing commands or troubleshooting package dependencies.
Table of contents
To find which package provides a command on various Linux distributions, you usually use a package management system specific to your distribution (such as Apk, Apt, DNF, Pacman, Zypper, etc.).
Here's how to do this in some of the most common Linux distributions:
In Alpine Linux, you can use the apk package manager to find which package provides a specific command.
<code># apk search -e pstree pstree-2.40-r1</code>
This command searches for packages related to the pstree command in the Alpine Linux package repository.
Here is a breakdown of the commands:
By running apk search -e pstree, Alpine Linux will search its package repository for any package that provides the pstree command or precisely named "pstree".
If the pstree utility is not installed on your Alpine Linux system, this can help you find and install the package that contains the pstree utility.
On Arch Linux and its variants such as EndeavourOS and Manjaro Linux, you can use the pacman command with the -F or -Qo flag to search for files (or commands) in a package.
For example, the following command will display the package containing the grep command:
<code>$ pacman -F grep</code>
The command pacman -F grep is used to find packages that provide specific files or commands.
Here are the meanings of different parts of the command:
When you run pacman -F grep, the package manager searches its package database and lists all installed packages containing files or executables named grep.
The output of this command will usually show the package name and the full path to the file matching grep. For example, the output might look like this:
<code>core/grep 3.11-1 usr/bin/grep [...]</code>
This indicates that the grep command is provided by the grep package in the core repository and the executable is located in /usr/bin/grep.
If multiple packages provide files that match grep, all of them will 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.
<code>$ pacman -Qo grep</code>
Here are the meanings of different parts of the command:
When you run pacman -Qo grep, pacman will search for all installed packages on the system and find packages that contain or provide files or executables named grep.
The output of this command will usually show the package name that has a file that matches grep. For example, the output might look like this:
<code>/usr/bin/grep is owned by grep 3.11-1</code>
This indicates that the grep command (located in /usr/bin/grep) is provided by the grep package.
If multiple packages provide files that match grep, all of them will be listed. If no package has 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 the Arch Linux system. It can help you troubleshoot missing files or dependencies, or help selectively reinstall packages that provide specific components.
The main difference between pacman -F grep and pacman -Qo grep is that -F searches the package database to find packages that contain specific files, while -Qo searches for files that are installed on the system and looks for packages that have them.
On Debian-based systems like Ubuntu, you can use the dpkg command with the -S option to search for packages that install specific files.
However, if the file is not installed, you need to use the apt-file command. First, make sure that apt-file is installed and its database is updated:
<code>$ sudo apt update $ sudo apt install apt-file $ sudo apt-file update</code>
Then, use the following command to search for a package that provides a specific command (such as the pstree command):
<code>$ apt-file search pstree</code>
Sample output:
<code>criu: /usr/lib/python3/dist-packages/pycriu/images/pstree_pb2.py manpages-ja: /usr/share/man/ja/man1/pstree.1.gz<strong></strong></code><mark> psmisc: /usr/bin/pstree</mark> 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
As you noticed in the output above, the psmisc package provides the pstree command. This approach allows you to identify the packages you need to install or make sure 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 can use:
<code>$ dpkg -S pstree</code>
On Fedora and other RPM-based systems such as AlmaLinux, CentOS, RHEL, and Rocky Linux, you can use the dnf command. On older systems, you may need to use yum.
For example, to search for a package that provides files that match pattern*/pstree, you can run:
<code>$ dnf provides */pstree</code>
The following is a breakdown of the functions of the command:
When you run this command, DNF will search its package database and list all available packages that contain files named pstree. This file is usually an executable file for the pstree utility, which displays the process tree.
The output of this command will display the package name and version number of the pstree file. For example, the output might look like this:
<code>psmisc-23.6-4.fc39.x86_64 : Utilities for managing processes on your system Repo : fedora Matched from: Provide : /usr/bin/pstree</code>
This indicates that the pstree file (located in /usr/bin/pstree) is mainly provided by the psmisc package (version 23.6-4) from the Fedora repository.
By using the dnf provides command, you can find out which packages you need to install to get specific files or utilities on your system.
On SUSE and openSUSE, you can use the zypper se --provides command to search for packages that provide a specified file or executable file.
<code>$ zypper se --provides '/usr/bin/grep'</code>
Here is a breakdown of the commands:
When you run this command, zypper will search its package database and list all available packages that contain or provide the file /usr/bin/grep.
The output of this command displays the name, version, and repository information of the package that provides the specified file. For example, the output might look like this:
<code>Loading repository data... Reading installed packages... S | Name | Summary | Type -- ------------------------- ------------------------------------------ ------- | grep-3.11-3 | Pattern matching utilities | package [...]</code>
This output indicates that the file /usr/bin/grep is mainly provided by the grep package (version 3.11-3).
In NixOS Linux, you can use the nix-env utility to find which package provides a specific command.
For example, to find which package provides the pstree command, you can run:
<code>$ nix-env -qaP pstree</code>
This will search for all installed packages and print out the package name and path when a match is found.
Sample output:
<code>nixpkgs.pstree pstree-2.39</code>
Indicates 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 specific command. Although this command is still in the experimental stage, you can use it to search for packages.
The first run may be slow, but subsequent runs will use cached results.
For example, to find a package containing the pstree command, run:
<code>$ nix --extra-experimental-features "nix-command flakes" search nixpkgs pstree</code>
Sample output:
<code>* 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</code>
We can use the Equery tool in the app-portage/gentoolkit package in Gentoo Linux to find which package provides specific commands.
Make sure you have installed app-portage/gentoolkit:
<code># emerge --ask app-portage/gentoolkit</code>
To search for packages that provide specific commands, use the equation with belongs option:
<code>equery belongs /path/to/command</code>
Replace /path/to/command with the full path to the command you are looking for.
If you don't know the path to the command, you can use the whereis command to find it.
<code># whereis pstree</code>
Sample output:
<code># whereis pstree pstree:<strong></strong></code><mark> /usr/bin/pstree</mark> /usr/share/man/man1/pstree.1.bz2
Now let's use the command to find out which package provides the pstree command:
<code># equery belongs /usr/bin/pstree</code>
This outputs the package name and category that provides the grep command, for example:
<code> * Searching for /usr/bin/pstree ... sys-process/psmisc-23.6 (/usr/bin/pstree)</code>
Indicates that the pstree command is provided by the sys-apps/psmisc package.
If you want to search for the command name only without specifying the full path, you can use the hasuse option:
<code># equery hasuse search-term</code>
This will search for packages with a specific USE flag or provide a specific executable file.
Package managers for most major Linux distributions offer built-in options to identify packages that provide specific commands or files. They allow you to search for the package database and find the source package for any given command or file.
This feature often helps troubleshoot missing dependencies, selectively reinstall packages, and ensure that your system has the necessary components installed.
Related Articles: How to Find Packages that Provide Specific Files in Linux
The above is the detailed content of How To Find Which Package Provides A Command In Linux. For more information, please follow other related articles on the PHP Chinese website!