tar.texi

来自「gnu tar 源码包。 tar 软件是 Unix 系统下的一个打包软件」· TEXI 代码 · 共 1,767 行 · 第 1/5 页

TEXI
1,767
字号
@cindex listing member and file names@anchor{listing member and file names}It is important to notice that the output of @kbd{tar --list--verbose} does not necessarily match that produced by @kbd{tar--create --verbose} while creating the archive.  It is because@GNUTAR{}, unless told explicitly not to do so, removes some directoryprefixes from file names before storing them in the archive(@xref{absolute}, for more information).  In otherwords, in verbose mode @GNUTAR{} shows @dfn{file names} when creatingan archive and @dfn{member names} when listing it.  Consider thisexample:@smallexample@group$ @kbd{tar cfv archive /etc/mail}tar: Removing leading `/' from member names/etc/mail//etc/mail/sendmail.cf/etc/mail/aliases$ @kbd{tar tf archive}etc/mail/etc/mail/sendmail.cfetc/mail/aliases@end group@end smallexample@opindex show-stored-names  This default behavior can sometimes be inconvenient.  You can force@GNUTAR{} show member names when creating archive by supplying@option{--show-stored-names} option.@table @option@item --show-stored-namesPrint member (as opposed to @emph{file}) names when creating the archive.@end table@cindex File name arguments, using @option{--list} with@xopindex{list, using with file name arguments}You can specify one or more individual member names as arguments whenusing @samp{list}.  In this case, @command{tar} will only list thenames of members you identify.  For example, @w{@kbd{tar --list--file=afiles.tar apple}} would only print @file{apple}.Because @command{tar} preserves file names, these must be specified asthey appear in the archive (i.e., relative to the directory from whichthe archive was created).  Therefore, it is essential when specifyingmember names to @command{tar} that you give the exact member names.For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce anerror message something like @samp{tar: birds: Not found in archive},because there is no member named @file{birds}, only one named@file{./birds}.  While the names @file{birds} and @file{./birds} namethe same file, @emph{member} names by default are compared verbatim.However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respondwith @file{baboon}, because this exact member name is in the archive file@file{bfiles.tar}.  If you are not sure of the exact file name,use @dfn{globbing patterns}, for example:@smallexample$ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}@end smallexample@noindentwill list all members whose name contains @samp{b}.  @xref{wildcards},for a detailed discussion of globbing patterns and related@command{tar} command line options.@menu* list dir::@end menu@node list dir@unnumberedsubsec Listing the Contents of a Stored DirectoryTo get information about the contents of an archived directory,use the directory name as a file name argument in conjunction with@option{--list} (@option{-t}).  To find out file attributes, include the@option{--verbose} (@option{-v}) option.For example, to find out about files in the directory @file{practice}, inthe archive file @file{music.tar}, type:@smallexample$ @kbd{tar --list --verbose --file=music.tar practice}@end smallexample@command{tar} responds:@smallexampledrwxrwxrwx myself user 0 1990-05-31 21:49 practice/-rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues-rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk-rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz-rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar@end smallexampleWhen you use a directory name as a file name argument, @command{tar} acts onall the files (including sub-directories) in that directory.@node extract@section How to Extract Members from an Archive@UNREVISED@cindex Extraction@cindex Retrieving files from an archive@cindex Resurrecting files from an archive@opindex extractCreating an archive is only half the job---there is no point in storingfiles in an archive if you can't retrieve them.  The act of retrievingmembers from an archive so they can be used and manipulated asunarchived files again is called @dfn{extraction}.  To extract filesfrom an archive, use the @option{--extract} (@option{--get} or@option{-x}) operation.  As with @option{--create}, specify the nameof the archive with @option{--file} (@option{-f}) option. Extractingan archive does not modify the archive in any way; you can extract itmultiple times if you want or need to.Using @option{--extract}, you can extract an entire archive, or specificfiles.  The files can be directories containing other files, or not.  Aswith @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or thelong form of the operation without affecting the performance.@menu* extracting archives::* extracting files::* extract dir::* extracting untrusted archives::* failing commands::@end menu@node extracting archives@subsection Extracting an Entire ArchiveTo extract an entire archive, specify the archive file name only, withno individual file names as arguments.  For example,@smallexample$ @kbd{tar -xvf collection.tar}@end smallexample@noindentproduces this:@smallexample-rw-r--r-- me user     28 1996-10-18 16:31 jazz-rw-r--r-- me user     21 1996-09-23 16:44 blues-rw-r--r-- me user     20 1996-09-23 16:44 folk@end smallexample@node extracting files@subsection Extracting Specific FilesTo extract specific archive members, give their exact member names asarguments, as printed by @option{--list} (@option{-t}).  If you hadmistakenly deleted one of the files you had placed in the archive@file{collection.tar} earlier (say, @file{blues}), you can extract itfrom the archive without changing the archive's structure.  Itscontents will be identical to the original file @file{blues} that youdeleted.First, make sure you are in the @file{practice} directory, and list thefiles in the directory.  Now, delete the file, @samp{blues}, and listthe files in the directory again.You can now extract the member @file{blues} from the archive file@file{collection.tar} like this:@smallexample$ @kbd{tar --extract --file=collection.tar blues}@end smallexample@noindentIf you list the files in the directory again, you will see that the file@file{blues} has been restored, with its original permissions, datamodification times, and owner.@footnote{This is only accidentallytrue, but not in general.  Whereas modification times are alwaysrestored, in most cases, one has to be root for restoring the owner,and use a special option for restoring permissions.  Here, it justhappens that the restoring user is also the owner of the archivedmembers, and that the current @code{umask} is compatible with originalpermissions.}  (These parameters will be identical to those whichthe file had when you originally placed it in the archive; any changesyou may have made before deleting the file from the file system,however, will @emph{not} have been made to the archive member.)  Thearchive file, @samp{collection.tar}, is the same as it was before youextracted @samp{blues}.  You can confirm this by running @command{tar} with@option{--list} (@option{-t}).Remember that as with other operations, specifying the exact membername is important.  @w{@kbd{tar --extract --file=bfiles.tar birds}}will fail, because there is no member named @file{birds}.  To extractthe member named @file{./birds}, you must specify @w{@kbd{tar--extract --file=bfiles.tar ./birds}}.  If you don't remember theexact member names, use @option{--list} (@option{-t}) option(@pxref{list}).  You can also extract those members that match aspecific @dfn{globbing pattern}.  For example, to extract from@file{bfiles.tar} all files that begin with @samp{b}, no matter theirdirectory prefix, you could type:@smallexample$ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}@end smallexample@noindentHere, @option{--wildcards} instructs @command{tar} to treatcommand line arguments as globbing patterns and @option{--no-anchored}informs it that the patterns apply to member names after any @samp{/}delimiter.  The use of globbing patterns is discussed in detail in@xref{wildcards}.You can extract a file to standard output by combining the above optionswith the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to StandardOutput}).If you give the @option{--verbose} option, then @option{--extract}will print the names of the archive members as it extracts them.@node extract dir@subsection Extracting Files that are DirectoriesExtracting directories which are members of an archive is similar toextracting other files.  The main difference to be aware of is that ifthe extracted directory has the same name as any directory already inthe working directory, then files in the extracted directory will beplaced into the directory of the same name.  Likewise, if there arefiles in the pre-existing directory with the same names as the memberswhich you extract, the files from the extracted archive will replacethe files already in the working directory (and possiblesubdirectories).  This will happen regardless of whether or not thefiles in the working directory were more recent than those extracted(there exist, however, special options that alter this behavior@pxref{Writing}).However, if a file was stored with a directory name as part of its filename, and that directory does not exist under the working directory whenthe file is extracted, @command{tar} will create the directory.We can demonstrate how to use @option{--extract} to extract a directoryfile with an example.  Change to the @file{practice} directory if youweren't there, and remove the files @file{folk} and @file{jazz}.  Then,go back to the parent directory and extract the archive@file{music.tar}.  You may either extract the entire archive, or you mayextract only the files you just deleted.  To extract the entire archive,don't give any file names as arguments after the archive name@file{music.tar}.  To extract only the files you deleted, use thefollowing command:@smallexample$ @kbd{tar -xvf music.tar practice/folk practice/jazz}practice/folkpractice/jazz@end smallexample@noindentIf you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}would have displayed more detail about the extracted files, as shownin the example below:@smallexample$ @kbd{tar -xvvf music.tar practice/folk practice/jazz}-rw-r--r-- me user     28 1996-10-18 16:31 practice/jazz-rw-r--r-- me user     20 1996-09-23 16:44 practice/folk@end smallexample@noindentBecause you created the directory with @file{practice} as part of thefile names of each of the files by archiving the @file{practice}directory as @file{practice}, you must give @file{practice} as partof the file names when you extract those files from the archive.@node extracting untrusted archives@subsection Extracting Archives from Untrusted SourcesExtracting files from archives can overwrite files that already exist.If you receive an archive from an untrusted source, you should make anew directory and extract into that directory, so that you don't haveto worry about the extraction overwriting one of your existing files.For example, if @file{untrusted.tar} came from somewhere else on theInternet, and you don't necessarily trust its contents, you canextract it as follows:@smallexample$ @kbd{mkdir newdir}$ @kbd{cd newdir}$ @kbd{tar -xvf ../untrusted.tar}@end smallexampleIt is also a good practice to examine contents of the archivebefore extracting it, using @option{--list} (@option{-t}) option, possibly combinedwith @option{--verbose} (@option{-v}).@node failing commands@subsection Commands That Will FailHere are some sample commands you might try which will not work, and whythey won't work.If you try to use this command,@smallexample$ @kbd{tar -xvf music.tar folk jazz}@end smallexample@noindentyou will get the following response:@smallexampletar: folk: Not found in archivetar: jazz: Not found in archive$@end smallexample@noindentThis is because these files were not originally @emph{in} the parentdirectory @file{..}, where the archive is located; they were in the@file{practice} directory, and their file names reflect this:@smallexample$ @kbd{tar -tvf music.tar}practice/folkpractice/jazzpractice/rock@end smallexample@FIXME{make sure the above works when going through the examples inorder...}@noindentLikewise, if you try to use this command,@smallexample$ @kbd{tar -tvf music.tar folk jazz}@end smallexample@noindentyou would get a similar response.  Members with those names are not in thearchive.  You must use the correct member names, or wildcards, in orderto extract the files from the archive.If you have forgotten the correct names of the files in the archive,use @w{@kbd{tar --list --verbose}} to list them correctly.@FIXME{more examples, here?  hag thinks it's a good idea.}@node going further@section Going Further Ahead in this Manual@UNREVISED@FIXME{need to write up a node here about the things that are going tobe in th

⌨️ 快捷键说明

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