How to List All Debian/Ubuntu Packages That Provide a Specific Feature Using dpkg/apt


3 views

In Debian-based systems like Ubuntu, the Provides field in packages indicates virtual packages or features that a package makes available. This mechanism allows multiple packages to satisfy a dependency requirement.


# Example showing the Provides field
$ apt-cache show vim-tiny | grep Provides
Provides: editor

The most straightforward way to find packages providing a specific feature:


# Basic syntax
$ apt-cache search --names-only "^.*$" | xargs -n 1 apt-cache show | grep -B 10 "Provides: editor"

# More efficient version
$ apt-cache dumpavail | grep -B 5 -A 1 "Provides: editor"

For installed packages only, use dpkg-query:


$ dpkg-query -W -f='${Package} ${Provides}\n' | grep "editor"

Directly parse the dpkg status file for comprehensive results:


$ grep -B 5 -A 1 "Provides: editor" /var/lib/dpkg/status

# For all available packages (including uninstalled)
$ zgrep -h -B 5 -A 1 "Provides: editor" /var/lib/apt/lists/*_Packages

# Find all packages providing any virtual package
$ apt-cache dumpavail | awk '/^Package:/ { pkg=$2 } /^Provides:/ { print pkg, $0 }'

# JSON output format
$ apt-cache dumpavail | awk '/^Package:/ { pkg=$2 } /^Provides:/ { print "{\"package\":\"" pkg "\",\"provides\":\"" $0 "\"}" }' | jq -s .

For frequent queries, consider building a local cache:


# Create a provides index file
$ mkdir -p ~/.cache/apt_provides
$ apt-cache dumpavail | awk '/^Package:/ { pkg=$2 } /^Provides:/ { for (i=2;i<=NF;i++) print $i, pkg }' > ~/.cache/apt_provides/index

# Query the cache
$ grep "^editor " ~/.cache/apt_provides/index

For more user-friendly output, consider these alternatives:


# Using aptitude
$ aptitude search '?provides(editor)'

# Using wajig
$ wajig what-provides editor

In Debian-based systems like Ubuntu, the Provides field in packages indicates virtual packages or features that multiple packages can satisfy. For example, many text editors can provide the editor virtual package.

The most straightforward way is using apt-cache with the --installed flag for local packages:

apt-cache search --names-only "editor" | grep -i "editor"

Or for a more precise search of all packages providing a feature:

apt-cache --no-generate showpkg "editor" | grep -A 100 "Reverse Provides"

For installed packages only, use dpkg-query with a custom format:

dpkg-query -W -f='${Package} ${Provides}\n' | grep "editor"

The -f flag specifies a custom output format showing both package names and their provides.

For more comprehensive results including uninstalled packages:

apt-file search --package-only --regexp '/var/lib/dpkg/status|Provides:.*editor'

First install apt-file if needed:

sudo apt install apt-file
apt-file update

Let's say you want to find all packages providing editor functionality:

apt-cache search --names-only "editor" | sort

Sample output might include:

emacs-nox - GNU Emacs editor (without X support)
nano - small, friendly text editor inspired by Pico
vim-tiny - Vi IMproved - enhanced vi editor - compact version

For better formatted output, use this awk command:

dpkg-query -W -f='${Package}\t${Provides}\n' | awk -F'\t' '$2 ~ /editor/ {print $1}'

For large systems, the dpkg-query method is faster as it doesn't require network access. However, apt-cache provides more complete results including uninstalled packages.