Linux apt-file command
What is apt-file?
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.
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:
To update your user cache, you can click Run this action now, and then Close.
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.
apt-file [options] [action] [pattern]
apt-file -f [options] search [file...]
apt-file -D [options] search [debian-package-name.deb...]
|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.|
|Different packages exist for different computer architectures. Use this option to specify which architecture's packages should be searched.|
|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/.|
|Use mnt-point as a CD-ROM mount point for reading package information.|
|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.|
|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.|
|Interpret all search pattern characters literally. Use this to match pattern exactly.|
|Treat uppercase and lowercase letters the same when matching the search pattern.|
|Only display the package names, and omit file names.|
|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.|
|Use a custom list of APT sources. The default APT sources.list is typically located at /etc/apt/sources.list.|
|Display additional information when running.|
|Treat the pattern as a perl regular expression.|
|Run in "dummy" mode — simulate all actions. For instance, apt-file -y update will download nothing and create no cache files, but will still examine existing caches and return some output.|
|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.|
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.
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 that has "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 that has "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.