如何搜索提供虚拟包的包?
例如,我想在 Ubuntu 12.04 的“主”存储库中搜索提供“x-terminal-emulator”的软件包。一种方法是解析软件包索引:
curl http://archive.ubuntu.com/ubuntu/dists/precise/main/binary-amd64/Packages.gz | zcat | grep -B12 '^Provides: x-terminal-emulator' | grep ^Package:
结果如下:
Package: gnome-terminal
Package: konsole
Package: xterm
有没有更好(更干净)的方法来做到这一点? 可以使用任何官方工具(apt-get/apt-cache/etc)来完成吗?
答案1
使用aptitude
。它有非常丰富的搜索语言。要搜索“提供”字段,请使用以下~P
术语:
$ aptitude search '~Px-terminal-emulator'
p aterm - transitional dummy package for rxvt-unicod
p aterm-ml - transitional dummy package for rxvt-unicod
p eterm - Enlightened Terminal Emulator
p evilvte - lightweight terminal emulator based on VTE
p gnome-terminal - GNOME terminal emulator application
p guake - Drop-down terminal for GNOME Desktop Envir
p konsole - X terminal emulator
p kterm - Multi-lingual terminal emulator for X
p lilyterm - Light and eazy-to-use terminal emulator fo
i A lxterminal - LXDE terminal emulator
p mate-terminal - MATE terminal emulator application
p mlterm - MultiLingual TERMinal
p mlterm-tiny - MultiLingual TERMinal, tiny version
p mrxvt - lightweight multi-tabbed X terminal emulat
p mrxvt-cjk - lightweight multi-tabbed X terminal emulat
p mrxvt-mini - lightweight multi-tabbed X terminal emulat
p pterm - PuTTY terminal emulator
p qterminal - Lightweight Qt terminal emulator
p roxterm-gtk2 - Multi-tabbed GTK+/VTE terminal emulator -
p roxterm-gtk3 - Multi-tabbed GTK+/VTE terminal emulator -
i rxvt - VT102 terminal emulator for the X Window S
p rxvt-ml - multi-lingual VT102 terminal emulator for
p rxvt-unicode - RXVT-like terminal emulator with Unicode s
p rxvt-unicode-256color - multi-lingual terminal emulator with Unico
p rxvt-unicode-lite - RXVT-like terminal emulator with basic Uni
p sakura - simple but powerful libvte-based terminal
p stterm - suckless tools simple terminal for windowe
p terminal.app - Terminal Emulator for GNUstep
i terminator - multiple GNOME terminals in one window
p terminology - Enlightenment efl based terminal emulator
p termit - Simple terminal emulator based on vte libr
p vala-terminal - Terminal emulator for mobile devices
p xfce4-terminal - Xfce terminal emulator
p xiterm+thai - X terminal program with Thai languague sup
i xterm - X terminal emulator
p xvt - X terminal-emulator similar to xterm, but
理论上,该~s
术语应该能够按部分(主要,贡献,非免费)进行限制,但由于某种原因,这对我来说无法正常工作。
答案2
假设你知道x-terminal-emulator
是一个虚拟包,你可以尝试
# absolutely blunt method
apt-provides() {
apt-cache show '.*' |
sed -n '/^Package: \(.*\)$/ {s//\1/;h}; /^Provides:.*'"$1"'/ {x;p}' | sort | uniq
}
# better method
apt-provides() {
apt-cache show $(apt-cache search "$1" | awk '{ print $1 }' | tr '\n' ' ') |
sed -n '/^Package: \(.*\)$/ {s//\1/;h}; /^Provides:.*'"$1"'/ {x;p}'
}
例如,
$ apt-provides x-terminal-emulator
gnome-terminal
xterm
aterm
aterm-ml
eterm
evilvte
guake
konsole
kterm
lxterminal
mlterm
mlterm-tiny
mrxvt
mrxvt-cjk
mrxvt-mini
pterm
roxterm-gtk2
roxterm-gtk3
rxvt
rxvt-beta
rxvt-ml
rxvt-unicode
rxvt-unicode-256color
rxvt-unicode-lite
sakura
terminal.app
terminator
termit
vala-terminal
xfce4-terminal
xiterm+thai
xvt
编辑:包括一种直接的错误检查方法,使sed
表达更加优美