[yum]06.yum provides和rpm -qf的比较
在前边说yum的几篇文章中我曾说过如何通过记忆中的一小段包名中的字符串来查找到包名,并举了"setup"这个工具的例子:
现在我想查看linux系统发行版的信息,用到lsb_release -a命令:
[[email protected] ~]#lsb_release -a -bash: lsb_release: command not found [[email protected] ~]#
那我就用上边这种方法查查吧,查到了再使用yum安装:
[[email protected] init.d]# yum list |grep lsb_release [[email protected] init.d]#
哦,你这不是逗我吗,可能因为我输入的字符串太精准了,少输入点吧,那我grep lsb得了:
[[email protected] init.d]# yum list |grep lsb redhat-lsb-core.x86_64 4.1-27.el7.centos.1 @base redhat-lsb-submod-security.x86_64 4.1-27.el7.centos.1 @base redhat-lsb.i686 4.1-27.el7.centos.1 base redhat-lsb.x86_64 4.1-27.el7.centos.1 base redhat-lsb-core.i686 4.1-27.el7.centos.1 base redhat-lsb-cxx.i686 4.1-27.el7.centos.1 base redhat-lsb-cxx.x86_64 4.1-27.el7.centos.1 base redhat-lsb-desktop.i686 4.1-27.el7.centos.1 base redhat-lsb-desktop.x86_64 4.1-27.el7.centos.1 base redhat-lsb-languages.i686 4.1-27.el7.centos.1 base redhat-lsb-languages.x86_64 4.1-27.el7.centos.1 base redhat-lsb-printing.i686 4.1-27.el7.centos.1 base redhat-lsb-printing.x86_64 4.1-27.el7.centos.1 base redhat-lsb-submod-multimedia.i686 4.1-27.el7.centos.1 base redhat-lsb-submod-multimedia.x86_64 4.1-27.el7.centos.1 base redhat-lsb-submod-security.i686 4.1-27.el7.centos.1 base redhat-lsb-supplemental.x86_64 4.1-27.el7.centos.1 base redhat-lsb-trialuse.i686 4.1-27.el7.centos.1 base redhat-lsb-trialuse.x86_64 4.1-27.el7.centos.1 base
还真巧了,接下来安装:
[[email protected] system]# yum -y install redhat-lsb-core
就可以了。但是这种方法还有一个不足的地方,就是我要grep xxx,这xxx完全靠猜啊,心里总感觉没底啊。在这里我再介绍另外一种方法。因为我们知道lsb_release它是个命令,本质上肯定是在PATH路径下有这么一个同名的文件,慢慢的,真相将要浮出水面了,就是说我现在知道我要找的这个rpm安装包将来安装完成之后一定会有个名字叫做lsb_release的文件。
现在要介绍的方法就是如何查询包含某个文件名的所有安装包,不管是本机安装的还是没有安装的,你就从yum源上给我列出来,使用命令"yum provides lsb_release",yum provides 参数,这里的参数是你要查询的文件名:
[[email protected] system]# yum provides lsb_release Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.cn99.com base/7/x86_64/filelists_db | 6.7 MB 00:00:11 extras/7/x86_64/filelists_db | 528 kB 00:00:05 updates/7/x86_64/filelists_db | 2.7 MB 00:00:27 redhat-lsb-core-4.1-27.el7.centos.1.i686 : LSB Core module support Repo : base Matched from: Filename : /usr/bin/lsb_release redhat-lsb-core-4.1-27.el7.centos.1.x86_64 : LSB Core module support Repo : base Matched from: Filename : /usr/bin/lsb_release
看到了吧,接下来我直接使用
[[email protected] system]# yum -y install redhat-lsb-core
就可以安装了。
总结:
1.yum provides 参数:这里的参数是你要查询的文件名,不管是本机安装的还是没有安装的,都会把信息列出来。这个功能很类似于
"rpm -qf 文件名"这个命令,因为他们都是根据文件名来查询该文件所在的rpm安装包。
2.yum provides 参数,这里的参数就是一个文件名,没有绝对路径相对路径的要求,而“rpm -qf 文件名”里面的文件名必须是本地已经安装过的真实存在的文件的绝对路径才可以查出它的rpm安装包信息:
[[email protected] ~]# rpm -qf /etc/httpd/conf/httpd.conf httpd-2.4.6-67.el7.centos.6.x86_64 [[email protected] ~]# rpm -qf httpd.conf error: file /root/httpd.conf: No such file or directory