我不断得到如下答案:
yum list installed | grep bind
要么
rpm -qa | grep bind
但是,这是不正确的,因为我得到像这些其他几个绑定包的列表:
bind-utils-9.8.2-0.17.rc1.el6_4.5.x86_64 rpcbind-0.2.0-11.el6.x86_64 bind-libs-9.8.2-0.17.rc1.el6_4.5.x86_64 samba-winbind-3.6.9-151.el6.x86_64 samba-winbind-clients-3.6.9-151.el6.x86_64 ypbind-1.20.4-30.el6.x86_64
那不是我想要的。 相反,我想要准确地检查是否已经安装了绑定核心包。 例如。 bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6
我希望有这样的东西:
yum check installed bind
但希望有人可以摆脱这种光。
你尝试过吗?
$ yum list installed bind
parsing这个命令的结果是最完整的答案。 你需要知道确切的包名称。
yum info bind Loaded plugins: refresh-packagekit, rhnplugin This system is receiving updates from RHN Classic or RHN Satellite. Installed Packages Name : bind Arch : x86_64 Epoch : 32 Version : 9.8.2 Release : 0.17.rc1.el6_4.6 Size : 7.3 M Repo : installed From repo : rhel-x86_64-workstation-6 Summary : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server URL : http://www.isc.org/products/BIND/ License : ISC Description : BIND (Berkeley Internet Name Domain) is an implementation of the DNS : (Domain Name System) protocols. BIND includes a DNS server (named), : which resolves host names to IP addresses; a resolver library : (routines for applications to use when interfacing with DNS); and : tools for verifying that the DNS server is operating properly.
发出这个查询有一个更简单的方法: rpm -qa | grep bind
rpm -qa | grep bind
或rpm -q bind
。 前者是最好的,如果你不完全确定的包名称。
我已经想出了最好的一个方法(这对于在脚本中快速使用非常有用):
yum info <package_name> | grep Repo | awk '{ print $3 }'
例如:如果我目前已经安装了git
:
yum info git | grep Repo | awk '{ print $3 }'
这将返回installed
如果我目前没有安装git
,那么以前的命令将会返回: base/7/x86_64
这是git
当前可用的安装
使用Python代码来检查是否使用yum在python中安装了一个包:
def is_installed(package_name): return "not installed" in commands.getstatusoutput("rpm -q " + package_name)[1]
yum list installed bind >/dev/null ; echo $?
如果结果是0(零),则安装软件包