Product SiteDocumentation Site

4.2.14. 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:
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" bash
bash-4.1.7-1.fc13 Fri 27 Aug 2010 07:02:33 PM EDT
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:
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 4
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)
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 sections on the dependency and file information tags.