Product SiteDocumentation Site

4.2.10.4. Special Formatting

Some of the tags within an RPM package header contain special binary information that usually makes no sense when printed out. To help with these header tags, you can use special RPM formatting options, using a syntax like the following:
%{tag:special_format}
For example, to print the INSTALLTIME tag, use %{INSTALLTIME:date}, which specifies to print the INSTALLTIME tag in date format. For example:
$ rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE} %{INSTALLTIME:date}\n" jikes
jikes-1.18-1 Fri 06 Dec 2002 09:19:30 PM CST
This example prints the NAME-VERSION-RELEASE of the package, along with the INSTALLTIME in date format.
Most tags in a header are optional. You can print the value of these tags, but you may get nothing. To help deal with this, you can use a conditional operator based loosely on the C language ternary operator. The basic syntax is:
%|tag?{print_if_present}:{print_if_absent}|
With the normal %{tag} syntax, this conditional syntax gets complicated really fast. You need to break the elements down. For example:
$ rpm -q --qf "%{NAME} %|EPOCH?{%{EPOCH}}:{(no Epoch)}|\n" perl
perl 1
If the package has a value for the EPOCH tag, you will see output as shown in this example. Most packages do not have an EPOCH defined, in which case, you will see output like the following:
RPM files likely hold packages that are not installed. If you query one of these packages, you will get the alternative text, as shown following:
$ rpm -q --qf "%{NAME} %|EPOCH?{%{EPOCH}}:{(no Epoch)}|\n" sendmail
sendmail (no Epoch)
Cross Reference
See the "Getting Information on Package Files" section in this chapter for more on querying RPM package files.
Other special-formatting options are described in the following section on the dependency and file information tags.