LLMpediaThe first transparent, open encyclopedia generated by LLMs

dpkg-query

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: dpkg Hop 5
Expansion Funnel Raw 53 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted53
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
dpkg-query
Namedpkg-query
AuthorDebian Project
DeveloperDebian Project
Released1995
Operating systemDebian and derivatives
LicenseGNU General Public License
WebsiteDebian Project

dpkg-query dpkg-query is a command-line inspection tool for package information in Debian and its derivatives such as Ubuntu, Linux Mint, and Kali Linux. It provides queries against the local package database maintained by the Debian Project's package management system, complementing installation tools from APT and the core dpkg suite. Administrators use dpkg-query alongside utilities like apt-get, aptitude, Synaptic, and Ubuntu Software Center to audit, script, and report package metadata.

Overview

dpkg-query reads the package status database produced by dpkg and exposes metadata fields defined in the Debian Policy Manual and individual control files such as Package, Version, Architecture, and Maintainer. It enumerates installed, unpacked, and configured package records used by higher-level tools including apt, aptitude, and configuration management systems like Ansible, Puppet, Chef, and SaltStack. The tool is lightweight, written in C, and distributed under the GNU General Public License as part of the base Debian Project toolchain. dpkg-query is complementary to scripting utilities such as bash, Python, and Perl when creating reproducible system inventory reports.

Usage and Options

Common invocations include listing packages, showing control fields, and pattern matching using shell globs or explicit package names. Typical command options mirror dpkg semantics: show, -l, -s, --showformat, and -W. The tool interoperates with terminals and automation tools like systemd, cron, Jenkins, and GitLab CI/CD by returning structured strings for parsing. Administrators often combine dpkg-query with text processors such as grep, awk, sed, and cut to extract specific fields for integration with monitoring services like Nagios, Prometheus, and Zabbix.

Output Formats and Examples

dpkg-query supports default human-readable output and customizable formats via --showformat, allowing tokens that map to control fields such as ${Package}, ${Version}, ${Status}, and ${Architecture}. Example patterns include "%-20s %-10s\n" style formatting suitable for piping into CSV processors or ingestion into databases like PostgreSQL, MySQL, or SQLite. Scripts used in continuous integration pipelines for projects such as Debian Med or Debian Science commonly transform dpkg-query output to JSON via jq wrappers or to YAML for Ansible inventories. Administrators working with containers and runtimes like Docker or LXC use dpkg-query inside images based on Debian or Ubuntu to assert base-image package sets.

Integration with dpkg and APT

dpkg-query reads the same status files updated by dpkg operations such as --install, --remove, and --purge; it does not modify the database and is safe for read-only inspection. Higher-level APT front-ends — apt-get, aptitude, apt — rely on dpkg for actual package unpacking and configuration while consulting dpkg-query for status checks in scripts and hooks. In repository workflows involving reprepro, dak, or apt-ftparchive, dpkg-query can be used on build hosts to verify package control fields and ensure compliance with the Debian Policy Manual and archive signing practices used with debsign and GnuPG.

Exit Codes and Error Handling

dpkg-query follows conventional UNIX exit codes where success returns 0 and failure returns nonzero values. Failures arise from missing status information, malformed control fields, lock contention on dpkg database files, or invalid query formats. When invoked in automation contexts such as systemd units or cron jobs, scripts should inspect both exit code and stderr output to discriminate between no-matches (often treated as success with empty output) and actual errors signaled by messages referencing file access, parsing, or version mismatches against archive metadata. Integrations with orchestration tools like Kubernetes or CI systems must consider transient errno conditions and implement retries or fallbacks.

Implementation and History

dpkg-query originated alongside dpkg in the mid-1990s as part of the packaging infrastructure maintained by the Debian Project. Its implementation in C emphasizes low dependency footprint and direct access to the dpkg status files under /var/lib/dpkg. Over time, its feature set expanded to include customizable output formats and pattern matching driven by developer contributions coordinated through Debian mailing lists and version control in repositories associated with the Debian Project and mirrored on collaborative platforms used by projects such as GNU Project contributors. The tool remains integral to packaging workflows in related distributions including Ubuntu, Kali Linux, Raspbian, and other ecosystems derived from Debian.

Category:Debian