Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I see that dpkg has a "Provides" field for packages.

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

How do I know which packages provide i.e. "editor"?

share|improve this question
add comment

5 Answers

up vote 2 down vote accepted

You can achieve the desired effect without aptitude (which appears to be discouraged these days) by using apt-cache showpkg, which includes a listing of Reverse Provides. Piping it through a small sed script will get rid of the other things:

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

A slightly prettier (but longer to type) example (lists package names only, not versions, and sorts them alphabetically) can be achieved with awk:

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

...and this can be piped through uniq to remove duplicates (which may exist due to multiple versions of package being reverse-provides). Note that the use of uniq won't help with the first version, as uniq only removes duplicates if they're on adjacent lines and the sed version doesn't sort the output.

Finally, one can define a function for easier use, as follows:

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

Stick this in (for example) .bashrc, so that it'll load when the shell does, and it becomes possible to run provides <package> to get a package's reverse-provides.

share|improve this answer
    
sort -u will remove the duplicates, so the call to uniq isn't needed. But whatever, nice solution, it's much faster. aptitude will match doom-wad-editor too, so they're no completely equivalent. –  Janus Troelsen Feb 27 '13 at 22:22
    
Ooh, good shout on sort -u. Didn't know that one. I wonder why it doesn't pick up doom-wad-editor...? That's particularly interesting since apt-cache showpkg shows it as having no depends at all. –  Darael Feb 27 '13 at 22:33
    
Ah. Further inspection shows that aptitude's search will match substrings in the Provides: field (thus picking up deutex), where the apt-cache showpkg method uses exact package names. Both, therefore, presumably have their place. –  Darael Feb 27 '13 at 22:37
add comment
$ 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
$
share|improve this answer
add comment

Aptitude provides this functionality as well. So a command like this will show all the packages that provide an editor.

aptitude search '~Peditor'

You can even add other constraints. Like show only installed editors.

aptitude search '~i~Peditor'
share|improve this answer
    
I prefer this because it includes many more packages than the other solutions. My solutions only showed the packages listed with "i" (installed) in the start of the line. This solution also shows lines with "p" (meaning that no trace of the package exists on the system). –  Janus Troelsen Feb 28 '12 at 19:14
add comment

Reading the database directly:

#!/usr/bin/env python3
import sys
import shlex

def whichPkgsProvide(filter,l):
    for pkg in l:
            dic = {}
            pairs = [x.split(": ") for x in pkg.split("\n")]
            for j in pairs:
                    try:
                            dic[j[0]] = j[1]
                    except IndexError:
                            pass

            try:
                    if filter in dic["Provides"]:
                            yield dic["Package"]
            except KeyError:
                    pass


if __name__ == "__main__":
    l = sys.stdin.read().split("\n\n")
    print(list(whichPkgsProvide(sys.argv[1],l)))

Usage:

$ python3 whichPkgsProvide.py editor <  /var/lib/dpkg/available
['vim-gnome', 'nano', 'vim-tiny']
$
share|improve this answer
add comment

base on your example. I can list package provide editor by use 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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.