How do I find which rpm package supplies a file I'm looking for?

centos, rpm, yum

Solution

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.

Problem

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.

Original source

Related problems