Linux apt-file command

Updated: 05/04/2019 by Computer Hope
apt-file command

On Linux operating systems that use the APT package management system, the apt-file command searches available packages for a specific file or files. The packages do not need to be installed to perform the search.

Description

The apt-file tool can list, and search for, individual files in the software packages used by APT. It's similar to using dpkg -L, but apt-file can search all available packages, not just the ones already installed. It accomplishes this by maintaining a local cache of package contents.

Installing apt-file

If apt-file is not already installed on your system, you can install it with the command:

sudo apt update && sudo apt install apt-file

After installation, you will receive a message about creating the apt-file cache:

The system-wide cache is empty. You may want to run 'apt-file update'
as root to update the cache. You can also run 'apt-file update' as
normal user to use a cache in the user's home directory.

You may also receive a notification window:

Apt-file notification window

To update your user cache, click Run this action now, and then Close.

Apt-file update

Or, in a terminal you can run:

sudo apt-file update && apt-file update

To update both the system-wide cache and your user cache.

When the update is complete, you are ready to use apt-file.

Syntax

apt-file [options] [action] [pattern]
apt-file -f [options] search [file...]
apt-file -D [options] search [debian-package-name.deb...]

Actions

find The same as search.
list List all the files contained in packages whose names match pattern. One file per line is listed.
purge Clear "Contents-" files from the apt-file cache directory. If you receive any errors listing or searching, it's a good idea to perform a purge and then an update.
search Search for a file, whose name matches pattern, inside all available packages. Directory names are not searched, only file names.
show The same as list.
update Update apt-file's user cache of package contents from all configured APT sources.

Options

-a arch,
--architecture arch
Different packages exist for different computer architectures. Use this option to specify which architecture's packages should be searched.
-c cache-dir,
--cache cache-dir
Set the cache directory to cache-dir, instead of the default. If you run apt-file as a regular user, the default cache directory is $HOME/.cache/apt-file/. If you run apt-file as root, or if your user cache does not exist, the default cache directory is /var/cache/apt/apt-file/.
-d mnt-point,
--cdrom-mount mnt-point
Use mnt-point as a CD-ROM mount point for reading package information.
-D,
--from-deb
When this option is specified with the search action, apt-file reads the contents of a specific Debian package file, debian-package-file.deb, as the search pattern. This can be useful if you need to compare the contents of a broken package. This option implies -F.
-f,
--from-file
Read the search pattern from the given file or files, one per line. To read patterns from standard input, use a single dash ("-") as the file name.
-F,
--fixed-string
Interpret all search pattern characters literally. Use this to match pattern exactly.
-i,
--ignore-case
Treat uppercase and lowercase letters the same when matching the search pattern.
-l,
--package-only
Only display the package names, and omit file names.
-N,
--non-interactive
If using one of the connection methods listed in the interactive value in the configuration file, skip all interactive prompts. This is useful when running apt-file in non-interactive modes such as a cron job.
-s sources.list,
--sources-list sources.list
Use a custom list of APT sources. The default APT sources.list is often located at /etc/apt/sources.list.
-v,
--verbose
Display additional information when running.
-x,
--regexp
Treat the pattern as a perl regular expression.
-y,
--dummy
Run in "dummy" mode — simulate all actions. For instance, apt-file -y update downloads nothing and creates no cache files, but still examines existing caches and returns some output.
-h,
--help
Display a brief help message, summarizing actions and options.
-- The special option of two dashes ("--") indicates the end of options. This is necessary if your search pattern begins with a dash.

Examples

apt-file purge

Purge the user cache. An apt-file update will be needed before a search can be performed on the user cache. If the user cache doesn't exist, the system-wide cache can be used for user searches.

apt-file update

Download information from sources, and create or update the user cache.

sudo apt-file purge

Purge the system-wide cache. sudo apt-file update is required before the systemwide cache can be used.

sudo apt-file update

Download information from sources, and create or update the system-wide cache.

apt-file search gimp

Show every file with "gimp" in its name, in every available APT package.

apt-file --package-only search gimp

Perform the same search as above, but list only the names of matching packages.

apt-file list gimp

List every file contained in every package with "gimp" in its name.

apt-file --package-only list gimp

Perform the same search as above, but list only the matching package names. Running this command provides output similar to apt-cache --names-only search gimp.

Relevant files and directories

/etc/apt/apt-file.conf The default apt-file configuration file.
/var/cache/apt/apt-file/ The system-wide apt-file cache.
~/.cache/apt-file/ The user apt-file cache.
/etc/apt/sources.list[.d] The default APT sources list.

apt — A unified APT front end for the command line.
apt-cache — Get information about installed and available APT software packages.
apt-get — Download and install APT software packages.
apt-cache — Change the settings of individual APT software packages.
aptitude — An enhanced APT front end for the terminal.
dpkg — Install, remove, and maintain Debian software packages.