-->
Page 105
This is just the first screen of RPM's help command. To see the rest, give the command a try. Practically everything there is to know about RPM is present in the --help output. It's a bit too concise to learn RPM from, but it's enough to refresh your memory when the syntax of a particular option escapes you.
If you're not sure what version of RPM is presently installed on your system, the easiest way to find out is to ask RPM itself using the --version option:
# rpm --version RPM version 2.3 #
From time to time, you might find it necessary to extract one or more files from a package file. One way to do this would be the following:
An easier way would be to use rpm2cpio.
As the name implies, rpm2cpio takes an RPM package file and converts it to a cpio archive. Because it's written to be used primarily as a filter, there's not much to be specified. rpm2cpio takes only one argument, and even that's optional!
The optional argument is the name of the package file to be converted. If there is no filename specified on the command line, rpm2cpio will simply read from standard input and convert that to a cpio archive. Let's give it a try:
# rpm2cpio logrotate-1.0-1.i386.rpm 0707020001a86a000081a4000000000000000000000001313118bb000002c200000008000 000030000000000000000000000190000e73eusr/man/man8/logrotate.8." logrotate - log file rotator .TH rpm 8 "28 November 1995" "Red Hat Software" "Red Hat Linux" .SH NAME
Note that this is only the first few lines of output.
What on earth is all that stuff? Remember that rpm2cpio is written as a filter. It writes the cpio archive contained in the package file to standard output, which, if you've not redirected it somehow, is your screen. Here's a more reasonable example:
Page 106
# rpm2cpio logrotate-1.0-1.i386.rpm > blah.cpio # file blah.cpio blah.cpio: ASCII cpio archive (SVR4 with CRC) #
Here we've directed rpm2cpio to convert the logrotate package file. We've also redirected rpm2cpio's output to a file called blah.cpio. Next, using the file command, we find that the resulting file is indeed a bona fide cpio archive file. The following command is entirely equivalent to the previous one and shows rpm2cpio's capability to read the package file from its standard input:
# cat logrotate-1.0-1.i386.rpm | rpm2cpio > blah.cpio #
While there's nothing wrong with using rpm2cpio to create a cpio archive file, it takes a few more steps and uses a bit more disk space than is strictly necessary. A somewhat cleaner approach would be to pipe rpm2cpio's output directly into cpio:
# rpm2cpio logrotate-1.0-1.i386.rpm | cpio -t usr/man/man8/logrotate.8 usr/sbin/logrotate 14 blocks #
In this example, we used the -t option to direct cpio to produce a table of contents of the archive created by rpm2cpio. This can make it much easier to get the right filename and path when you want to extract a file.
Continuing the previous example, let's extract the man page from the logrotate package. In the table of contents, we see that the full path is usr/man/man8/logrotate.8. All we need to do is to use the filename and path as shown here:
# rpm2cpio logrotate-1.0-1.i386.rpm |cpio -ivd usr/man/man8/logrotate.8 usr/man/man8/logrotate.8 14 blocks #
In this case, the cpio options -i, -v, and -d direct cpio to do the following:
Page 107
So where did the file end up? The last option (-d) to cpio provides a hint. Let's take a look:
# ls -al total 5 -rw-rw-r-- 1 root root 3918 May 30 11:02 logrotate-1.0-1.i386.rpm drwx------ 3 root root 1024 Jul 14 12:42 usr # cd usr # ls -al total 1 drwx------ 3 root root 1024 Jul 14 12:42 man # cd man # ls -al total 1 drwx------ 2 root root 1024 Jul 14 12:42 man8 # cd man8 # ls -al total 1 -rw-r--r-- 1 root root 706 Jul 14 12:42 logrotate.8 # cat logrotate.8 .\" logrotate - log file rotator .TH rpm 8 "28 November 1995" "Red Hat Software" "Red Hat Linux" .SH NAME logrotate \- log file rotator .SH SYNOPSIS \fBlogrotate\fP [configfiles] .SH DESCRIPTION \fBlogrotate\fP is a tool to prevent log files from growing without . . .
Since the current directory didn't have a usr/man/man8/ path in it, the -d option caused cpio to create all the directories leading up to the logrotate.8 file in the current directory. Based on this, it's probably safest to use cpio outside the normal system directories unless you're comfortable with cpio and you know what you're doing!
One day, you may run across a package file with a name similar to the following:
etcskel-1.0-3.src.rpm
Notice the src. Is that a new kind of computer? If you use RPM on an Intel-based computer, you'd normally expect to find i386 there. Maybe someone messed up the name of the file. Well, we know that the file command can display information about a package file, even if the filename has been changed. We've used it before to figure out what package a file contains:
# file foo.bar foo.bar: RPM v2 bin i386 eject-1.2-2 #
In this example, foo.baris an RPM version 2 file. bin indicates that the file contains an executable package, and i386 means that the package was built for Intel processors. The package is called eject version 1.2, release 2.