📄 ch19_09.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 19] 19.9 A System V Tape Archiver: cpio </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:39:31Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch19_01.htm"TITLE="19. Creating and Reading Archives"><LINKREL="prev"HREF="ch19_08.htm"TITLE="19.8 Problems with Verbose tar "><LINKREL="next"HREF="ch20_01.htm"TITLE="20. Backing Up Files"></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch19_08.htm"TITLE="19.8 Problems with Verbose tar "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 19.8 Problems with Verbose tar "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 19<BR>Creating and Reading Archives</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="CHAPTER"HREF="ch20_01.htm"TITLE="20. Backing Up Files"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 20. Backing Up Files"BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-3700">19.9 A System V Tape Archiver: cpio </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-21611"></A><ACLASS="indexterm"NAME="AUTOID-21614"></A><ACLASS="indexterm"NAME="AUTOID-21617"></A><ACLASS="indexterm"NAME="AUTOID-21619"></A>There was a time when people used to debate whether the BSD <SPANCLASS="link"><EMCLASS="emphasis">tar</EM> (<ACLASS="linkend"HREF="ch20_01.htm#UPT-ART-8024"TITLE="tar in a Nutshell ">20.1</A>, <ACLASS="linkend"HREF="ch19_05.htm"TITLE="Using tar to Create and Unpack Archives ">19.5</A>)</SPAN>(tape archiver)or the System V <EMCLASS="emphasis">cpio</EM> (copy in/out) was the better file archive andbackup program.At this point, there's no question.No one shipsout <EMCLASS="emphasis">cpio</EM> archives over <SPANCLASS="link">the Net (<ACLASS="linkend"HREF="ch01_33.htm"TITLE="UNIX Networking and Communications ">1.33</A>)</SPAN>.<EMCLASS="emphasis">tar</EM> is widespread, and because there are free versionsavailable, including<SPANCLASS="link">GNU <EMCLASS="emphasis">tar</EM> (<ACLASS="linkend"HREF="ch19_06.htm"TITLE="GNU tar Sampler ">19.6</A>)</SPAN>,there's no reason why you should have to read a <EMCLASS="emphasis">cpio</EM> archivefrom someone else.</P><PCLASS="para">Still, if you're on an older System V machine, you might use <EMCLASS="emphasis">cpio</EM>.Though we don't give it much air time in this book, hereare a few basics:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-21636"></A>To write out an archive, use the <EMCLASS="emphasis">-o</EM> option and redirect outputeither to a tape device or to an archive file.The list of files tobe archived is often specified with <SPANCLASS="link"><EMCLASS="emphasis">find</EM> (<ACLASS="linkend"HREF="ch17_01.htm#UPT-ART-7410"TITLE="The find Command Is Great; The Problem Is Finding How to Use It">17.1</A>)</SPAN>,but can be generated in other ways-<EMCLASS="emphasis">cpio</EM> expects a list offilenames on its standard input.For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>find . -name "*.old" -print | cpio -ocBv > /dev/rst8</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">or:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>find . -print | cpio -ocBv > mydir.cpio</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"></P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-21653"></A><ACLASS="indexterm"NAME="AUTOID-21656"></A>To read an archive in, use the <EMCLASS="emphasis">-i</EM> option and redirect inputfrom the file or tape drive containing the archive. The <EMCLASS="emphasis">-d</EM> option isoften important; it tells <EMCLASS="emphasis">cpio</EM> to create directories as neededwhen copying files in.You can restore all files from the archiveor specify a filename pattern (with wildcards quoted to protect themfrom the shell) to selectonly some of the files.For example, thefollowing command willrestore from a tape drive all C source files:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cpio -icdv "*.c" < /dev/rst8</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-21666"></A>Subdirectories are created if needed (<EMCLASS="emphasis">-d</EM>), and <EMCLASS="emphasis">cpio</EM> willbe verbose (<EMCLASS="emphasis">-v</EM>), announcing the name of each file that itsuccessfully reads in.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-21674"></A><ACLASS="indexterm"NAME="AUTOID-21677"></A>To copy an archive to another directory, use the <EMCLASS="emphasis">-o</EM> option,followed by the name of the destination directory.(This is one ofthe nicer features of <EMCLASS="emphasis">cpio</EM>.) For example, you could use thefollowing command to copy the contentsof the current directory (including all subdirectories) to anotherdirectory:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>find . -depth -print | cpio -pd newdir</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"></P></LI><LICLASS="listitem"><PCLASS="para">There are lots of other options for things like resetting file accesstimes or ownership or changing the blocking factor on the tape. Seeyour friendly neighborhood manual page for details. Notice thatoptions are typically "squashed together" into an option string ratherthan written out as separate options.</P></LI></UL><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch19_08.htm"TITLE="19.8 Problems with Verbose tar "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 19.8 Problems with Verbose tar "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="CHAPTER"HREF="ch20_01.htm"TITLE="20. Backing Up Files"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 20. Backing Up Files"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">19.8 Problems with Verbose tar </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">20. Backing Up Files</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -