How to Querying the RPM database - tuxfiles.org

Posted on November 12, 2007 in How-to

How to Querying the RPM database
As you already know, the RPM database contains a list of all installed RPM packages on your system. You can query this database to get info of the packages on your Linux system. To query a single package, you use the -q option. For example, to query a package whose name is "software":
# rpm -q software

After issuing this command, rpm either tells you the version of the package, or that the package isnt installed.

If you want a list of all packages installed on your system, youll have to query all with -qa:
# rpm -qa
Most likely this list will be very long, so youll need a way to scroll it. The best way is to pipe the list to less:
# rpm -qa | less
If youre looking for packages whose names contain a specific word, you can use grep for finding those packages. For example, to get a list of all installed RPM packages whose names contain the word "kde", you could do something like this:
# rpm -qa | grep kde

The above command makes rpm list all packages in its database and pass the list to grep. Then grep checks every line for "kde" and finally shows you all the lines that contain the word "kde".