How do I get a list of packages that "Provides" something" using dpkg?

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


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.


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'

$ 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
$