The grep-dctrl program can answer such questions as 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?, 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).
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).
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! 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
% grep-available -P foo
which is pretty much the same thing. We can also search in both descriptions and names; if match is found in either, the package record is printed:
% grep-available -P -F Description foo
% grep-available -F Package -F Description foo
This kind of search is the exactly same that apt-cache
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.
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, interest 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 'email@example.com'
If you want to see the packages' names, too, use
% grep-available -F Maintainer -s Package,Depends \ 'firstname.lastname@example.org'
Note that there must be no spaces in the argument to the -s
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 'email@example.com' \ -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.
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.