Home > System Tutorial > LINUX > How To Find Which Package Provides A Command In Linux

How To Find Which Package Provides A Command In Linux

Christopher Nolan
Release: 2025-03-19 09:12:11
Original
450 people have browsed it

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

    1. Identify packages that have Linux commands in Alpine Linux
    1. Find package sources for Linux commands in Arch Linux, EndeavourOS, and Manjaro Linux
    1. Find packages for Linux commands in Debian, Ubuntu and its derivatives
    1. Find packages for specific commands in Fedora, CentOS, RHEL and its derivatives
    1. Identify software packages associated with Linux commands in SUSE, openSUSE
    1. Find packages behind Linux commands in NixOS
    1. 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>
Copy after login

How To Find Which Package Provides A Command In Linux

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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 
Copy after login

How To Find Which Package Provides A Command In Linux

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

To search for packages that provide specific commands, use the equation with belongs option:

 <code>equery belongs /path/to/command</code>
Copy after login

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>
Copy after login

Sample output:

 <code># whereis pstree pstree:<strong></strong></code><mark> /usr/bin/pstree</mark> /usr/share/man/man1/pstree.1.bz2
Copy after login

Now let's use the command to find out which package provides the pstree command:

 <code># equery belongs /usr/bin/pstree</code>
Copy after login

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>
Copy after login

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

How To Find Which Package Provides A Command In Linux

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>
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template