Programming

How do I find which rpm package supplies a file Im looking for

19 September 2026 · 9 min read

How do I find which rpm package supplies a file Im looking for

In the world of Linux system administration, one common task is figuring out which RPM package installed a particular file. Whether you’re troubleshooting a configuration issue, auditing your system’s software, or simply curious about a file’s origin, understanding how to find which RPM package supplies a file is a crucial skill. Red Hat Package Manager (RPM) is a powerful package management system that allows you to install, update, uninstall, and query software packages on Red Hat-based Linux distributions such as Fedora, CentOS, and Red Hat Enterprise Linux (RHEL). Knowing how to effectively query the RPM database is essential for maintaining a stable and well-managed system. This guide will walk you through various methods and commands to pinpoint the exact package responsible for a given file, empowering you to better understand and manage your Linux environment.

Using the rpm Command to Identify Package Origins

The primary tool for querying RPM databases is, unsurprisingly, the rpm command itself. This versatile command offers a multitude of options, but the -qf (query file) flag is the key to discovering which package owns a specific file. The basic syntax is rpm -qf /path/to/file. When you run this command, RPM will search its database and, if the file is managed by a package, output the name of that package. For example, if you want to know which package provides the /etc/passwd file, you would execute rpm -qf /etc/passwd. The output will be something like setup-2.8.14-5.el7.x86_64, indicating that the setup package installed this file.

However, the rpm -qf command has a limitation: it only works if the file exists on the system and is part of a currently installed package. If the file has been deleted or belongs to a package that has been uninstalled, rpm -qf will return an error. For instance, if you’ve recently removed a package and are trying to trace its files, this method won’t work. In such cases, you may need to explore alternative methods, such as examining package archives or using more advanced querying techniques. According to Red Hat documentation, the rpm command is the primary method for querying installed packages Red Hat Documentation.

Here’s a quick summary of the rpm -qf command:

  • Simple and direct method.
  • Requires the file to exist and be part of an installed package.
  • Outputs the package name if found.

Leveraging rpm with Wildcards and Alternatives

Sometimes, you might not know the exact path to the file, or you might want to find all packages that provide files matching a certain pattern. In such cases, you can use wildcards with the rpm -qf command. However, directly using wildcards like rpm -qf /etc/httpd/ will usually result in an error because rpm -qf expects a specific file path. Instead, you can combine find with rpm -qf to achieve the desired result. For example, find /etc/httpd/ -type f -print0 | xargs -0 rpm -qf will find all files under /etc/httpd/ and then use rpm -qf to identify the package for each file.

Another useful alternative is the rpm -V (verify) command. While not directly designed to identify package origins, it can help you determine if a file has been modified since it was installed by a package. If a file fails the verification, it suggests that the file might have been altered or replaced, which could be useful in troubleshooting scenarios. The command rpm -V package_name verifies the integrity of files installed by the specified package. For example, rpm -V httpd will verify the files installed by the httpd package.

Consider a scenario where you suspect a configuration file has been tampered with. You can use rpm -V to check if the file matches the original version installed by the package. If the verification fails, it indicates that the file has been modified, which might explain unexpected behavior. This approach complements rpm -qf by providing additional context about the file’s state and integrity. According to a study by the SANS Institute, verifying file integrity is a crucial step in maintaining system security SANS Institute.

Dealing with Files Not Owned by Any Package

Sometimes, you might encounter files that are not owned by any RPM package. This can happen if the file was manually created, copied from another system, or installed by a method other than RPM (e.g., compiled from source). In such cases, rpm -qf will return an error indicating that the file is not owned by any package. This information can be useful in identifying files that might not be managed by your system’s package management system.

Using yum provides or dnf provides for Package Discovery

Modern Red Hat-based systems often use yum (Yellowdog Updater, Modified) or dnf (Dandified Yum) as higher-level package management tools built on top of RPM. These tools offer a more user-friendly interface and can resolve dependencies automatically. The yum provides or dnf provides command is particularly useful for finding which package provides a specific file, even if the file is not currently installed on the system. This is a powerful feature that allows you to discover packages that contain a file before you even install them.

The syntax is yum provides /path/to/file or dnf provides /path/to/file. For example, if you want to find the package that provides the ls command, you would run yum provides /bin/ls or dnf provides /bin/ls. The output will list one or more packages that contain the specified file. yum is depreciated in newer systems, and dnf is the preferred package manager. According to the Fedora Project wiki, dnf is the successor to yum and offers improved performance and dependency resolution Fedora Project Wiki.

Here’s how to use yum provides or dnf provides:

  1. Open your terminal.
  2. Type yum provides /path/to/file or dnf provides /path/to/file and press Enter.
  3. Examine the output to identify the package that provides the file.
  4. If multiple packages are listed, consider the package name and version to determine the most appropriate one.
Infographic here illustrating the process of using rpm -qf, yum provides, and dnf provides
Advanced Techniques and Troubleshooting ---------------------------------------

Sometimes, simply using rpm -qf or yum provides might not be enough to find the package you’re looking for. This could be due to various reasons, such as package conflicts, corrupted RPM databases, or files being overwritten by other applications. In such cases, you might need to employ more advanced techniques to troubleshoot the issue. One approach is to rebuild the RPM database. This can be done using the command rpm –rebuilddb. This command rebuilds the RPM database from the installed packages, which can resolve inconsistencies and improve the accuracy of package queries. You might also need to clear the yum or dnf cache to ensure you’re using the latest package information. This can be done using yum clean all or dnf clean all.

Another useful technique is to examine the RPM package files directly. You can download the RPM package from a repository and then use the rpm -qlp package.rpm command to list the files contained within the package. This can be helpful if you suspect that a file is part of a specific package but rpm -qf or yum provides is not returning the expected result. For example: rpm -qlp downloaded_package.rpm will list all the files within the downloaded package archive. Another LSI keyword is RPM package contents.

Let’s say you’re encountering issues with a shared library and want to identify which package provides it. The standard tools might not immediately reveal the source if the library has been overwritten or replaced. By downloading potential package candidates and examining their contents, you can manually verify which package originally provided the library. This hands-on approach can be invaluable for resolving complex dependency issues and ensuring system stability. Remember to always download packages from trusted sources to avoid security risks.

FAQ: Finding RPM Package Origins

What if rpm -qf returns "file is not owned by any package"?
This means the file was not installed by an RPM package. It might have been manually created, copied from another system, or installed using a different method.
How can I find the package for a file if I only know part of the file name?
Use find to locate the file based on its partial name, then use rpm -qf on the located file path.
Why is yum provides or dnf provides not finding the package?
Make sure your package lists are up-to-date by running yum update or dnf update. Also, ensure that the file path is correct.
Can I use these methods on remote systems?
No, these commands work on the local system's RPM database. To query a remote system, you would need remote access and the ability to execute commands on that system.
Pinpointing the RPM package responsible for a specific file is a fundamental skill for any Linux administrator. By mastering the techniques outlined above – from the basic rpm -qf command to the more advanced yum provides or dnf provides and troubleshooting methods – you'll be well-equipped to manage your system's software effectively. Understanding the origin of files not only aids in troubleshooting and auditing but also empowers you to maintain a stable and secure Linux environment. Further explore related topics such as package dependency resolution and RPM database management to deepen your expertise. Check out this [guide to troubleshooting RPM issues](https://courthousezoological.com/n7sqp6kh?key=e6dd02bc5dbf461b97a9da08df84d31c) for more help.

Question & Answer :
As an example, I am looking for a mod_files.sh file which presumably would come with the php-devel package. I guessed that yum would install the mod_files.sh file with the php-devel x86_64 5.1.6-23.2.el5_3 package, but the file appears to not to be installed on my filesystem.

How do I find out which package installs a specific file? I’m looking for where I have not necessarily already locally downloaded the package which may include the file that I’m looking for.

I’m using CentOS 5.

This is an old question, but the current answers are incorrect :)

Use yum whatprovides, with the absolute path to the file you want (which may be wildcarded). For example:

yum whatprovides '*bin/grep' 

Returns

grep-2.5.1-55.el5.x86_64 : The GNU versions of grep pattern matching utilities. Repo : base Matched from: Filename : /bin/grep 

You may prefer the output and speed of the repoquery tool, available in the yum-utils package.

sudo yum install yum-utils repoquery --whatprovides '*bin/grep' grep-0:2.5.1-55.el5.x86_64 grep-0:2.5.1-55.el5.x86_64 

repoquery can do other queries such as listing package contents, dependencies, reverse-dependencies, etc.