如何找到哪个rpm包提供我正在寻找的文件?

时间:2009-07-15 19:35:38

标签: centos rpm yum

作为一个例子,我正在寻找一个mod_files.sh文件,可能会附带php-devel包。我猜测yum将使用mod_files.sh包安装php-devel x86_64 5.1.6-23.2.el5_3文件,但该文件似乎不会安装在我的文件系统上。

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

我正在使用CentOS 5.

7 个答案:

答案 0 :(得分:258)

这是一个老问题,但目前的答案是不正确的:)

使用 yum whatprovides ,使用所需文件的绝对路径(可能是通配符)。例如:

yum whatprovides '*bin/grep'

返回

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

您可能更喜欢repoquery包中提供的yum-utils工具的输出和速度。

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可以执行其他查询,例如列出包内容,依赖项,反向依赖项等。

答案 1 :(得分:194)

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

rpm -qf myfilename

注意:此命令不需要以root身份运行(与sudo yum whatprovides myfilename相反)

答案 2 :(得分:30)

最受欢迎的答案是不完整的:

由于此搜索通常仅针对已安装软件包中的文件执行,因此通过禁用所有外部存储库(隐式"已安装" repo can&#39)可以快速实现 yum whatprovides ;被禁用)。

yum --disablerepo=* whatprovides <file>

答案 3 :(得分:4)

当您连接到Internet(存储库)时很容易找到包,但是当您只能访问Redhat或Centos DVD中的RPM包时(当我必须恢复服务器并且需要应用程序时,这种情况经常发生在我身上)我建议使用下面的命令,它完全独立于Internet和存储库。 (可能你在DVD中有很多未安装的软件包)。 假设您已在〜/ cent_os_dvd中安装了Package文件夹,并且您正在寻找提供“semanage”的软件包,然后您就可以运行:

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

答案 4 :(得分:3)

您转到http://www.rpmfind.net并搜索该文件。

你会得到许多不同的发行版和版本的结果,但很可能会弹出Fedora和/或CentOS,你会知道要用yum安装的软件包名称

答案 5 :(得分:0)

您可以在这里使用打包程序,同样地执行此操作。就我而言,它是lsb_release

运行:yum whatprovides lsb_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`

运行以安装:yum install redhat-lsb-core

软件包名称应没有数字和系统类型,以便yum打包程序可以选择最适合他的软件包。

答案 6 :(得分:0)

仅使用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/