GREP-DCTRL(1)
omg bestie, welcome to GREP-DCTRL(1) โ the Debian user's manual page for the whole grep-dctrl squad. It's giving "grep, but make it Debian control files," and honestly? We're obsessed. ๐
โจ NAME โจ
grep-dctrl,grep-status,grep-available,grep-aptavail,grep-debtagsโ these are the besties that grep Debian control files. Periodt. ๐
๐ธ SYNOPSIS ๐ธ
command --copying|-C | --help|-h | --version|-V
command [options] filter [ file... ]
where command is one of grep-dctrl, grep-status, grep-available, grep-aptavail and grep-debtags.
๐ DESCRIPTION ๐
okay so grep-dctrl is literally the program you call when you need answers like: "What is the Debian package foo?", "Which version of the Debian package bar is now current?", "Which Debian packages does John Doe maintain?", "Which Debian packages are somehow related to the Scheme programming language?", and, with some help, "Who maintain the essential packages of a Debian system?" โ all given a useful input file. ๐
The programs grep-available, grep-status, grep-aptavail and grep-debtags are aliases of (actually, symbolic links to) grep-dctrl. These aliases use as their default input the dpkg(1) available and status files, the apt-cache dumpavail output and the debtags dumpavail output, respectively. ๐ซถ
grep-dctrl is a specialised grep program that is meant for processing any file which has the general format of a Debian package control file, as described in the Debian Policy. These include the dpkg available file, the dpkg status file, and the Packages files on a distribution medium (such as a Debian CD-ROM or an FTP site carrying Debian). No cap. โจ
You must give a filter expression on the command line. The filter defines which kind of paragraphs (aka package records) are output. A simple filter is a search pattern along with any options that modify it. Possible modifiers are --eregex, --field, --ignore-case, --regex and --exact-match, along with their single-letter equivalents. By default, the search is a case-sensitive fixed substring match on each paragraph (in other words, package record) in the input. With suitable modifiers, this can be changed: the search can be case-insensitive and the pattern can be seen as an extended POSIX regular expression. ๐
Filters can be combined to form more complex filters using the connectives --and, --or and --not. Parentheses (which usually need to be escaped for the shell) can be used for grouping. ๐ธ
By default, the full matching paragraphs are printed on the standard output; specific fields can be selected for output with the -s option. ๐
After the filter expression comes zero or more file names. The file name - is taken to mean the standard input stream. The files are searched in order but separately; they are not concatenated together. In other words, the end of a file always implies the end of the current paragraph. ๐
If no file names are specified, the program name is used to identify a default input file. The program names are matched with the base form of the name of the current program (the 0'th command line argument, if you will). ๐
โจ OPTIONS โจ
okay bestie, this is the part where the real power lives ๐ every single flag, no skips, let's go
๐ธ Specifying the search pattern
--pattern=patternโ tell grep-dctrl what pattern to hunt for. ngl you'll barely ever need this one, because you can just hand the pattern over on its own like a normal person. BUT ๐จ if your pattern starts with a dash (-), you have to use this switch, otherwise it gets mistaken for a switch and everything gets weird. periodt.
๐ Modifiers of simple filters
these are the lil' seasonings you sprinkle on a simple filter to change how it matches ๐
-F field,field, ...|--field=field,field, ...โ keep the pattern matching locked to only the fields you name. you can stack multiple field names inside one-Foption and stack multiple-Foptions in one simple filter, and that's totally fine ๐ the search happens across all the fields you named, and the moment any one of them matches, the whole simple filter counts as matching. slay.
a field spec can contain a colon (:). when it does, everything before the colon is the name of the field you're searching in, and everything after the colon is the name of the field whose content gets used if the field you're searching in turns out empty. ๐ซถ
-Pโ cute shorthand for-FPackage. โจ-Sโ cute shorthand for-FSource:Package. โจ-e,--eregexโ treat the pattern of the current simple filter as an extended POSIX regular expression. regex girlies rise ๐-r,--regexโ treat the pattern of the current simple filter as a standard POSIX regular expression.-i,--ignore-caseโ ignore case when matching in the current simple filter. casing? never heard of her ๐-X,--exact-matchโ do an exact match, as opposed to a substring match, in the current simple filter. no half-matches, we're precise here ๐-w,--whole-pkgโ do an extended regular expression match on whole package names, assuming the syntax of inter-package relationship fields such asDepends,Recommends, ... when this flag is on, you don't have to stress about sub-package names like"libpcre3"also matching"libpcre3-dev"๐ญ this flag implies (and is incompatible with)-e.--eqโ do an equality comparison under the Debian version number system. if the pattern, or the field being searched in, isn't a valid Debian version number, the paragraph is treated as not matching. as a special case, this can compare simple nonnegative integers for equality. ๐งฎ--ltโ do a strictly-less-than comparison under the Debian version number system. if the pattern, or the field being searched in, isn't a valid Debian version number, the paragraph is treated as not matching. as a special case, this can compare simple nonnegative integers. ๐งฎ--leโ do a less-than-or-equal comparison under the Debian version number system. if the pattern, or the field being searched in, isn't a valid Debian version number, the paragraph is treated as not matching. as a special case, this can compare simple nonnegative integers. ๐งฎ--gtโ do a strictly-greater-than comparison under the Debian version number system. if the pattern, or the field being searched in, isn't a valid Debian version number, the paragraph is treated as not matching. as a special case, this can compare simple nonnegative integers. ๐งฎ--geโ do a greater-than-or-equal comparison under the Debian version number system. if the pattern, or the field being searched in, isn't a valid Debian version number, the paragraph is treated as not matching. as a special case, this can compare simple nonnegative integers. ๐งฎ
๐ฆ Combining filters
this is where you build the actual logic tree, and honestly? main character energy ๐
-!,--not,!โ match if the following filter does not match. ๐-o,--orโ match if either one or both of the preceding and following filters matches. yes queen, inclusivity ๐ซถ-a,--andโ match if both the preceding and the following filter match. both. not one. both. ๐ฏ( ... )โ parentheses for grouping, bestie ๐ heads up though: you'll need to escape them for most shells. filter modifiers can be placed before the opening parenthesis, and they get treated as if they'd been repeated for every single simple filter inside the parentheses. so you can be lazy and efficient at the same time, iconic.
๐ Output format modifiers
-l,--files-with-matchesโ output only the file names, each on its own line, of the files that contain at least one matching paragraph. this is incompatible with-vand-L, and literally every other output format modifier just gets ignored. ๐-L,--files-without-matchesโ output only the file names, each on its own line, of the files that contain no matching paragraphs. this is incompatible with-vand-l, and again all other output format modifiers get ignored. ๐-s field,field, ...|--show-field=field,field, ...โ show only the body of these fields from the matching paragraphs. the field names must not include any colons or commas (commas are what delimits field names in this option's argument, so yeah). the fields get shown in the order you gave them here. also see-I๐ and note that without the--ensure--dctrloption, if only one field is selected, no paragraph separator is output.-I,--invert-showโ flip the meaning of-s: show only the fields that were not named using a-soption. as an artefact of the implementation, the order of the fields in the original paragraph is not preserved. ๐
A field specification can contain a colon. In such a case, the part up to the colon is taken as the name of the field to be shown, and the part after the colon is taken as the name of the field whose content is to be used if the field to be shown is empty.
-dโ show only the first line of theDescriptionfield from the matching paragraphs. if no-soption is specified, this option also effects-s Description; if there is a-soption but it doesn't include theDescriptionfield name, one gets appended to the option. so theDescriptionfield's location in the output is decided by the-soption, if any, with the last field being the default. ๐-n,--no-field-namesโ suppress field names when showing specified fields, so only their bodies show up. each field is printed in its original form, without the field name, the colon after it, and any whitespace before the start of the body. โจ-v,--invert-matchโ instead of showing all the paragraphs that match, show the ones that don't match. ๐-c,--countโ instead of showing the matching paragraphs (or, with-v, the non-matching ones), show the count of those paragraphs. ๐ข-q,--quiet,--silentโ output nothing to the standard output stream. instead, exit immediately after finding the first match. gone. vanished. silent like a ninja ๐ฅท
๐ง Miscellaneous
--ensure-dctrlโ make sure the output is in dctrl format, specifically that there's always an empty line separating paragraphs. this option is not honored if-nhas been selected, because that option deliberately requests a non-dctrl output format. heads up: in a future version, this option may be made the default behaviour. โ ๏ธ--compatโ override any--ensure-dctrloption given earlier on the command line. ๐ซก--ignore-parse-errorsโ ignore errors while parsing input. a paragraph that can't be parsed is ignored in its entirety, and the next paragraph is assumed to start after the first newline since the location of the error. ๐--debug-optparseโ show how the current command line has been parsed. peek behind the curtain, bestie ๐--errorlevel=levelโ set the log level to level. level is one offatal,important,informationalanddebugโ though that last one may not be available, depending on the compile-time options ๐ these categories are given here in order; every message emitted whenfatalis in effect will also be emitted at theimportanterror level, and so on. the default isimportant.-V,--versionโ print out version information. ๐-C,--copyingโ print out the copyright license. this produces a lot of output, so be sure to redirect or pipe it somewhere, like your favourite pager. no cap, it's long ๐-h,--helpโ print out a help summary. ๐ซถ
โจ EXAMPLES โจ
okay bestie, this is the fun part ๐ โ let's actually do stuff with this thing.
The almost simplest use of this program is to print out the status or available record of a package. In this respect, grep-dctrl is like dpkg -s or dpkg --print-avail. To print out the status record of the package "mixal", do
% grep-status -PX mixal
and to get its available record, use
% grep-available -PX mixal
In fact, you can ask for the record of the "mixal" package from any Debian control file. Say you have the Debian 6.0 CD-ROM's Packages file in the current directory; now you can do a
% grep-dctrl -PX mixal Packages
But grep-dctrl can do more than just emulate dpkg. It can more-or-less emulate apt-cache too! ๐ That program has a search feature that searches package descriptions. But we can do that too:
% grep-available -F Description foo
searches for the string "foo" case-sensitively in the descriptions of all available packages. If you want case-insensitivity, use
% grep-available -F Description -i foo
Truth to be told, apt-cache searches package names too. We can separately search in the names; to do so, do
% grep-available -F Package foo
or
% grep-available -P foo
which is pretty much the same thing. We can also search in both descriptions and names; if a match is found in either, the package record is printed:
% grep-available -P -F Description foo
or
% grep-available -F Package -F Description foo
This kind of search is the exactly same that apt-cache does. ๐
Here's one thing neither dpkg nor apt-cache do. Search for a string in the whole status or available file (or any Debian control file, for that matter) and print out all package records where we have a match. Try
% grep-available dpkg
sometime and watch how thoroughly dpkg has infiltrated Debian. ๐ญ iconic honestly.
All the above queries were based on simple substring searches. But grep-dctrl can handle regular expressions in the search pattern. For example, to see the status records of all packages with either "apt" or "dpkg" in their names, use
% grep-status -P -e 'apt|dpkg'
Now that we have seen all these fine and dandy queries, you might begin to wonder whether it is necessary to always see the whole paragraph. You may be, for example, interested only in the dependency information of the packages involved. Fine. To show the depends lines of all packages maintained by me, do a
% grep-available -F Maintainer -s Depends 'ajk@debian.org'
If you want to see the packages' names too, use
% grep-available -F Maintainer -s Package,Depends \
'ajk@debian.org'
Note that there must be no spaces in the argument to the -s switch. ๐ซถ
More complex queries are also possible. For example, to see the list of packages maintained by me and depending on libc6, do
% grep-available -F Maintainer 'ajk@debian.org' \
-a -F Depends libc6 -s Package,Depends
Remember that you can use other UNIX filters to help you too. Ever wondered who's the most active Debian developer based on the number of source packages being maintained? Easy. You just need to have a copy of the most recent Sources file from any Debian mirror.
% grep-dctrl -n -s Maintainer '' Sources | sort | \
uniq -c | sort -nr
This example shows a neat trick: if you want to selectively show only some field of all packages, just supply an empty pattern. ๐ธ
The term "bogopackage" means the count of the packages that a Debian developer maintains. To get the bogopackage count for the maintainer of dctrl-tools, say
% grep-available -c -FMaintainer \
"`grep-available -sMaintainer -n -PX dctrl-tools`"
Sometimes it is useful to output the data of several fields on the same line. For example, the following command outputs the list of installed packages, sorted by their Installed-Size.
% grep-status -FStatus -sInstalled-Size,Package -n \
"install ok installed" -a -FInstalled-Size --gt 0 \
| paste -sd " \n" | sort -n
Note that there should be exactly 2 spaces in the " \n" string. not one, not three, TWO. ๐
Another usual use-case is looking for packages that have another one as build dependency:
% grep-dctrl -s Package -F Build-Depends,Build-Depends-Indep \
quilt /var/lib/apt/lists/*Sources
These examples cover a lot of typical uses of this utility, but not all possible uses. Use your imagination! โจ The building blocks are there, and if something's missing, let me know.
๐ฉบ DIAGNOSTICS ๐ฉบ
In the absence of errors, the exit code 0 is used if at least one match was found, and the exit code 1 is used if no matches were found. If there were errors, the exit code is 2, with one exception. If the -q, --quiet or --silent options are used, the exit code 0 is used when a match is found regardless of whether there have been non-fatal errors. ๐
These messages are emitted in log levels fatal and important. Additional messages may be provided by the system libraries. This list is incomplete. (ngl, very "we tried our best" energy ๐)
- A pattern is mandatory โ You must specify a pattern to be searched for.
- malformed filter โ No filter was specified, but one is required.
- cannot find enough memory โ More memory was needed than was available. This error may be transient, that is, if you try again, all may go well.
- cannot suppress field names when showing whole paragraphs โ When you do not use the
-sswitch,grep-dctrljust passes the matching paragraphs through, not touching them any way. This means, for example, that you can only use-nwhen you use-s. - inconsistent modifiers of simple filters โ Conflicting modifiers of simple filters were used; for example, perhaps both
-Xand-ewere specified for the same simple filter. - missing
')'in command line โ There were more opening than closing parentheses in the given filter. - no such log level โ The argument to
--errorlevelwas invalid. - too many file names โ The number of file names specified in the command line exceeded a compile-time limit.
- too many output fields โ The argument to
-shad too many field names in it. This number is limited to256. - unexpected
')'in command line โ There was no opening parenthesis that would match some closing parenthesis in the command line.
๐ FILES ๐
/var/lib/dpkg/availableโ The default input file ofgrep-available./var/lib/dpkg/statusโ The default input file ofgrep-status.
๐๏ธ AUTHOR ๐๏ธ
The program and this manual page were written by Antti-Juhani Kaijanaho <gaia@iki.fi>. Bill Allombert <ballombe@debian.org> provided one of the examples in the manual page. (shoutout to both of them fr fr ๐ซถ)
๐ SEE ALSO ๐
Debian Policy Manual. Published as the Debian package debian-policy. Also available in the Debian website.
apt-cache(1), ara(1), dpkg-awk(1), sgrep(1), dpkg(8)
and that's the whole page bestie!! ๐ this lil gem comes to you from the Debian Project, dated 2013-11-26, and it lives in the man pages as GREP-DCTRL(1). go grep something, you're gonna slay ๐
โจ
๐ฆ where this page comes from
- debian bookworm: dctrl-tools 2.24-3+b1 ยท GPL-2.0-or-later
- debian trixie: dctrl-tools 2.24-3+b1 ยท GPL-2.0-or-later
- ubuntu jammy: dctrl-tools 2.24-3build2 ยท GPL-2.0-or-later
- ubuntu noble: dctrl-tools 2.24-3build3 ยท GPL-2.0-or-later
- ubuntu resolute: dctrl-tools 2.24-3build4 ยท GPL-2.0-or-later
- ubuntu stonking: dctrl-tools 2.24-3build4 ยท GPL-2.0-or-later
- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2011 2012, 2013
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms