Software Development

Piping rpm output with the help of grep

In this Daily Feature, Jack Wallen, Jr. uses the Red Hat Package Management System in conjunction with a very powerful search tool (<I>grep</I>) to query the <I>rpm</I> database.

Many times, you’ll need to know the release numbers of a large group of packages on your Linux system. Say, for instance, you're not sure which GNOME you’re running. With the help of rpm, grep, a pipe, and a couple of switches, you can figure this out quickly.

In this Daily Feature, I’ll use the Red Hat Package Management System in conjunction with a very powerful search tool (grep) to query the rpm database. These two commands (rpm and grep) are combined with what is commonly called the pipe (|).

Basics
The command syntax goes something like this:
rpm -qa | grep PACKAGE_NAME

If you take the command apart, you'll see that you are actually using grep to query (the q switch) all (the a switch) of the rpm database for anything that is relevant to PACKAGE_NAME. Although this does not explain the command to its full complexity, you should get the idea.

Example
So, let's say you want to check to see what packages are installed by GNOME. If you run the command
rpm -qa | grep gnome

you may end up with output similar to:
[jwallen@giles jwallen]$ rpm -qa |grep gnome
sawfish-gnome-0.28.1-0_helix_2
gnome-pim-conduits-1.2.0-0_helix_1
gnome-games-devel-1.2.0-0_helix_1
gnome-audio-1.0.0-7
gnome-audio-extra-1.0.0-7
gnome-pim-devel-1.2.0-0_helix_1
gnome-linuxconf-0.23-1
.........

The output has been truncated.
As you can see, every package listed contains the name gnome. This illustrates the obvious limitation to this system—there are packages required by GNOME that do not contain the word gnome. For example, GNOME depends on a large number of libraries, such as the gtk libraries. Within the gtk set, there are the following packages (which you can find by using the command rpm -qa | grep gtk):
[jwallen@giles jwallen]$ rpm -qa | grep gtk
pygtk-libglade-0.6.4-1
rep-gtk-libglade-0.11-0_helix_2
gtk---1.0.3-1
gtk+10-1.0.6-6
rep-gtk-0.11-0_helix_2
rep-gtk-gnome-0.11-0_helix_2
gtk---devel-1.0.3-1
pygtk-0.6.3-1
gtk+-1.2.7-1_helix_1
gtk-engines-0.10-1_helix_2
gtk+-devel-1.2.7-1_helix_1

Notice above that the package rep-gtk-gnome-0.11-0_helix_2 was also found by the first rpm command.
Obviously, this system is of little help for those needing to find all package dependencies. However, piping rpm and grep will aid you in finding out release numbers and package names.

Conclusion
Although the above system is a bit limited, it has its uses. For finding package names, finding installed packages, and finding release numbers, piping grep and rpm can’t be beat!

Jack Wallen, Jr. is very pleased to have joined the TechRepublic staff as editor in chief of Linux content. Jack was thrown out of the "Window" back in 1995, when he grew tired of the "blue screen of death" and realized that "computing does not equal rebooting." Prior to Jack's headfirst dive into the computer industry, he was a professional actor with film, TV, and Broadway credits. Now, Jack is content with his new position of Linux Evangelist. Ladies and gentlemen—the poster boy for the Linux Generation!

The authors and editors have taken care in preparation of the content contained herein, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

0 comments

Editor's Picks