Linux rpm列出已安装的软件包命令

时间:2020-01-09 10:40:30  来源:igfitidea点击:

如何在CentOS/Suse/Fedora/RHEL/Scientific和Red Hat Enterprise Linux上使用rpm命令列出所有已安装的软件包?
您能告诉我Linux命令列出服务器上安装的所有rpm吗?

rpm命令是功能强大的软件包管理器。
它用于在基于RPM的发行版(例如OpenSUSE,RHEL或CentOS)上构建,安装,查询,验证,更新和擦除单个软件包。

Red Hat和朋友的最新版本建议使用yum命令或dnf命令。

本教程说明如何在Linux操作系统上列出或计算已安装的RPM软件包。

Linux rpm列表安装的软件包命令语法

rpm命令具有-a选项来查询(列出)所有已安装的软件包。

使用rpm -a选项列出所有已安装的软件包

打开终端或使用ssh客户端登录到远程服务器。
以root用户身份执行以下命令:

# rpm -qa

输出示例:

filesystem-2.4.0-1
comps-extras-11.1-1.1
gnome-mime-data-2.4.2-3.1
glibc-2.5-12
atk-1.12.2-1.fc6
libICE-1.0.1-2.1
db4-4.3.29-9.fc6
elfutils-libelf-0.125-3.el5
db4-4.3.29-9.fc6
iptables-1.3.5-1.2.1
libXrender-0.9.1-3.1
libXi-1.0.1-3.1
xorg-x11-font-utils-7.1-2
slang-2.0.6-4.el
.....
..
....

也可以如下列出安装日期:

rpm -qa --qf '(%{INSTALLTIME:date}): %{NAME}-%{VERSION}\n

输出示例:

(Tuesday 17 September 2019 11:54:48 PM IST): python-jinja2-2.7.2
(Saturday 27 January 2016 08:46:16 PM IST): python-markupsafe-0.11
(Tuesday 17 September 2019 11:53:12 PM IST): nss-pem-1.0.3
(Tuesday 17 September 2019 11:54:50 PM IST): neon-0.30.0
(Tuesday 17 September 2019 11:53:12 PM IST): rpm-python-4.11.3
(Friday 21 September 2016 05:10:19 AM IST): python34-msgpack-0.5.6
(Tuesday 17 September 2019 11:54:50 PM IST): iwl6000-firmware-9.221.4.1
(Tuesday 17 September 2019 11:53:13 PM IST): make-3.82
(Wednesday 29 November 2016 12:57:00 AM IST): gettext-0.19.8.1
(Sunday 25 June 2016 07:08:26 PM IST): ppp-2.4.5
(Tuesday 17 September 2019 11:54:51 PM IST): iwl1000-firmware-39.31.5.1
(Tuesday 17 September 2019 11:53:14 PM IST): libgfortran-4.8.5
(Sunday 02 July 2016 02:11:41 AM IST): mtools-4.0.18
(Wednesday 05 December 2016 06:54:19 AM IST): radvd-2.17
(Sunday 25 June 2016 07:08:28 PM IST): alsa-firmware-1.0.28
(Tuesday 17 September 2019 11:54:53 PM IST): libgcc-4.8.5
(Thursday 10 May 2016 02:10:20 PM IST): opus-1.0.2
(Tuesday 17 September 2019 11:53:17 PM IST): passwd-0.79
(Tuesday 17 September 2019 11:54:56 PM IST): rdma-core-22.1

获取有关特定软件包的信息

您可以使用以下命令显示有关软件包的更多信息:

# rpm -qi iptables

输出示例:

Name        : iptables                     Relocations: /usr 
Version     : 1.3.5                             Vendor: Red Hat, Inc.
Release     : 1.2.1                         Build Date: Thu 13 Jul 2006 07:17:24 PM CDT
Install Date: Tue 10 Jul 2007 08:49:20 AM CDT      Build Host: ls20-bc2-14.build.redhat.com
Group       : System Environment/Base       Source RPM: iptables-1.3.5-1.2.1.src.rpm
Size        : 676805                           License: GPL
Signature   : DSA/SHA1, Thu 18 Jan 2007 09:47:22 AM CST, Key ID 5326810137017186
Packager    : Red Hat, Inc. 
URL         : http://www.netfilter.org/
Summary     : Tools for managing Linux kernel packet filtering capabilities.
Description :
The iptables utility controls the network packet filtering code in the
Linux kernel. If you need to set up firewalls and/or IP masquerading,
you should install this package.

列出RPM软件包安装的所有文件

您可以使用以下命令列出软件包文件:

# rpm -ql iptables

输出示例:

/etc/rc.d/init.d/iptables
/etc/sysconfig/iptables-config
/lib64/iptables
/lib64/iptables/libipt_CLASSIFY.so
/lib64/iptables/libipt_CONNMARK.so
/lib64/iptables/libipt_DNAT.so
/lib64/iptables/libipt_DSCP.so
/lib64/iptables/libipt_ECN.so
.....
.......
...

随意添加诸如更少或更多的寻呼机,一次显示一个屏幕:

# rpm -qa | less
# rpm -qa | more
# rpm -qa | grep 'something'
# rpm -ql iptables | more

要查找特定软件包的安装日期,例如nginx,请运行:

# rpm -q --last nginx
package nginx is not installed
# rpm -q --last ufw
ufw-0.35-9.el7.noarch Thursday 21 June 2016 11:33:26 PM IST

在Linux上使用yum或dnf列出已安装的RPM软件包

以root用户身份运行以下命令(使用grep命令或更多命令作为寻呼机/过滤器):

# yum list installed
# yum list installed | more
# yum list installed | grep nginx

对于Fedora和最新版本的CentOS/RHEL 8.x,请使用dnf命令

# dnf list installed
# dnf list installed | less
# dnf list installed | grep -i mysql

在Linux中使用yum/dnf计算所有已安装的RPM软件包

将yum命令输出传递给wc命令以计算CentOS或RHEL或SUSE上已安装的软件包:

# yum list installed | wc -l
# dnf list installed | wc -l

列出RHEL,CentOS,Oracle和Fedora Linux中所有已安装的软件包

另一个选择是执行以下rpmquery命令。
但是,首先安装dnf-utils/yum-utils软件包:

# dnf install dnf-utils ## <-- Fedora latest or CentOS/RHEL 8x. -- ##
# yum install yum-utils ## <-- CentOS/RHEL 6.x/7.x -- ##

接下来,执行以下命令:

# repoquery -a --installed
# repoquery -a --installed | grep httpd
# repoquery -a --installed | more

也可以列出来自特定存储库的已安装软件包,例如CentOS/RHEL 7上的epel存储库或RHEL 8上的ELEP存储库或CentOS 8上的EPEL存储库。
首先,获取存储库,运行:

# yum repolist

输出示例:

Loaded plugins: changelog, copr
repo id                          repo name                                             status
base/7/x86_64                    CentOS-7 - Base                                       10,097
epel/x86_64                      Extra Packages for Enterprise Linux 7 - x86_64        13,501
extras/7/x86_64                  CentOS-7 - Extras                                        307
ngompa-snapcore-el7/x86_64       Copr repo for snapcore-el7 owned by ngompa                19
updates/7/x86_64                 CentOS-7 - Updates                                     1,010
repolist: 24,934

记下RepoID,例如基础,Epel,追加等。
最后列出epel repo中所有已安装的软件包:

yumdb search from_repo reop_id_here
yumdb search from_repo extras
yumdb search from_repo epel