LinuxCommandLibrary

dpkg-query

Query installed Debian package information

TLDR

List all installed packages

$ dpkg-query [[-l|--list]]
copy

List installed packages matching a pattern
$ dpkg-query [[-l|--list]] '[libc6*]'
copy

List all files installed by a package
$ dpkg-query [[-L|--listfiles]] [libc6]
copy

Show information about a package
$ dpkg-query [[-s|--status]] [libc6]
copy

Search for packages that own files matching a pattern
$ dpkg-query [[-S|--search]] [/etc/ld.so.conf.d]
copy

SYNOPSIS

dpkg-query [option...] command [package-name|pattern ...]

PARAMETERS

--help, -h
    Display usage summary and exit.

--version, -V
    Show version information and exit.

--list, -l [pattern]
    List installed packages matching shell pattern.

--show, -s [package-name]
    Show status and details for packages.

--status [package-name]
    Display package status from database.

--listfiles, -L package-name
    List files installed by package.

--search, -S filename|dir|glob
    Search packages owning specified files.

--listselections
    List selections from dselect/dpkg.

--showselections
    Show package selections.

--audit, --verify
    Verify installed packages for issues.

--print-avail [package-name]
    Print available package info.

--showformat=format
    Custom printf-like output format.

--loadavaildir=dir
    Load Available data from directory.

--loadavailfile=file
    Load Available data from file.

--admindir=dir
    Change dpkg admin directory.

--root=dir
    Override installation root.

--no-pager
    Disable pager for output.

DESCRIPTION

dpkg-query is a command-line utility in Debian and derivatives for querying the local dpkg package database. It retrieves details on installed packages, available packages (from status/available files), file ownership, and more, without modifying the system.

Key uses include listing all installed packages (dpkg-query -l), displaying package status and info (dpkg-query -s pkg), searching which package owns a file (dpkg-query -S /path/to/file), and listing files installed by a package (dpkg-query -L pkg). It supports pattern matching with shell globs and custom output formats via --showformat for scripting.

The tool reads primarily from /var/lib/dpkg/status for installed info and can load Available data from files or directories. It's invaluable for troubleshooting, inventory, and automation, distinguishing it from higher-level tools like apt by focusing solely on low-level dpkg data.

Output can be controlled with pagers, formats resembling printf, and options for security or verification checks. No network access; purely local queries.

CAVEATS

Queries only local dpkg database (/var/lib/dpkg); no remote repo access. Some detailed output requires root. Patterns are shell globs, not regex. Ignores virtual packages unless specified.

FORMAT VARIABLES

Use in --showformat: ${Package}, ${Version}, ${Status}, ${Maintainer}, etc. Full list in man page.

EXAMPLES

dpkg-query -l '*apache*'
List Apache-related packages.
dpkg-query --search /usr/bin/gcc
Find GCC package.
dpkg-query -W -f='${Package} ${Version}\n' '*kernel*'
Script-friendly output.

HISTORY

Introduced with dpkg 1.0 in 1993 as part of Debian's package manager. Evolved with Debian releases; modern versions (1.21+) add JSON-like formats, verification, and chroot support for container use.

SEE ALSO

dpkg(8), dpkg-deb(1), apt-cache(8), apt(8)

Copied to clipboard