-->
Page 57
Querying based on package labels may seem a bit restrictive. After all, you need to know the exact name of a package in order to perform a query on it. But there are other ways of specifying packages.
5.2.1.2. -a: Query All Installed PackagesWant lots of information fast? Using the -a option, you can query every package installed on your system. Here's an example:
# rpm -qa ElectricFence-2.0.5-2 ImageMagick-3.7-2 ... tetex-xtexsh-0.3.3-8 lout-3.06-4 #
On a system installed using RPM, the number of packages can easily be 200 or more; we've deleted most of the output.
The -a option can produce mountains of output, which makes it a prime candidate for piping through the many Linux/UNIX commands available. One of the prime candidates would be a pager such as more, so that the list of installed packages could be viewed a screenful at a time.
Another handy command to pipe rpm -qa's output through is grep. In fact, using grep, it's possible to get around RPM's lack of built-in wildcard processing:
# rpm -qa | grep -i sysv SysVinit-2.64-2 #
In this example, we were able to find the SysVinit package even though we didn't have the complete package name or capitalization.
5.2.1.3. -f <file>: Query the Package Owning <file>How many times have you found a program sitting on your system and wondered what it does? Well, if the program was installed by RPM as part of a package, it's easy to find out. Simply use the -f option. For example, you find a strange program called ls in /bin (okay, it is a contrived example). Wonder what package installed it? It's as easy as this to find out:
# rpm -qf /bin/ls fileutils-3.12-3 #
If you happen to point RPM to a file it didn't install, you'll get a message similar to the following:
# rpm -qf .cshrc file /home/ed/.cshrc is not owned by any package #
Page 58
It's possible that you'll get the not owned by any package message in error. Here's an example of how it can happen:
# rpm -qf /usr/X11/bin/xterm file /usr/X11/bin/xterm is not owned by any package #
As you can see, we're trying to find out what package the xterm program is part of. The first example failed, which might lead you to believe that xterm really isn't owned by any package.
However, let's look at a directory listing:
# ls -lF /usr ... lrwxrwxrwx 1 root root 5 May 13 12:46 X11 -> X11R6/ drwxrwxr-x 7 root root 1024 Mar 21 00:21 X11R6/ ... #
NOTE |
I've truncated the list; normally /usr is quite a bit more crowded than this. |
The key here is the line ending with X11 -> X11R6/. This is known as a symbolic link, or symlink. It's a way of referring to a file (here, a directory file) by another name. In this case, if we used the path /usr/X11 or /usr/X11R6, it shouldn't make a difference. It certainly doesn't make a difference to programs that simply want access to the file. But it does make a difference to RPM because RPM doesn't use the filename to access the file. RPM uses the filename as a key into its database. It would be very difficult, if not impossible, to keep track of all the symlinks on a system and try every possible path to a file during a query.
What to do? There are two options:
# namei /usr/X11/bin/xterm f: /usr/X11/bin/xterm d / d usr l X11 -> X11R6 d X11R6 d bin - xterm #
It's pretty easy to see the X11 to X11R6 symlink. Using this approach you can enter the nonsymlinked path and get the desired results: >
# rpm -qf /usr/X11R6/bin/xterm XFree86-3.1.2-5 #
Page 59
# cd /usr/X11/bin # rpm -qf xterm XFree86-3.1.2-5 #
So if you get a not owned by any package error and you think it might not be true, try one of these approaches.
5.2.1.4. -p <file>: Query a Specific RPM Package FileUntil now, every means of specifying a package to an RPM query focused on packages that had already been installed. While it's certainly very useful to be able to dredge up information about packages that are already on your system, what about packages that haven't yet been installed? The -p option can do that for you.
One situation where this capability would help occurs when the name of a package file has been changed. Because the name of the file containing a package has nothing to do with the name of the package (although by tradition it's nice to name package files consistently), we can use this option to find out exactly what package a file contains:
# rpm -qp foo.bar rpm-2.3-1 #
With one command, RPM gives you the answer. (On most Linux systems, the file command can be used to obtain similar information. See Appendix A, "The Format of the RPM File," for details on how to add this capability to your system's file command.)
The -p option can also use URLs to specify package files. See section 2.2.1 in Chapter 2,
"Using RPM to Install Packages," for more information on using URLs.
There's one last trick up -p's sleeveit can also perform a query by reading a package from standard input. Here's an example:
# cat bother-3.5-1.i386.rpm | rpm -qp - bother-3.5-1 #
We piped the output of cat into RPM. The dash at the end of the command line directs RPM to read the package from standard input.
5.2.1.5. -g <group>: Query Packages Belonging to Group <group>When a package is built, the package builder must classify the package, grouping it with other packages that perform similar functions. RPM gives you the ability to query installed packages based on their groups. For example, there is a group known as Base, which consists of packages