dpkg -l and dpkg -L: Query Installed Packages
dpkg -l lists installed packages with their status and version, and dpkg -L shows the files a package installed.
To assert that CI installed the right version, or to find where a package put its binary, dpkg queries the local database. It is read-only.
What it does
dpkg -l prints the package database: name, version, and a status field (ii means installed, rc means removed but config remains). dpkg -L <pkg> lists every file the package owns, and dpkg -s <pkg> prints its status stanza.
Common usage
dpkg -l | grep -i nginx
dpkg -L nginx # files installed by nginx
dpkg -s nginx # status and version
# machine-readable version string
dpkg-query -W -f='${Version}' nginxOptions
| Command | What it does |
|---|---|
| dpkg -l [pattern] | List installed packages (ii = installed) |
| dpkg -L <pkg> | List files installed by the package |
| dpkg -s <pkg> | Show status and metadata for the package |
| dpkg -S <path> | Find which package owns a file path |
| dpkg-query -W -f=<fmt> | Print a custom, scriptable field format |
In CI
Use dpkg-query -W -f='${Version}' <pkg> in a verify step to assert an exact installed version, since it prints only the value with no header. dpkg -l output columns can wrap on narrow terminals; prefer dpkg-query for parsing.
Common errors in CI
"dpkg-query: no packages found matching <pkg>" means the package is not installed (or the name is wrong). A status of "rc" in dpkg -l means the package was removed but its config remains; purge with dpkg -P if that matters. Parsing dpkg -l with grep can match partial names; anchor the pattern.