如何准确检查 yum 包是否安装?

如何准确检查 yum 包是否安装?

我不断收到这样的答案:

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 核心包是否已安装。例如。bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6

我希望的是这样的:

yum check installed bind

但希望有人能够阐明这一点。

答案1

你尝试过这个吗?

$ yum list installed bind

答案2

有一种更简单的方法来发出此查询:rpm -qa | grep bindrpm -q bind。如果您不完全确定包名称,前者是最好的。

答案3

解析此命令的结果是最完整的答案。您需要知道确切的包名称。

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.

答案4

使用 Python 代码检查某个包是否已通过 yum 安装在 Python 中:

def is_installed(package_name):
    return "not installed" in commands.getstatusoutput("rpm -q " + package_name)[1]

相关内容