210

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.

Kevin Panko
  • 7,844
  • 19
  • 46
  • 58
wherestheph
  • 2,279
  • 2
  • 14
  • 6

7 Answers7

269

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.

rjh
  • 46,345
  • 3
  • 47
  • 60
202

To know the package owning (or providing) an already installed file:

rpm -qf myfilename
John Kugelman
  • 307,513
  • 65
  • 473
  • 519
dj_segfault
  • 11,455
  • 3
  • 26
  • 35
  • 4
    this command looks to be more efficient than yum whatprovides--no need to get updates from possibly slow repositories. – 80x25 May 21 '14 at 15:30
  • 1
    This version also works on non redhat based distro's that still use rpm's such as openSUSE – simotek Apr 11 '16 at 01:57
  • 5
    It seems to me that `rpm -qf ` is best suited for determining which package provides an installed application (since it may be different than what is in the current yum repository cache), and `yum whatprovides ` is best suited for determining which package provides a yet-to-be-installed application. Each has their own purpose. – StockB Oct 31 '17 at 14:26
  • Furthermore, `yum whatprovides ...` only requires root if the application is a root package (i.e. it resides in `/sbin`). However, `rpm -qf ...` also requires root in order to read rpms from `/sbin`. Therefore, I propose that the root requirements are functionally equivalent for both methods. – StockB Oct 31 '17 at 14:28
  • 1
    Anyone using this command, please note that you have to use full file path + filename, and not just the file name. – Ashish May 11 '18 at 05:34
  • @StockB Are you sure rpm and dnf do not use exactly the same database of locally installed packages to determine the package that own specific file? – Piotr Dobrogost Jul 19 '18 at 11:46
31

The most popular answer is incomplete:

Since this search will generally be performed only for files from installed packages, yum whatprovides is made blisteringly fast by disabling all external repos (the implicit "installed" repo can't be disabled).

yum --disablerepo=* whatprovides <file>
pavon
  • 16,449
  • 1
  • 20
  • 23
user93374
  • 421
  • 4
  • 4
  • 4
    In this case, however, the OP is specifically looking for a missing file that was **not installed** on the system, even after installing a package he thought would have it, so he can't use `--disablerepo=*` – Randall Feb 14 '17 at 20:02
4

You go to http://www.rpmfind.net and search for the file.

You'll get results for a lot of different distros and versions, but quite likely Fedora and/or CentOS will pop up too and you'll know the package name to install with yum

nos
  • 207,058
  • 53
  • 381
  • 474
  • This website is offline! – Peter Oct 22 '13 at 08:02
  • 1
    The website does not appear to search for files; only package names with the search term. – jww Aug 17 '15 at 10:41
  • 1
    @jww Searching for files works fine for me at least. As the docs says, you can search for executables by their single path name or any file with the absolute path name. – nos Aug 17 '15 at 10:50
4

Well finding the package when you are connected to internet (repository) is easy however when you only have access to RPM packages inside Redhat or Centos DVD (this happens frequently to me when I have to recover a server and I need an application) I recommend using the commands below which is completely independent of internet and repositories. (supposably you have lots of uninstalled packages in a DVD). Let's say you have mounted Package folder in ~/cent_os_dvd and you are looking for a package that provides "semanage" then you can run:

for file in `find ~/cent_os_dvd/ -iname '*.rpm'`;  do rpm -qlp $file |grep '.*bin/semanage';  if [ $? -eq 0 ]; then echo "is in";echo $file  ; fi;  done
Arash
  • 531
  • 5
  • 8
3

Using only the rpm utility, this should work in any OS that has rpm:

rpm -q --whatprovides [file name]

Ref. https://www.thegeekdiary.com/how-to-find-which-rpm-package-provides-a-specific-file-or-library-in-rhel-centos/

Slivicon
  • 83
  • 2
  • 7
0

You can do this alike here but with your package. In my case, it was lsb_release

Run: yum whatprovides lsb_release

Response:

redhat-lsb-core-4.1-24.el7.i686 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release

redhat-lsb-core-4.1-24.el7.x86_64 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release

redhat-lsb-core-4.1-27.el7.i686 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release

redhat-lsb-core-4.1-27.el7.x86_64 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release`

Run to install: yum install redhat-lsb-core

The package name SHOULD be without number and system type so yum packager can choose what is best for him.

matson kepson
  • 1,284
  • 12
  • 14