linux极简小知识:18、rpm的查询命令大揭秘(-q、-qa、-i、-p、-l、-f、-R)

459 阅读4分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

rpm提供了强大的查询操作,包括:

  • 查询软件包是否已安装;
  • 查询系统中所有已安装的软件包;
  • 查看软件包的详细信息;
  • 查询软件包的文件列表(安装的路径);
  • 查询某系统文件具体属于哪个 RPM 包。

rpm -q:查询软件包是否安装,查询包全名

rpm -q <package_name> 查询软件包是否安装、安装的包全名。

-q|--query:执行查询。

此处使用的是包名,而不是包全名。(已安装的软件,使用包全名反而无法识别)

$ rpm -q mysql80-community-release
mysql80-community-release-el7-3.noarch
# rpm -q httpd
httpd-2.4.6-95.el7.centos.x86_64.rpm

rpm -qa:查询安装的所有软件包

rpm -qa:查询 Linux 系统中所有已安装的软件包。

-a|--all:查询所有的软件包。

# rpm -qa
libgusb-0.2.9-1.el7.x86_64
gnome-disk-utility-3.28.3-1.el7.x86_64
tcsh-6.18.01-13.el7_3.1.x86_64
gnome-bluetooth-libs-3.28.2-1.el7.x86_64
libappstream-glib-0.7.8-2.el7.x86_64
libXdmcp-1.1.2-6.el7.x86_64
khmeros-base-fonts-5.0-17.el7.noarch
glibc-static-2.17-157.el7_3.2.i686
gstreamer-plugins-bad-free-0.10.23-23.el7.x86_64
wayland-devel-1.15.0-1.el7.x86_64
sed-4.2.2-5.el7.x86_64
python-gobject-3.22.0-1.el7_4.1.x86_64
ModemManager-1.6.10-1.el7.x86_64
python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch
gnome-keyring-pam-3.28.2-1.el7.x86_64
cronie-1.4.11-14.el7_2.1.x86_64
qemu-img-1.5.3-160.el7_6.2.x86_64
...... # 省略

rpm -qa 通过管道符结合 grep 查找指定的软件(模糊查询)

rpm -qa 使用管道符结合 grep 可以查找指定的软件包。

如下,查询mysql相关的软件包:

# rpm -qa | grep mysql
mysql-community-client-8.0.26-1.el7.x86_64
mysql-community-common-8.0.26-1.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-libs-8.0.26-1.el7.x86_64
mysql-community-client-plugins-8.0.26-1.el7.x86_64
mysql-community-server-8.0.26-1.el7.x86_64

rpm -qpl:查询软件包的默认安装路径

查询指定包的安装路径信息:

# rpm -qpl mysql-community-server-8.0.26-1.el7.x86_64.rpm

后面的包名,为包全名。

  • -p|--package 表示查询指定的软件包(尤其是未安装的包)。如果一个包未安装,不指定 -p 将会提示未安装。

rpm -ql:命令查询软件包的文件列表

rpm 软件包通常默认将各安装文件,分门别类安装在适当的目录文件下。

rpm -ql <package_name>:查询已安装的软件包中包含的所有文件及各自安装路径。

此处为包名即可,不需要包全名。

  • -l|--list:表示列出软件包中包含的所有文件及各自安装路径。

比如查询 apache(httpd)包中所有文件及其安装位置:

rpm -ql httpd

rpm -qi:查询软件包的详细信息

rpm -qi <package_name>:查询软件包的详细信息。

-i|--info 选项表示查询软件的信息。

同样的,使用-prpm -qip <package_full_name> 可以查询指定包的详细信息。

# rpm -qip mysql-community-server-8.0.26-1.el7.x86_64.rpm
Name        : mysql-community-server
Version     : 8.0.26
Release     : 1.el7
Architecture: x86_64
Install Date: (not installed)
Group       : Applications/Databases
Size        : 2212303102
License     : Copyright (c) 2000, 2021, Oracle and/or its affiliates. Under GPLv2 license as shown in the Description field.
Signature   : DSA/SHA256, Fri 02 Jul 2021 02:50:54 AM CST, Key ID 8c718d3b5072e1f5
Source RPM  : mysql-community-8.0.26-1.el7.src.rpm
Build Date  : Thu 01 Jul 2021 04:54:44 PM CST
Build Host  : pb2-el7-14.appad3iad.mysql2iad.oraclevcn.com
Relocations : (not relocatable)
Packager    : MySQL Release Engineering <mysql-build@oss.oracle.com>
Vendor      : Oracle and/or its affiliates
URL         : http://www.mysql.com/
Summary     : A very fast and reliable SQL database server
Description :
The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,
and robust SQL (Structured Query Language) database server. MySQL Server
is intended for mission-critical, heavy-load production systems as well
as for embedding into mass-deployed software. MySQL is a trademark of
Oracle and/or its affiliates

The MySQL software has Dual Licensing, which means you can use the MySQL
software free of charge under the GNU General Public License
(http://www.gnu.org/licenses/). You can also purchase commercial MySQL
licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of
the GPL. See the chapter "Licensing and Support" in the manual for
further info.

The MySQL web site (http://www.mysql.com/) provides the latest news and
information about the MySQL software.  Also please see the documentation
and the manual for more information.

This package includes the MySQL server binary as well as related utilities
to run and administer a MySQL server.

rpm -qf:命令查询系统文件属于哪个RPM包

rpm -qf <file_name> 用于查询某个文件属于哪个RPM软件包。

-f|--file:表示的是文件。

只有使用 RPM 包安装的文件才能使用该命令。

查询 ls 命令对应的文件,及其所属的软件包。

# which ls
alias ls='ls --color=auto'
        /usr/bin/ls
# rpm -qf /usr/bin/ls
coreutils-8.22-18.el7.x86_64

rpm -qR:查询软件包的依赖关系

rpm -qR <package_name> 用来查询某已安装的软件包依赖的其他包。

-R|--requires:表示查询软件包的依赖性。

同样的,添加 -p 命令,可实现查找指定软件包的依赖性。

# rpm -qpR mysql-community-server-8.0.26-1.el7.x86_64.rpm
/bin/bash
/bin/sh
/bin/sh
/bin/sh
/bin/sh
/usr/bin/perl
config(mysql-community-server) = 8.0.26-1.el7
coreutils
grep
ld-linux-x86-64.so.2()(64bit)
ld-linux-x86-64.so.2(GLIBC_2.3)(64bit)
libaio.so.1()(64bit)
libaio.so.1(LIBAIO_0.1)(64bit)
libaio.so.1(LIBAIO_0.4)(64bit)
libc.so.6()(64bit)
libc.so.6(GLIBC_2.10)(64bit)
...... # 省略

参考

Linux rpm命令查询软件包(-q、-qa、-i、-p、-l、-f、-R)