Apt-cache command

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search

Query the apt' package cache. The apt-cache does not manipulate the state of the system but does provide operations to search and generate interesting output from the package metadata. The metadata is acquired and updated via the 'update' command of e.g. apt-get command, so that it can be outdated if the last update is too long ago, but in exchange apt-cache works independently of the availability of the configured sources (e.g. offline). You can get information about installed and installable packages.

apt-cache syntax

apt-cache [options] command
apt-cache [options] show pkg1 [pkg2 ...]
apt-cache [-agipns] [-o=config_string] [-c=config_file] {gencaches | showpkg pkg...  | showsrc pkg...  | stats | dump | dumpavail | unmet | search regex...  |
                 show pkg [{=pkg_version_number | /target_release}]...  | depends pkg [{=pkg_version_number | /target_release}]...  | rdepends pkg [{=pkg_version_number | /target_release}]...  |
                 pkgnames [prefix]  | dotty pkg [{=pkg_version_number | /target_release}]...  | xvcg pkg [{=pkg_version_number | /target_release}]...  | policy [pkg...]  | madison pkg...  |
                 {-v | --version} | {-h | --help}}

apt-cache commands

Most used commands:

  • showsrc - Show source records
  • search - Search the package list for a regex pattern
  • depends - Show raw dependency information for a package
  • rdepends - Show reverse dependency information for a package
  • show - Show a readable record for the package
  • pkgnames - List the names of all packages in the system
  • policy - Show policy settings

apt-cache examples

Let us see some examples of apt-cache command.

Search the APT repositories for a package named htop

You can display a package name and short description:

apt-cache search htop

Sample outputs:

aha - ANSI color to HTML converter
htop - interactive processes viewer
libauthen-oath-perl - Perl module for OATH One Time Passwords
pftools - build and search protein and DNA generalized profiles

You can install a package named htop if found using the apt command:

sudo apt install htop

See dependency information for a package named htop

apt-cache depends htop

Sample outputs:

htop
  Depends: libc6
  Depends: libncursesw5
  Depends: libtinfo5
  Suggests: lsof
  Suggests: strace

Display statics about your cache

apt-cache stats

Sample outputs:

Total package names: 75466 (1,509 k)
Total package structures: 114553 (5,040 k)
  Normal packages: 83191
  Pure virtual packages: 1056
  Single virtual packages: 11056
  Mixed virtual packages: 3907
  Missing: 15343
Total distinct versions: 87703 (7,016 k)
Total distinct descriptions: 145773 (3,499 k)
Total dependencies: 683188/219893 (17.2 M)
Total ver/file relations: 53250 (1,278 k)
Total Desc/File relations: 14701 (353 k)
Total Provides mappings: 21129 (507 k)
Total globbed strings: 166342 (3,701 k)
Total slack space: 8,040 
Total space accounted for: 40.5 M
Total buckets in PkgHashTable: 50503
  Unused: 11332
  Used: 39171
  Utilization: 77.5617%
  Average entries: 2.92443
  Longest: 16
  Shortest: 1
Total buckets in GrpHashTable: 50503
  Unused: 11332
  Used: 39171
  Utilization: 77.5617%
  Average entries: 1.92658
  Longest: 9
  Shortest: 1

See a list of all installed or uninstalled packages

apt-cache pkgnames
apt-cache pkgnames | more
apt-cache pkgnames | less
apt-cache pkgnames | grep 'mariadb'

How Do I List All Available Packages.png

Display info or record for the package named nmap

apt-cache show nmap

Sample outputs:

Package: nmap
Architecture: amd64
Version: 7.60-1ubuntu1
Priority: extra
Section: net
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Security Tools Packaging Team <pkg-security-team@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 23415
Depends: libc6 (>= 2.15), libgcc1 (>= 1:3.0), liblinear3 (>= 2.01+dfsg), liblua5.3-0, libpcap0.8 (>= 0.9.8), libpcre3, libssl1.0.0 (>= 1.0.2~beta3), libstdc++6 (>= 5.2), zlib1g (>= 1:1.1.4)
Recommends: ndiff
Filename: pool/main/n/nmap/nmap_7.60-1ubuntu1_amd64.deb
Size: 5176134
MD5sum: d89dcf5f72e00b5b6f18a70e06dda0d8
SHA1: 84e3dbac3db6c49c29ef08c6be3aea20a129524d
SHA256: 1dbb5599843154386d60b2b11e1485ffeebd4763df3a63a35615f32eebba984a
Homepage: http://nmap.org/
Description-en: The Network Mapper
 Nmap is a utility for network exploration or security auditing. It
 supports ping scanning (determine which hosts are up), many port
 scanning techniques, version detection (determine service protocols
 and application versions listening behind ports), and TCP/IP
 fingerprinting (remote host OS or device identification). Nmap also
 offers flexible target and port specification, decoy/stealth scanning,
 sunRPC scanning, and more. Most Unix and Windows platforms are
 supported in both GUI and commandline modes. Several popular handheld
 devices are also supported, including the Sharp Zaurus and the iPAQ.
Description-md5: bc417f4c1fdba7d8d9b0ca8a2a90b7a8
Supported: 9m