I originally wrote this article for the same web site back on January 30th, 2008. Much of it still applies today.
Linux has reached a graphical state where “ordinary desktop users” can use Linux for daily activities they might use other operating systems for. While it’s possible to install software using a graphical tool like pirut (Fedora Core/Red Hat) or yast (Novell SuSE) sometimes you want to know a bit more about what’s being installed on your system, what’s already on your system, or exactly what’s in the package you just installed. This is where the Redhat Package Manager (RPM) command-line tool comes in handy. Rpm is a pretty slick package management tool on its own, this article discusses extending the usefulness of rpm for doing more than just installing and removing packages, and why you might want to do it.
Step #1 – Get to know all your installed packages with query all
In a terminal session run the following 2 separate commands:
rpm -qa | sort > allfiles.txt
The command(s) rpm -qa | sort > allfiles.txt has three parts worthy of noting. The -qa switch after the rpm queries all the packages installed (q = query, a = all). In English, this command on its own will list all the packages installed on your computer. Think of a package as a collection of programs that comprise one program, for example: the firefox web browser. The second part of this string is the sort command. The | symbol takes the output of the previous command (rpm -qa) and dishes it up to the next command, in this case sort; so our list of installed packages gets sorted alphabetically. The last part of this string of commands is the redirection pipe and filename allfiles.txt. The redirection > symbol takes the output from sort and redirects it into a file, in this case allfiles.txt. Now allfiles.txt can be read with any text editor or word processor (it’s just a text file after all). Some common text editors on Linux systems are: gedit, kate/kwrite, emacs, vim, nano, and pico.
Step #2 – List all files within a single package
Run the command:
rpm -ql aspell | less
If you get a return that says package aspell is not installed try running rpm -ql with one of the packages you viewed in step #1.
Remembering that the -q switch is query, we simply added the (-l) list switch. Why would you want to list all the files in a package? There are a couple of good reasons, one you might find documentation that provides useful information about a package (i.e. README.txt), two, sometimes a program gets installed to a non-standard location, such as /opt, and you need to know the location to run the program.
Step #3 – Find out information about a single package
Run the command:
rpm -qi aspell
Again, the -q switch queries the aspell package. The -i switch gives information about a package such as the package size (in bytes), the key it was signed with (to ensure it comes from a good source, for example the software package’s author), the home web page for the package, a description of what the package does, and other information about the build date, vendor, version, etc… you get the idea. Not all packages will necessarily have all information fields filled out, but most are maintained for Fedora/Red Hat or Mandriva should have good descriptions for the rpm packages.
Step #4 – Combine bash commands with rpm commands for more effect
We’ve already seen how bash commands like less and sort can extend the usefulness. Other commands like wc (word count) and grep can also be used to extend the usefulness of the rpm command. Using bash shell commands along with the commands’ switches can produce interesting results.
For example: to find out how many files are installed by all of the packages on your system use the command:
rpm -qal | wc -l
Remember the query, all, and list files switches (-qal) from our previous examples? We've added the word count (wc) bash shell command with the line (-l) switch to count the number of lines.
Grep is a tremendously useful bash command that lets you search for patterns within text. For example, if we wanted to find out of aspell had a README file in it we could run:
rpm -ql aspell | grep README
Of course, aspell must be installed to query it.