dpkg-query(1)

๐Ÿฆ‹ dpkg-query(1) ๐Ÿฆ‹

okay bestie, this is the dpkg-query(1) page from the dpkg suite manual โ€” yes, the whole vibe is โ€œletโ€™s peek inside the dpkg database togetherโ€ ๐Ÿ’–

โœจ NAME โœจ

dpkg-query โ€” a tool to query the dpkg database

๐ŸŒธ SYNOPSIS ๐ŸŒธ

dpkg-query [option...] command

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

dpkg-query is a tool to show information about packages listed in the dpkg database. Thatโ€™s it, thatโ€™s the whole mission, and itโ€™s lowkey iconic.

๐Ÿ’… COMMANDS ๐Ÿ’…

  • -l, --list [package-name-pattern...] โ€” List all known packages matching one or more patterns, regardless of their status. This includes any real or virtual package referenced in any dependency relationship field (such as Breaks, Enhances, etc.). If no package-name-pattern is given, list all packages in /var/lib/dpkg/status, excluding the ones marked as not-installed (i.e. those which have been previously purged). Normal shell wildcard characters are allowed in package-name-pattern. Note you will probably have to quote package-name-pattern to prevent the shell from performing filename expansion. For example this will list all package names starting with โ€œlibc6โ€:
dpkg-query -l 'libc6*'

The first three columns of the output show the desired action, the package status, and errors, in that order. โœจ

  • Desired action:
    • u = Unknown
    • i = Install
    • h = Hold
    • r = Remove
    • p = Purge
  • Package status:
    • n = Not-installed
    • c = Config-files
    • H = Half-installed
    • U = Unpacked
    • F = Half-configured
    • W = Triggers-awaiting
    • t = Triggers-pending
    • i = Installed
  • Error flags:
    • <empty> = (none)
    • R = Reinst-required

An uppercase status or error letter indicates the package is likely to cause severe problems. See dpkg(1) for information about the above states and flags.

The output format of this option is not configurable, but varies automatically to fit the terminal width. It is intended for human readers, and is not easily machine-readable. See -W (--show) and --showformat for a way to configure the output format.

  • -W, --show [package-name-pattern...] โ€” Just like the --list option this will list all packages matching the given patterns. However the output can be customized using the --showformat option.

The default output format gives one line per matching package, each line consisting of the package name and its installed version, separated by a tab. The package name will be architecture qualified for packages with a Multi-Arch field with the value same or with a foreign architecture, which is an architecture that is neither the native one nor all.

  • -s, --status [package-name...] โ€” Report status of specified packages. This just displays the entry in the installed package status database. If no package-name is specified it will display all package entries in the status database (since dpkg 1.19.1). When multiple package-name entries are listed, the requested status entries are separated by an empty line, with the same order as specified on the argument list.
  • -L, --listfiles package-name... โ€” List files installed to your system from package-name. When multiple package-names are listed, the requested lists of files are separated by an empty line, with the same order as specified on the argument list.

Each file diversion is printed on its own line after its diverted file, prefixed with one of the following localized strings:

locally diverted to: diverted-to
package diverts others to: diverted-to
diverted by pkg to: diverted-to

Hint: When machine parsing the output, it is customary to set the locale to C.UTF-8 to get reproducible results. On some systems this might also require adapting the LANGUAGE environment variable appropriately if it is already set (see locale(7)).

This command will not list extra files created by maintainer scripts, nor will it list alternatives.

  • --control-list package-name โ€” List control files installed to your system from package-name. These can be used as input arguments to --control-show.

Supported since dpkg 1.16.5.

  • --control-show package-name control-file โ€” Print the control-file installed to your system from package-name to the standard output.

Supported since dpkg 1.16.5.

  • -c, --control-path package-name [control-file] โ€” List paths for control files installed to your system from package-name. If control-file is specified then only list the path for that control file if it is present.
Warning: This command is deprecated as it gives direct access to the internal dpkg database, switch to use --control-list and --control-show instead for all cases where those commands might give the same end result. Although, as long as there is still at least one case where this command is needed (i.e. when having to remove a damaging postrm maintainer script), and while there is no good solution for that, this command will not get removed.

Supported since dpkg 1.15.4.

  • -S, --search filename-search-pattern... โ€” Search for packages that own files corresponding to the given patterns. Standard shell wildcard characters can be used in the pattern, where asterisk (*) and question mark (?) will match a slash, and backslash (\) will be used as an escape character.

If the first character in the filename-search-pattern is none of *, [, ?, or / then it will be considered a substring match and will be implicitly surrounded by * (as in *filename-search-pattern*). If the subsequent string contains any of *, [, ?, or \, then it will be handled like a glob pattern; otherwise any trailing / or /. will be removed and a literal path lookup will be performed.

This command will not list extra files created by maintainer scripts, nor will it list alternatives.

The output format consists of one line per matching pattern, with a list of packages owning the pathname separated by a comma (U+002C โ€˜,โ€™) and a space (U+0020 โ€˜ โ€™), followed by a colon (U+003A โ€˜:โ€™) and a space, followed by the pathname. As in:

pkgname1, pkgname2: pathname1
pkgname3: pathname2

File diversions are printed with the following localized strings:

diversion by pkgname from: diverted-from
diversion by pkgname to: diverted-to

or for local diversions:

local diversion from: diverted-from
local diversion to: diverted-to

Hint: When machine parsing the output, it is customary to set the locale to C.UTF-8 to get reproducible results.

  • -p, --print-avail [package-name...] โ€” Display details about packages, as found in /var/lib/dpkg/available. If no package-name is specified, it will display all package entries in the available database (since dpkg 1.19.1). When multiple package-name are listed, the requested available entries are separated by an empty line, with the same order as specified on the argument list.

Users of APT-based frontends should use apt show package-name instead as the available file is only kept up-to-date when using dselect.

  • -?, --help โ€” Show the usage message and exit.
  • --version โ€” Show the version and exit.

โœจ OPTIONS โœจ

okay bestie, this is the part where dpkg-query gets all its little knobs and dials. every single one is here, no skips ๐Ÿ’…

  • --admindir=dir โ€” changes where the dpkg database lives. the default location is /var/lib/dpkg.
  • --root=directory โ€” sets the root directory to directory, which also sets the administrative directory to directory/var/lib/dpkg.

supported since dpkg 1.21.0 โœจ

  • --load-avail โ€” also loads the available file when you use the --show and --list commands, which now default to only querying the status file.

supported since dpkg 1.16.2.

  • --no-pager โ€” disables the use of any pager when showing information.

supported since dpkg 1.19.2.

  • -f, --showformat=format โ€” this one specifies the format of the output that --show will produce. the format is a string that gets output for each package listed. support for the short option -f has been around since dpkg 1.13.1 ๐Ÿซถ

in the format string, \ introduces escapes:

  • \n โ€” newline
  • \r โ€” carriage return
  • \t โ€” tab

a \ before any other character suppresses any special meaning of the following character, which is useful for \ and $.

package information can be included by inserting variable references to package fields using the syntax ${field[;width]}. fields are printed right-aligned unless the width is negative, in which case left alignment is used. the following fields are recognized, but they are not necessarily available in the status file (only internal fields or fields stored in the binary package end up in it):

  • Architecture
  • Bugs
  • Conffiles (internal)
  • Config-Version (internal)
  • Conflicts
  • Breaks
  • Depends
  • Description
  • Description-md5 (internal, front-end related)
  • Enhances
  • Protected
  • Essential
  • Filename (internal, front-end related)
  • Homepage
  • Installed-Size
  • MD5sum (internal, front-end related)
  • Maintainer
  • Multi-Arch
  • Origin
  • Package
  • Pre-Depends
  • Priority
  • Provides
  • Recommends
  • Replaces
  • Revision (obsolete)
  • Section
  • SHA1 (internal, front-end related)
  • SHA256 (internal, front-end related)
  • SHA512 (internal, front-end related)
  • Size (internal, front-end related)
  • Source
  • Status (internal)
  • Suggests
  • Tag (usually not in .deb but in repository Packages files)
  • Triggers-Awaited (internal)
  • Triggers-Pending (internal)
  • Version

the following are virtual fields, generated by dpkg-query from values from other fields (note that these do not use valid names for fields in control files):

  • binary:Package โ€” contains the binary package name with a possible architecture qualifier like libc6:amd64. an architecture qualifier will be present to make the package name unambiguous, for packages with a Multi-Arch field with the value same or with a foreign architecture, which is an architecture that is neither the native one nor all.

supported since dpkg 1.16.2.

  • binary:Synopsis โ€” contains the package short description.

supported since dpkg 1.19.1.

  • binary:Summary โ€” this is an alias for binary:Synopsis.

supported since dpkg 1.16.2.

  • db:Status-Abbrev โ€” contains the abbreviated package status (as three characters), such as ii or iHR. see the --list command description for more details.

supported since dpkg 1.16.2.

  • db:Status-Want โ€” contains the package wanted status, part of the Status field.

supported since dpkg 1.17.11.

  • db:Status-Status โ€” contains the package status word, part of the Status field.

supported since dpkg 1.17.11.

  • db:Status-Eflag โ€” contains the package status error flag, part of the Status field.

supported since dpkg 1.17.11.

  • db-fsys:Files โ€” contains the list of the package filesystem entries separated by newlines.

supported since dpkg 1.19.3.

  • db-fsys:Last-Modified โ€” contains the timestamp in seconds of the last time the package filesystem entries were modified.

supported since dpkg 1.19.3.

  • source:Package โ€” contains the source package name for this binary package.

supported since dpkg 1.16.2.

  • source:Version โ€” contains the source package version for this binary package.

supported since dpkg 1.16.2.

  • source:Upstream-Version โ€” contains the source package upstream version for this binary package.

supported since dpkg 1.18.16.

the default format string is ${binary:Package}\t${Version}\n. actually, all other fields found in the status file (i.e. user defined fields) can be requested, too. they will be printed as-is, though, no conversion nor error checking is done on them. to get the name of the dpkg maintainer and the installed version, you could run:

            dpkg-query -f='${binary:Package} ${Version}\t${Maintainer}\n' \
             -W dpkg

๐Ÿ’– EXIT STATUS ๐Ÿ’–

  • 0 โ€” the requested query was successfully performed. slay โœ…
  • 1 โ€” the requested query failed either fully or partially, due to no file or package being found. exception: --control-path, --control-list, and --control-show treat those errors as fatal ๐Ÿ˜ญ
  • 2 โ€” fatal or unrecoverable error due to invalid command-line usage, or interactions with the system, such as accesses to the database, memory allocations, etc. this is the "bestie what happened" tier ๐Ÿ’€

๐Ÿฆ‹ ENVIRONMENT ๐Ÿฆ‹

External environment

  • SHELL โ€” sets the program to execute when spawning a command via a shell.

supported since dpkg 1.19.2.

  • COLUMNS โ€” sets the number of columns to expect in the --list output, to determine the padding to use, without causing any truncation.

supported since dpkg 1.23.8.

  • PAGER, DPKG_PAGER โ€” sets the pager command to use, which will be executed with $SHELL -c. if SHELL is not set, sh will be used instead.

when non-empty, DPKG_PAGER overrides the PAGER environment variable. if none of the programs pointed by DPKG_PAGER or PAGER are present, the following programs will be tried in order (since dpkg 1.22.12): the default pager more, then less(1), more(1), and finally cat(1).

the cat value is special, and it is equivalent to disabling paging entirely.

support for PAGER since dpkg 1.19.1. support for DPKG_PAGER since dpkg 1.19.2.

  • DPKG_ROOT โ€” if set and the --root option has not been specified, it will be used as the filesystem root directory.

supported since dpkg 1.21.0.

  • DPKG_ADMINDIR โ€” if set and the --admindir option has not been specified, it will be used as the dpkg data directory.
  • DPKG_DEBUG โ€” sets the debug mask from an octal value. the currently accepted flags are described in the dpkg --debug option, but not all these flags might have an effect on this program.

supported since dpkg 1.21.10.

  • DPKG_COLORS โ€” sets the color mode. the currently accepted values are: auto (default), always, and never.

supported since dpkg 1.18.5.

  • DPKG_NLS โ€” if set, it will be used to decide whether to activate Native Language Support, also known as internationalization (or i18n) support. the accepted values are: 0 and 1 (default).

supported since dpkg 1.22.7.

Internal environment

  • LESS โ€” defined by dpkg-query to -FRSXMQ, if not already set, when spawning a pager. to change the default behavior, this variable can be preset to some other value including an empty string, or the PAGER or DPKG_PAGER variables can be set to disable specific options with -+, for example DPKG_PAGER="less -+F".

supported since dpkg 1.19.2.


๐Ÿ”’ SECURITY ๐Ÿ”’

query operations should never require root, and delegating their execution to unprivileged users via some gain-root command can have security implications (such as privilege escalation), for example when a pager is automatically invoked by the tool. bestie, this is the "do not hand random people the keys" section โ€” fr fr ๐Ÿšจ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

that's the whole dpkg-query(1) saga, bestie โ€” page version 1.23.11-dirty, dated 2026-09-09. go touch some grass now ๐ŸŒฑ๐Ÿ’–

๐Ÿ“ฆ where this page comes from