Reputation: 2597
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.
Upvotes: 242
Views: 365489
Reputation: 561
Depending upon whether we know the file path or not we can choose one of the 2 options mentioned below.
If we know the path of the file then as per the man page for the RPM command
QUERY OPTIONS
The general form of an rpm query command is
rpm {-q|--query} [select-options] [query-options]
PACKAGE SELECTION OPTIONS:
PACKAGE_NAME
Query installed package named PACKAGE_NAME.
-f, --file FILE
Query package owning FILE.
it's pretty straightforward to identify the corresponding RPM package. For example:
[root@e2e-64-147 ~]# rpm -qf /usr/bin/lesspipe.sh
less-458-9.el7.x86_64
If only the file name is known and the path is not, then we can use the yum command with provides option to identify the corresponding RPM package. For example:
[root@e2e-64-147 ~]# yum -q provides '*lesspipe.sh*'
less-458-9.el7.x86_64 : A text file browser similar to more, but better
Repo : base
Matched from:
Filename : /usr/bin/lesspipe.sh
Upvotes: 0
Reputation: 12459
To know the package owning (or providing) an already installed file:
rpm -qf myfilename
Upvotes: 232
Reputation: 155
Using only the rpm utility, this should work in any OS that has rpm:
rpm -q --whatprovides [file name]
Upvotes: 5
Reputation: 3241
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.
Upvotes: 0
Reputation: 441
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>
Upvotes: 33
Reputation: 639
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
Upvotes: 4
Reputation: 50324
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.
Upvotes: 292
Reputation: 229344
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
Upvotes: 5