With the -q option, rpm initiates queries, making it possible to inspect an RPM archive (by adding the option -p) and also to query the RPM database of installed packages. Several switches are available to specify the type of information required. See Table 6-1.
Table 6-1 The Most Important RPM Query Options
-i |
Package information |
-l |
File list |
-f FILE |
Query the package that contains the file FILE (the full path must be specified with FILE) |
-s |
File list with status information (implies -l) |
-d |
List only documentation files (implies -l) |
-c |
List only configuration files (implies -l) |
--dump |
File list with complete details (to be used with -l, -c, or -d) |
--provides |
List features of the package that another package can request with --requires |
--requires, -R |
Capabilities the package requires |
--scripts |
Installation scripts (preinstall, postinstall, uninstall) |
For example, the command rpm -q -i wget displays the information shown in Example 6-1.
Example 6-1 rpm -q -i wget
Name : wget Relocations: (not relocatable) Version : 1.9.1 Vendor: SUSE LINUX AG, Nuernberg, Germany Release : 50 Build Date: Sat 02 Oct 2004 03:49:13 AM CEST Install date: Mon 11 Oct 2004 10:24:56 AM CEST Build Host: f53.suse.de Group : Productivity/Networking/Web/Utilities Source RPM: wget-1.9.1-50.src.rpm Size : 1637514 License: GPL Signature : DSA/SHA1, Sat 02 Oct 2004 03:59:56 AM CEST, Key ID a84edae89c800aca Packager : http://www.suse.de/feedback URL : http://wget.sunsite.dk/ Summary : A tool for mirroring FTP and HTTP servers Description : Wget enables you to retrieve WWW documents or FTP files from a server. This can be done in script files or via the command line. [...]
The option -f only works if you specify the complete filename with its full path. Provide as many filenames as desired. For example, the following command
rpm -q -f /bin/rpm /usr/bin/wget
results in:
rpm-4.1.1-191 wget-1.9.1-50
If only part of the filename is known, use a shell script as shown in Example 6-2. Pass the partial filename to the script shown as a parameter when running it.
Example 6-2 Script to Search for Packages
#! /bin/sh for i in $(rpm -q -a -l | grep $1); do echo "\"$i\" is in package:" rpm -q -f $i echo "" done
The command rpm -q --changelog rpm displays a detailed list of change information about a specific package, sorted by date. This example shows information about the package rpm.
With the help of the installed RPM database, verification checks can be made. Initiate these with -V, -y, or --verify. With this option, rpm shows all files in a package that have been changed since installation. rpm uses eight character symbols to give some hints about the following changes:
Table 6-2 RPM Verify Options
5 |
MD5 check sum |
S |
File size |
L |
Symbolic link |
T |
Modification time |
D |
Major and minor device numbers |
U |
Owner |
G |
Group |
M |
Mode (permissions and file type) |
In the case of configuration files, the letter c is printed. For example, for changes to /etc/wgetrc (wget):
rpm -V wget S.5....T c /etc/wgetrc
The files of the RPM database are placed in /var/lib/rpm. If the partition /usr has a size of 1 GB, this database can occupy nearly 30 MB, especially after a complete update. If the database is much larger than expected, it is useful to rebuild the database with the option --rebuilddb. Before doing this, make a backup of the old database. The cron script cron.daily makes daily copies of the database (packed with gzip) and stores them in /var/adm/backup/rpmdb. The number of copies is controlled by the variable MAX_RPMDB_BACKUPS (default: 5) in /etc/sysconfig/backup. The size of a single backup is approximately 1 MB for 1 GB in /usr.