0105-0107.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 296 行

HTML
296
字号




<HTML>

<HEAD>

<TITLE>Maximum RPM (RPM):Miscellanea:EarthWeb Inc.-</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311054 //-->

<!-- TITLE=Maximum RPM (RPM)//-->

<!-- AUTHOR=Edward Bailey//-->

<!-- PUBLISHER=Macmillan Computer Publishing//-->

<!-- IMPRINT=Sams//-->

<!-- CHAPTER=08 //-->

<!-- PAGES=0101-0110 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0101-0104.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0108-0110.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-105"><P>Page 105</P></A>





<P>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.

</P>



<H4><A NAME="ch08_ 7">

8.1.5. --version: Display the Current RPM Version

</A></H4>



<P>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:

</P>



<!-- CODE SNIP //-->

<PRE>

# rpm --version

RPM version 2.3

#

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch08_ 8">

8.2. Using rpm2cpio

</A></H4>



<P>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:

</P>



<OL>

<LI>          Install the package.

<LI>          Make a copy of the file(s) you need.

<LI>          Erase the package.

</OL>



<P>

An easier way would be to use rpm2cpio.

</P>



<H4><A NAME="ch08_ 9">

8.2.1. rpm2cpio: What Does It Do?

</A></H4>



<P>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!

</P>



<P>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:

</P>



<!-- CODE //-->

<PRE>

# rpm2cpio logrotate-1.0-1.i386.rpm

0707020001a86a000081a4000000000000000000000001313118bb000002c200000008000

000030000000000000000000000190000e73eusr/man/man8/logrotate.8.&quot; logrotate

- log file rotator

.TH rpm 8 &quot;28 November 1995&quot; &quot;Red Hat Software&quot; &quot;Red Hat Linux&quot;

.SH NAME

</PRE>

<!-- END CODE //-->



<P>Note that this is only the first few lines of output.

</P>



<P>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:

</P>



<A NAME="PAGENUM-106"><P>Page 106</P></A>





<!-- CODE SNIP //-->

<PRE>

# rpm2cpio logrotate-1.0-1.i386.rpm &gt; blah.cpio

# file blah.cpio

blah.cpio: ASCII cpio archive (SVR4 with CRC)

#

</PRE>

<!-- END CODE SNIP //-->



<P>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:

</P>



<!-- CODE SNIP //-->

<PRE>

# cat logrotate-1.0-1.i386.rpm | rpm2cpio &gt; blah.cpio

#

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch08_ 10">

8.2.2. A More Real-World Example: Listing the Files in a

Package File

</A></H4>



<P>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:

</P>



<!-- CODE SNIP //-->

<PRE>

# rpm2cpio logrotate-1.0-1.i386.rpm | cpio -t

usr/man/man8/logrotate.8

usr/sbin/logrotate

14 blocks

#

</PRE>

<!-- END CODE SNIP //-->



<P>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.

</P>



<H4><A NAME="ch08_ 11">

8.2.3. Extracting One or More Files from a Package File

</A></H4>



<P>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:

</P>



<!-- CODE SNIP //-->

<PRE>

# rpm2cpio logrotate-1.0-1.i386.rpm |cpio -ivd usr/man/man8/logrotate.8

usr/man/man8/logrotate.8

14 blocks

#

</PRE>

<!-- END CODE SNIP //-->



<P>In this case, the cpio options -i, -v, and -d direct

cpio to do the following:

</P>



<OL>

<LI>          Extract one or more files from an archive.

<LI>          Display the names of any files processed, along with the size of the archive file, in

512-byte blocks. (Note that the size displayed by

cpio is the size of the cpio archive and not the package file.)

<LI>          Create any directories that precede the filename specified in the

cpio command.

</OL>



<A NAME="PAGENUM-107"><P>Page 107</P></A>







<P>So where did the file end up? The last option

(-d) to cpio provides a hint. Let's take a look:

</P>

<!-- CODE //-->

<PRE>

# 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

.\&quot; logrotate - log file rotator

.TH rpm 8 &quot;28 November 1995&quot; &quot;Red Hat Software&quot; &quot;Red Hat Linux&quot;

.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

. . .

</PRE>

<!-- END CODE //-->



<P>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!

</P>



<H4><A NAME="ch08_ 12">

8.3. Source Package Files and How to Use Them

</A></H4>



<P>One day, you may run across a package file with a name similar to the following:

</P>



<!-- CODE SNIP //-->

<PRE>

etcskel-1.0-3.src.rpm

</PRE>

<!-- END CODE SNIP //-->



<P>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:

</P>



<!-- CODE SNIP //-->

<PRE>

# file foo.bar

foo.bar: RPM v2 bin i386 eject-1.2-2

#

</PRE>

<!-- END CODE SNIP //-->



<P>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.

</P>



<P><CENTER>

<a href="0101-0104.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0108-0110.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?