9

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"?

4

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.

6
  • 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. 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
  • I believe that it must be made clear that <package> is a virtual package here. Like, editor.
    – x-yuri
    Jun 20 '19 at 15:25
  • @x-yuri for there to be any results, sure, but that's only because a virtual package is a name for which there exists at least one Provides: line in the repository. In the same way as apt-cache search, then, the correct result when there are none is a lack of output - which is what these options provide. There can be concrete and virtual versions of the same package, and I suppose we could enhance these to show the concrete version where it exists, but that's all.
    – Darael
    Jun 20 '19 at 15:42
7

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'
1
  • 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). Feb 28 '12 at 19:14
6
$ 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
$
2
  • 1
    -1 : This only queries installed packages.
    – MoonSweep
    Mar 12 '18 at 18:07
  • @MoonSweep Agree, however it could be useful for some cases.
    – user.dz
    Apr 29 '20 at 20:36
0

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']
$
-1

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
1
  • 1
    -1 : apropos search through manual pages, so this will list only installed commands... Plus, OP wants a list of packages.
    – MoonSweep
    Mar 12 '18 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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