Useful RPM and YUM Commands
RPM and YUM commands are used daily by RHEL/CentOS/Fedora Administrators and sometimes having a few more tricks up you sleeve for getting information from the command line are always handy to have. Listed in this post are 14 useful commands for RPM and YUM.
1. Getting rpm to display architecture
This one is a pretty simple tip, and very useful especially for people using x86_64 systems. Just one line in ~/.rpmmacros will save all sorts of trouble later.
$ echo "%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}" >> ~/.rpmmacros
2. Query packages not from Redhat
Want to query all those packages installed from 3rd party repositories, not Redhat?
$ rpm -qa --qf '%{NAME} %{VENDOR}\n' | grep -v -i redhat
3. Reset File Permissions
Have you managed to completely mess up file permissions for a given package? Not a problem, because RPM has you covered.
$ rpm --setperms <packagename>
4. View the Changelog
Because Redhat and the upstream vendor have backported security patches, the version numbers can often be misleading when you look for CVE fixes. Checking the changelog of a package is a good way to see if the fix has been implemented. Once again, rpm comes to the rescue.
$ rpm -q --changelog <packagename>
5. Where’s the Documentation?
To quickly list documentation relating to a package, you can use the following two options:
$ rpm -qd <packagename>
This will show you the documentation contained in that rpm, or if you only have a filename you can do:
$ rpm -qdf /path/to/file
and rpm will show you the documentation in the package that owns the file.
6. Package Origin
Occasionally it’s nice to know where you got certain packages, or how many packages you have on your system from a particular repository or vendor. There are a couple of search options that you can use which are not in the rpm man pages to help you out here. While they’re not 100% perfect, they certainly help out. Most package repositories tag their packages with an identifier in the Release string. For example rpmforge uses rf as their identifier. You can use this to see what you have of theirs installed with
$ rpm -qa release="*rf*"
or if you want to see just how many packages you have installed built by Fred you could use
$ rpm -qa packager="Fred*"
This trick works for most categories visible in rpm -qi <packagename>.
Another approach is to use the keychecker package available in the EPEL repository, which lists rpm packages based on the GPG key they were signed with.
7. Extract just one File
If you need to extract just one file from an rpm without reinstalling the whole package, you can do this with rpm2cpio. For example, to extract just the config file from the logrotate rpm you would use the following statement:
$ rpm2cpio logrotate-1.0-1.i386.rpm |cpio -ivd etc/logrotate.conf
8. Query Package Install Order and Dates
Useful after an upgrade to find old packages that were not upgraded.
$ rpm -qa --last >~/RPMS_by_Install_Date
Review the end of the output file in “less” to find all RPMS older than the install date. Can also grep for specific packages and see when they were installed.
9. Query Available Packages from a Repo
Find all packages available from a specific repository, e.g. RPMfusion. This does not show the already installed packages from this repository.
$ yum --disablerepo "*" --enablerepo "rpmfusion" list available
10. Search yum repositories for a string
Find packages containing a string in package name or description.
$ yum search buildrpmtree | less
11. Using yum with a proxy server
To enable yum operations to use a proxy server you should first add the following parameter to /etc/yum.conf
$ proxy=http://yourproxy:8080/
where yourproxy is the name of the proxy server you want to access and 8080 is the proxy port. If the server requires authentication you can specify the login credentials like:
$ proxy=http://username:password@yourproxy:8080/
The rpm package manager makes use of the proxy environment variable. This can be set system wide in /etc/profile or user specific in ~/.bash_profile::
$ export http_proxy=http://yourproxy:8080/ export ftp_proxy=http://yourproxy:8080/
To use wget through a proxy server add the following lines to /etc/wgetrc
$ http_proxy = http://yourproxy:8080/ ftp_proxy = http://yourproxy:8080/
In both cases, login information can be set like in the example above.
12. Use yum to install a local package, automatically checking/satisfying dependencies
$ yum --nogpgcheck localinstall packagename.arch.rpm
13. Display priority scores for all repositories
You can list all repositories set up on your system by a yum repolist all. However, this does not show priority scores. Here’s a one liner for that. If no number is defined, the default is the lowest priority (99).
$ sed -n -e "/^\[/h; /priority *=/{ G; s/\n/ /; s/ity=/ity = /; p }" /etc/yum.repos.d/*.repo | sort -k3n
14. Show all installed GPG keys
Shows all GPG keys along with the corresponding repo information.
rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n'
Hope this has added a few more ticks up your sleeve as it has mine!
Leave a Reply