8

How to search for packages that provides a virtual package?

For example, I want to search for packages that provides "x-terminal-emulator" in the "main" repository of Ubuntu 12.04. One way to do this is to parse the package index:

curl http://archive.ubuntu.com/ubuntu/dists/precise/main/binary-amd64/Packages.gz | zcat | grep -B12 '^Provides: x-terminal-emulator' | grep ^Package:

which gives me the following results:

Package: gnome-terminal
Package: konsole
Package: xterm

Is there a better (and cleaner) way to do this? Can it be done with any of the official tools (apt-get/apt-cache/etc)?

2 Answers 2

5

Use aptitude. It's got a very rich search language. For searching "Provides" fields, use the ~P term:

$ 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 

In theory, the ~s term should be able to limit by section (main, contrib, non-free), but that wasn't working properly for me for some reason.

4

Assuming you know x-terminal-emulator is a virtual package, you may try

# 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}'
}

For example,

$ 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

edit: included a blunt method for error-checking and made sed expression nicer

1
  • 1
    Thank you for your answer. I agree that your chain of commands is less error-prone then mine, although my original intent was to look for a cleaner or an official method. Apparently that doesn't exist :)
    – netvope
    Oct 26, 2013 at 20:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .