< Previous | Contents | Next >
Querying the Database of Available Packages with apt-cache and apt
The apt-cache command can display much of the information stored in APT’s internal database. This information is a sort of cache since it is gathered from the different sources listed in the sources.list file. This happens during the apt update operation.
VOCABULARY A cache is a temporary storage system used to speed up frequent data access when
VOCABULARY A cache is a temporary storage system used to speed up frequent data access when
Cache
the usual access method is expensive (performance-wise). This concept can be applied
in numerous situations and at different scales, from the core of microprocessors up to high-end storage systems.
In the case of APT, the reference Packages files are those located on Debian mirrors. That said, it would be very ineffective to push every search through the online package databases. That is why APT stores a copy of those files (in /var/lib/apt/lists/) and searches are done within those local files. Similarly, /var/cache/apt/archives/ contains a cached copy of already downloaded packages to avoid downloading them again if you need to reinstall them.
To avoid excessive disk usage when you upgrade frequently, you should regularly sort through the /var/cache/apt/archives/ directory. Two commands can be used for this: apt clean (or apt-get clean) entirely empties the directory; apt autoclean (apt-get autoclean) only removes packages that can no longer be downloaded be- cause they have disappeared from the mirror and are therefore useless. Note that the configuration parameter APT::Clean-Installed can be used to prevent the removal of .deb files that are currently installed. Also, note that apt drops the downloaded files once they have been installed, so this matters mainly when you use other tools.
Cache
The apt-cache command can do keyword-based package searches with apt-cache search key word. It can also display the headers of the package’s available versions with apt-cache show package. This command provides the package’s description, its dependencies, and the name of its maintainer. This feature is particularly useful in determining the packages that are installed via meta-packages, such as kali-linux-wireless, kali-linux-web, and kali-linux-gpu. Note that apt search, apt show, aptitude search, and aptitude show work in the same way.
An Alternative: axi-cache apt-cache search is a very rudimentary tool, basically implementing grep on pack- age’s descriptions. It often returns too many results or none at all, when too many keywords are included. axi-cache search term, on the other hand, provides better results, sorted by rele- vancy. It uses the Xapian search engine and is part of the apt-xapian-index package, which indexes all package information (and more, like the .desktop files from all De- bian packages). It knows about tags and returns results in a matter of milliseconds. | |
$ axi-cache search forensics graphical 5 results found. Results 1-5: 100% autopsy - graphical interface to SleuthKit 82% forensics-colorize - show differences between files using ➥ color graphics 73% dff - Powerful, efficient and modular digital forensic ➥ framework 53% gpart - Guess PC disk partition table, find lost ➥ partitions 46% testdisk - Partition scanner and disk recovery tool, and ➥ PhotoRec file recovery tool |
More terms: colorize partitions file disklabel autopsy
➥ digital differences
More tags: admin::forensics security::forensics role::program
➥ admin::recovery interface::commandline admin::boot
➥ scope::utility
Some features are more rarely used. For instance, apt-cache policy displays the priorities of package sources as well as those of individual packages. Another example is apt-cache dumpa vail, which displays the headers of all available versions of all packages. apt-cache pkgnames displays the list of all the packages that appear at least once in the cache.