How To Find Which Package Provides A Command In Linux
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
- Identify packages that have Linux commands in Alpine Linux
- Find package sources for Linux commands in Arch Linux, EndeavourOS, and Manjaro Linux
- Find packages for Linux commands in Debian, Ubuntu and its derivatives
- Find packages for specific commands in Fedora, CentOS, RHEL and its derivatives
- Identify software packages associated with Linux commands in SUSE, openSUSE
- Find packages behind Linux commands in NixOS
- Revealing command source in Gentoo
- in conclusion
Find packages that provide specific commands in Linux
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:
1. Identify packages that own Linux commands in Alpine Linux
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:
- apk is a package management utility for Alpine Linux, similar to apt for Debian-based distributions or yum for Red Hat-based distributions.
- Search is a command to search for packages in a repository.
- -e or --exact is an option that tells apk to search for the exact package name instead of performing a substring search.
- pstree is the name of the package or command you are searching for.
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.
2. Find the source of packages for Linux commands in Arch Linux, EndeavourOS, and Manjaro Linux
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:
- pacman: This is the package manager for Arch Linux.
- -F (or --files): This option tells pacman to search for packages containing specific files.
- grep: This is the file or command you are searching for. In this case, it is the grep 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:
- 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 packages that have specific files.
- grep: This is the file or command you are searching for. In this case, it is the grep 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.
3. Find Linux command packages in Debian, Ubuntu and its derivatives
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>
4. Find packages for specific commands in Fedora, CentOS, RHEL and its derivatives
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:
- dnf: This is the DNF package manager command.
- provide: This subcommand tells DNF to search for packages that provide specific files or functions.
- */pstree: This is a glob pattern that matches any file named pstree. * Partial means "any character" before the file name.
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.
5. Identify software packages associated with Linux commands in SUSE, openSUSE
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:
- zypper: This is the command line interface of the ZYpp package manager.
- se: This is the abbreviation of the search subcommand, which searches for packages.
- --provides: This option tells zypper to search for packages that provide specific files or functions.
- '/usr/bin/grep': This is the file or executable path you are searching for. In this case, it is the path to the grep command, usually located in /usr/bin/grep.
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).
6. Find packages behind Linux commands in NixOS
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>
7. Reveal the source of the command in Gentoo
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.
in conclusion
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.
