如何使用 dpkg 获取“提供”某些内容的软件包列表?

如何使用 dpkg 获取“提供”某些内容的软件包列表?

我看到 dpkg 有一个用于包的“提供”字段。

$ apt-cache show vim-tiny | grep Provides
Provides: editor
$

我如何知道哪些软件包提供了“编辑器”?

答案1

您可以使用 来实现所需的效果aptitude(现在似乎不鼓励这样做)apt-cache showpkg,其中包括 的列表Reverse Provides。通过一个小脚本进行管道传输sed将摆脱其他事情:

apt-cache showpkg <package> | sed '/Reverse Provides/,$!d'

可以使用以下命令实现一个稍微漂亮一些(但输入起来较长)的示例(仅列出包名称,而不列出版本,并按字母顺序排列)awk

apt-cache showpkg httpd | awk '/Pa/, /Reverse P/ {next} {print $1 | "sort"}'

...并且可以通过管道传输来uniq删除重复项(由于包的多个版本是反向提供的,因此可能存在重复项)。请注意,使用uniq对第一个版本没有帮助,因为仅当它们位于相邻行上并且版本不对输出进行排序uniq时才会删除重复项。sed

最后,可以定义一个更易于使用的函数,如下所示:

provides () { apt-cache showpkg $1 | awk '/Pa/, /Reverse P/ {next} {print $1 | "sort"}' | uniq;}

将其粘贴在(例如)中.bashrc,以便它在 shell 加载时加载,然后可以运行provides <package>以获取包的反向提供。

答案2

Aptitude 也提供了此功能。因此,这样的命令将显示所有提供编辑器的软件包。

aptitude search '~Peditor'

您甚至可以添加其他约束。例如仅显示已安装的编辑器。

aptitude search '~i~Peditor'

答案3

$ dpkg-query -W -f='Package: ${Package}\nProvides: ${Provides}\n' \
  | grep -B 1 -E "^Provides: .*editor"
Package: nano
Provides: editor
--
Package: vim-gnome
Provides: editor, gvim, vim, vim-perl, vim-python, vim-ruby, vim-tcl
--
Package: vim-tiny
Provides: editor
$

答案4

基于您的示例。我可以列出editor按用途提供的包apropos

hvn@lappy: ~ () $ apropos editor
atobm (1)            - bitmap editor and converter utilities for the X W...
bitmap (1)           - bitmap editor and converter utilities for the X W...
bmtoa (1)            - bitmap editor and converter utilities for the X W...
ed (1)               - text editor
editor (1)           - Vi IMproved, a programmers text editor
editres (1)          - a dynamic resource editor for X Toolkit applications
ex (1)               - Vi IMproved, a programmers text editor
gedit (1)            - text editor for the GNOME Desktop
gnome-text-editor (1) - text editor for the GNOME Desktop
gview (1)            - Vi IMproved, a programmers text editor
gvim (1)             - Vi IMproved, a programmers text editor
i3-sensible-editor (1) - launches $EDITOR with fallbacks
nano (1)             - Nano's ANOther editor, an enhanced free Pico clone
notepad (1)          - Wine text editor
pico (1)             - Nano's ANOther editor, an enhanced free Pico clone
psed (1)             - a stream editor
ptked (1p)           - an editor in Perl/Tk
red (1)              - text editor
regedit (1)          - Wine registry editor
rgview (1)           - Vi IMproved, a programmers text editor
rgvim (1)            - Vi IMproved, a programmers text editor
rnano (1)            - Restricted mode for Nano's ANOther editor, an enh...
rview (1)            - Vi IMproved, a programmers text editor
rvim (1)             - Vi IMproved, a programmers text editor
s2p (1)              - a stream editor
sdlBasic (1)         - sdlBasic program editor
sed (1)              - stream editor for filtering and transforming text
select-editor (1)    - select your default sensible-editor from all inst...
sensible-editor (1)  - sensible editing, paging, and web browsing
software-properties-gtk (1) - Software Sources List editor
Tk::ColorEditor (3pm) - a general purpose Tk widget Color Editor
vi (1)               - Vi IMproved, a programmers text editor
view (1)             - Vi IMproved, a programmers text editor
vim (1)              - Vi IMproved, a programmers text editor
winecfg (1)          - Wine Configuration Editor
xedit (1)            - simple text editor for X
zshzle (1)           - zsh command line editor

相关内容