Skip to content

Apt-file

What is apt-file?

  • apt-file queries the Debian package database to locate files contained in packages.
  • Unlike dpkg -L, which only works for installed packages, apt-file can search all available packages in the repositories.
  • Helps find:

  • Which package provides a particular executable, library, or config file.

  • Files in development packages (-dev) for compiling software.
  • Missing headers or libraries when compiling from source.

Installation

=== "Ubuntu / Debian"

```bash
sudo apt update
sudo apt install apt-file
sudo pacman -S apt-file
sudo dnf install apt-file
sudo zypper install apt-file
After installation, **update the package index**:

```bash
sudo apt-file update

This downloads the latest database of files in packages from the repositories.


How to Use apt-file

1. Search for a File Across All Packages

apt-file search filename

Example:

apt-file search /usr/bin/git
  • Lists all packages that provide /usr/bin/git.

2. List Contents of a Package (Even If Not Installed)

apt-file list package_name

Example:

apt-file list curl
  • Shows all files installed by the curl package.

3. Update the apt-file Database

sudo apt-file update
  • Must be done periodically to get the latest repository information.

4. Search with Wildcards or Patterns

apt-file search '*/libssl*.so'
  • Useful for locating libraries, headers, or other files using patterns.

5. Advanced Usage

  • Search only installed packages:
dpkg -S filename
  • Search for executables in PATH using apt-file:
apt-file search bin/program_name
  • Combine with grep for filtering:
apt-file search program | grep 'bin'

Practical Examples

  1. Finding Development Headers
apt-file search zlib.h
  • Tells you which -dev package contains zlib.h so you can install it for compilation.

  • Troubleshooting Missing Binaries

apt-file search /usr/bin/htop
  • If htop isn’t installed, you’ll see which package provides it (htop package).

  • Locating Configuration Files

apt-file search /etc/nginx/nginx.conf
  • Shows which package provides the configuration file.