Linux查看软件包是否默认安装

今天同事问我:CentOS里的ss这个命令是在系统安装时就装了的么?那Ubuntu下也默认安装了?

对CentOS,咱还是熟悉的,想知道是否在系统安装时就默认安装了,首先得先知道这个命令是在那个包里的。可以用这个命令进行查看。

1
2
[root@localhost ~]# rpm -qf `which ss`
iproute-4.11.0-25.el7_7.2.x86_64

可以得知,ss命令是在iproute包中,那下一个问题,就是查这个包是否在系统安装时就默认安装了。CentOS 的yum groups里有一个Minimal Install 软件包组,这个里面就是最小安装时使用到的软件了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[root@localhost ~]# yum group info Minimal Install
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile

Environment Group: Minimal Install
Environment-Id: minimal
Description: Basic functionality.
Mandatory Groups:
+core
Optional Groups:
+debugging

[root@localhost ~]# yum group info core
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile

Group: Core
Group-Id: core
Description: Smallest possible installation.
Mandatory Packages:
audit
basesystem
bash
....
initscripts
iproute
iprutils
iptables
....

可以看出,iproute 包在core软件包组里,因此,ss命令是在系统安装时就默认给装上了。

再是Ubuntu,Ubuntu需要用apt-file工具进行查看,这个命令默认没有安装,需要用apt install apt-file 命令进行安装,安装后还需要更新下数据库,更新命令是apt-file update,数据库更新了就可以搜索了。

1
2
3
4
5
6
7
8
9
root@localhost:~# apt-file search /bin/ss
alsa-firmware-loaders: /usr/bin/sscape_ctl
dacs: /usr/bin/sslclient
....
embassy-domainatrix: /usr/bin/ssematch
hash-slinger: /usr/bin/sshfp
iproute2: /bin/ss
libnet-proxy-perl: /usr/bin/sslh
....

这个命令并不如rpm好用,首先得更新数据库,然后会列出所有符合搜索条件的结果(包括未安装的包里的文件,因此可以用这个命令来搜索只记得部分内容的软件包),因此搜索会比较慢。人工判断识别后得知Ubuntu里是在iproute2软件包中,再对比Ubuntu最小号安装列表(https://packages.ubuntu.com/bionic/ubuntu-minimal ),得知iproute2包是默认安装的包。

事后搜索了一番,Debian系其实也有类似rpm -qf的命令工具,使用dpkg -S whereis就可以直接得到结果了。这篇文章还整理了其他Linux发行版的命令,收藏以备查阅。