作为一个例子,我正在寻找一个mod_files.sh文件,该文件可能会随php-devel包而来。我猜yum会用php-devel x86_64 5.1.6-23.2安装mod_files.sh文件。El5_3包,但文件似乎没有安装在我的文件系统。

如何找出哪个包安装了特定的文件?我正在寻找我不一定已经在本地下载的包,其中可能包括我正在寻找的文件。

我用的是CentOS 5。


当前回答

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

其他回答

只使用rpm实用程序,这应该适用于任何有rpm的操作系统:

rpm -q --whatprovides [file name]

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

您访问http://www.rpmfind.net并搜索该文件。

您将得到许多不同发行版和版本的结果,但很可能也会弹出Fedora和/或CentOS,并且您将知道要与yum一起安装的软件包名称

要知道包拥有(或提供)一个已经安装的文件:

rpm -qf myfilename

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

你可以在这里做同样的事情,但是用你的包。在我的例子中,它是lsb_release

执行命令:yum whatproviders lb_release

回应:

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`

执行命令install: yum install redhat-lsb-core

包装名称应该没有数字和系统类型,以便包装商可以选择最适合他的。