这是对Alexx Roche出色答案的扩展。我试图对该答案进行编辑,但遭到拒绝(尽管不是Alexx)
我试图跟踪which
系统上安装了什么。经过一点工作,我创建了/usr/local/bin/apt-whatprovides
#!/bin/sh
#apt-whatprovides ver. 201801010101 Copyright alexx, MIT Licence
#rdfa:deps="[realpath,apt-file,grep,which,sh,echo]"
BINARY="$(realpath $(which $@) 2>/dev/null)"
[ -z "$BINARY" ] && BINARY="$@"
echo Searching for $BINARY
PACKAGE="$(apt-file search $BINARY|grep -E ":.*[^-.a-zA-Z0-9]${BINARY}$")"
echo "${PACKAGE}"
尽管对于大多数已安装的东西,您可以使用:
apt-file search $(realpath $(which THING)) | grep 'THING$'
对于未安装的事物,可以使用:
apt-file search THING | grep '/THING$'
该apt-whatprovides
脚本适用于系统上存在和不在系统上的文件。例如,我的系统缺少,dig
但是有ping
这样的结果:
pi@raspberrypi:~ $ apt-whatprovides ping
Searching for /bin/ping
inetutils-ping: /bin/ping
iputils-ping: /bin/ping
pi@raspberrypi:~ $ apt-whatprovides dig
Searching for dig
dnsutils: /usr/bin/dig
epic4: /usr/share/epic4/script/dig
epic4-help: /usr/share/epic4/help/8_Scripts/dig
knot-dnsutils: /usr/bin/dig
请注意,这Searching for
是ping
(已安装)的完整路径,而只是dig
未安装的二进制名称。这帮助我发现我dnsutils
无需进行搜索即可安装https://packages.ubuntu.com/#search_contents