LinuxCommandLibrary

apt-file

Find package containing a specific file

TLDR

Update the metadata database

$ sudo apt update
copy

Search for packages that contain the specified file or path
$ apt-file [search|find] [path/to/file]
copy

List the contents of a specific package
$ apt-file [show|list] [package]
copy

Search for packages that match the regex
$ apt-file [search|find] [[-x|--regexp]] [regex]
copy

SYNOPSIS

apt-file [options] command [arguments]

Common commands:
apt-file [options] update
apt-file [options] search pattern
apt-file [options] list package
apt-file [options] show package

PARAMETERS

-a, --case-insensitive
    Perform case-insensitive matching for the pattern.

--architecture=
    Specify a particular architecture to search for files within (e.g., amd64, i386).

--force-all-architectures
    Force searching all architectures, ignoring the default architecture.

--force-specific-architecture
    Force searching only the specified architecture, ignoring other architecture configurations.

-c, --config-file=
    Specify an alternative configuration file for apt-file.

-e, --regexp
    Treat the search pattern as a regular expression. This is the default for 'search'.

-f, --from-file=
    Read patterns from the specified file, one per line.

-i, --ignore-missing
    Do not complain if the local cache for a repository is missing.

-l, --long
    Show full path, package name, and architecture for results.

-o, --option
    Set a configuration option (e.g., 'apt-file::Dir::Cache=/tmp/cache').

-s, --show-description
    Display the package description along with the search results.

-v, --verbose
    Enable verbose output, showing more details about operations.

-x, --fixed-string
    Perform an exact match on the pattern, disabling regular expression interpretation.

DESCRIPTION

apt-file is a command-line utility used to search for files contained within packages available in Debian/Ubuntu-based APT repositories. Unlike dpkg -S, which searches only installed packages, apt-file searches packages that are not yet installed on your system. It relies on a local cache of package contents, which must be updated periodically using sudo apt-file update. This tool is invaluable for tasks such as identifying which package provides a specific header file, a shared library, or a configuration file, especially when debugging compilation errors or missing dependencies. It can search by exact filename, by pattern, and provides options to list all files in a specific package.

CAVEATS

Requires a local cache of package contents, which must be updated regularly using sudo apt-file update. If the cache is stale or missing, apt-file will not function correctly or provide outdated results.
The search results reflect packages available in your APT repositories, not necessarily packages currently installed on your system.
The initial apt-file update can be time-consuming and consume significant disk space, as it downloads package content lists from all configured repositories.

UPDATING THE CACHE

Before using apt-file for the first time, or after adding new repositories or running apt update, it is crucial to update its local cache. This is done via sudo apt-file update. This command downloads and processes package lists, building an index of all files contained within available packages from your APT sources. Regular updates are recommended to keep the cache synchronized with the repositories, ensuring accurate and up-to-date search results.

COMMON USE CASES

apt-file is extremely useful for:
- Identifying which package provides a specific header file (e.g., apt-file search stdio.h).
- Finding the package containing a shared library (e.g., apt-file search libssl.so.1.1).
- Determining which package a specific command or configuration file belongs to (e.g., apt-file search apache2.conf).
- Listing all files contained within a specific package (e.g., apt-file list vim).

HISTORY

apt-file was developed to fill a crucial gap in the APT ecosystem, providing a convenient way to search for files within uninstalled packages, a feature not natively offered by apt or dpkg for uninstalled packages. It offers similar functionality to rpm -qf on RPM-based systems but tailored for Debian/Ubuntu's APT. Its development is closely tied to the Debian and Ubuntu communities, aiming to provide a more comprehensive package management experience. It has become a standard and indispensable tool for system administrators and developers working with Debian-based distributions.

SEE ALSO

dpkg-query(1), apt-cache(8), apt(8), find(1)

Copied to clipboard