Practical RPM

Advanced usage

Package requirements
RPM is well-known for its dependecies headaches. It is, therefor, often important to see what the package requires:

$ rpm -q --requires vim-enhanced

and/or what it provides:

$ rpm -q --provides vim-enhanced

Quering not installed packages
Sometimes it is desirable to query RPM files before installing them. This can be done by adding -p to the query and specifying the filename of the package in question.For example, what will the vim-enhanced.rpm file install?

$ rpm -qlp vim-enhanced.rpm

More shell magic
Let’s erase all packages which have “emacs” in their names.

$ rpm -e ` rpm -qa | grep -i emacs ` 

Quering for package groups
Each and every RPM package belongs to a predefined group of packages. The complete list of all groups is can be found in RPM-Howto. Below is an example of a query for the packages which are in “Applications/Editors” group.

$ rpm -q --group 'Applications/Editors'

Listing installed packages sorted by size
RPM has an extremely useful –qf (query format) option, which allows you to specify exactly how do you want the results of the query to appear. It is very similar in syntax to the traditional printf command. Additionally, it allows you to use any of the RPM information fields in your query, like “SIZE”, “NAME”, “VERSION”, etc.

$ rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -n 

Crash/malfunction recovery helpers
RPM is a very useful tool in case you had your system crashed and/or compromised. For example, in case your apache stopped working for some reason, you can easily check which files are missing or were changed.

$ rpm --verify ` rpm -qa | grep -i apache `

In case you accidentally changed mode (permissions) of a file and you want to bring it to the original state without doing a timely restore from tape, –dump gets handy. Below is an example of retreiving original mode for /bin/bash file from the RPM database.

$ rpm -q --dump bash | grep '/bin/bash' 

Building packages from source RPMs
Most of the times, RPM packages are provided in both binary and source form. Rebuild RPM from source package can save you a lot of dependancy/compatibility troubles.

# rpmbuild --rebuild vim-6.1-14.src.rpm

If everything went fine, then you will find the resulting RPM in /usr/src/redhat/RPMS/i386/ directory (or the one appropriate for your distribution and architecture). You can now proceed with installation of the freshly built package.

Leave a Comment