# dpkg-query(1) - man - phpMan

[dpkg-query(1)](https://www.chedong.com/phpMan.php/man/dpkg-query/1/markdown)                                dpkg suite                                [dpkg-query(1)](https://www.chedong.com/phpMan.php/man/dpkg-query/1/markdown)



## 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.

## COMMANDS
### -l --list
           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.  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. Please refer to [**dpkg**(1)](https://www.chedong.com/phpMan.php/man/dpkg/1/markdown) 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
           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.

### -s --status
           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
           List files installed to your system from _package-name_. When multiple _package-name_s 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.

           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_ (since dpkg 1.16.5).  These
           can be used as input arguments to **--control-show**.

       **--control-show** _package-name_ _control-file_
           Print the _control-file_ installed to your system from _package-name_ to the standard output
           (since dpkg 1.16.5).

### -c --control-path
           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.

### -S --search
           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:


             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
           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
       **--admindir=**_dir_
           Change the location of the **dpkg** database. The default location is _/var/lib/dpkg_.

       **--root=**_directory_
           Set the root directory to _directory_, which sets the administrative directory to
           «_directory_/var/lib/dpkg» (since dpkg 1.21.0).

### --load-avail
           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).

### --no-pager
           Disables the use of any pager when showing information (since dpkg 1.19.2).

### -f --showformat=
           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:

           **\n** newline
           **\r** carriage return
           **\t** tab

           “**\**” 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 _field_s 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**
           **Enhances**
           **Protected**
           **Essential**
           **Filename** (internal, front-end related)
           **Homepage**
           **Installed-Size**
           **MD5sum** (internal, front-end related)
           **MSDOS-Filename** (internal, front-end related)
           **Maintainer**
           **Origin**
           **Package**
           **Pre-Depends**
           **Priority**
           **Provides**
           **Recommends**
           **Replaces**
### Revision (obsolete)
           **Section**
           **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**
               It contains the binary package name with a possible architecture qualifier like
               “libc6:amd64” (since dpkg 1.16.2).  An architecture qualifier will be present to make
               the package name unambiguous, for example if the package has a **Multi-Arch** field with
               a value of **same** or the package is of a foreign architecture.

           **binary:Synopsis**
               It contains the package short description (since dpkg 1.19.1).

           **binary:Summary**
               This is an alias for **binary:Synopsis** (since dpkg 1.16.2).

           **db:Status-Abbrev**
               It contains the abbreviated package status (as three characters), such as “ii ” or
               “iHR” (since dpkg 1.16.2).  See the **--list** command description for more details.

           **db:Status-Want**
               It contains the package wanted status, part of the Status field (since dpkg 1.17.11).

           **db:Status-Status**
               It contains the package status word, part of the Status field (since dpkg 1.17.11).

           **db:Status-Eflag**
               It contains the package status error flag, part of the Status field (since dpkg
               1.17.11).

           **db-fsys:Files**
               It contains the list of the package filesystem entries separated by newlines (since
               dpkg 1.19.3).

           **db-fsys:Last-Modified**
               It contains the timestamp in seconds of the last time the package filesystem entries
               were modified (since dpkg 1.19.3).

           **source:Package**
               It contains the source package name for this binary package (since dpkg 1.16.2).

           **source:Version**
               It contains the source package version for this binary package (since dpkg 1.16.2)

           **source:Upstream-Version**
               It contains the source package upstream version for this binary package (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.

       **1**   The requested query failed either fully or partially, due to no file or package being
           found (except for **--control-path**, **--control-list** and **--control-show** were such errors are
           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.

## ENVIRONMENT
### External environment
       **SHELL**
           Sets the program to execute when spawning a command via a shell (since dpkg 1.19.2).

       **PAGER**
       **DPKG**___**PAGER**
           Sets the pager command to use (since dpkg 1.19.1), which will be executed with «**$SHELL**
           **-c**».  If **SHELL** is not set, «**sh**» will be used instead.  The **DPKG**___**PAGER** overrides the **PAGER**
           environment variable (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 (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**___**COLORS**
           Sets the color mode (since dpkg 1.18.5).  The currently accepted values are: **auto**
           (default), **always** and **never**.

### Internal environment
       **LESS**
           Defined by **dpkg-query** to “**-FRSXMQ**”, if not already set, when spawning a pager (since dpkg
           1.19.2).  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"**.

## SEE ALSO
       [**dpkg**(1)](https://www.chedong.com/phpMan.php/man/dpkg/1/markdown).



1.21.1                                       2025-09-09                                [dpkg-query(1)](https://www.chedong.com/phpMan.php/man/dpkg-query/1/markdown)
