-->
Page 53
Page 54
Table 5.1. Query-mode command syntax and options.
rpm -q (or --query) | Options | |
Package Selection Options | Section | pkg1...pkgN |
Query installed package(s) | 5.2.1.1 | -p <file> (or -) |
Query package file <file> (URLs are usable) | 5.2.1.4 | -f <file> |
Query package owning <file> | 5.2.1.3 | -a |
Query all installed packages | 5.2.1.2 | --whatprovides <x> |
Query packages providing capability <x> | 5.2.1.6 | -g <group> |
Query packages belonging to group <group> | 5.2.1.5 | --whatrequires <x> |
Query packages requiring capability <x> | 5.2.1.7 | |
Information Selection Options | Section | <null> |
Display full package label | 5.2.2 | -i |
Display summary package information | 5.2.2.1 | -l |
Display list of files in package | 5.2.2.2 | -c |
Display list of configuration files | 5.2.2.4 | -d |
Display list of documentation files | 5.2.2.5 | -s |
Display list of files in package, with state | 5.2.2.6 | --scripts |
Display install, uninstall, verify scripts | 5.2.2.10 | --queryformat (or --qf) |
Display queried data in custom format | 5.2.2.11 | --dump |
Display all verifiable information for each file | 5.2.2.9 | --provides |
Display capabilities package provides | 5.2.2.7 | --requires (or -R) |
Display capabilities package requires | 5.2.2.8 | |
General Options | Section | -v |
Display additional information | 5.2.2.3 | -vv |
Display debugging information | 5.2.3 | --root <path> |
Set alternate root to <path> | 5.2.4 | --rcfile <rcfile> |
Set alternate rpmrc file to <rcfile> | 5.2.5 | --dbpath <path> |
Use <path> to find the RPM database | 5.2.6 |
Page 55
One of the nice things about using RPM is that the packages you manage don't end up going into some kind of black hole. Nothing would be worse than to install, upgrade, and erase several different packages and not have a clue as to what's on your system. In fact, RPM's query function can help you get out of sticky situations such as the following:
The list could go on, but you get the idea. The rpm -q command is what you need. If you're the kind of person who doesn't like to have more options than you know what to do with, rpm -q might look imposing. But fear not. Once you have a handle on the basic structure of an RPM query, it'll be a piece of cake.
It becomes easy to construct a query command when you understand the individual parts. First is the -q (you can also use --query, if you like). After all, you need to tell RPM what function to perform, right? The rest of a query command consists of two distinct parts: package selection (or what packages you'd like to query) and information selection (or what information you'd like to see). Let's take a look at package selection first.
The first thing you'll need to decide when issuing an RPM query is what package (or packages) you'd like to query. RPM has several ways to specify packages, so you have quite an assortment to choose from.
5.2.1.1. The Package LabelEarlier chapters discuss RPM's package label, a string that uniquely identifies every installed package. Every label contains three pieces of information:
Page 56
When issuing a query command using package labels, you must always include the package name. You can also include the version and even the release, if you like. The only restrictions are that each part of the package label specified must be complete and that if any parts of the package label are missing, all parts to the right must be omitted as well. This second restriction is just a long way of saying that if you specify the release, you must specify the version as well. Let's look at a few examples.
Say, for instance, you've recently installed a new version of the C libraries, but you can't remember the version number:
# rpm -q libc libc-5.2.18-1 #
In this type of query, RPM returns the complete package label for all installed packages that match the given information. In this example, if version 5.2.17 of the C libraries were also installed, its package label would have been displayed, too.
In this example, we've included the version as well as the package name:
# rpm -q rpm-2.3 rpm-2.3-1 #
Note, however, that RPM is a bit picky about specifying package names. Here are some queries for the C library that won't work:
# rpm -q LibC package LibC is not installed # # rpm -q lib package lib is not installed # # rpm -q "lib*" package lib* is not installed # # rpm -q libc-5 package libc-5 is not installed # # rpm -q libc-5.2.1 package libc-5.2.1 is not installed #
As you can see, RPM is case sensitive about package names and cannot match partial names, version numbers, or release numbers. Nor can it use the wildcard characters we've come to know and love. As we've seen, however, RPM can perform the query when more than one field of the package label is present. In this case, rpm -q libc-5.2.18, or even rpm -q libc-5.2.18-1 would have found the package, libc-5.2.18-1.