File Explorer

/proc/self/root/proc/self/root/usr/share/doc/rpm

This explorer reads the filesystem of the server it runs on, so /workspace/user isn't present here. Browsing and the terminal still work against this server's own disk from /.

queryformat5.5 KB · 161 lines
/*! \page queryformat Query formats As it is impossible to please everyone with one style of query output, RPMallows you to specify what information should be printed during a queryoperation and how it should be formatted. \section queryformat_tags Tags All of the information a package contains, apart from signatures and theactual files, is in a part of the package called the header. Each pieceof information in the header has a tag associated with it which allowsRPM to to tell the difference between the name and description of apackage. To get a list of all of the tags your version of RPM knows about, run thecommand 'rpm --querytags'. It will print out a list like (but much longerthen) this: \verbatim    BUILDHOST    BUILDTIME    DESCRIPTION    EPOCH    INSTALLTIME    NAME    RELEASE    SIZE    SUMMARY    VERSION\endverbatim Each of these tags also has a version with a RPMTAG_ prefix, such asRPMTAG_NAME. You can use this tags with or without the RPMTAG_ prefix. A tag can consist of one element or an array of elements. Each element canbe a string or number only. \section queryformat_format Query Formats A query format is passed to RPM after the --queryformat argument, and normallyshould be enclosed in quotes. This query format is then used to printthe information section of a query. The query format is similar to a C style printf string, which the printf(2)man page provides a good introduction to. However, as RPM already knows thetype of data that is being printed, you must omit the type specifier. Inits place put the tag name you wish to print enclosed in curly braces({}). For example, the following RPM command prints the names and sizesof all of the packages installed on a system: \verbatim    rpm -qa --queryformat "%{NAME} %{SIZE}\n"\endverbatim If you want to use printf formatters, they go between the % and {. Tochange the above command to print the NAME in the first 30 bytes andright align the size to, use: \verbatim    rpm -qa --queryformat "%-30{NAME} %10{SIZE}\n"\endverbatim \section queryformat_arrays Arrays RPM uses many parallel arrays internally. For example, file sizes and file names are kept as an array of numbers and an array of stringsrespectively, with the first element in the size array correspondingto the first element in the name array.  To iterate over a set of parallel arrays, enclose the format to be usedto print each item in the array within square brackets ([]). For example,to print all of the files and their sizes in the slang-devel packagefollowed by their sizes, with one file per line, use this command: \verbatim    rpm -q --queryformat "[%-50{FILENAMES} %10{FILESIZES}\n]" slang-devel\endverbatim Note that since the trailing newline is inside of the square brackets, onenewline is printed for each filename. A popular query format to try to construct is one that prints thename of a package and the name of a file it contains on one line, repeated for every file in the package. This query can be very usefulfor passing information to any program that's line oriented (such asgrep or awk). If you try the obvious, \verbatim    rpm -q --queryformat "[%{NAME} %{FILENAMES}\n]" cdp\endverbatim you'll see RPM complain about an "array iterator used with differentsized arrays". Internally, all items in RPM are actually arrays, so theNAME is a string array containing one element. When you tell RPM to iterateover the NAME and FILENAMES elements, RPM notices the two tags havedifferent numbers of elements and complains. To make this work properly, you need to tell RPM to always print the firstitem in the NAME element. You do this by placing a '=' before the tagname, like this: \verbatim    rpm -q --queryformat "[%{=NAME} %{FILENAMES}\n]" cdp\endverbatim which will give you the expected output. \verbatim    cdp /usr/bin/cdp    cdp /usr/bin/cdplay    cdp /usr/man/man1/cdp.1\endverbatim \section queryformat_formatting Formatting Tags One of the weaknesses with query formats is that it doesn't recognizethat the INSTALLTIME tag (for example) should be printed as a date insteadof as a number. To compensate, you can specify one of a few differentformats to use when printing tags by placing a colon followed the formatting name after the tag name. Here are some examples: \verbatim    rpm -q --queryformat "%{NAME} %{INSTALLTIME:date}\n" fileutils    rpm -q --queryformat "[%{FILEMODES:perms} %{FILENAMES}\n]" rpm    rpm -q --queryformat \	"[%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}\n]" \	vlock\endverbatim The :shescape may be used on plain strings to get a string which can passthrough a single level of shell and give the original string. Formatting names "humansi" and "humaniec" display a number in a humanreadable format in SI resp IEC 80000 standard.humansi uses 1K = 1000, 1M = 1000000, ...humaniec uses 1K = 1024, 1M = 1048576, ... The formatting tags are documented in rpm (8) manual in the QUERY OPTIONSsection. \section queryformat_expressions Query Expressions Simple conditionals may be evaluated through query expressions. Expressionsare delimited by %|...|. The only type of expression currently supportedis a C-like ternary conditional, which provides simple if/then/elseconditions. For example, the following query format display "present" ifthe SOMETAG tag is present, and "missing" otherwise: \verbatim    %|SOMETAG?{present}:{missing}|\endverbatim Notice that the subformats "present" and "missing" must be inside of curlybraces. \verbatim    rpm -qa --queryformat "%-30{NAME} %|PREINPROG?{%{PREINPROG}}:{no}|\n"\endverbatim */