dpkg-query - a tool to query the dpkg database
| Use Case | Command | Description |
|---|---|---|
| 📋 List all packages | dpkg-query -l | List all known packages |
| 🔍 Search by pattern | dpkg-query -l 'libc6*' | List packages matching pattern |
| 📊 Show package status | dpkg-query -s package-name | Report status of specified package |
| 📁 List installed files | dpkg-query -L package-name | List files from package |
| 🔎 Search file ownership | dpkg-query -S filename | Find which package owns a file |
| 📄 Show package details | dpkg-query -p package-name | Display details from available database |
| 🎨 Custom output format | dpkg-query -W --showformat=... | Show packages with custom format |
| 📦 List control files | dpkg-query --control-list package-name | List control files from package |
dpkg-query [option...] command
dpkg-query is a tool to show information about packages listed in the dpkg database.
List all known packages matching one or more patterns, regardless of their status, which 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. Please note you will probably have to quote package-name-pattern to prevent the shell from performing filename expansion.
Example:
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:
Package status:
Error flags:
An uppercase status or error letter indicates the package is likely to cause severe problems. Please refer to 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.
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 having the name (extended with the architecture qualifier for Multi-Arch same packages) and installed version of the package, separated by a tab.
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.
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:
Hint: When machine parsing the output, it is customary to set the locale to C.UTF-8 to get reproducible results.
This command will not list extra files created by maintainer scripts, nor will it list alternatives.
List control files installed to your system from package-name (since dpkg 1.16.5). These can be used as input arguments to --control-show.
Print the control-file installed to your system from package-name to the standard output (since dpkg 1.16.5).
List paths for control files installed to your system from package-name (since dpkg 1.15.4). 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, please 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.
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 '*[?/' 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 '*[?\', then it will 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:
or for local diversions:
Hint: When machine parsing the output, it is customary to set the locale to C.UTF-8 to get reproducible results.
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.
Show the usage message and exit.
Show the version and exit.
Change the location of the dpkg database. The default location is /var/lib/dpkg.
Set the root directory to directory, which sets the administrative directory to «directory/var/lib/dpkg» (since dpkg 1.21.0).
Also load the available file when using the --show and --list commands, which now default to only querying the status file (since dpkg 1.16.2).
Disables the use of any pager when showing information (since dpkg 1.19.2).
This option is used to specify the format of the output --show will produce (short option since dpkg 1.13.1). The format is a string that will be output for each package listed.
In the format string, “\” introduces escapes:
“\” 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 will be 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):
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):
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
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-04 17:24 @216.73.216.185
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)