Linux上查询某个文件或命令所属的软件包
当我们在Linux系统上需要执行某个命令的时候,发现此命令对应的软件包并未安装,无法执行,然而又忘记了命令所属的软件包是哪一个,此时我们就可以使用yum provides或apt-file search查询某个文件或命令所属的软件包。
CentOS/Redhat系统:
[root@VM-20-10-centos nginx]# yum provides iostat
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
sysstat-10.1.5-19.el7.x86_64 : Collection of performance monitoring tools for Linux
Repo : os
Matched from:
Filename : /usr/bin/iostat
#通过如上输出可以得出iostat命令所属软件包为sysstat
Debian/Ubuntu系统:
首次使用前需安装 apt-file 并更新数据库:
apt install apt-file # 安装工具
apt-file update # 更新文件索引(需定期执行以保持最新)
root@ubuntu:~# apt-file search -x "/iostat$" #查找包含文件名以 iostat 结尾的软件包,-x:启用正则表达式
munin-plugins-extra: /usr/share/munin/plugins/iostat
pcp: /etc/pcp/pmlogconf/tools/iostat
pcp: /var/lib/pcp/config/pmlogconf/tools/iostat
pcp-testsuite: /var/lib/pcp/testsuite/sadist/iostat
sysstat: /usr/bin/iostat
zfsutils-linux: /etc/zfs/zpool.d/iostat
zfsutils-linux: /usr/lib/zfs-linux/zpool.d/iostat