apt-file
Find package containing a specific file
TLDR
Update the metadata database
Search for packages that contain the specified file or path
List the contents of a specific package
Search for packages that match the regex
SYNOPSIS
apt-file [options] {update|search|list|show|contents|autoclean|clean} [pattern|package]
PARAMETERS
-c, --cache DIR
Use DIR for cache storage
-D, --deb-path DIR
Search deb files in DIR for local packages
-x, --regex
Treat pattern as regular expression
-F, --from-file FILE
Read search patterns from FILE, one per line
-i, --ignore-case
Ignore case in pattern matching
-l, --list-changes
List only changed package contents
-w, --wildcard
Enable wildcard (*) matching
-y, --yes
Automatically answer 'yes' to prompts
-v, --verbose (-vv)
Increase verbosity (twice for more)
-q, --quiet (-qq)
Reduce output (twice for silent)
--explain
Explain search criteria and results
-h, --help
Display help and exit
-V, --version
Show version information
DESCRIPTION
apt-file is a powerful command-line tool for Debian-based Linux systems like Ubuntu, designed to locate files provided by any package in the APT repositories, even if not installed. It maintains a local database of package contents, enabling quick searches for libraries, headers, binaries, or config files during troubleshooting, compilation, or dependency resolution.
Unlike dpkg -S, which only queries installed packages, apt-file indexes all available packages from configured repositories. This makes it invaluable for scenarios like "which package provides /usr/include/foo.h?" or finding missing shared objects.
Workflow: Install via sudo apt install apt-file, initialize the database with sudo apt-file update (downloads package lists and indexes files, ~100-500MB). Search with apt-file search pattern, where pattern can be a filename, path fragment, or regex (with -x). Results show matching packages and file paths.
Key features include case-insensitive matching (-i), wildcards (-w), multi-pattern from file (-F), and verbose/quiet modes. List package contents with apt-file list pkg or bulk via apt-file contents pkg. Maintenance commands like autoclean remove stale indices, keeping the cache efficient.
It's widely used by developers and sysadmins for rapid package discovery, reducing reliance on web searches or manual repo browsing. Regular updates ensure accuracy as repositories evolve.
CAVEATS
Requires root for update (downloads/indexes repos).
Database grows large (100-500MB+); use autoclean regularly.
Accuracy depends on fresh apt-file update after repo changes.
May miss very new/unindexed packages.
INSTALLATION & SETUP
sudo apt update && sudo apt install apt-file
sudo apt-file update (first run takes time).
COMMON EXAMPLES
apt-file search libcrypto.so — find SSL library.
apt-file list vim — list vim package files.
apt-file -x search 'foo[.]h' — regex header search.
CACHE MANAGEMENT
apt-file autoclean — remove outdated indices.
apt-file clean — delete entire cache.
HISTORY
Developed by Eric Dorland in 2003 for Debian. Integrated into apt-file package, maintained in Debian/Ubuntu repos. Evolved with regex/wildcard support; key tool for pre-APT 1.0 dependency hunting.
SEE ALSO
apt-cache(8), dpkg-query(1), apt(8), dpkg(1), find(1)


