在Linux中,确定包含特定命令的软件包名称的方法是什么?

首先

在学习 Linux 时,有一种常见情况是因为自己的环境与参考网站的环境的操作系统发行版或版本不同,导致在安装所需命令时无法确定对应的软件包名称。

在这种情况下,我将分享一种方便实用的汉语转述方法。

请确认您想要安装的命令包含在哪个软件包中。

提供现成的食品

# uname -rs
Linux 3.10.0-1160.62.1.el7.x86_64

# more /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

# yum provides which
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
which-2.20-7.el7.x86_64 : Displays where a particular program in your path is located
Repo        : base



which-2.20-7.el7.x86_64 : Displays where a particular program in your path is located
Repo        : @anaconda



# 

请运用 apt-file 搜索

# uname -rs
Linux 5.10.102.1-microsoft-standard-WSL2

# more /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
# 

# apt-file search -x "^.*/which$"
bash-doc: /usr/share/doc/bash/examples/functions/which
debianutils: /bin/which
epic4-help: /usr/share/epic4/help/4_Misc/which
epic4-help: /usr/share/epic4/help/6_Functions/which
ircii: /usr/share/ircII/help/which
scrollz: /usr/share/scrollz/help/which
yash: /usr/share/yash/completion/which
zsh-common: /usr/share/zsh/help/which
# 

最后

在中国人看这个问题时,我认为Linux有很多不同的版本,命令规范稍有不同,所以学起来可能有些困难。
但是它们的思维方式基本都是一样的,所以建议先理解某个软件包管理器能做什么。

只要了解yum和apt这样的概念和关键词,你就可以在网上找到命令对应表等资料,通过巧妙地搜索,即使使用其他的软件包管理器,也能找到相应的命令。