grep-dctrl
Search Debian control files for packages
SYNOPSIS
grep-dctrl [options] expression [files ...]
PARAMETERS
-F field
Search only in the specified field (e.g., Package, Version)
-s field
Show only the specified field(s) in output
-n
Prefix each line with record number
-N
Prefix with 1-based record number
-v
Invert match (show non-matching records)
-f file
Read additional search fields from file
-P pattern
Use Perl-compatible regex instead of POSIX
-r flags
Regex flags (e.g., i for case-insensitive)
-m count
Stop after matching count records
--exact
Match whole field value exactly
--and
Combine expressions with AND (default)
--or
Combine with OR
--not
Negate the expression
--quoting=style
Output quoting: shell, csv, c, escape
--no-field-names
Omit field names in output
-X chars
Show substring starting after prefix chars
--help
Display usage summary
--version
Show version information
DESCRIPTION
grep-dctrl is a specialized tool from the dctrl-tools package designed to query Debian package database files in control format, such as /var/lib/dpkg/status or /var/lib/apt/lists/*Packages. Unlike standard grep, it understands the structured format of Debian control files, where records consist of multi-line fields separated by blank lines. It allows efficient searching by field name, supports regular expressions, and can output specific fields or counts.
Key features include field-specific searches (-F), showing only certain fields (-s), exact matching, logical operators for complex queries, and options for output formatting like quoting styles. It's invaluable for package maintainers, sysadmins, and users querying installed packages, dependencies, versions, or descriptions without parsing files manually. By default, it searches all fields unless specified otherwise, making it faster and more precise than piping grep through dpkg commands.
CAVEATS
Does not support multi-character field names with -F; assumes standard Debian control format. May be slower on very large files without field restriction. Perl regex (-P) requires Perl compatibility.
COMMON USAGE
grep-dctrl -F Package '^apache' /var/lib/dpkg/status
grep-dctrl -s Maintainer,Version 'Status: install ok' /var/lib/dpkg/status
INPUT FILES
Typically /var/lib/dpkg/status, /var/lib/dpkg/available, or APT Packages lists. Reads from stdin if no files given.
HISTORY
Originally developed by Erik Andersen in 2001 as part of debtags tools, evolved into dctrl-tools by Frank Lichtenheld for Debian. Maintained in Debian since 2004 (version 2.0+), with ongoing updates for new regex features and Debian policy compliance. Widely used in Debian derivatives like Ubuntu.
SEE ALSO
grep(1), pgrep-dctrl(1), dpkg-query(1), dctrl(5)


