tar.texi 144 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename tar.info
  4. @settitle The Tar Manual: DRAFT
  5. @setchapternewpage odd
  6. @c %**end of header
  7. @c Note: the edition number and date is listed in *two* places; please update.
  8. @c subtitle and top node; search for !!set
  9. @c Search for comments marked with !! or <<< (or >>>)
  10. @c <<< CONVENTIONS: this manual refers to "ordinary files" , "directory
  11. files" (or "directories"), "archive files", "archive members", and
  12. various I/O devices (which have names and file names).>>>
  13. @c <<< it's "file name" (not filename) unless we are talking about an
  14. argument, ie. @var{file-name}. also, you "use" a "file-name argument"
  15. to "specify" a "file".>>>
  16. @c <<< @code{tar} is always lower case, in bold. >>>
  17. @c <<< it's "operations of tar", "options to tar" also, it's " @samp{tar
  18. --foo}" or "the @samp{--foo} operation". MIB doesn't like using
  19. operations and options as separate concepts. I disagree --- would be a
  20. mess to explain otherwise
  21. @c <<< (don't forget to comment these out in final draft) -ringo
  22. @c <<< please dont' change this without sending me e-mail. some things
  23. @c are in progress or waiting to be edited in hardcopy. -ringo
  24. @c smallbook
  25. @iftex
  26. @c finalout
  27. @end iftex
  28. @ifinfo
  29. This file documents @code{tar}, a utility used to store, backup, and
  30. transport files.
  31. Copyright (C) 1992 Free Software Foundation, Inc. DRAFT!
  32. @c Need to put distribution information here when ready.
  33. @end ifinfo
  34. @c !!set edition number and date here
  35. @titlepage
  36. @title @code{tar}
  37. @subtitle The GNU Tape Archiver
  38. @subtitle Edition 0.01, for @code{tar} Version 1.10
  39. @subtitle @today{}
  40. @c remove preceding today line when ready
  41. @sp 1
  42. @subtitle DRAFT
  43. @c subtitle insert month here when ready
  44. @author Amy Gorin, Michael I. Bushnell, and Jay Fenlason
  45. @c <<<best to have hack read this over and see if anything is left he
  46. @c wrote. I don't think so. -ringo>>>>
  47. @page
  48. @vskip 0pt plus 1filll
  49. Copyright @copyright{} 1992 Free Software Foundation, Inc.
  50. @sp 2
  51. This draft is not yet ready for distribution.
  52. @end titlepage
  53. @ifinfo
  54. @node Top, Introduction, (dir), (dir)
  55. @top @code{tar}
  56. This file documents @code{tar}, a utility used to store, backup, and
  57. transport files.
  58. @c !!set edition number and date here
  59. This is DRAFT Edition 0.01 of the @code{tar} documentation, @today{}, for @code{tar}
  60. version 1.12.
  61. @end ifinfo
  62. @c <<< The menus need to be gone over, and node names fixed.
  63. @menu
  64. * Introduction:: @code{tar}: The GNU Tape Archiver
  65. * Invoking @code{tar}:: How to invoke @code{tar}
  66. * Tutorial:: Getting started
  67. * Wizardry:: Some More Advanced Uses for @code{tar}
  68. * Archive Structure:: The structure of an archive
  69. * Reading and Writing:: Reading and writing archives
  70. * Insuring Accuracy:: How to insure the accuracy of an archive
  71. * Selecting Archive Members:: How to select archive members
  72. * User Interaction:: How @code{tar} interacts with people.
  73. * Backups and Restoration:: How to restore files and perform backups
  74. * Media:: Using tapes and other archive media
  75. * Quick Reference:: A quick reference guide to
  76. @code{tar} operations and options
  77. * Data Format Details:: Details of the archive data format
  78. * Concept Index:: Concept Index
  79. @end menu
  80. @node Introduction, Invoking @code{tar}, Top, Top
  81. @chapter @code{tar}: The GNU Tape Archiver
  82. You can use @code{tar} to create an @dfn{archive}---a single file
  83. which contains other files' contents as well as a listing of those
  84. files' characteristics. You can also use @code{tar} to read, add to,
  85. or manipulate already existing archives. Because an archive created
  86. by @code{tar} is capable of preserving file information and directory
  87. structure, @code{tar} is ideal for performing full and incremental
  88. backups, as well as for transferring groups of files between disks and
  89. over networks.
  90. The name @code{tar} comes from the words ``Tape ARchiver'', but
  91. @code{tar} can actually process archives wherever they are stored; on
  92. tapes and disk files, for example. In addition, tar can read archives
  93. from standard input or write them to standard output. (This is often
  94. useful if redirected another program with a pipe.)
  95. @c <<< this menu will conflict with menu above in info mode. -ringo
  96. @menu
  97. * Invoking @code{tar}:: How to invoke @code{tar} and specify arguments.
  98. * Tutorial:: An introduction to @code{tar}.
  99. * Operations:: What you can use @code{tar} to do.
  100. * Options:: How to change the way @code{tar} behaves.
  101. * Problems:: Common problems with @code{tar}.
  102. @end menu
  103. @node Invoking @code{tar}, Tutorial, Introduction, Top
  104. @chapter How To Invoke @code{tar}
  105. The usual way to invoke tar is
  106. @example
  107. @code{tar} @var{options}... [@var{file-names}...]
  108. @end example
  109. All the options start with @samp{-}. The arguments which do not start
  110. with @samp{-} are taken to be file-name arguments. (But
  111. @xref{Argument Form}.) You can actually type in arguments in any
  112. order. In this manual the options always precede the file-name
  113. arguments, to make examples easier to understand.
  114. @menu
  115. * Option Form:: The Forms of Arguments
  116. * Argument Functions:: The Functions of Arguments
  117. * Old Syntax for Commands:: An Old, but Still Supported, Syntax
  118. for @code{tar} Commands
  119. @end menu
  120. @node Option Form, Old Syntax for Commands, Argument Functions, Invoking @code{tar}
  121. @section The Forms of Arguments
  122. Most options of @code{tar} have a single letter form (a single letter
  123. preceded by @samp{-}), and at least one mnemonic form (a word or
  124. abbreviation preceded by @samp{--}). The forms are absolutely
  125. identical in function. For example, you can use either @samp{tar -t}
  126. or @samp{tar --list} to list the contents of an archive. In addition,
  127. mnemonic names can be given unique abbreviations. For example,
  128. @samp{--cre} can be used in place of @samp{--create} because there is
  129. no other option which begins with @samp{cre}.
  130. Some options require an additional argument. Single letter options
  131. which require arguments use the immediately following argument. (This
  132. is an exception to the rule that @code{tar} arguments which are not
  133. options are file-name arguments.) Mnemonic options are separated from
  134. their arguments by an @samp{=} sign. For example, to create an an
  135. archive file named @file{george}, use either @samp{tar --create
  136. --file=george} or @samp{tar --create -f george}. Both
  137. @samp{--file=@var{archive-name}} and @samp{-f @var{archive-name}}
  138. denote the option to give the archive a non-default name, which in the
  139. example is @samp{george}.
  140. You can mix single letter and mnemonic forms in the same command. You
  141. could type the above example as @samp{tar -c --file=george} or
  142. @samp{tar --create -f george}. However, @code{tar} operations and
  143. options are case sensitive. You would not type the above example as
  144. @samp{tar -C --file=george}, because @samp{-C} is an option that
  145. causes @code{tar} to change directories, not an operation that creates
  146. an archive. In fact, @samp{-C} requires a further argument (the name
  147. of the directory which to change to). In this case, tar would think
  148. it needs to change to a directory named @samp{--file=george}, and
  149. wouldn't interpret @samp{--file-george} as an option at all!
  150. @node Argument Functions, Argument Form, Invoking @code{tar}, Invoking @code{tar}
  151. @section The Functions of Arguments
  152. You must give exactly one option from the following list to tar. This
  153. option specifies the basic operation for tar to perform.
  154. @itemize
  155. @item
  156. Add files to an existing archive (@samp{--add-file}, @samp{--append} or
  157. @samp{-r})
  158. @item
  159. Compare files in an archive with files in the file system
  160. (@samp{--compare}, @samp{--diff} or @samp{-d})
  161. @item
  162. Add archives to another archive (@samp{--add-archive}, @samp{--catenate}
  163. or @samp{-A})
  164. @c was --concatenate. -ringo
  165. @item
  166. Create a new archive (@samp{--create} or @samp{-c})
  167. @item
  168. Delete files from an archive (@samp{--delete})
  169. @item
  170. Extract files from an archive (@samp{--extract}, @samp{--get} or @samp{-x})
  171. @item
  172. List the files in an archive (@samp{--list} or @samp{-t})
  173. @item
  174. Update an archive by appending newer versions of already stored files
  175. (@samp{--update} or @samp{-u})
  176. @end itemize
  177. @xref{Reading and Writing}, for more information about these
  178. operations.
  179. The remaining options to @code{tar} change details of the operation,
  180. such as archive format, archive name, or level of user interaction.
  181. You can specify more than one option.
  182. The remaining arguments are file-name arguments. For --add-file and
  183. --create these arguments specify the names of files (which must
  184. already exist) to place in the archive. For the remaining operation
  185. types, the file-name arguments specify archive members to compare,
  186. delete, extract, list, or update. When naming archive members, you
  187. must give the exact name of the member in the archive. When naming
  188. files, the normal file name rules apply.
  189. If you don't use any file-name arguments, @samp{--add-file},
  190. @samp{--update} and @samp{--delete} will do nothing. Naturally,
  191. @samp{--create} will make an empty archive if given no file-name
  192. arguments. The other operations of @code{tar} will act on defaults.
  193. Anytime you use a file-name argument to specify a directory file,
  194. @code{tar} acts recursively on all the files and directories beneath
  195. that directory.
  196. @node Old Syntax for Commands, , Argument Form, Invoking @code{tar}
  197. @section An Old, but Still Supported, Syntax for @code{tar} Commands
  198. For historical reasons, GNU @code{tar} also accepts a syntax for
  199. commands which splits options that require additional arguments into
  200. two parts. That syntax is of the form:
  201. @example
  202. @code{tar} @var{option-letters}... [@var{option-arguments}...] [@var{file-names}...]@refill
  203. @end example
  204. @noindent
  205. where arguments to the options appear in the same order as the letters
  206. to which they correspond, and the operation and all the option letters
  207. appear as a single argument, without separating spaces.
  208. This command syntax is useful because it lets you type the single
  209. letter forms of the operation and options as a single argument to
  210. @code{tar}, without writing preceding @samp{-}s or inserting spaces
  211. between letters. @samp{tar cv} or @samp{tar -cv} are equivalent to
  212. @samp{tar -c -v}.
  213. On the other hand, this old style syntax makes it difficult to match
  214. option letters with their corresponding arguments, and is often
  215. confusing. In the command @samp{tar cvbf 20 /dev/rmt0}, for example,
  216. @samp{20} is the argument for @samp{-b}, @samp{/dev/rmt0} is the
  217. argument for @samp{-f}, and @samp{-v} does not have a corresponding
  218. argument. The modern syntax---@samp{tar -c -v -b 20 -f
  219. /dev/rmt0}---is clearer.
  220. @node Tutorial, Wizardry, Invoking @code{tar}, Top
  221. @chapter Getting Started With @code{tar}
  222. This chapter guides you through some basic examples of @code{tar}
  223. operations. If you already know how to use some other version of tar,
  224. then you probably don't need to read this chapter. In the examples,
  225. the lines you should type are preceded by a @samp{%}, which is a
  226. typical shell prompt.
  227. @menu
  228. * Creating Archives:: Creating Archives
  229. * Extracting Files:: Extracting Files from an Archive
  230. * Listing Archive Contents:: Listing the Contents of an Archive
  231. * Comparing Files:: Comparing Archives with the File System
  232. * Adding to Archives:: Adding Files to Existing Archives
  233. * Concatenate:: Concatenating Archives
  234. * Deleting Files:: Deleting Files From an Archive
  235. @end menu
  236. @node Creating Archives, Listing Archive Contents, Tutorial, Tutorial
  237. @section Creating Archives
  238. To create a new archive, use @code{tar --create} (or @code{tar -c}).
  239. You can use options to specify the name and format of the archive (as
  240. well as other characteristics), and you can use file-name arguments to
  241. specify which files to put in the archive. If you don't use any
  242. options or file-name arguments, @code{tar} will use default values.
  243. @xref{Creating Example}, for more information about the
  244. @samp{--create} operation.
  245. @menu
  246. * Creating Example:: Creating Archives of Files
  247. * Subdirectory:: Creating an Archive of a Subdirectory
  248. @end menu
  249. @node Creating Example, Subdirectory, Creating Archives, Creating Archives
  250. @subsection Creating Archives of Files
  251. This example shows you how to create an archive file in the working
  252. directory containing other files in the working directory. The three
  253. files you archive in this example are called @file{blues},
  254. @file{folk}, and @file{jazz}. The archive file is called
  255. @file{records}. While the archive in this example is written to the
  256. file system, it could also be written to any other device.
  257. (If you want to follow along with this and future examples, create a
  258. directory called @file{practice} containing files called @file{blues},
  259. @file{folk} and @file{jazz}. To create the directory, type
  260. @samp{mkdir practice} at the system prompt. It will probably be
  261. easiest to create the files using a text editor, such as Emacs.)
  262. First, change into the directory containing the files you want to
  263. archive:
  264. @example
  265. % cd practice
  266. @end example
  267. @noindent
  268. @file{~/practice} is now your working directory.
  269. Then, check that the files to be archived do in fact exist in the
  270. working directory, and make sure there isn't already a file in the
  271. working directory with the archive name you intend to use. If you
  272. specify an archive file name that is already in use, @code{tar} will
  273. overwrite the old file and its contents will be lost.
  274. To list the names of files in the working directory, type:
  275. @example
  276. % ls
  277. @end example
  278. The system responds:
  279. @example
  280. blues folk jazz
  281. %
  282. @end example
  283. @noindent
  284. Then,
  285. @itemize @bullet
  286. @item
  287. Create a new archive (@samp{tar -c} or @samp{tar --create})
  288. @item
  289. Explicitly name the archive file being created (@samp{-f
  290. @var{archive-name}} or @samp{--file=@var{archive-name}}). If you don't
  291. use this option @code{tar} will write the archive to the default
  292. storage device, which varies from system to system.
  293. @c <<< this syntax may change. OK now---check before printing -ringo
  294. @code{tar} interprets archive file names relative to the working
  295. directory. Make sure you have write access to the working directory
  296. before using @code{tar}.
  297. @item
  298. Specify which files to put into the archive (@code{tar} interprets
  299. file names relative to the working directory). If you don't use any
  300. @var{file-name} arguments, @code{tar} will archive everything in the
  301. working directory.
  302. @end itemize
  303. @noindent
  304. Type:
  305. @example
  306. % tar --create --file=records blues folk jazz
  307. @end example
  308. @noindent
  309. If you now list the contents of the working directory (@samp{ls}), you
  310. will find the archive file listed as well as the files you saw
  311. previously.
  312. @example
  313. % ls
  314. blues folk jazz records
  315. %
  316. @end example
  317. @menu
  318. * Listing Files:: Listing files in an archive
  319. * Verbose:: Using @code{tar} in Verbose Mode
  320. @end menu
  321. @node Listing Files, Verbose, Creating Example, Creating Example
  322. @subsubsection Listing files in an archive
  323. You can list the contents of an archive with another operation of
  324. @code{tar}---@samp{--list} or @samp{-l}. To list the contents of the
  325. archive you just created, type:
  326. @example
  327. % tar --list --file=records
  328. @end example
  329. @noindent
  330. @code{tar} will respond:
  331. @example
  332. blues folk jazz
  333. @end example
  334. @xref{Listing Archive Contents}, for a more detailed tutorial of the
  335. @samp{--list} operation. @xref{Listing Contents}, for more information
  336. about the @samp{--list} operation.
  337. @node Verbose, , Listing Files, Creating Example
  338. @subsubsection Using @code{tar} in Verbose Mode
  339. If you include the @samp{--verbose} or @samp{-v} option on the command
  340. line, @code{tar} will list the files it is acting on as it is working.
  341. In verbose mode, the creation example above would appear as:
  342. @cindex Verbose mode example
  343. @findex -v (verbose mode example)
  344. @example
  345. % tar --create --file=records --verbose blues folk jazz
  346. blues
  347. folk
  348. jazz
  349. @end example
  350. @noindent
  351. The first line is the command typed in by the user. The remaining
  352. lines are generated by @code{tar}. In the following examples we
  353. usually use verbose mode, though it is almost never required.
  354. @node Subdirectory, Changing, Creating Example, Creating Archives
  355. @subsection Creating an Archive of a Subdirectory
  356. You can store a directory in an archive by using the directory name as
  357. a file-name argument to @code{tar}. When you specify a directory
  358. file, @code{tar} archives the directory file and all the files it
  359. contains. The names of the directory and the files it contains are
  360. stored in the archive relative to the current working directory---when
  361. the directory is extracted they will be written into the file system
  362. relative to the working directory at that time.
  363. @c <<< add an xref to --absolute-paths -ringo
  364. To archive a directory, first move to its superior directory. If you
  365. have been following the tutorial, you should type:
  366. @example
  367. % cd ..
  368. %
  369. @end example
  370. Once in the superior directory, specify the subdirectory using a
  371. file-name argument. To store the directory file @file{~/practice} in
  372. the archive file @file{music}, type:
  373. @example
  374. % tar --create --verbose --file=music practice
  375. @end example
  376. @noindent
  377. @code{tar} should respond:
  378. @example
  379. practice/
  380. practice/blues
  381. practice/folk
  382. practice/jazz
  383. practice/records
  384. @end example
  385. Note that @file{~/practice/records}, another archive file, has
  386. itself been archived. @code{tar} will accept any file as a file to be
  387. archived, even an archive file.
  388. @c >>> symbolic links and changing directories are now in main body, not in
  389. @c >>> tutorial. -ringo
  390. @node Extracting Files
  391. @section Extracting Files from an Archive
  392. Creating an archive is only half the job---there would be no point in
  393. storing files in an archive if you couldn't retrieve them. To extract
  394. files from an archive, use the @samp{--extract} or @samp{-x} operation.
  395. To extract specific files, use their names as file-name arguments. If
  396. you use a directory name as a file-name argument, @code{tar} extracts
  397. all the files (including subdirectories) in that directory. If you
  398. don't use any file-name arguments, @code{tar} extracts all the files
  399. in the archive.
  400. Note: @code{tar} will extract an archive member into the file system
  401. without checking to see if there is already a file with the archive
  402. member's file name. If there is a file with that name, @code{tar}
  403. will @strong{overwrite} that file and its contents will be lost.
  404. @c <<<xref keep-old -ringo
  405. @node Extracting Specific Files, , ,
  406. @subsection Extracting Specific Files
  407. To extract specific files, specify them using file-name arguments.
  408. In an example above, you created the archive file
  409. @file{~/practice/records}, which contained the files @file{blues},
  410. @file{folk} and @file{jazz} in the @file{practice} directory. If, for
  411. some reason, you were to lose one of those text files (@samp{rm
  412. ~/practice/blues}), you could extract it from the archive file.
  413. First, change into the @file{practice} directory. Then,
  414. @itemize @bullet
  415. @item
  416. Invoke @code{tar} and specify the @samp{--extract} operation
  417. (@samp{--extract}, @samp{--get} or @samp{-x})
  418. @item
  419. Specify the archive that the files will be extracted from
  420. (@samp{--file=@var{archive-name}} or @samp{-f @var{archive-name}})
  421. @item
  422. Specify the files to extract, using file-name arguments (if you don't
  423. specify any files, @code{tar} extracts all the archive members)
  424. @end itemize
  425. @example
  426. % tar --extract --file=records blues
  427. @end example
  428. If you list the contents of the directory, you will see that
  429. @file{blues} is back:
  430. @example
  431. % ls
  432. folk
  433. jazz
  434. records
  435. blues
  436. @end example
  437. @node Extracting Directories, , ,
  438. @subsection Extracting Directories
  439. To extract a directory and all the files it contains, use the
  440. directory's name as a file-name argument in conjunction with @samp{tar
  441. --extract}. Remember---@code{tar} stores and extracts file names
  442. relative to the working directory.
  443. In a previous example you stored the directory @file{~/practice} in
  444. the archive file @file{~/music}. If you delete the contents of
  445. @file{practice}, you can restore them using @code{tar}.
  446. First, change into the @file{practice} subdirectory (@samp{cd
  447. ~/practice}). Then, remove all the files in @samp{~/practice}
  448. (@samp{rm *}). If you list the contents of the directory, you should
  449. now see that it is empty:
  450. @example
  451. %ls
  452. %
  453. @end example
  454. @noindent Let's try to restore the contents of @file{practice} by extracting
  455. them from the archive file @file{~/music}:
  456. @example
  457. tar --extract --file=~/music practice
  458. @end example
  459. @noindent Now, list the contents of @file{practice} again:
  460. @example
  461. %ls
  462. practice
  463. @end example
  464. What happened to the files? When you created @file{~/music}, your
  465. working directory was your home directory. When you extracted
  466. @file{~/music}, your working directory was @file{~/practice}.
  467. @code{tar} stored the files in @file{practice} relative to your home
  468. directory, and then extracted them relative to @file{~/practice}. The
  469. files are now in a new subdirectory, called
  470. @file{~/practice/practice}.
  471. To restore your files to their old positions, delete the new directory
  472. and its contents, and then redo the example above with your home
  473. directory as the working directory:
  474. @example
  475. % rm ~/practice/practice/*
  476. % rmdir practice
  477. % cd ..
  478. % tar --extract --file=music practice
  479. @end example
  480. @noindent (@code{tar} will report that it is unable to create the
  481. directory @file{~/practice} because it already exists. This will not
  482. effect the extraction of the other archive members.)
  483. @node Listing Archive Contents, Adding to Archives, Creating Archives, Tutorial
  484. @section Listing the Contents of an Archive
  485. Use @samp{--list} or @samp{-t} to print the names of files stored in an
  486. archive. If you use file-name arguments with this operation,
  487. @code{tar} prints the names of the specified files if they are stored
  488. in the archive. If you use a directory name as a file-name argument,
  489. @code{tar} also prints the names of all underlying files, including
  490. sub-directories. If you use no file-name arguments, @code{tar} prints
  491. the names of all the archive members.
  492. You can use @samp{--list} with the @samp{--verbose} option to print
  493. archive members' attributes (owner, size, etc.).
  494. @menu
  495. * Listing names:: Listing the names of stored files
  496. * Additional File Info:: Getting Additional File Information
  497. * Specific File:: List A Specific File in an Archive
  498. * Listing Directories:: Listing the Contents of a Stored Directory
  499. @end menu
  500. @node Listing names, Additional File Info, Listing Archive Contents, Listing Archive Contents
  501. @subsection Listing the names of stored files
  502. To list the names of files stored in an archive, use the @samp{--list}
  503. operation of @code{tar}.
  504. In a previous example, you created the archive @file{~/music}. To
  505. list the contents of @file{music}, while in your home directory:
  506. @itemize @bullet
  507. @item
  508. List the contents of an archive (@samp{tar -t} or @samp{tar --list})
  509. @item
  510. Specify the archive to be listed (@samp{-f @var{archive-name}} or
  511. @samp{--file=@var{archive-name}}) @refill
  512. @end itemize
  513. Thus:
  514. @example
  515. % tar --list --file=music
  516. practice/
  517. practice/blues
  518. practice/folk
  519. practice/jazz
  520. practice/records
  521. @end example
  522. @node Additional File Info, Specific File, Listing names, Listing Archive Contents
  523. @subsection Listing Additional File Information
  524. To get more information when you list the names of files stored in an
  525. archive, specify the @samp{--verbose} option in conjunction with
  526. @samp{tar --list}. @code{tar} will print archive member's file
  527. protection, owner and group ID, size, and date and time of creation.
  528. For example:
  529. @example
  530. % tar --list --verbose --file=music
  531. drwxrwxrwx myself/user 0 May 31 21:49 1990 practice/
  532. -rw-rw-rw- myself/user 42 May 21 13:29 1990 practice/blues
  533. -rw-rw-rw- myself/user 62 May 23 10:55 1990 practice/folk
  534. -rw-rw-rw- myself/user 40 May 21 13:30 1990 practice/jazz
  535. -rw-rw-rw- myself/user 10240 May 31 21:49 1990 practice/records
  536. %
  537. @end example
  538. Note that when you use @samp{--verbose} with @samp{--list}, @code{tar}
  539. doesn't print the names of files as they are being acted on, though
  540. the @samp{--verbose} option will have this effect when used with all
  541. other operations.
  542. @node Specific File, Comparing Files, Additional File Info, Listing Archive Contents
  543. @subsection List A Specific File in an Archive
  544. To to see if a particular file is in an archive, use the name of the
  545. file in question as a file-name argument while specifying the
  546. @samp{--list} operation. For example, to see whether the file
  547. @file{folk} is in the archive file @file{music}, do the following:
  548. @itemize @bullet
  549. @item
  550. Invoke @code{tar}, and specify the @samp{--list} operation
  551. (@samp{--list} or @samp{-t}).
  552. @item
  553. Specify the archive file to be acted on (@samp{--file
  554. @var{archive-name}} or @samp{-f @var{archive-name}}).
  555. @item
  556. Specify the files to look for, by typing their names as file-name
  557. arguments. You have to type the file name as it appears in the
  558. archive (normally, as it is relative to the relative to the directory
  559. from which the archive was created). <<< xref absolute-paths -ringo
  560. @end itemize
  561. Type:
  562. @example
  563. % tar --list --file=music practice/folk
  564. @end example
  565. @noindent
  566. @code{tar} responds:
  567. @example
  568. practice/folk
  569. @end example
  570. @noindent
  571. If the file were not stored in the archive (for example, the file
  572. @file{practice/rock}), the example above would look like:
  573. @example
  574. % tar --list --file=music practice/rock
  575. tar: practice/rock not found in archive
  576. @end example
  577. @noindent
  578. If you had used @samp{--verbose} mode, the example above would look
  579. like:
  580. @example
  581. % tar --list --file=music practice/folk
  582. -rw-rw-rw- myself/user 62 May 23 10:55 1990 practice/folk
  583. @end example
  584. @node Listing Directories, , ,
  585. @subsection Listing the Contents of a Stored Directory
  586. To get information about the contents of an archived directory, use
  587. the directory name as a file-name argument in conjunction with
  588. @samp{--list}. To find out file attributes, include the
  589. @samp{--verbose} option.
  590. For example, to find out about files in the directory @file{practice},
  591. in the archive file @file{music}, type:
  592. @example
  593. % tar --list --file=music practice
  594. @end example
  595. @noindent @code{tar} responds:
  596. @example
  597. drwxrwxrwx myself/user 0 May 31 21:49 1990 practice/
  598. -rw-rw-rw- myself/user 42 May 21 13:29 1990 practice/blues
  599. -rw-rw-rw- myself/user 62 May 23 10:55 1990 practice/folk
  600. -rw-rw-rw- myself/user 40 May 21 13:30 1990 practice/jazz
  601. -rw-rw-rw- myself/user 10240 May 31 21:49 1990 practice/records
  602. @end example
  603. When you use a directory name as a file-name argument, @code{tar} acts
  604. on all the files (including sub-directories) in that directory.
  605. @node Comparing Files, , ,
  606. @section Comparing Files in an Archive with Files in the File System
  607. To compare the attributes of archive members with the attributes of
  608. their counterparts in the file system, use the @samp{--compare},
  609. @samp{--diff}, or @samp{-d}) operation. While you could use
  610. @samp{--list --verbose} to manually compare some file attributes, it is
  611. simpler to have @code{tar} itself compare file attributes and report
  612. back on file differences.
  613. @c <<<"manually"? suggestions? -ringo
  614. The @samp{--compare} operation, as its name implies, compares archive
  615. members with files of the same name in the file system, and reports
  616. back differences in file size, mode, owner and modification date.
  617. @samp{tar --compare} acts only on archive members---it ignores files in
  618. the file system that are not stored in the archive. If you give
  619. @samp{tar --compare} a file-name argument that does not correspond to
  620. the name of an archive member, @code{tar} responds with an error
  621. message.
  622. To compare archive members in the archive file @file{records} with
  623. files in the @file{~/practice} directory, first change into the
  624. @file{practice} directory. Then:
  625. @itemize @bullet
  626. @item
  627. Invoke @code{tar} and specify the @samp{--compare} operation.
  628. (@samp{--compare}, @samp{--diff}, or @samp{-d}).
  629. @item
  630. Specify the archive where the files to be compared are stored
  631. (@samp{--file=@var{archive-name}} or @samp{-f @var{archive-name}})
  632. @item
  633. Specify the archive members to be compared. (In this example you are
  634. comparing all the archive members in the archive. Since this is the
  635. default, you don't need to use any file-name arguments).
  636. @end itemize
  637. @example
  638. % tar --compare --file=records
  639. %
  640. @end example
  641. @noindent
  642. While it looks like nothing has happened, @code{tar} has, in fact,
  643. done the comparison---and found nothing to report.
  644. Use the @samp{--verbose} option to list the names of archive members as
  645. they are being compared with their counterparts of the same name in
  646. the file system:
  647. @example
  648. % tar --compare --verbose --file=records
  649. blues
  650. folk
  651. jazz
  652. %
  653. @end example
  654. @noindent
  655. If @code{tar} had had anything to report, it would have done so as it
  656. was comparing each file.
  657. If you remove the file @file{jazz} from the file system (@samp{rm
  658. jazz}), and modify the file @file{blues} (for instance, by adding text
  659. to it with an editor such as Emacs), the above example would look
  660. like:
  661. @example
  662. % tar --compare --verbose --file=records
  663. blues
  664. blues: mod time differs
  665. blues: size differs
  666. folk
  667. jazz
  668. jazz: does not exist
  669. %
  670. @end example
  671. Note again that while @samp{tar --compare} reports the names of archive
  672. members that do not have counterparts in the file system, @samp{tar
  673. --compare} ignores files in the file system that do not have
  674. counterparts in the archive. To demonstrate this, create a file in
  675. the @file{practice} directory called @file{rock} (using any text
  676. editor). The new file appears when you list the directory's contents:
  677. @example
  678. % ls
  679. blues folk records rock
  680. @end example
  681. @noindent
  682. If you type the @samp{--compare} example again, @code{tar} prints the
  683. following:
  684. @example
  685. % tar --compare --verbose --file=records
  686. blues
  687. blues: mod time differs
  688. blues: size differs
  689. folk
  690. jazz
  691. jazz: does not exist
  692. %
  693. @end example
  694. @noindent
  695. @code{tar} ignores the file @file{rock} because @code{tar} is
  696. comparing archive members to files in the file system, not vice versa.
  697. If you specify @file{rock} explicitly (using a file-name argument),
  698. @code{tar} prints an error message:
  699. @example
  700. % tar --compare --verbose --file=records rock
  701. tar: rock not found in archive
  702. %
  703. @end example
  704. @menu
  705. * Comparing Directories:: Using Compare on Directories
  706. @end menu
  707. @node Comparing Directories, , ,
  708. @subsubsection Using Compare on Directories
  709. In addition to using @samp{--compare} to compare text files, you can
  710. use @samp{--compare} to compare directories. To illustrate this,
  711. re-create the examples above using your home directory as the working
  712. directory, and using the archive file @file{~/music} instead of the
  713. archive file @file{~/practice/records}.
  714. First, change into your home directory (@samp{cd ~}). Then, try the
  715. above example using @file{music} as the specified archive file, and
  716. @file{practice} as a file-name argument.
  717. @example
  718. % tar --compare --verbose --file=music practice
  719. @end example
  720. @noindent
  721. If you have been following along with the tutorial, @code{tar} will
  722. respond:
  723. @example
  724. practice
  725. practice/blues
  726. practice/blues: mod time differs
  727. practice/blues: size differs
  728. practice/folk
  729. practice/jazz
  730. practice/jazz: does not exist
  731. practice/records
  732. @end example
  733. @node Adding to Archives, Concatenate, Listing Archive Contents, Tutorial
  734. @section Adding Files to Existing Archives
  735. @c >>> we want people to use the script for backups, so I an not going to
  736. @c >>> use backups as an explanation in the tutorial. (people can still
  737. @c >>> do it if they really want to) -ringo
  738. While you can use @code{tar} to create a new archive every time you
  739. want to store a file, it is more sometimes efficient to add files to
  740. an existing archive.
  741. To add new files to an existing archive, use the @samp{--add-file},
  742. @samp{--append} or @samp{-r} operation. To add newer versions of
  743. archive members to an archive, use the @samp{--update} or @samp{-u}
  744. operation.
  745. @menu
  746. * Append:: Appending Files to an Archive
  747. * Update:: Updating Files in an Archive
  748. @end menu
  749. @node Append, Update, Adding to Archives, Adding to Archives
  750. @subsection Appending Files to an Archive
  751. The simplest method of adding a file to an existing archive is the
  752. @samp{--add-file}, @samp{-r} or @samp{--append} operation, which writes
  753. files into the archive without regard to whether or not they are
  754. already archive members. When you use @samp{--add-file} you must use
  755. file-name arguments; there is no default. If you specify a file that
  756. is already stored in the archive, @code{tar} adds another copy of the
  757. file to the archive.
  758. If you have been following the previous examples, you should have a
  759. text file called @file{~/practice/rock} which has not been stored in
  760. either the archive file @file{~/practice/records}, or the archive file
  761. @file{~/music}. To add @file{rock} to @file{records}, first make
  762. @file{practice} the working directory (@samp{cd practice}). Then:
  763. @itemize @bullet
  764. @item
  765. Invoke @code{tar} and specify the @samp{--add-file} operation
  766. (@samp{--add-file}, @samp{-r} or @samp{--append})
  767. @item
  768. Specify the archive to which the file will be added
  769. (@samp{--file=@var{archive-name}} or @samp{-f @var{archive-name}})
  770. @item
  771. Specify the files to be added to the archive, using file-name
  772. arguments
  773. @end itemize
  774. @noindent
  775. For example:
  776. @example
  777. % tar --add-file --file=records rock
  778. @end example
  779. @noindent
  780. If you list the archive members in @file{records}, you will see that
  781. @file{rock} has been added to the archive:
  782. @example
  783. % tar --list --file=records
  784. blues
  785. folk
  786. jazz
  787. rock
  788. @end example
  789. @c <<< this should be some kind of node.
  790. You can use @samp{--add-file} to keep archive members current with
  791. active files. Because @samp{--add-file} stores a file whether or not
  792. there is already an archive member with the same file name, you can
  793. use @samp{--add-file} to add newer versions of archive members to an
  794. archive. When you extract the file, only the version stored last will
  795. wind up in the file system. Because @samp{tar --extract} extracts
  796. files from an archive in sequence, and overwrites files with the same
  797. name in the file system, if a file name appears more than once in an
  798. archive the last version of the file will overwrite the previous
  799. versions which have just been extracted.
  800. If you recall from the examples using @samp{--compare} above,
  801. @file{blues} was changed after the archive @file{records} was created.
  802. It is simple, however, to use @samp{--add-file} to add the new version
  803. of @file{blues} to @file{records}:
  804. @example
  805. % tar --add-file --verbose --file=records blues
  806. blues
  807. @end example
  808. @noindent
  809. If you now list the contents of the archive, you will obtain the following:
  810. @example
  811. % tar --list -f records
  812. blues
  813. folk
  814. jazz
  815. rock
  816. blues
  817. @end example
  818. @noindent
  819. The newest version of @file{blues} is at the end of the archive. When
  820. the files in @file{records} are extracted, the newer version of
  821. @file{blues} (which has the same name as the older) will overwrite the
  822. version stored first. When @samp{tar --extract} is finished, only the
  823. newer version of @file{blues} is in the file system. <<<xref
  824. keep-old-files>>>
  825. @node Update, , Append, Adding to Archives
  826. @subsection Updating Files in an Archive
  827. To keep archive members up to date with their counterparts of the same
  828. name in the file system, use the @samp{--update} or @samp{-u}
  829. operation. @samp{tar --update} adds a specified file to an archive if
  830. no file of that name is already stored in the archive. If there is
  831. already an archive member with the same name, @code{tar} checks the
  832. modification date of the archive member, and adds the file only if its
  833. modification date is later. If a file is stored in the archive but no
  834. longer exists under the same name in the active file system,
  835. @code{tar} reports an error.
  836. You could use the @samp{--add-file} option to keep an archive current,
  837. but do so you would either have to use the @samp{--compare} and
  838. @samp{--list} options to determine what files needed to be re-archived
  839. (which could waste a lot of time), or you would have to be willing to
  840. add identical copies of already archived files to the archive (which
  841. could waste a lot of space).
  842. You must use file-name arguments with the @samp{--update}
  843. operation---if you don't specify any files, @code{tar} won't act on
  844. any files.
  845. To see the @samp{--update} option at work, create a new file,
  846. @file{~/practice/classical}, and modify the file
  847. @file{~/practice/blues} (you can use a text editor, such as Emacs, to
  848. do both these things). Then, with @file{practice} as your working
  849. directory, invoke @samp{tar --update} using the names of all the files
  850. in the practice directory as file-name arguments, and specifying the
  851. @samp{--verbose} option:
  852. @example
  853. % tar --update --verbose --file=records blues folk rock classical
  854. blues
  855. classical
  856. %
  857. @end example
  858. @noindent
  859. Because you specified verbose mode, @code{tar} printed out the names
  860. of the files it acted on. If you now list the archive members of the
  861. archive, (@samp{tar --list --file=records}), you will see that the file
  862. @file{classical} and another version of the file @file{blues} have
  863. been added to @file{records}.
  864. Note: When you update an archive, @code{tar} does not overwrite old
  865. archive members when it stores newer versions of a file. This is
  866. because archive members appear in an archive in the order in which
  867. they are stored, and some archive devices do not allow writing in the
  868. middle of an archive.
  869. @node Concatenate, Extracting Files Example, Adding to Archives, Tutorial
  870. @comment node-name, next, previous, up
  871. @section Concatenating Archives
  872. To concatenate archive files, use @samp{tar --concatenate} or @samp{tar
  873. -A}. This operation adds other archives to the end of an archive.
  874. While it may seem intuitive to concatenate archives using @code{cat},
  875. the utility for adding files together, archive files which have been
  876. "catted" together cannot be read properly by @code{tar}. Archive
  877. files incorporate an end of file marker---if archives are concatenated
  878. using @code{cat}, this marker will appear before the end of the new
  879. archive. This will interfere with operations on that archive.
  880. @c <<<xref ignore-zeros>>>
  881. In earlier examples, you stored the @file{~/practice} directory in an
  882. archive file, @file{~/music}. If you have been following the
  883. examples, you have since changed the contents of the @file{~/practice}
  884. directory. There is a current version of the files in the
  885. @file{practice} directory, however, stored in the archive file
  886. @file{~/practice/records}.
  887. To store current versions of the files in @file{practice} in the
  888. archive file @file{music}, you can use @samp{tar --concatenate} to add
  889. the archive file @file{~/practice/records} to @file{music}. First,
  890. make sure you are in your home directory (@samp{cd ~}). Then:
  891. @itemize @bullet
  892. @item
  893. Invoke @code{tar}, and specify the @samp{--concatenate} operation
  894. (@samp{-A} or @samp{--concatenate})
  895. @item
  896. Specify the archive file to be added to
  897. (@samp{--file=@var{archive-name}} or @samp{-f @var{archive-name}})
  898. @item
  899. Specify the archives to be added, using file-name arguments. In this
  900. case, the file-name arguments are, unusually, the names of archive
  901. files. (Remember to include the path in the archive name, if the
  902. archive file is not in your working directory.)
  903. @end itemize
  904. @example
  905. % cd ~
  906. % tar --concatenate --file=music practice/records
  907. @end example
  908. If you now list the contents of the @file{music}, you see it now
  909. contains the archive members of @file{practice/records}:
  910. @example
  911. %tar --list --file=music
  912. blues
  913. folk
  914. jazz
  915. rock
  916. blues
  917. practice/blues
  918. practice/folk
  919. practice/jazz
  920. practice/rock
  921. practice/blues
  922. practice/classical
  923. @end example
  924. @node Deleting Files, , , Tutorial
  925. @comment node-name, next, previous, up
  926. @section Deleting Files From an Archive
  927. In some instances, you may want to remove some files from an archive
  928. stored on disk
  929. @quotation
  930. @emph{Caution:} you should never delete files from an archive stored
  931. on tape---because of the linear nature of tape storage, doing this is
  932. likely to scramble the archive.
  933. @end quotation
  934. To remove archive members from an archive, use the @samp{--delete}
  935. operation. You must specify the names of files to be removed as
  936. file-name arguments. All versions of the named file are removed from
  937. the archive.
  938. Execution of the @samp{--delete} operation can be very slow.
  939. To delete all versions of the file @file{blues} from the archive
  940. @file{records} in the @file{practice} directory, make sure you are in
  941. that directory, and then:
  942. @itemize @bullet
  943. @item
  944. List the contents of the archive file @file{records} (see above for
  945. the steps involved) to insure that the file(s) you wish to delete are
  946. stored in the archive. (This step is optional)
  947. @item
  948. Invoke @code{tar} and specify the @samp{--delete} operation
  949. (@samp{--delete}).
  950. @item
  951. Specify the name of the archive file that the file(s) will be deleted
  952. from (@samp{--file=@var{archive-name}} or @samp{-f @var{archive-name}})
  953. @item
  954. Specify the files to be deleted, using file-name arguments.
  955. @item
  956. List the contents of the archive file again---note that the files have
  957. been removed. (this step is also optional)
  958. @end itemize
  959. @example
  960. % tar --list --file=records
  961. blues
  962. folk
  963. jazz
  964. % tar --delete --file=records blues
  965. % tar --list --file=records
  966. folk
  967. jazz
  968. %
  969. @end example
  970. @node Wizardry, Archive Structure, Tutorial, Top
  971. @chapter Wizardry
  972. <<<This section needs to be written -ringo
  973. @strong{To come:} using Unix file linking capability to recreate directory
  974. structures---linking files into one subdirectory and then tarring that
  975. directory.
  976. @strong{to come:} nice hairy example using absolute-paths, newer, etc.
  977. Piping one @code{tar} to another is an easy way to copy a directory's
  978. contents from one disk to another, while preserving the dates, modes, owners
  979. and link-structure of all the files therein.
  980. @example
  981. cd sourcedirectory; tar cf - . | (cd targetdir; tar xf -)
  982. @end example
  983. @noindent
  984. or
  985. <<< the following using standard input/output correct??
  986. @example
  987. cd sourcedirectory; tar --create --file=- . | (cd targetdir; tar --extract --file=-)
  988. @end example
  989. @noindent
  990. Archive files can be used for transporting a group of files from one system
  991. to another: put all relevant files into an archive on one computer system,
  992. transfer the archive to another, and extract the contents there. The basic
  993. transfer medium might be magnetic tape, Internet FTP, or even electronic
  994. mail (though you must encode the archive with @code{uuencode} in order to
  995. transport it properly by mail). Both machines do not have to use the same
  996. operating system, as long as they both support the @code{tar} program.
  997. @findex uuencode
  998. <<< mention uuencode on a paragraph of its own
  999. <<<<<end construction>>>>>
  1000. @node Archive Structure, Reading and Writing, Wizardry, Top
  1001. @chapter The Structure of an Archive
  1002. While an archive may contain many files, the archive itself is a
  1003. single ordinary file. Like any other file, an archive file can be
  1004. written to a storage device such as a tape or disk, sent through a
  1005. pipe or over a network, saved on the active file system, or even
  1006. stored in another archive. An archive file is not easy to read or
  1007. manipulate without using the @code{tar} utility or Tar mode in Emacs.
  1008. Physically, an archive consists of a series of file entries terminated
  1009. by an end-of-archive entry, which consists of 512 zero bytes. A file
  1010. entry usually describes one of the files in the archive (an
  1011. @dfn{archive member}), and consists of a file header and the contents
  1012. of the file. File headers contain file names and statistics, checksum
  1013. information which @code{tar} uses to detect file corruption, and
  1014. information about file types.
  1015. More than archive member can have the same file name. One way this
  1016. situation can occur is if more than one version of a file has been
  1017. stored in the archive. For information about adding new versions of a
  1018. file to an archive, @pxref{Modifying}.
  1019. In addition to entries describing archive members, an archive may contain
  1020. entries which @code{tar} itself uses to store information.
  1021. @xref{Archive Label}, for an example of such an archive entry.
  1022. @menu
  1023. * Old Style File Information:: Old Style File Information
  1024. * Archive Label::
  1025. * Format Variations::
  1026. @end menu
  1027. @node Old Style File Information, Archive Label, Archive Structure, Archive Structure
  1028. @section Old Style File Information
  1029. @cindex Format, old style
  1030. @cindex Old style format
  1031. @cindex Old style archives
  1032. Archives record not only an archive member's contents, but also its
  1033. file name or names, its access permissions, user and group, size in
  1034. bytes, and last modification time. Some archives also record the file
  1035. names in each archived directory, as well as other file and directory
  1036. information.
  1037. Certain old versions of @code{tar} cannot handle additional
  1038. information recorded by newer @code{tar} programs. To create an
  1039. archive which can be read by these old versions, specify the
  1040. @samp{--old-archive} option in conjunction with the @samp{tar --create}
  1041. operation. When you specify this option, @code{tar} leaves out
  1042. information about directories, pipes, fifos, contiguous files, and
  1043. device files, and specifies file ownership by group and user ids
  1044. instead of names.
  1045. The @samp{--old-archive} option is needed only if the archive must be
  1046. readable by an older tape archive program which cannot handle the new format.
  1047. Most @code{tar} programs do not have this limitation, so this option
  1048. is seldom needed.
  1049. @table @samp
  1050. @item --old-archive
  1051. @itemx -o
  1052. @itemx --old
  1053. @itemx --portable
  1054. @c has portability been changed to portable?
  1055. Creates an archive that can be read by an old @code{tar} program.
  1056. Used in conjunction with the @samp{tar --create} operation.
  1057. @end table
  1058. @node Archive Label, Format Variations, Old Style File Information, Archive Structure
  1059. @section Including a Label in the Archive
  1060. @cindex Labeling an archive
  1061. @cindex Labels on the archive media
  1062. @c !! Should the arg to --label be a quoted string?? no - ringo
  1063. To avoid problems caused by misplaced paper labels on the archive
  1064. media, you can include a @dfn{label} entry---an archive member which
  1065. contains the name of the archive---in the archive itself. Use the
  1066. @samp{--label=@var{archive-label}} option in conjunction with the
  1067. @samp{--create} operation to include a label entry in the archive as it
  1068. is being created.
  1069. If you create an archive using both @samp{--label=@var{archive-label}}
  1070. and @samp{--multi-volume}, each volume of the archive will have an
  1071. archive label of the form @samp{@var{archive-label} Volume @var{n}},
  1072. where @var{n} is 1 for the first volume, 2 for the next, and so on.
  1073. @xref{Multi-Volume Archives}, for information on creating multiple
  1074. volume archives.
  1075. If you extract an archive using @samp{--label=@var{archive-label}},
  1076. @code{tar} will print an error if the archive label doesn't match the
  1077. @var{archive-label} specified, and will then not extract the archive.
  1078. You can include a regular expression in @var{archive-label}, in this
  1079. case only.
  1080. @c >>> why is a reg. exp. useful here? (to limit extraction to a
  1081. @c >>>specific group? ie for multi-volume??? -ringo
  1082. To find out an archive's label entry (or to find out if an archive has
  1083. a label at all), use @samp{tar --list --verbose}. @code{tar} will print the
  1084. label first, and then print archive member information, as in the
  1085. example below:
  1086. @example
  1087. % tar --verbose --list --file=iamanarchive
  1088. V--------- 0/0 0 Mar 7 12:01 1992 iamalabel--Volume Header--
  1089. -rw-rw-rw- ringo/user 40 May 21 13:30 1990 iamafilename
  1090. @end example
  1091. @table @samp
  1092. @item --label=@var{archive-label}
  1093. @itemx -V @var{archive-label}
  1094. Includes an @dfn{archive-label} at the beginning of the archive when
  1095. the archive is being created (when used in conjunction with the
  1096. @samp{tar --create} operation). Checks to make sure the archive label
  1097. matches the one specified (when used in conjunction with the @samp{tar
  1098. --extract} operation.
  1099. @end table
  1100. @c was --volume
  1101. @node Format Variations, , Archive Label, Archive Structure
  1102. @section Format Variations
  1103. @cindex Format Parameters
  1104. @cindex Format Options
  1105. @cindex Options to specify archive format.
  1106. Format parameters specify how an archive is written on the archive
  1107. media. The best choice of format parameters will vary depending on
  1108. the type and number of files being archived, and on the media used to
  1109. store the archive.
  1110. To specify format parameters when accessing or creating an archive,
  1111. you can use the options described in the following sections. If you
  1112. do not specify any format parameters, @code{tar} uses default
  1113. parameters. You cannot modify a compressed archive. If you create an
  1114. archive with the @samp{--block-size} option specified (@pxref{Blocking
  1115. Factor}), you must specify that block-size when operating on the
  1116. archive. @xref{Matching Format Parameters}, for other examples of
  1117. format parameter considerations.
  1118. @menu
  1119. * Multi-Volume Archives::
  1120. * Sparse Files::
  1121. * Blocking Factor::
  1122. * Compressed Archives::
  1123. @end menu
  1124. @node Multi-Volume Archives, Sparse Files, Format Variations, Format Variations
  1125. @subsection Archives Longer than One Tape or Disk
  1126. @cindex Multi-volume archives
  1127. To create an archive that is larger than will fit on a single unit of
  1128. the media, use the @samp{--multi-volume} option in conjunction with the
  1129. @samp{tar --create} operation (@pxref{Creating Archives}). A
  1130. @dfn{multi-volume} archive can be manipulated like any other archive
  1131. (provided the @samp{--multi-volume} option is specified), but is stored
  1132. on more than one tape or disk.
  1133. When you specify @samp{--multi-volume}, @code{tar} does not report an
  1134. error when it comes to the end of an archive volume (when reading), or
  1135. the end of the media (when writing). Instead, it prompts you to load
  1136. a new storage volume. If the archive is on a magnetic tape, you
  1137. should change tapes when you see the prompt; if the archive is on a
  1138. floppy disk, you should change disks; etc.
  1139. You can read each individual volume of a multi-volume archive as if it
  1140. were an archive by itself. For example, to list the contents of one
  1141. volume, use @samp{tar --list}, without @samp{--multi-volume} specified.
  1142. To extract an archive member from one volume (assuming it is described
  1143. that volume), use @samp{tar --extract}, again without
  1144. @samp{--multi-volume}.
  1145. If an archive member is split across volumes (ie. its entry begins on
  1146. one volume of the media and ends on another), you need to specify
  1147. @samp{--multi-volume} to extract it successfully. In this case, you
  1148. should load the volume where the archive member starts, and use
  1149. @samp{tar --extract --multi-volume}---@code{tar} will prompt for later
  1150. volumes as it needs them. @xref{Extracting From Archives} for more
  1151. information about extracting archives.
  1152. @samp{--info-script=@var{program-file}} is like @samp{--multi-volume},
  1153. except that @code{tar} does not prompt you directly to change media
  1154. volumes when a volume is full---instead, @code{tar} runs commands you
  1155. have stored in @var{program-file}. This option can be used to
  1156. broadcast messages such as @samp{someone please come change my tape}
  1157. when performing unattended backups. When @var{program-file} is done,
  1158. @code{tar} will assume that the media has been changed.
  1159. <<< There should be a sample program here, including an exit before
  1160. <<< end.
  1161. @table @samp
  1162. @item --multi-volume
  1163. @itemx -M
  1164. Creates a multi-volume archive, when used in conjunction with
  1165. @samp{tar --create}. To perform any other operation on a multi-volume
  1166. archive, specify @samp{--multi-volume} in conjunction with that
  1167. operation.
  1168. @item --info-script=@var{program-file}
  1169. @itemx -F @var{program-file}
  1170. Creates a multi-volume archive via a script. Used in conjunction with
  1171. @samp{tar --create}.
  1172. @end table
  1173. @node Sparse Files, Blocking Factor, Multi-Volume Archives, Format Variations
  1174. @subsection Archiving Sparse Files
  1175. @cindex Sparse Files
  1176. A file is sparse if it contains blocks of zeros whose existance is
  1177. recorded, but that have no space allocated on disk. When you specify
  1178. the @samp{--sparse} option in conjunction with the @samp{--create}
  1179. operation, @code{tar} tests all files for sparseness while archiving.
  1180. If @code{tar} finds a file to be sparse, it uses a sparse
  1181. representation of the file in the archive. @xref{Creating Archives},
  1182. for more information about creating archives.
  1183. @samp{--sparse} is useful when archiving files, such as dbm files,
  1184. likely to contain many nulls. This option dramatically
  1185. decreases the amount of space needed to store such an archive.
  1186. @quotation
  1187. @strong{Please Note:} Always use @samp{--sparse} when performing file
  1188. system backups, to avoid archiving the expanded forms of files stored
  1189. sparsely in the system.@refill
  1190. Even if your system has no no sparse files currently, some may be
  1191. created in the future. If you use @samp{--sparse} while making file
  1192. system backups as a matter of course, you can be assured the archive
  1193. will always take no more space on the media than the files take on
  1194. disk (otherwise, archiving a disk filled with sparse files might take
  1195. hundreds of tapes).@refill
  1196. <<< xref incremental when node name is set.
  1197. @end quotation
  1198. @code{tar} ignores the @samp{--sparse} option when reading an archive.
  1199. @table @samp
  1200. @item --sparse
  1201. @itemx -S
  1202. Files stored sparsely in the file system are represented sparsely in
  1203. the archive. Use in conjunction with write operations.
  1204. @end table
  1205. @node Blocking Factor, Compressed Archives, Sparse Files, Format Variations
  1206. @subsection The Blocking Factor of an Archive
  1207. @cindex Blocking Factor
  1208. @cindex Block Size
  1209. @cindex Number of records per block
  1210. @cindex Number of bytes per block
  1211. @cindex Bytes per block
  1212. @cindex Records per block
  1213. The data in an archive is grouped into records, which are 512 bytes.
  1214. Records are read and written in whole number multiples called
  1215. @dfn{blocks}. The number of records in a block (ie. the size of a
  1216. block in units of 512 bytes) is called the @dfn{blocking factor}. The
  1217. @samp{--block-size=@var{number}} option specifies the blocking factor
  1218. of an archive. The default blocking factor is typically 20 (ie.@:
  1219. 10240 bytes), but can be specified at installation. To find out the
  1220. blocking factor of an existing archive, use @samp {tar --list
  1221. --file=@var{archive-name}}. This may not work on some devices.
  1222. Blocks are seperated by gaps, which waste space on the archive media.
  1223. If you are archiving on magnetic tape, using a larger blocking factor
  1224. (and therefore larger blocks) provides faster throughput and allows
  1225. you to fit more data on a tape (because there are fewer gaps). If you
  1226. are archiving on cartridge, a very large blocking factor (say 126 or
  1227. more) greatly increases performance. A
  1228. smaller blocking factor, on the other hand, may be usefull when
  1229. archiving small files, to avoid archiving lots of nulls as @code{tar}
  1230. fills out the archive to the end of the block. In general, the ideal block size
  1231. depends on the size of the inter-block gaps on the tape you are using,
  1232. and the average size of the files you are archiving. @xref{Creating
  1233. Archives}, for information on writing archives.
  1234. Archives with blocking factors larger than 20 cannot be read by very
  1235. old versions of @code{tar}, or by some newer versions of @code{tar}
  1236. running on old machines with small address spaces. With GNU
  1237. @code{tar}, the blocking factor of an archive is limited only by the
  1238. maximum block size of the device containing the archive, or by the
  1239. amount of available virtual memory.
  1240. If you use a non-default blocking factor when you create an archive,
  1241. you must specify the same blocking factor when you modify that
  1242. archive. Some archive devices will also require you to specify the
  1243. blocking factor when reading that archive, however this is not
  1244. typically the case. Usually, you can use @samp{tar --list} without
  1245. specifying a blocking factor---@code{tar} reports a non-default block
  1246. size and then lists the archive members as it would normally. To
  1247. extract files from an archive with a non-standard blocking factor
  1248. (particularly if you're not sure what the blocking factor is), you can
  1249. usually use the {--read-full-blocks} option while specifying a blocking
  1250. factor larger then the blocking factor of the archive (ie. @samp{tar
  1251. --extract --read-full-blocks --block-size=300}. @xref{Listing Contents}
  1252. for more information on the @samp{--list} operation.
  1253. @xref{read-full-blocks} for a more detailed explanation of that
  1254. option.
  1255. @table @samp
  1256. @item --block-size=@var{number}
  1257. @itemx -b @var{number}
  1258. Specifies the blocking factor of an archive. Can be used with any
  1259. operation, but is usually not necessary with @samp{tar --list}.
  1260. @end table
  1261. @node Compressed Archives, , Blocking Factor, Format Variations
  1262. @subsection Creating and Reading Compressed Archives
  1263. @cindex Compressed archives
  1264. @cindex Storing archives in compressed format
  1265. @samp{--compress} indicates an archive stored in compressed format.
  1266. The @samp{--compress} option is useful in saving time over networks and
  1267. space in pipes, and when storage space is at a premium.
  1268. @samp{--compress} causes @code{tar} to compress when writing the
  1269. archive, or to uncompress when reading the archive.
  1270. To perform compression and uncompression on the archive, @code{tar}
  1271. runs the @code{compress} utility. @code{tar} uses the default
  1272. compression parameters; if you need to override them, avoid the
  1273. @samp{--compress} option and run the @code{compress} utility
  1274. explicitly. It is useful to be able to call the @code{compress}
  1275. utility from within @code{tar} because the @code{compress} utility by
  1276. itself cannot access remote tape drives.
  1277. The @samp{--compress} option will not work in conjunction with the
  1278. @samp{--multi-volume} option or the @samp{--add-file}, @samp{--update},
  1279. @samp{--add-file} and @samp{--delete} operations. @xref{Modifying}, for
  1280. more information on these operations.
  1281. If there is no compress utility available, @code{tar} will report an
  1282. error.
  1283. @samp{--compress-block} is like @samp{--compress}, but when used in
  1284. conjunction with @samp{--create} also causes @code{tar} to pad the last
  1285. block of the archive out to the next block boundary as it is written.
  1286. This is useful with certain devices which require all write operations
  1287. be a multiple of a specific size.
  1288. @quotation
  1289. @strong{Please Note:} The @code{compress} program may be covered by a patent,
  1290. and therefore we recommend you stop using it. We hope to have a
  1291. different compress program in the future. We may change the name of
  1292. this option at that time.
  1293. @end quotation
  1294. @table @samp
  1295. @item --compress
  1296. @itemx --uncompress
  1297. @itemx -z
  1298. @itemx -Z
  1299. When this option is specified, @code{tar} will compress (when writing
  1300. an archive), or uncompress (when reading an archive). Used in
  1301. conjunction with the @samp{--create}, @samp{--extract}, @samp{--list} and
  1302. @samp{--compare} operations.
  1303. @item --compress-block
  1304. @itemx -z -z
  1305. Acts like @samp{--compress}, but pads the archive out to the next block
  1306. boundary as it is written when used in conjunction with the
  1307. @samp{--create} operation.
  1308. @end table
  1309. @c >>> MIB -- why not use -Z instead of -z -z ? -ringo
  1310. @node Reading and Writing, Insuring Accuracy, Archive Structure, Top
  1311. @chapter Reading and Writing Archives
  1312. The @samp{--create} operation writes a new archive, and the
  1313. @samp{--extract} operation reads files from an archive and writes them
  1314. into the file system. You can use other @code{tar} operations to
  1315. write new information into an existing archive (adding files to it,
  1316. adding another archive to it, or deleting files from it), and you can
  1317. read a list of the files in an archive without extracting it using the
  1318. @samp{--list} operation.
  1319. @menu
  1320. * Archive Name:: The name of an archive
  1321. * Creating in Detail:: Creating in detail
  1322. * Modifying:: Modifying archives
  1323. * Listing Contents:: Listing the contents of an archive
  1324. * Extracting From Archives:: Extracting files from an archive
  1325. @end menu
  1326. @node Archive Name, Creating in Detail, Reading and Writing, Reading and Writing
  1327. @section The Name of an Archive
  1328. @cindex Naming an archive
  1329. @cindex Archive Name
  1330. @cindex Directing output
  1331. @cindex Where is the archive?
  1332. An archive can be saved as a file in the file system, sent through a
  1333. pipe or over a network, or written to an I/O device such as a tape or
  1334. disk drive. To specify the name of the archive, use the
  1335. @samp{--file=@var{archive-name}} option.
  1336. An archive name can be the name of an ordinary file or the name of an
  1337. I/O device. @code{tar} always needs an archive name---if you do not
  1338. specify an archive name, the archive name comes from the environment
  1339. variable @code{TAPE} or, if that variable is not specified, a default
  1340. archive name, which is usually the name of tape unit zero (ie.
  1341. /dev/tu00).
  1342. If you use @file{-} as an @var{archive-name}, @code{tar} reads the
  1343. archive from standard input (when listing or extracting files), or
  1344. writes it to standard output (when creating an archive). If you use
  1345. @file{-} as an @var{archive-name} when modifying an archive,
  1346. @code{tar} reads the original archive from its standard input and
  1347. writes the entire new archive to its standard output.
  1348. @c >>> MIB--does standard input and output redirection work with all
  1349. @c >>> operations?
  1350. @c >>> need example for standard input and output (screen and keyboard?)
  1351. @cindex Standard input and output
  1352. @cindex tar to standard input and output
  1353. To specify an archive file on a device attached to a remote machine,
  1354. use the following:
  1355. @example
  1356. --file=@var{hostname}:/@var{dev}/@var{file name}
  1357. @end example
  1358. @noindent
  1359. @code{tar} will complete the remote connection, if possible, and
  1360. prompt you for a username and password. If you use
  1361. @samp{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @code{tar}
  1362. will complete the remote connection, if possible, using your username
  1363. as the username on the remote machine.
  1364. @c >>>MIB --- is this clear?
  1365. @table @samp
  1366. @item --file=@var{archive-name}
  1367. @itemx -f @var{archive-name}
  1368. Names the archive to create or operate on. Use in conjunction with
  1369. any operation.
  1370. @end table
  1371. @node Creating in Detail, Modifying, Archive Name, Reading and Writing
  1372. @section Creating in Detail
  1373. @c operations should probably have examples, not tables.
  1374. @cindex Writing new archives
  1375. @cindex Archive creation
  1376. To create an archive, use @samp{tar --create}. To name the archive,
  1377. use @samp{--file=@var{archive-name}} in conjunction with the
  1378. @samp{--create} operation (@pxref{Archive Name}). If you do not name
  1379. the archive, @code{tar} uses the value of the environment variable
  1380. @code{TAPE} as the file name for the archive, or, if that is not
  1381. available, @code{tar} uses a default archive name, usually that for tape
  1382. unit zero. @xref{Archive Name}, for more information about specifying
  1383. an archive name.
  1384. The following example creates an archive named @file{stooges},
  1385. containing the files @file{larry}, @file{moe} and @file{curley}:
  1386. @example
  1387. tar --create --file=stooges larry moe curley
  1388. @end example
  1389. If you specify a directory name as a file-name argument, @code{tar}
  1390. will archive all the files in that directory. The following example
  1391. creates an archive named @file{hail/hail/fredonia}, containing the
  1392. contents of the directory @file{marx}:
  1393. @example
  1394. tar --create --file=hail/hail/fredonia marx
  1395. @end example
  1396. If you don't specify files to put in the archive, @code{tar} archives
  1397. all the files in the working directory. The following example creates
  1398. an archive named @file{home} containing all the files in the working
  1399. directory:
  1400. @example
  1401. tar --create --file=home
  1402. @end example
  1403. @xref{File Name Lists}, for other ways to specify files to archive.
  1404. Note: In the example above, an archive containing all the files in the
  1405. working directory is being written to the working directory. GNU
  1406. @code{tar} stores files in the working directory in an archive which
  1407. is itself in the working directory without falling into an infinite
  1408. loop. Other versions of @code{tar} may fall into this trap.
  1409. @node Modifying, Listing Contents, Creating in Detail, Reading and Writing
  1410. @section Modifying Archives
  1411. @cindex Modifying archives
  1412. Once an archive is created, you can add new archive members to it, add
  1413. the contents of another archive, add newer versions of members already
  1414. stored, or delete archive members already stored.
  1415. To find out what files are already stored in an archive, use @samp{tar
  1416. --list --file=@var{archive-name}}. @xref{Listing Contents}.
  1417. @menu
  1418. * Adding Files::
  1419. * Appending Archives::
  1420. * Deleting Archive Files:: Deleting Files From an Archive
  1421. * Matching Format Parameters::
  1422. @end menu
  1423. @node Adding Files, Appending Archives, Modifying, Modifying
  1424. @subsection Adding Files to an Archive
  1425. @cindex Adding files to an archive
  1426. @cindex Updating an archive
  1427. To add files to an archive, use @samp{tar --add-file}. The archive to
  1428. be added to must already exist and be in proper archive format (which
  1429. normally means it was created previously using @code{tar}). If the
  1430. archive was created with a different block size than now specified,
  1431. @code{tar} will report an error (@pxref{Blocking Factor}). If the
  1432. archive is not a valid @code{tar} archive, the results will be
  1433. unpredictable. You cannot add files to a compressed archive, however
  1434. you can add files to the last volume of a multi-volume archive.
  1435. @xref{Matching Format Parameters}.
  1436. The following example adds the file @file{shemp} to the archive
  1437. @file{stooges} created above:
  1438. @example
  1439. tar --add-file --file=stooges shemp
  1440. @end example
  1441. You must specify the files to be added; there is no default.
  1442. @samp{tar --update} acts like @samp{tar --add-file}, but does not add
  1443. files to the archive if there is already a file entry with that name
  1444. in the archive that has the same modification time.
  1445. Both @samp{--update} and @samp{--add-file} work by adding to the end of
  1446. the archive. When you extract a file from the archive, only the
  1447. version stored last will wind up in the file system. Because
  1448. @samp{tar --extract} extracts files from an archive in sequence, and
  1449. overwrites files with the same name in the file system, if a file name
  1450. appears more than once in an archive the last version of the file will
  1451. overwrite the previous versions which have just been extracted. You
  1452. should avoid storing older versions of a file later in the archive.
  1453. Note: @samp{--update} is not suitable for performing backups, because
  1454. it doesn't change directory content entries, and because it lengthens
  1455. the archive every time it is used.
  1456. @c <<< xref to scripted backup, listed incremental, for info on backups.
  1457. @node Appending Archives, Deleting Archive Files, Adding Files, Modifying
  1458. @subsection Appending One Archive's Contents to Another Archive
  1459. @cindex Adding archives to an archive
  1460. @cindex Concatenating Archives
  1461. To append copies of an archive or archives to the end of another
  1462. archive, use @samp{tar --add-archive}. The source and target archives
  1463. must already exist and have been created using compatable format
  1464. parameters (@pxref{Matching Format Parameters}).
  1465. @code{tar} will stop reading an archive if it encounters an
  1466. end-of-archive marker. The @code{cat} utility does not remove
  1467. end-of-archive markers, and is therefore unsuitable for concatenating
  1468. archives. @samp{tar --add-archive} removes the end-of-archive marker
  1469. from the target archive before each new archive is appended.
  1470. @c <<< xref ignore-zeros
  1471. You must specify the source archives using
  1472. @samp{--file=@var{archive-name}} (@pxref{Archive Name}). If you do not
  1473. specify the target archive , @code{tar} uses the value of the
  1474. environment variable @code{TAPE}, or, if this has not been set, the
  1475. default archive name.
  1476. The following example adds the contents of the archive
  1477. @file{hail/hail/fredonia} to the archive @file{stooges} (both archives
  1478. were created in examples above):
  1479. @example
  1480. tar --add-archive --file=stooges hail/hail/fredonia
  1481. @end example
  1482. If you need to retrieve files from an archive that was added to using
  1483. the @code{cat} utility, use the @samp{--ignore-zeros} option
  1484. (@pxref{Archive Reading Options}).
  1485. @node Deleting Archive Files, Matching Format Parameters, Appending Archives, Modifying
  1486. @subsection Deleting Files From an Archive
  1487. @cindex Deleting files from an archive
  1488. @cindex Removing files from an archive
  1489. To delete archive members from an archive, use @samp{tar --delete}.
  1490. You must specify the file names of the members to be deleted. All
  1491. archive members with the specified file names will be removed from the
  1492. archive.
  1493. The following example removes the file @file{curley} from the archive
  1494. @file{stooges}:
  1495. @example
  1496. tar --delete --file=stooges curley
  1497. @end example
  1498. You can only use @samp{tar --delete} on an archive if the archive
  1499. device allows you to write to any point on the media.
  1500. @quotation
  1501. @strong{Warning:} Don't try to delete an archive member from a
  1502. magnetic tape, lest you scramble the archive. There is no safe way
  1503. (except by completely re-writing the archive) to delete files from
  1504. most kinds of magnetic tape.
  1505. @end quotation
  1506. @c <<< MIB -- how about automatic detection of archive media? give error
  1507. @c <<< unless the archive device is either an ordinary file or different
  1508. @c <<< input and output (--file=-).
  1509. @node Matching Format Parameters, , Deleting Archive Files, Modifying
  1510. @subsection Matching the Format Parameters
  1511. Some format parameters must be taken into consideration when modifying
  1512. an archive:
  1513. Compressed archives cannot be modified.
  1514. You have to specify the block size of the archive when modifying an
  1515. archive with a non-default block size.
  1516. Multi-volume archives can be modified like any other archive. To add
  1517. files to a multi-volume archive, you need to only mount the last
  1518. volume of the archive media (and new volumes, if needed). For all
  1519. other operations, you need to use the entire archive.
  1520. If a multi-volume archive was labeled using @samp{--label}
  1521. (@pxref{Archive Label}) when it was created, @code{tar} will not
  1522. automatically label volumes which are added later. To label
  1523. subsequent volumes, specify @samp{--label=@var{archive-label}} again in
  1524. conjunction with the @samp{--add-file}, @samp{--update} or
  1525. @samp{--add-archive} operation.
  1526. @cindex Labelling multi-volume archives
  1527. @c <<< example
  1528. @c <<< xref somewhere, for more information about format parameters.
  1529. @node Listing Contents, Extracting From Archives, Modifying, Reading and Writing
  1530. @section Listing the Contents of an Archive
  1531. @cindex Names of the files in an archive
  1532. @cindex Archive contents, list of
  1533. @cindex Archive members, list of
  1534. @samp{tar --list} prints a list of the file names of the archive
  1535. members on the standard output. If you specify @var{file-name}
  1536. arguments on the command line (or using the @samp{--files-from} option,
  1537. @pxref{File Name Lists}), only the files you specify will be listed,
  1538. and only if they exist in the archive. Files not specified will be
  1539. ignored, unless they are under a specific directory.
  1540. If you include the @samp{--verbose} option, @code{tar} prints an
  1541. @samp{ls -l} type listing for the archive. @pxref{Additional
  1542. Information}, for a description of the @samp{--verbose} option.
  1543. If the blocking factor of the archive differs from the default,
  1544. @code{tar} reports this. @xref{Blocking Factor}.
  1545. @xref{Archive Reading Options} for a list of options which can be used
  1546. to modify @samp{--list}'s operation.
  1547. This example prints a list of the archive members of the archive
  1548. @file{stooges}:
  1549. @example
  1550. tar --list --file=stooges
  1551. @end example
  1552. @noindent
  1553. @code{tar} responds:
  1554. @example
  1555. larry
  1556. moe
  1557. shemp
  1558. marx/julius
  1559. marx/alexander
  1560. marx/karl
  1561. @end example
  1562. This example generates a verbose list of the archive members of the
  1563. archive file @file{dwarves}, which has a blocking factor of two:
  1564. @example
  1565. tar --list -v --file=blocks
  1566. @end example
  1567. @noindent
  1568. @code{tar} responds:
  1569. @example
  1570. tar: Blocksize = 2 records
  1571. -rw------- ringo/user 42 May 1 13:29 1990 .bashful
  1572. -rw-rw-rw- ringo/user 42 Oct 4 13:29 1990 doc
  1573. -rw-rw-rw- ringo/user 42 Jul 20 18:01 1969 dopey
  1574. -rw-rw---- ringo/user 42 Nov 26 13:42 1963 grumpy
  1575. -rw-rw-rw- ringo/user 42 May 5 13:29 1990 happy
  1576. -rw-rw-rw- ringo/user 42 May 1 12:00 1868 sleepy
  1577. -rw-rw-rw- ringo/user 42 Jul 4 17:29 1776 sneezy
  1578. @end example
  1579. @node Extracting From Archives, , Listing Contents, Reading and Writing
  1580. @section Extracting Files from an Archive
  1581. @cindex Extraction
  1582. @cindex Retrieving files from an archive
  1583. @cindex Resurrecting files from an archive
  1584. To read archive members from the archive and write them into the file
  1585. system, use @samp{tar --extract}. The archive itself is left
  1586. unchanged.
  1587. If you do not specify the files to extract, @code{tar} extracts all
  1588. the files in the archive. If you specify the name of a directory as a
  1589. file-name argument, @code{tar} will extract all files which have been
  1590. stored as part of that directory. If a file was stored with a
  1591. directory name as part of its file name, and that directory does not
  1592. exist under the working directory when the file is extracted,
  1593. @code{tar} will create the directory. @xref{Selecting Archive
  1594. Members}, for information on specifying files to extract.
  1595. The following example shows the extraction of the archive
  1596. @file{stooges} into an empty directory:
  1597. @example
  1598. tar --extract --file=stooges
  1599. @end example
  1600. @noindent
  1601. Generating a listing of the directory (@samp{ls}) produces:
  1602. @example
  1603. larry
  1604. moe
  1605. shemp
  1606. marx
  1607. @end example
  1608. @noindent
  1609. The subdirectory @file{marx} contains the files @file{julius},
  1610. @file{alexander} and @file{karl}.
  1611. If you wanted to just extract the files in the subdirectory
  1612. @file{marx}, you could specify that directory as a file-name argument
  1613. in conjunction with the @samp{--extract} operation:
  1614. @example
  1615. tar --extract --file=stooges marx
  1616. @end example
  1617. @quotation
  1618. @strong{Warning:} Extraction can overwrite files in the file system.
  1619. To avoid losing files in the file system when extracting files from
  1620. the archive with the same name, use the @samp{--keep-old-files} option
  1621. (@pxref{File Writing Options}).
  1622. @end quotation
  1623. If the archive was created using @samp{--block-size}, @samp{--compress}
  1624. or @samp{--multi-volume}, you must specify those format options again
  1625. when extracting files from the archive (@pxref{Format Variations}).
  1626. @menu
  1627. * Archive Reading Options::
  1628. * File Writing Options::
  1629. * Scarce Disk Space:: Recovering From Scarce Disk Space
  1630. @end menu
  1631. @node Archive Reading Options, File Writing Options, Extracting From Archives, Extracting From Archives
  1632. @subsection Options to Help Read Archives
  1633. @cindex Options when reading archives
  1634. @cindex Reading incomplete blocks
  1635. @cindex Blocks, incomplete
  1636. @cindex End of archive markers, ignoring
  1637. @cindex Ignoring end of archive markers
  1638. @cindex Large lists of file names on small machines
  1639. @cindex Small memory
  1640. @cindex Running out of space
  1641. @c <<< each option wants its own node. summary after menu
  1642. Normally, @code{tar} will request data in full block increments from
  1643. an archive storage device. If the device cannot return a full block,
  1644. @code{tar} will report an error. However, some devices do not always
  1645. return full blocks, or do not require the last block of an archive to
  1646. be padded out to the next block boundary. To keep reading until you
  1647. obtain a full block, or to accept an incomplete block if it contains
  1648. an end-of-archive marker, specify the @samp{--read-full-blocks} option
  1649. in conjunction with the @samp{--extract} or @samp{--list} operations.
  1650. @xref{Listing Contents}.
  1651. The @samp{--read-full-blocks} option is turned on by default when
  1652. @code{tar} reads an archive from standard input, or from a remote
  1653. machine. This is because on BSD Unix systems, attempting to read a
  1654. pipe returns however much happens to be in the pipe, even if it is
  1655. less than was requested. If this option were not enabled, @code{tar}
  1656. would fail as soon as it read an incomplete block from the pipe.
  1657. If you're not sure of the blocking factor of an archive, you can read
  1658. the archive by specifying @samp{--read-full-blocks} and
  1659. @samp{--block-size=@var{n}}, where @var{n} is a blocking factor larger
  1660. than the blocking factor of the archive. This lets you avoid having
  1661. to determine the blocking factor of an archive. @xref{Blocking
  1662. Factor}.
  1663. @table @samp
  1664. @item --read-full-blocks
  1665. @item -B
  1666. Use in conjunction with @samp{tar --extract} to read an archive which
  1667. contains incomplete blocks, or one which has a blocking factor less
  1668. than the one specified.
  1669. @end table
  1670. Normally @code{tar} stops reading when it encounters a block of zeros
  1671. between file entries (which usually indicates the end of the archive).
  1672. @samp{--ignore-zeros} allows @code{tar} to completely read an archive
  1673. which contains a block of zeros before the end (i.e.@: a damaged
  1674. archive, or one which was created by @code{cat}-ing several archives
  1675. together).
  1676. The @samp{--ignore-zeros} option is turned off by default because many
  1677. versions of @code{tar} write garbage after the end of archive entry,
  1678. since that part of the media is never supposed to be read. GNU
  1679. @code{tar} does not write after the end of an archive, but seeks to
  1680. maintain compatablity among archiving utilities.
  1681. @table @samp
  1682. @item --ignore-zeros
  1683. @itemx -i
  1684. To ignore blocks of zeros (ie.@: end-of-archive entries) which may be
  1685. encountered while reading an archive. Use in conjunction with
  1686. @samp{tar --extract} or @samp{tar --list}.
  1687. @end table
  1688. If you are using a machine with a small amount of memory, and you need
  1689. to process large list of file-names, you can reduce the amount of
  1690. space @code{tar} needs to process the list. To do so, specify the
  1691. @samp{--same-order} option and provide an ordered list of file names.
  1692. This option tells @code{tar} that the @file{file-name} arguments
  1693. (provided on the command line, or read from a file using the
  1694. @samp{--files-from} option) are listed in the same order as the files
  1695. in the archive.
  1696. You can create a file containing an ordered list of files in the
  1697. archive by storing the output produced by @samp{tar --list
  1698. --file=@var{archive-name}}. @xref{Listing Contents}, for information
  1699. on the @samp{--list} operation.
  1700. This option is probably never needed on modern computer systems.
  1701. @table @samp
  1702. @item --same-order
  1703. @itemx --preserve-order
  1704. @itemx -s
  1705. To process large lists of file-names on machines with small amounts of
  1706. memory. Use in conjunction with @samp{tar --compare}, @samp{tar --list}
  1707. or @samp{tar --extract}.
  1708. @end table
  1709. @c we don't need/want --preserve to exist any more
  1710. @node File Writing Options, Scarce Disk Space, Archive Reading Options, Extracting From Archives
  1711. @subsection Changing How @code{tar} Writes Files
  1712. @c <<< find a better title
  1713. @cindex Overwriting old files, prevention
  1714. @cindex Protecting old files
  1715. @cindex Modification times of extracted files
  1716. @cindex Permissions of extracted files
  1717. @cindex Modes of extracted files
  1718. @cindex Writing extracted files to standard output
  1719. @cindex Standard output, writing extracted files to
  1720. Normally, @code{tar} writes extracted files into the file system
  1721. without regard to the files already on the system---files with the
  1722. same name as archive members are overwritten. To prevent @code{tar}
  1723. from extracting an archive member from an archive, if doing so will
  1724. overwrite a file in the file system, use @samp{--keep-old-files} in
  1725. conjunction with the @samp{--extract} operation. When this option is
  1726. specified, @code{tar} reports an error stating the name of the files
  1727. in conflict, instead of writing the file from the archive.
  1728. @table @samp
  1729. @item --keep-old files
  1730. @itemx -k
  1731. Prevents @code{tar} from overwriting files in the file system during
  1732. extraction.
  1733. @end table
  1734. Normally, @code{tar} sets the modification times of extracted files to
  1735. the modification times recorded for the files in the archive, but
  1736. limits the permissions of extracted files by the current @code{umask}
  1737. setting.
  1738. To set the modification times of extracted files to the time when
  1739. the files were extracted, use the @samp{--modification-time} option in
  1740. conjunction with @samp{tar --extract}.
  1741. @table @samp
  1742. @item --modification-time
  1743. @itemx -m
  1744. Sets the modification time of extracted archive members to the time
  1745. they were extracted, not the time recorded for them in the archive.
  1746. Use in conjunction with @samp{--extract}.
  1747. @end table
  1748. To set the modes (access permissions) of extracted files to those
  1749. recorded for those files in the archive, use the
  1750. @samp{--preserve-permissions} option in conjunction with the
  1751. @samp{--extract} operation.
  1752. @c <<<mib --- should be aliased to ignore-umask.
  1753. @table @samp
  1754. @item --preserve-permission
  1755. @itemx --same-permission
  1756. @itemx --ignore-umask
  1757. @itemx -p
  1758. Set modes of extracted archive members to those recorded in the
  1759. archive, instead of current umask settings. Use in conjunction with
  1760. @samp{--extract}.
  1761. @end table
  1762. @c <<< following paragraph needs to be rewritten:
  1763. @c <<< why doesnt' this cat files together, why is this useful. is it
  1764. @c <<< really useful with more than one file?
  1765. To write the files extracted to the standard output, instead of
  1766. creating the files on the file system, use @samp{--to-stdout} in
  1767. conjunction with @samp{tar --extract}. This option is useful if you
  1768. are extracting files to send them through a pipe, and do not need to
  1769. preserve them in the file system.
  1770. @table @samp
  1771. @item --to-stdout
  1772. @itemx -O
  1773. Writes files to the standard output. Used in conjunction with
  1774. @samp{--extract}.
  1775. @end table
  1776. @c <<< why would you want to do such a thing, how are files separated on
  1777. @c <<< the standard output? is this useful with more that one file? are
  1778. @c <<< pipes the real reason?
  1779. @node Scarce Disk Space, , File Writing Options, Extracting From Archives
  1780. @subsection Recovering From Scarce Disk Space
  1781. @cindex Middle of the archive, starting in the
  1782. @cindex Running out of space during extraction
  1783. @cindex Disk space, running out of
  1784. @cindex Space on the disk, recovering from lack of
  1785. If a previous attempt to extract files failed due to lack of disk
  1786. space, you can use @samp{--starting-file=@var{file-name}} to start
  1787. extracting only after file @var{file-name} when extracting files from
  1788. the archive. This assumes, of course, that there is now free space,
  1789. or that you are now extracting into a different file system.
  1790. @table @samp
  1791. @item --starting-file=@var{file-name}
  1792. @itemx -K @var{file-name}
  1793. Starts an operation in the middle of an archive. Use in conjunction
  1794. with @samp{--extract} or @samp{--list}.
  1795. @end table
  1796. If you notice you are running out of disk space during an extraction
  1797. operation, you can also suspend @code{tar}, remove unnecessary files
  1798. from the file system, and then restart the same @code{tar} operation.
  1799. In this case, @samp{--starting-file} is not necessary.
  1800. @c <<< xref incremental, xref --interactive, xref --exclude
  1801. @node Insuring Accuracy, Selecting Archive Members, Reading and Writing, Top
  1802. @chapter Insuring the Accuracy of an Archive
  1803. You can insure the accuracy of an archive by comparing files in the
  1804. system with archive members. @code{tar} can compare an archive to the
  1805. file system as the archive is being written, to verify a write
  1806. operation, or can compare a previously written archive, to insure that
  1807. it is up to date.
  1808. @menu
  1809. * Write Verification::
  1810. * Comparing::
  1811. @end menu
  1812. @node Write Verification, Comparing, Insuring Accuracy, Insuring Accuracy
  1813. @section Verifying Data as It is Stored
  1814. @cindex Verifying a write operation
  1815. @cindex Double-checking a write operation
  1816. To check for discrepancies in an archive immediately after it is
  1817. written, use the @samp{--verify} option in conjunction with the
  1818. @samp{tar --create} operation. When this option is specified,
  1819. @code{tar} checks archive members against their counterparts in the file
  1820. system, and reports discrepancies on the standard error. In
  1821. multi-volume archives, each volume is verified after it is written,
  1822. before the next volume is written.
  1823. To verify an archive, you must be able to read it from before the end
  1824. of the last written entry. This option is useful for detecting data
  1825. errors on some tapes. Archives written to pipes, some cartridge tape
  1826. drives, and some other devices cannot be verified.
  1827. @table @samp
  1828. @item --verify
  1829. @itemx -W
  1830. Checks for discrepancies in the archive immediately after it is
  1831. written. Use in conjunction with @samp{tar --create}.
  1832. @end table
  1833. @node Comparing, , Write Verification, Insuring Accuracy
  1834. @section Comparing an Archive with the File System
  1835. @cindex Verifying the currency of an archive
  1836. @samp{tar --compare} compares archive members in an existing archive
  1837. with their counterparts in the file system, and reports differences in
  1838. file size, mode, owner, modification date and contents. If a file is
  1839. represented in the archive but does not exist in the file system,
  1840. @code{tar} reports a difference.
  1841. If you use @var{file-name} arguments in conjunction with @samp{tar
  1842. --compare}, @code{tar} compares the archived versions of the files
  1843. specified with their counterparts in the file system. If you specify
  1844. a file that is not in the archive, @code{tar} will report an error. If
  1845. you don't specify any files, @code{tar} compares all the files in the
  1846. archive.
  1847. Because @code{tar} only checks files in the archive against files in
  1848. the file system, and not vice versa, it ignores files in the file
  1849. system that do not exist in the archive.
  1850. The following example compares the archive members @file{larry},
  1851. @file{moe} and @file{curly} in the archive @file{stooges} with files
  1852. of the same name in the file system.
  1853. @example
  1854. tar --compare --file=stooges larry moe curly
  1855. @end example
  1856. @noindent
  1857. If a file, for example @file{curly}, did not exist in the archive,
  1858. @code{tar} would report an error, as follows:
  1859. @example
  1860. curly: does not exist
  1861. @end example
  1862. @node Selecting Archive Members, User Interaction, Insuring Accuracy, Top
  1863. @chapter Selecting Archive Members
  1864. @cindex Specifying files to act on
  1865. @cindex Specifying archive members
  1866. @dfn{File-name arguments} specify which files in the file system
  1867. @code{tar} operates on, when creating or adding to an archive, or
  1868. which archive members @code{tar} operates on, when reading or
  1869. deleting from an archive. (@pxref{Reading and Writing}.)
  1870. To specify file names, you can include them as the last arguments on
  1871. the command line, as follows:
  1872. @example
  1873. tar @var{operation} [@var{option1} @var{option2} ..] [@var{file-name-1} @var{file-name-2} ...]
  1874. @end example
  1875. If you specify a directory name as a file name argument, all the files
  1876. in that directory are operated on by @code{tar}.
  1877. If you do not specify files when @code{tar} is invoked, @code{tar}
  1878. operates on all the non-directory files in the working directory (if
  1879. the operation is @samp{--create}), all the archive members in the
  1880. archive (if a read operation is specified), or does nothing (if any
  1881. other operation is specified).
  1882. @menu
  1883. * File Name Lists:: Reading File Names from a File
  1884. * File Name Interpretation:: this needs a better title
  1885. * File Exclusion:: so does this
  1886. @end menu
  1887. @node File Name Lists, File Name Interpretation, Selecting Archive Members, Selecting Archive Members
  1888. @section Reading a List of File Names from a File
  1889. @cindex Lists of file names
  1890. @cindex File-name arguments, alternatives
  1891. To read file names from a file on the file system, instead of from the
  1892. command line, use the @samp{--files-from=@var{file}} option. If you
  1893. specify @samp{-} as @var{file}, the file names are read from standard
  1894. input. Note that using both @samp{--files-from=-} and @samp{--file=-}
  1895. in the same command will not work unless the operation is
  1896. @samp{--create}. @xref{Archive Name}, for an explanation of the
  1897. @samp{--file} option.
  1898. @table @samp
  1899. @item --files-from=@var{file}
  1900. @itemx -T @var{file}
  1901. Reads file-name arguments from a file on the file system, instead of
  1902. from the command line. Use in conjunction with any operation.
  1903. @end table
  1904. @node File Name Interpretation, File Exclusion, File Name Lists, Selecting Archive Members
  1905. @section File Name Interpretation
  1906. @cindex File Names, interpreting
  1907. @c <<<<add some text -ringo
  1908. @menu
  1909. * Absolute File Names::
  1910. * Changing Working Directory::
  1911. * Archiving with Symbolic Links:: Archiving Using Symbolic Links
  1912. @end menu
  1913. @node Absolute File Names, Changing Working Directory, File Name Interpretation, File Name Interpretation
  1914. @subsection Storing and Extracting Files Relative to Root
  1915. @c <<< is this what this does, or does it just preserve the slash?
  1916. @c <<< is it still called --absolute-paths?
  1917. @c To archive or extract files relative to the root directory, specify
  1918. @c the @samp{--absolute-paths} option.
  1919. @c Normally, @code{tar} acts on files relative to the working
  1920. @c directory---ignoring superior directory names when archiving, and
  1921. @c ignoring leading slashes when extracting.
  1922. @c When you specify @samp{--absolute-paths}, @code{tar} stores file names
  1923. @c including all superior directory names, and preserves leading slashes.
  1924. @c If you only invoked @code{tar} from the root directory you would never
  1925. @c need the @samp{--absolute-paths} option, but using this option may be
  1926. @c more convenient than switching to root.
  1927. @c >>> should be an example in the tutorial/wizardry section using this
  1928. @c >>> to transfer files between systems.
  1929. @c >>> is write access an issue?
  1930. @table @samp
  1931. @item --absolute-paths
  1932. Preserves full file names (inclusing superior dirctory names) when
  1933. archiving files. Preserves leading slash when extracting files.
  1934. @end table
  1935. @node Changing Working Directory, Archiving with Symbolic Links, Absolute File Names, File Name Interpretation
  1936. @subsection Changing the Working Directory Within a List of File-names
  1937. @cindex Directory, changing in mid-stream
  1938. @cindex Working directory, specifying
  1939. To change working directory in the middle of a list of file names,
  1940. (either on the command line or in a file specified using
  1941. @samp{--files-from}), use @samp{--directory=@var{directory}}. This will
  1942. change the working directory to the directory @var{directory} after
  1943. that point in the list. For example,
  1944. @example
  1945. tar --create iggy ziggy --directory=baz melvin
  1946. @end example
  1947. @noindent
  1948. will place the files @file{iggy} and @file{ziggy} from the current
  1949. directory into the archive, followed by the file @file{melvin} from
  1950. the directory @file{baz}. This option is especially useful when you
  1951. have several widely separated files that you want to store in the same
  1952. directory in the archive.
  1953. Note that the file @file{melvin} is recorded in the archive under the
  1954. precise name @file{melvin}, @emph{not} @file{baz/melvin}. Thus, the
  1955. archive will contain three files that all appear to have come from the
  1956. same directory; if the archive is extracted with plain @samp{tar
  1957. --extract}, all three files will be written in the current directory.
  1958. Contrast this with the command
  1959. @example
  1960. tar -c iggy ziggy bar/melvin
  1961. @end example
  1962. @noindent
  1963. which records the third file in the archive under the name
  1964. @file{bar/melvin} so that, if the archive is extracted using @samp{tar
  1965. --extract}, the third file will be written in a subdirectory named
  1966. @file{bar}.
  1967. @table @samp
  1968. @item --directory=@file{directory}
  1969. @itemx -C @file{directory}
  1970. Changes the working directory.
  1971. @end table
  1972. @c <<<need to test how extract deals with this, and add an example -ringo
  1973. @node Archiving with Symbolic Links, , Changing Working Directory, File Name Interpretation
  1974. @subsection Archiving Using Symbolic Links
  1975. @cindex File names, using symbolic links
  1976. @cindex Symbolic link as file name
  1977. @samp{--dereference} is used with @samp{tar --create}, and causes
  1978. @code{tar} to archive files which are referenced by a symbolic link,
  1979. using the name of the link as the file name.
  1980. <<<this needs to be checked by MIB and then re-written, with an example
  1981. The name under which the file is stored in the file system is not
  1982. recorded in the archive. To record both the symbolic link name and
  1983. the file name in the system, archive the file under both names. If
  1984. all links were recorded automatically by @code{tar}, an extracted file
  1985. might be linked to a file name that no longer exists in the file
  1986. system.
  1987. @c <<< is the following still true? - ringo
  1988. If a linked-to file is encountered again by @code{tar} while creating
  1989. the same archive, an entire second copy of it will be stored. This
  1990. could be considered a bug.
  1991. @table @samp
  1992. @item --dereference
  1993. @itemx -h
  1994. Stores files referenced by a symbolic link, using the name of the link
  1995. as the file name. Use in conjunction with any write operation.
  1996. @end table
  1997. @node File Exclusion, , File Name Interpretation, Selecting Archive Members
  1998. @section Selecting Files by Characteristic
  1999. @cindex File names, excluding files by
  2000. @cindex Excluding files by name and pattern
  2001. @cindex Excluding files by file system
  2002. @cindex File system boundaries, not crossing
  2003. @cindex Excluding file by age
  2004. @cindex Modification time, excluding files by
  2005. @cindex Age, excluding files by
  2006. To avoid crossing file system boundaries when archiving parts of a
  2007. directory tree, use @samp{--one-file-system}. This option only affects
  2008. files that are archived because they are in a directory that is being
  2009. archived; files explicitly named on the command line are archived
  2010. regardless of where they reside.
  2011. This option is useful for making full or incremental archival backups
  2012. of a file system.
  2013. If this option is used in conjunction with @samp{--verbose}, files that
  2014. are excluded are mentioned by name on the standard error.
  2015. @table @samp
  2016. @item --one-file-system
  2017. @itemx -l
  2018. Prevents @code{tar} from crossing file system boundaries when
  2019. archiving. Use in conjunction with any write operation.
  2020. @end table
  2021. To avoid operating on files whose names match a particular pattern,
  2022. use the @samp{--exclude=@var{pattern}} or
  2023. @samp{--exclude-from=@var{file}} options.
  2024. When you specify the @samp{--exclude=@var{pattern}} option, @code{tar}
  2025. ignores files which match the @var{pattern}, which can be a single
  2026. file name or a more complex expression. Thus, if you invoke
  2027. @code{tar} with @samp{tar --create --exclude=*.o}, no files whose names
  2028. end in @file{.o} are included in the archive.
  2029. @c <<< what other things can you use besides "*"?
  2030. @samp{--exclude-from=@var{file}} acts like @samp{--exclude}, but
  2031. specifies a file @var{file} containing a list of patterns. @code{tar}
  2032. ignores files with names that fit any of these patterns.
  2033. You can use either option more than once in a single command.
  2034. @table @samp
  2035. @item --exclude=@var{pattern}
  2036. Causes @code{tar} to ignore files that match the @var{pattern}.
  2037. @item --exclude-from=@var{file}
  2038. Causes @code{tar} to ignore files that match the patterns listed in
  2039. @var{file}.
  2040. @end table
  2041. @c --exclude-from used to be "--exclude", --exclude didn't used to exist.
  2042. To operate only on files with modification or status-change times
  2043. after a particular date, use @samp{--after-date=@var{date}}. You can
  2044. use this option with @samp{tar --create} or @samp{tar --add-file} to
  2045. insure only new files are archived, or with @samp{tar --extract} to
  2046. insure only recent files are resurrected. @refill
  2047. @c --after-date @var{date} or --newer @var{date}
  2048. @samp{--newer-mtime=@var{date}} acts like @samp{--after-date=@var{date}},
  2049. but tests just the modification times of the files, ignoring
  2050. status-change times.
  2051. @c <<<need example of --newer-mtime with quoted argument
  2052. Remember that the entire date argument should be quoted if it contains
  2053. any spaces.
  2054. @strong{Please Note:} @samp{--after-date} and @samp{--newer-mtime}
  2055. should not be used for incremental backups. Some files (such as those
  2056. in renamed directories) are not selected up properly by these options.
  2057. @c xref to incremental backup chapter when node name is decided.
  2058. @table @samp
  2059. @item --after-date=@var{date}
  2060. @itemx --newer=@var{date}
  2061. @itemx -N @var{date}
  2062. Acts on files only if their modification or inode-changed times are
  2063. later than @var{date}. Use in conjunction with any operation.
  2064. @item --newer-mtime=@var{date}
  2065. Acts like @samp{--after-date}, but only looks at modification times.
  2066. @end table
  2067. @c <<< following is the getdate date format --- needs to be re-written,
  2068. @c <<< made a sub-node:
  2069. Time/Date Formats Accepted by getdate
  2070. (omitting obscure constructions)
  2071. The input consists of one or more of: time zone day date year
  2072. in any order.
  2073. Those in turn consist of (`|' and `/' mean `or', `[]' means `optional'):
  2074. time: H am/pm | H:M [am/pm] | H:M:S [am/pm]
  2075. zone: timezone-name | timezone-name dst
  2076. day: day-name | day-name, | N day-name
  2077. date: M/D | M/D/Y | month-name D | month-name D, Y | D month-name | D month-name Y
  2078. year: Y
  2079. am can also be a.m., pm can also be p.m.
  2080. case and spaces around punctuation are not significant.
  2081. month and day names can be abbreviated. >>>
  2082. @node User Interaction, Backups and Restoration, Selecting Archive Members, Top
  2083. @chapter User Interaction
  2084. @cindex Getting more information during the operation
  2085. @cindex Information during operation
  2086. @cindex Feedback from @code{tar}
  2087. Once you have typed a @code{tar}command, it is usually performed
  2088. without any further information required of the user, or provided by
  2089. @code{tar}. The following options allow you to generate progress and
  2090. status information during an operation, or to confirm operations on
  2091. files as they are performed.
  2092. @menu
  2093. * Additional Information::
  2094. * Interactive Operation::
  2095. @end menu
  2096. @node Additional Information, Interactive Operation, User Interaction, User Interaction
  2097. @section Progress and Status Information
  2098. @cindex Progress information
  2099. @cindex Status information
  2100. @cindex Information on progress and status of operations
  2101. @cindex Verbose operation
  2102. @cindex Record number where error occured
  2103. @cindex Error message, record number of
  2104. @cindex Version of the @code{tar} program
  2105. Typically, @code{tar} performs most operations without reporting any
  2106. information to the user except error messages. If you have
  2107. encountered a problem when operating on an archive, however, you may
  2108. need more information than just an error message in order to solve the
  2109. problem. The following options can be helpful diagnostic tools.
  2110. When used with most operations, @samp{--verbose} causes @code{tar} to
  2111. print the file names of the files or archive members it is operating
  2112. on. When used with @samp{tar --list}, the verbose option causes
  2113. @code{tar} to print out an @samp{ls -l} type listing of the files in
  2114. the archive.
  2115. Verbose output appears on the standard output except when an archive
  2116. is being written to the standard output (as with @samp{tar --create
  2117. --file=- --verbose}). In that case @code{tar} writes verbose output to
  2118. the standard error stream.
  2119. @table @samp
  2120. @item --verbose
  2121. @itemx -v
  2122. Prints the names of files or archive members as they are being
  2123. operated on. Can be used in conjunction with any operation. When
  2124. used with @samp{--list}, generates an @samp{ls -l} type listing.
  2125. @end table
  2126. To find out where in an archive a message was triggered, use
  2127. @samp{--record-number}. @samp{--record-number} causes @code{tar} to
  2128. print, along with every message it produces, the record number within
  2129. the archive where the message was triggered.
  2130. This option is especially useful when reading damaged archives, since
  2131. it helps pinpoint the damaged sections. It can also be used with
  2132. @samp{tar --list} when listing a file-system backup tape, allowing you
  2133. to choose among several backup tapes when retrieving a file later, in
  2134. favor of the tape where the file appears earliest (closest to the
  2135. front of the tape).
  2136. @c <<< xref when the node name is set and the backup section written
  2137. @table @samp
  2138. @item --record-number
  2139. @itemx -R
  2140. Prints the record number whenever a message is generated by
  2141. @code{tar}. Use in conjunction with any operation.
  2142. @end table
  2143. @c rewrite below
  2144. To print the version number of the @code{tar} program, use @samp{tar
  2145. --version}. @code{tar} prints the version number to the standard
  2146. error. For example:
  2147. @example
  2148. tar --version
  2149. @end example
  2150. @noindent
  2151. might return:
  2152. @example
  2153. GNU tar version 1.09
  2154. @end example
  2155. @c used to be an option. has been fixed.
  2156. @node Interactive Operation, , Additional Information, User Interaction
  2157. @section Asking for Confirmation During Operations
  2158. @cindex Interactive operation
  2159. Typically, @code{tar} carries out a command without stopping for
  2160. further instructions. In some situations however, you
  2161. may want to exclude some files and archive members from the operation
  2162. (for instance if disk or storage space is tight). You can do this by
  2163. excluding certain files automatically (@pxref{File Exclusion}), or by
  2164. performing an operation interactively, using the @samp{--interactive}
  2165. operation.
  2166. When the @samp{--interactive} option is specified, @code{tar} asks for
  2167. confirmation before reading, writing, or deleting each file it
  2168. encounters while carrying out an operation. To confirm the action you
  2169. must type a line of input beginning with @samp{y}. If your input line
  2170. begins with anything other than @samp{y}, @code{tar} skips that file.
  2171. Commands which might be useful to perform interactively include
  2172. appending files to an archive, extracting files from an archive,
  2173. deleting a file from an archive, and deleting a file from disk during
  2174. an incremental restore.
  2175. If @code{tar} is reading the archive from the standard input,
  2176. @code{tar} opens the file @file{/dev/tty} to support the interactive
  2177. communications.
  2178. <<< this aborts if you won't OK the working directory. this is a bug. -ringo
  2179. @table @samp
  2180. @item --interactive
  2181. @itemx --confirmation
  2182. @itemx -w
  2183. Asks for confirmation before reading, writing or deleting an archive
  2184. member (when listing, comparing or writing an archive or deleting
  2185. archive members), or before writing or deleting a file (when
  2186. extracting an archive).
  2187. @end table
  2188. @node Backups and Restoration, Media, User Interaction, Top
  2189. @chapter Performing Backups and Restoring Files
  2190. To @dfn{back up} a file system means to create archives that contain
  2191. all the files in that file system. Those archives can then be used to
  2192. restore any or all of those files (for instance if a disk crashes or a
  2193. file is accidently deleted). File system @dfn{backups} are also
  2194. called @dfn{dumps}.
  2195. @menu
  2196. * Backup Levels:: Levels of backups
  2197. * Backup Scripts:: Using scripts to perform backups
  2198. and restoration
  2199. * incremental and listed-incremental:: The --incremental
  2200. and --listed-incremental Options
  2201. * Problems:: Some common problems and their solutions
  2202. @end menu
  2203. @node Backup Levels, Backup Scripts, Backups and Restoration, Backups and Restoration
  2204. @section Levels of Backups
  2205. An archive containing all the files in the file system is called a
  2206. @dfn{full backup} or @dfn{full dump}. You could insure your data by
  2207. creating a full dump every day. This strategy, however, would waste a
  2208. substantial amount of archive media and user time, as unchanged files
  2209. are daily re-archived.
  2210. It is more efficient to do a full dump only occasionally. To back up
  2211. files between full dumps, you can a incremental dump. A @dfn{level
  2212. one} dump archives all the files that have changed since the last full
  2213. dump.
  2214. A typical dump strategy would be to perform a full dump once a week,
  2215. and a level one dump once a day. This means some versions of files
  2216. will in fact be archived more than once, but this dump strategy makes
  2217. it possible to restore a file system to within one day of accuracy by
  2218. only extracting two archives---the last weekly (full) dump and the
  2219. last daily (level one) dump. The only information lost would be in
  2220. files changed or created since the last daily backup. (Doing dumps
  2221. more than once a day is usually not worth the trouble).
  2222. @node Backup Scripts, incremental and listed-incremental, Backup Levels, Backups and Restoration
  2223. @section Using Scripts to Perform Backups and Restoration
  2224. GNU @code{tar} comes with scripts you can use to do full and level-one
  2225. dumps. Using scripts (shell programs) to perform backups and
  2226. restoration is a convenient and reliable alternative to typing out
  2227. file name lists and @code{tar} commands by hand.
  2228. Before you use these scripts, you need to edit the file
  2229. @file{backup-specs}, which specifies parameters used by the backup
  2230. scripts and by the restore script. @xref{Script Syntax}.
  2231. Once the backup parameters are set, you can perform backups or
  2232. restoration by running the appropriate script.
  2233. The name of the restore script is @code{restore}. The names of the
  2234. level one and full backup scripts are, respectively, @code{level-1} and
  2235. @code{level-0}. The @code{level-0} script also exists under the name
  2236. @code{weekly}, and the @code{level-1} under the name
  2237. @code{daily}---these additional names can be changed according to your
  2238. backup schedule. @xref{Scripted Restoration}, for more information
  2239. on running the restoration script. @xref{Scripted Backups}, for more
  2240. information on running the backup scripts.
  2241. @emph{Please Note:} The backup scripts and the restoration scripts are
  2242. designed to be used together. While it is possible to restore files
  2243. by hand from an archive which was created using a backup script, and
  2244. to create an archive by hand which could then be extracted using the
  2245. restore script, it is easier to use the scripts. @xref{incremental
  2246. and listed-incremental}, before making such an attempt.
  2247. @c shorten node names
  2248. @menu
  2249. * Backup Parameters:: Setting parameters for backups and restoration
  2250. * Scripted Backups:: Using the backup scripts
  2251. * Scripted Restoration:: Using the restore script
  2252. @end menu
  2253. @node Backup Parameters, Scripted Backups, Backup Scripts, Backup Scripts
  2254. @subsection Setting Parameters for Backups and Restoration
  2255. The file @file{backup-specs} specifies backup parameters for the
  2256. backup and restoration scripts provided with @code{tar}. You must
  2257. edit @file{backup-specs} to fit your system configuration and schedule
  2258. before using these scripts.
  2259. @c <<< This about backup scripts needs to be written:
  2260. @c <<<BS is a shell script .... thus ... @file{backup-specs} is in shell
  2261. @c script syntax. @xref{Script Syntax}, for an explanation of this
  2262. @c syntax.
  2263. @c whats a parameter .... looked at by the backup scripts ... which will
  2264. @c be expecting to find ... now syntax ... value is linked to lame ...
  2265. @c @file{backup-specs} specifies the following parameters:
  2266. @table @code
  2267. @item ADMINISTRATOR
  2268. The user name of the backup administrator.
  2269. @item BACKUP_HOUR
  2270. The hour at which the backups are done. This can be a number from 0
  2271. to 23, or the string @samp{now}.
  2272. @item TAPE_FILE
  2273. The device @code{tar} writes the archive to. This device should be
  2274. attached to the host on which the dump scripts are run.
  2275. @c <<< examples for all ...
  2276. @item TAPE_STATUS
  2277. The command to use to obtain the status of the archive device,
  2278. including error count. On some tape drives there may not be such a
  2279. command; in that case, simply use `TAPE_STATUS=false'.
  2280. @item BLOCKING
  2281. The blocking factor @code{tar} will use when writing the dump archive.
  2282. @xref{Blocking Factor}.
  2283. @item BACKUP_DIRS
  2284. A list of file systems to be dumped. You can include any directory
  2285. name in the list---subdirectories on that file system will be
  2286. included, regardless of how they may look to other networked machines.
  2287. Subdirectories on other file systems will be ignored.
  2288. The host name specifies which host to run @code{tar} on, and should
  2289. normally be the host that actually contains the file system. However,
  2290. the host machine must have GNU @code{tar} installed, and must be able
  2291. to access the directory containing the backup scripts and their
  2292. support files using the same file name that is used on the machine
  2293. where the scripts are run (ie. what @code{pwd} will print when in that
  2294. directory on that machine). If the host that contains the file system
  2295. does not have this capability, you can specify another host as long as
  2296. it can access the file system through NFS.
  2297. @item BACKUP_FILES
  2298. A list of individual files to be dumped. These should be accessible
  2299. from the machine on which the backup script is run.
  2300. @c <<<same file name, be specific. through nfs ...
  2301. @end table
  2302. @menu
  2303. * backup-specs example:: An Example Text of @file{Backup-specs}
  2304. * Script Syntax:: Syntax for @file{Backup-specs}
  2305. @end menu
  2306. @node backup-specs example, Script Syntax, Backup Parameters, Backup Parameters
  2307. @subsubsection An Example Text of @file{Backup-specs}
  2308. The following is the text of @file{backup-specs} as it appears at FSF:
  2309. @example
  2310. # site-specific parameters for file system backup.
  2311. ADMINISTRATOR=friedman
  2312. BACKUP_HOUR=1
  2313. TAPE_FILE=/dev/nrsmt0
  2314. TAPE_STATUS="mts -t $TAPE_FILE"
  2315. BLOCKING=124
  2316. BACKUP_DIRS="
  2317. albert:/fs/fsf
  2318. apple-gunkies:/gd
  2319. albert:/fs/gd2
  2320. albert:/fs/gp
  2321. geech:/usr/jla
  2322. churchy:/usr/roland
  2323. albert:/
  2324. albert:/usr
  2325. apple-gunkies:/
  2326. apple-gunkies:/usr
  2327. gnu:/hack
  2328. gnu:/u
  2329. apple-gunkies:/com/mailer/gnu
  2330. apple-gunkies:/com/archive/gnu"
  2331. BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
  2332. @end example
  2333. @node Script Syntax, , backup-specs example, Backup Parameters
  2334. @subsubsection Syntax for @file{Backup-specs}
  2335. @file{backup-specs} is in shell script syntax. The following
  2336. conventions should be considered when editing the script:
  2337. @c <<< "conventions?"
  2338. A quoted string is considered to be contiguous, even if it is on more
  2339. than one line. Therefore, you cannot include commented-out lines
  2340. within a multi-line quoted string. BACKUP_FILES and BACKUP_DIRS are
  2341. the two most likely parameters to be multi-line.
  2342. A quoted string typically cannot contain wildcards. In
  2343. @file{backup-specs}, however, the parameters BACKUP_DIRS and
  2344. BACKUP_FILES can contain wildcards.
  2345. @node Scripted Backups, Scripted Restoration, Backup Parameters, Backup Scripts
  2346. @subsection Using the Backup Scripts
  2347. The syntax for running a backup script is:
  2348. @example
  2349. @file{script-name} [@var{time-to-be-run}]
  2350. @end example
  2351. where @var{time-to-be-run} can be a specific system time, or can be
  2352. @kbd{now}. If you do not specify a time, the script runs at the time
  2353. specified in @file{backup-specs} (@pxref{Script Syntax}).
  2354. You should start a script with a tape or disk mounted. Once you start
  2355. a script, it prompts you for new tapes or disks as it needs them.
  2356. Media volumes don't have to correspond to archive files---a
  2357. multi-volume archive can be started in the middle of a tape that
  2358. already contains the end of another multi-volume archive. The
  2359. @code{restore} script prompts for media by its archive volume, so to
  2360. avoid an error message you should keep track of which tape (or disk)
  2361. contains which volume of the archive. @xref{Scripted Restoration}.
  2362. @c <<<have file names changed? -ringo
  2363. The backup scripts write two files on the file system. The first is a
  2364. record file in @file{/etc/tar-backup/}, which is used by the scripts
  2365. to store and retrieve information about which files were dumped. This
  2366. file is not meant to be read by humans, and should not be deleted by
  2367. them. @xref{incremental and listed-incremental}, for a more
  2368. detailed explanation of this file.
  2369. The second file is a log file containing the names of the file systems
  2370. and files dumped, what time the backup was made, and any error
  2371. messages that were generated, as well as how much space was left in
  2372. the media volume after the last volume of the archive was written.
  2373. You should check this log file after every backup. The file name is
  2374. @file{log-@var{mmm-ddd-yyyy}-level-1} or
  2375. @file{log-@var{mmm-ddd-yyyy}-full}.
  2376. The script also prints the name of each system being dumped to the
  2377. standard output.
  2378. @c <<<the section on restore scripts is commented out.
  2379. @c <<< a section on non-scripted testore mya be a good idea
  2380. @ignore
  2381. @node Scripted Restoration, , Scripted Backups, Backup Scripts
  2382. @subsection Using the Restore Script
  2383. @c subject to change as things develop
  2384. To restore files that were archived using a scripted backup, use the
  2385. @code{restore} script. The syntax for the script is:
  2386. where ##### are the file systems to restore from, and
  2387. ##### is a regular expression which specifies which files to
  2388. restore. If you specify --all, the script restores all the files
  2389. in the file system.
  2390. You should start the restore script with the media containing the
  2391. first volume of the archive mounted. The script will prompt for other
  2392. volumes as they are needed. If the archive is on tape, you don't need
  2393. to rewind the tape to to its beginning---if the tape head is
  2394. positioned past the beginning of the archive, the script will rewind
  2395. the tape as needed. @xref{Media}, for a discussion of tape
  2396. positioning.
  2397. If you specify @samp{--all} as the @var{files} argument, the
  2398. @code{restore} script extracts all the files in the archived file
  2399. system into the active file system.
  2400. @quotation
  2401. @strong{Warning:}The script will delete files from the active file
  2402. system if they were not in the file system when the archive was made.
  2403. @end quotation
  2404. @xref{incremental and listed-incremental}, for an explanation of how
  2405. the script makes that determination.
  2406. @c this may be an option, not a given
  2407. @end ignore
  2408. @node incremental and listed-incremental, Problems, Backup Scripts, Backups and Restoration
  2409. @section The @code{--incremental} and @code{--listed-incremental} Options
  2410. @samp{--incremental} is used in conjunction with @samp{--create},
  2411. @samp{--extract} or @samp{--list} when backing up and restoring file
  2412. systems. An archive cannot be extracted or listed with the
  2413. @samp{--incremental} option specified unless it was created with the
  2414. option specified. This option should only be used by a script, not by
  2415. the user, and is usually disregarded in favor of
  2416. @samp{--listed-incremental}, which is described below.
  2417. @samp{--incremental} in conjunction with @samp{--create} causes
  2418. @code{tar} to write, at the beginning of the archive, an entry for
  2419. each of the directories that will be archived. The entry for a
  2420. directory includes a list of all the files in the directory at the
  2421. time the archive was created and a flag for each file indicating
  2422. whether or not the file is going to be put in the archive.
  2423. Note that this option causes @code{tar} to create a non-standard
  2424. archive that may not be readable by non-GNU versions of the @code{tar}
  2425. program.
  2426. @samp{--incremental} in conjunction with @samp{--extract} causes
  2427. @code{tar} to read the lists of directory contents previously stored
  2428. in the archive, @emph{delete} files in the file system that did not
  2429. exist in their directories when the archive was created, and then
  2430. extract the files in the archive.
  2431. This behavior is convenient when restoring a damaged file system from
  2432. a succession of incremental backups: it restores the entire state of
  2433. the file system to that which obtained when the backup was made. If
  2434. @samp{--incremental} isn't specified, the file system will probably
  2435. fill up with files that shouldn't exist any more.
  2436. @samp{--incremental} in conjunction with @samp{--list}, causes
  2437. @code{tar} to print, for each directory in the archive, the list of
  2438. files in that directory at the time the archive was created. This
  2439. information is put out in a format that is not easy for humans to
  2440. read, but which is unambiguous for a program: each file name is
  2441. preceded by either a @samp{Y} if the file is present in the archive,
  2442. an @samp{N} if the file is not included in the archive, or a @samp{D}
  2443. if the file is a directory (and is included in the archive). Each
  2444. file name is terminated by a null character. The last file is followed
  2445. by an additional null and a newline to indicate the end of the data.
  2446. @samp{--listed-incremental}=@var{file} acts like @samp{--incremental},
  2447. but when used in conjunction with @samp{--create} will also cause
  2448. @code{tar} to use the file @var{file}, which contains information
  2449. about the state of the file system at the time of the last backup, to
  2450. decide which files to include in the archive being created. That file
  2451. will then be updated by @code{tar}. If the file @var{file} does not
  2452. exist when this option is specified, @code{tar} will create it, and
  2453. include all appropriate files in the archive.
  2454. The file @var{file}, which is archive independent, contains the date
  2455. it was last modified and a list of devices, inode numbers and
  2456. directory names. @code{tar} will archive files with newer mod dates
  2457. or inode change times, and directories with an unchanged inode number
  2458. and device but a changed directory name. The file is updated after
  2459. the files to be archived are determined, but before the new archive is
  2460. actually created.
  2461. @c <<< this section needs to be written
  2462. @node Problems, , incremental and listed-incremental, Backups and Restoration
  2463. @section Some Common Problems and their Solutions
  2464. errors from system:
  2465. permission denied
  2466. no such file or directory
  2467. not owner
  2468. errors from tar:
  2469. directory checksum error
  2470. header format error
  2471. errors from media/system:
  2472. i/o error
  2473. device busy
  2474. @node Media, Quick Reference, Backups and Restoration, Top
  2475. @chapter Tapes and Other Archive Media
  2476. Archives are usually written on dismountable media---tape cartridges,
  2477. mag tapes, or floppy disks.
  2478. The amount of data a tape or disk holds depends not only on its size,
  2479. but also on how it is formatted. A 2400 foot long reel of mag tape
  2480. holds 40 megabytes of data when formated at 1600 bits per inch. The
  2481. physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
  2482. Magnetic media are re-usable---once the archive on a tape is no longer
  2483. needed, the archive can be erased and the tape or disk used over.
  2484. Media quality does deteriorate with use, however. Most tapes or disks
  2485. should be disgarded when they begin to produce data errors. EXABYTE
  2486. tape cartridges should be disgarded when they generate an @dfn{error
  2487. count} (number of non-usable bits) of more than 10k.
  2488. Magnetic media are written and erased using magnetic fields, and
  2489. should be protected from such fields to avoid damage to stored data.
  2490. Sticking a floppy disk to a filing cabinet using a magnet is probably
  2491. not a good idea.
  2492. @menu
  2493. * Write Protection:: Write Protection
  2494. * Tape Positioning:: Tape Positions and Tape Marks
  2495. @end menu
  2496. @node Write Protection, Tape Positioning, Media, Media
  2497. @section Write Protection
  2498. All tapes and disks can be @dfn{write protected}, to protect data on
  2499. them from being changed. Once an archive is written, you should write
  2500. protect the media to prevent the archive from being accidently
  2501. overwritten or deleted. (This will protect the archive from being
  2502. changed with a tape or floppy drive---it will not protect it from
  2503. magnet fields or other physical hazards).
  2504. The write protection device itself is usually an integral part of the
  2505. physical media, and can be a two position (write enabled/write
  2506. disabled) switch, a notch which can be popped out or covered, a ring
  2507. which can be removed from the center of a tape reel, or some other
  2508. changeable feature.
  2509. @node Tape Positioning, , Write Protection, Media
  2510. @section Tape Positions and Tape Marks
  2511. Just as archives can store more than one file from the file system,
  2512. tapes can store more than one archive file. To keep track of where
  2513. archive files (or any other type of file stored on tape) begin and
  2514. end, tape archive devices write magnetic @dfn{tape marks} on the
  2515. archive media. Tape drives write one tape mark between files,
  2516. two at the end of all the file entries.
  2517. If you think of data as a series of "0000"'s, and tape marks as "x"'s,
  2518. a tape might look like the following:
  2519. @example
  2520. 0000x000000x00000x00x00000xx-------------------------
  2521. @end example
  2522. Tape devices read and write tapes using a read/write @dfn{tape
  2523. head}---a physical part of the device which can only access one point
  2524. on the tape at a time. When you use @code{tar} to read or write
  2525. archive data from a tape device, the device will begin reading or
  2526. writing from wherever on the tape the tape head happens to be,
  2527. regardless of which archive or what part of the archive the tape head
  2528. is on. Before writing an archive, you should make sure that no data
  2529. on the tape will be overwritten (unless it is no longer needed).
  2530. Before reading an archive, you should make sure the tape head is at
  2531. the beginning of the archive you want to read. (The @code{restore}
  2532. script will find the archive automatically. @xref{Scripted
  2533. Restoration}). @xref{mt}, for an explanation of the tape moving
  2534. utility.
  2535. If you want to add new archive file entries to a tape, you should
  2536. advance the tape to the end of the existing file entries, backspace
  2537. over the last tape mark, and write the new archive file. If you were
  2538. to add two archives to the example above, the tape might look like the
  2539. following:
  2540. @example
  2541. 0000x000000x00000x00x00000x000x0000xx----------------
  2542. @end example
  2543. @menu
  2544. * mt:: The @code{mt} Utility
  2545. @end menu
  2546. @node mt, , Tape Positioning, Tape Positioning
  2547. @subsection The @code{mt} Utility
  2548. <<< is it true that this only works on non-block devices? should
  2549. <<< explain the difference, xref to block-size (fixed or variable).
  2550. You can use the @code{mt} utility to advance or rewind a tape past a
  2551. specified number of archive files on the tape. This will allow you to
  2552. move to the beginning of an archive before extracting or reading it,
  2553. or to the end of all the archives before writing a new one.
  2554. @c why isn't there an "advance 'til you find two tape marks together"?
  2555. The syntax of the @code{mt} command is:
  2556. @example
  2557. mt [-f @var{tapename}] @var{operation} [@var{number}]
  2558. @end example
  2559. where @var{tapename} is the name of the tape device, @var{number} is
  2560. the number of times an operation is performed (with a default of one),
  2561. and @var{operation} is one of the following:
  2562. @table @code
  2563. @item eof
  2564. @itemx weof
  2565. Writes @var{number} tape marks at the current position on the tape.
  2566. @item fsf
  2567. Moves tape position forward @var{number} files.
  2568. @item bsf
  2569. Moves tape position back @var{number} files.
  2570. @item rewind
  2571. Rewinds the tape. (Ignores @var{number}).
  2572. @item offline
  2573. @itemx rewoff1
  2574. Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
  2575. @item status
  2576. Prints status information about the tape unit.
  2577. @end table
  2578. <<< is there a better way to frob the spacing on the list? -ringo
  2579. If you don't specify a @var{tapename}, @code{mt} uses the environment
  2580. variable TAPE; if TAPE does not exist, @code{mt} uses the device
  2581. @file{/dev/rmt12}.
  2582. @code{mt} returns a 0 exit status when the operation(s) were
  2583. successful, 1 if the command was unrecognized, and 2 if an operation
  2584. failed.
  2585. @c <<< new node on how to find an archive? -ringo
  2586. If you use @code{tar --extract} with the
  2587. @samp{--label=@var{archive-name}} option specified, @code{tar} will
  2588. read an archive label (the tape head has to be positioned on it) and
  2589. print an error if the archive label doesn't match the
  2590. @var{archive-name} specified. @var{archive-name} can be any regular
  2591. expression. If the labels match, @code{tar} extracts the archive.
  2592. @xref{Archive Label}. @xref{Matching Format Parameters}.
  2593. <<< fix cross references
  2594. @code{tar --list --label} will cause @code{tar} to print the label.
  2595. @c <<< MIB -- program to list all the labels on a tape?
  2596. @node Quick Reference, Data Format Details, Media, Top
  2597. @appendix A Quick Reference Guide to @code{tar} Operations and Options
  2598. @c put in proper form for appendix. (unnumbered?)
  2599. @menu
  2600. * Operations:: A Table of Operations
  2601. * Options:: Table of Options
  2602. @end menu
  2603. @node Operations, Options, Quick Reference, Quick Reference
  2604. @appendixsec A Table of Operations
  2605. @c add xrefs, note synonyms
  2606. The operation argument to @code{tar} specifies which action you want to
  2607. take.
  2608. @table @samp
  2609. @item -A
  2610. Adds copies of an archive or archives to the end of another archive.
  2611. @item -c
  2612. Creates a new archive.
  2613. @item -d
  2614. Compares files in the archive with their counterparts in the file
  2615. system, and reports differences in file size, mode, owner,
  2616. modification date and contents.
  2617. @item -r
  2618. Adds files to the end of the archive.
  2619. @item -t
  2620. Prints a list of the contents of the archive.
  2621. @item -x
  2622. Reads files from the archive and writes them into the active file
  2623. system.
  2624. @item -u
  2625. Adds files to the end of the archive, but only if they are newer than
  2626. their counterparts already in the archive, or if they do not already
  2627. exist in the archive.
  2628. @item --add-archive
  2629. Adds copies of an archive or archives to the end of another archive.
  2630. @item --add-file
  2631. Adds files to the end of the archive.
  2632. @item --append
  2633. Adds files to the end of the archive.
  2634. @item --catenate
  2635. Adds copies of an archive or archives to the end of another archive.
  2636. @item --compare
  2637. Compares files in the archive with their counterparts in the file
  2638. system, and reports differences in file size, mode, owner,
  2639. modification date and contents.
  2640. @item --concatenate
  2641. Adds copies of an archive or archives to the end of another archive.
  2642. @item --create
  2643. Creates a new archive.
  2644. @item --delete
  2645. Deletes files from the archive. All versions of the files are deleted.
  2646. @item --diff
  2647. Compares files in the archive with their counterparts in the file
  2648. system, and reports differences in file size, mode, owner,
  2649. modification date and contents.
  2650. @item --extract
  2651. Reads files from the archive and writes them into the active file
  2652. system.
  2653. @item --get
  2654. Reads files from the archive and writes them into the active file
  2655. system.
  2656. @item --help
  2657. Prints a list of @code{tar} operations and options.
  2658. @item --list
  2659. Prints a list of the contents of the archive.
  2660. @item --update
  2661. Adds files to the end of the archive, but only if they are newer than
  2662. their counterparts already in the archive, or if they do not already
  2663. exist in the archive.
  2664. @item --version
  2665. Prints the version number of the @code{tar} program to the standard
  2666. error.
  2667. @end table
  2668. @node Options, , Operations, Quick Reference
  2669. @appendixsec Table of Options
  2670. Options change the way @code{tar} performs an operation.
  2671. @table @samp
  2672. @item --absolute-paths
  2673. WILL BE INPUT WHEN QUESTION IS RESOLVED
  2674. @item --after-date=@var{date}
  2675. Limit the operation to files changed after the given date.
  2676. @xref{File Exclusion}.
  2677. @item --block-size=@var{number}
  2678. Specify the blocking factor of an archive. @xref{Blocking Factor}.
  2679. @item --compress
  2680. Specify a compressed archive. @xref{Compressed Archives}.
  2681. @item --compress-block.
  2682. Create a whole block sized compressed archive. @xref{Compressed Archives}.
  2683. @item --confirmation
  2684. Solicit confirmation for each file. @xref{Interactive Operation}
  2685. <<< --selective should be a synonym.
  2686. @item --dereference
  2687. Treat a symbolic link as an alternate name for the file the link
  2688. points to. @xref{Symbolic Links}.
  2689. @item --directory=@file{directory}
  2690. Change the working directory. @xref{Changing Working Directory}.
  2691. @item --exclude=@var{pattern}
  2692. Exclude files which match the regular expression @var{pattern}.
  2693. @xref{File Exclusion}.
  2694. @item --exclude-from=@file{file}
  2695. Exclude files which match any of the regular expressions listed in
  2696. the file @file{file}. @xref{File Exclusion}.
  2697. @item --file=@var{archive-name}
  2698. Name the archive. @xref{Archive Name}).
  2699. @item --files-from=@file{file}
  2700. Read file-name arguments from a file on the file system.
  2701. @xref{File Name Lists}.
  2702. @item --ignore-umask
  2703. Set modes of extracted files to those recorded in the archive.
  2704. @xref{File Writing Options}.
  2705. @item --ignore-zeros
  2706. Ignore end-of-archive entries. @xref{Archive Reading Options}.
  2707. <<< this should be changed to --ignore-end
  2708. @item --listed-incremental=@var{file-name} (-g)
  2709. Take a file name argument always. If the file doesn't exist, run a level
  2710. zero dump, creating the file. If the file exists, uses that file to see
  2711. what has changed.
  2712. @item --incremental (-G)
  2713. @c <<<look it up>>>
  2714. @item --tape-length=@var{n} (-L)
  2715. @c <<<alternate way of doing multi archive, will go to that length and
  2716. @c prompts for new tape, automatically turns on multi-volume. >>>
  2717. @c <<< this needs to be written into main body as well -ringo
  2718. @item --info-script=@var{program-file}
  2719. Create a multi-volume archive via a script. @xref{Multi-Volume Archives}.
  2720. @item --interactive
  2721. Ask for confirmation before performing any operation on a file or
  2722. archive member.
  2723. @item --keep-old-files
  2724. Prevent overwriting during extraction. @xref{File Writing Options}.
  2725. @item --label=@var{archive-label}
  2726. Include an archive-label in the archive being created. @xref{Archive
  2727. Label}.
  2728. @item --modification-time
  2729. Set the modification time of extracted files to the time they were
  2730. extracted. @xref{File Writing Options}.
  2731. @item --multi-volume
  2732. Specify a multi-volume archive. @xref{Multi-Volume Archives}.
  2733. @item --newer=@var{date}
  2734. Limit the operation to files changed after the given date.
  2735. @xref{File Exclusion}.
  2736. @item --newer-mtime=@var{date}
  2737. Limit the operation to files modified after the given date. @xref{File
  2738. Exclusion}.
  2739. @item --old
  2740. Create an old format archive. @xref{Old Style File Information}.
  2741. @c <<< did we agree this should go away as a synonym?
  2742. @item --old-archive
  2743. Create an old format archive. @xref{Old Style File Information}.
  2744. @item --one-file-system
  2745. Prevent @code{tar} from crossing file system boundaries when
  2746. archiving. @xref{File Exclusion}.
  2747. @item --portable
  2748. Create an old format archive. @xref{Old Style File Information}.
  2749. @c <<< was portability, may still need to be changed
  2750. @item --preserve-order
  2751. Help process large lists of file-names on machines with small amounts of
  2752. memory. @xref{Archive Reading Options}.
  2753. @item --preserve-permission
  2754. Set modes of extracted files to those recorded in the archive.
  2755. @xref{File Writing Options}.
  2756. @item --read-full-blocks
  2757. Read an archive with a smaller than specified block size or which
  2758. contains incomplete blocks. @xref{Archive Reading Options}).
  2759. @c should be --partial-blocks (!!!)
  2760. @item --record-number
  2761. Print the record number where a message is generated.
  2762. @xref{Additional Information}.
  2763. @item --same-order
  2764. Help process large lists of file-names on machines with small amounts of
  2765. memory. @xref{Archive Reading Options}.
  2766. @item --same-permission
  2767. Set the modes of extracted files to those recorded in the archive.
  2768. @xref{File Writing Options}.
  2769. @item --sparse
  2770. Archive sparse files sparsely. @xref{Sparse Files}.
  2771. @item --starting-file=@var{file-name}
  2772. Begin reading in the middle of an archive. @xref{Scarce Disk Space}.
  2773. @item --to-stdout
  2774. Write files to the standard output. @xref{File Writing Options}.
  2775. @item --uncompress
  2776. Specifdo a compressed archive. @xref{Compressed Archives}.
  2777. @item -V @var{archive-label}
  2778. Include an archive-label in the archive being created. @xref{Archive
  2779. Label}.
  2780. @c was --volume
  2781. @item --verbose
  2782. Print the names of files or archive members as they are being
  2783. operated on. @xref{Additional Information}.
  2784. @item --verify
  2785. Check for discrepancies in the archive immediately after it is
  2786. written. @xref{Write Verification}.
  2787. @item -B
  2788. Read an archive with a smaller than specified block size or which
  2789. contains incomplete blocks. @xref{Archive Reading Options}).
  2790. @item -K @var{file-name}
  2791. Begin reading in the middle of an archive. @xref{Scarce Disk Space}.
  2792. @item -M
  2793. Specify a multi-volume archive. @xref{Multi-Volume Archives}.
  2794. @item -N @var{date}
  2795. Limit operation to files changed after the given date. @xref{File Exclusion}.
  2796. @item -O
  2797. Write files to the standard output. @xref{File Writing Options}.
  2798. @c <<<<- P is absolute paths, add when resolved. -ringo>>>
  2799. @item -R
  2800. Print the record number where a message is generated.
  2801. @xref{Additional Information}.
  2802. @item -S
  2803. Archive sparse files sparsely. @xref{Sparse Files}.
  2804. @item -T @var{file}
  2805. Read file-name arguments from a file on the file system.
  2806. @xref{File Name Lists}.
  2807. @item -W
  2808. Check for discrepancies in the archive immediately after it is
  2809. written. @xref{Write Verification}.
  2810. @item -Z
  2811. Specify a compressed archive. @xref{Compressed Archives}.
  2812. @item -b @var{number}
  2813. Specify the blocking factor of an archive. @xref{Blocking Factor}.
  2814. @item -f @var{archive-name}
  2815. Name the archive. @xref{Archive Name}).
  2816. @item -h
  2817. Treat a symbolic link as an alternate name for the file the link
  2818. points to. @xref{Symbolic Links}.
  2819. @item -i
  2820. Ignore end-of-archive entries. @xref{Archive Reading Options}.
  2821. @item -k
  2822. Prevent overwriting during extraction. @xref{File Writing Options}.
  2823. @item -l
  2824. Prevent @code{tar} from crossing file system boundaries when
  2825. archiving. @xref{File Exclusion}.
  2826. @item -m
  2827. Set the modification time of extracted files to the time they were
  2828. extracted. @xref{File Writing Options}.
  2829. @item -o
  2830. Create an old format archive. @xref{Old Style File Information}.
  2831. @item -p
  2832. Set the modes of extracted files to those recorded in the archive.
  2833. @xref{File Writing Options}.
  2834. @item -s
  2835. Help process large lists of file-names on machines with small amounts of
  2836. memory. @xref{Archive Reading Options}.
  2837. @item -v
  2838. Print the names of files or archive members they are being operated
  2839. on. @xref{Additional Information}.
  2840. @item -w
  2841. @c <<<see --interactive. WILL BE INPUT WHEN QUESTIONS ARE RESOLVED.>>>
  2842. @item -z
  2843. Specify a compressed archive. @xref{Compressed Archives}.
  2844. @item -z -z
  2845. Create a whole block sized compressed archive. @xref{Compressed Archives}.
  2846. @c I would rather this were -Z. it is the only double letter short
  2847. @c form.
  2848. @item -C @file{directory}
  2849. Change the working directory. @xref{Changing Working Directory}.
  2850. @item -F @var{program-file}
  2851. Create a multi-volume archive via a script. @xref{Multi-Volume Archives}.
  2852. @item -X @file{file}
  2853. Exclude files which match any of the regular expressions listed in
  2854. the file @file{file}. @xref{File Exclusion}.
  2855. @end table
  2856. @node Data Format Details, Concept Index, Quick Reference, Top
  2857. @appendix Details of the Archive Data Format
  2858. This chapter is based heavily on John Gilmore's @i{tar}(5) manual page
  2859. for the public domain @code{tar} that GNU @code{tar} is based on.
  2860. @c it's been majorly edited since, we may be able to lose this.
  2861. The archive media contains a series of records, each of which contains
  2862. 512 bytes. Each archive member is represented by a header record,
  2863. which describes the file, followed by zero or more records which
  2864. represent the contents of the file. At the end of the archive file
  2865. there may be a record consisting of a series of binary zeros, as an
  2866. end-of-archive marker. GNU @code{tar} writes a record of zeros at the
  2867. end of an archive, but does not assume that such a record exists when
  2868. reading an archive.
  2869. Records may be grouped into @dfn{blocks} for I/O operations. A block
  2870. of records is written with a single @code{write()} operation. The
  2871. number of records in a block is specified using the @samp{--block-size}
  2872. option. @xref{Blocking Factor}, for more information about specifying
  2873. block size.
  2874. @menu
  2875. * Header Data:: The Distribution of Data in the Header
  2876. * Header Fields:: The Meaning of Header Fields
  2877. * Sparse File Handling:: Fields to Handle Sparse Files
  2878. @end menu
  2879. @node Header Data, Header Fields, Data Format Details, Data Format Details
  2880. @appendixsec The Distribution of Data in the Header
  2881. The header record is defined in C as follows:
  2882. @c I am taking the following code on faith.
  2883. @example
  2884. @r{Standard Archive Format - Standard TAR - USTAR}
  2885. #define RECORDSIZE 512
  2886. #define NAMSIZ 100
  2887. #define TUNMLEN 32
  2888. #define TGNMLEN 32
  2889. #define SPARSE_EXT_HDR 21
  2890. #define SPARSE_IN_HDR 4
  2891. struct sparse @{
  2892. char offset[12];
  2893. char numbytes[12];
  2894. @};
  2895. union record @{
  2896. char charptr[RECORDSIZE];
  2897. struct header @{
  2898. char name[NAMSIZ];
  2899. char mode[8];
  2900. char uid[8];
  2901. char gid[8];
  2902. char size[12];
  2903. char mtime[12];
  2904. char chksum[8];
  2905. char linkflag;
  2906. char linkname[NAMSIZ];
  2907. char magic[8];
  2908. char uname[TUNMLEN];
  2909. char gname[TGNMLEN];
  2910. char devmajor[8];
  2911. char devminor[8];
  2912. @r{The following fields were added by gnu and are not used by other}
  2913. @r{versions of @code{tar}}.
  2914. char atime[12];
  2915. char ctime[12];
  2916. char offset[12];
  2917. char longnames[4];
  2918. @r{The next three fields were added by gnu to deal with shrinking down}
  2919. @r{sparse files.}
  2920. struct sparse sp[SPARSE_IN_HDR];
  2921. char isextended;
  2922. @r{This is the number of nulls at the end of the file, if any.}
  2923. char ending_blanks[12];
  2924. @} header;
  2925. struct extended_header @{
  2926. struct sparse sp[21];
  2927. char isextended;
  2928. @} ext_hdr;
  2929. @};
  2930. @c <<< this whole thing needs to be put into better english
  2931. @r{The checksum field is filled with this while the checksum is computed.}
  2932. #define CHKBLANKS " " @r{8 blanks, no null}
  2933. @r{Inclusion of this field marks an archive as being in standard}
  2934. @r{Posix format (though GNU tar itself is not Posix conforming). GNU}
  2935. @r{tar puts "ustar" in this field if uname and gname are valid.}
  2936. #define TMAGIC "ustar " @r{7 chars and a null}
  2937. @r{The magic field is filled with this if this is a GNU format dump entry.}
  2938. #define GNUMAGIC "GNUtar " @r{7 chars and a null}
  2939. @r{The linkflag defines the type of file.}
  2940. #define LF_OLDNORMAL '\0' @r{Normal disk file, Unix compatible}
  2941. #define LF_NORMAL '0' @r{Normal disk file}
  2942. #define LF_LINK '1' @r{Link to previously dumped file}
  2943. #define LF_SYMLINK '2' @r{Symbolic link}
  2944. #define LF_CHR '3' @r{Character special file}
  2945. #define LF_BLK '4' @r{Block special file}
  2946. #define LF_DIR '5' @r{Directory}
  2947. #define LF_FIFO '6' @r{FIFO special file}
  2948. #define LF_CONTIG '7' @r{Contiguous file}
  2949. @r{hhe following are further link types which were defined later.}
  2950. @r{This is a dir entry that contains the names of files that were in}
  2951. @r{the dir at the time the dump was made.}
  2952. #define LF_DUMPDIR 'D'
  2953. @r{This is the continuation of a file that began on another volume}
  2954. #define LF_MULTIVOL 'M'
  2955. @r{This is for sparse files}
  2956. #define LF_SPARSE 'S'
  2957. @r{This file is a tape/volume header. Ignore it on extraction.}
  2958. #define LF_VOLHDR 'V'
  2959. @r{These are bits used in the mode field - the values are in octal}
  2960. #define TSUID 04000 @r{Set UID on execution}
  2961. #define TSGID 02000 @r{Set GID on execution}
  2962. #define TSVTX 01000 @r{Save text (sticky bit)}
  2963. @r{These are file permissions}
  2964. #define TUREAD 00400 @r{read by owner}
  2965. #define TUWRITE 00200 @r{write by owner}
  2966. #define TUEXEC 00100 @r{execute/search by owner}
  2967. #define TGREAD 00040 @r{read by group}
  2968. #define TGWRITE 00020 @r{write by group}
  2969. #define TGEXEC 00010 @r{execute/search by group}
  2970. #define TOREAD 00004 @r{read by other}
  2971. #define TOWRITE 00002 @r{write by other}
  2972. #define TOEXEC 00001 @r{execute/search by other}
  2973. @end example
  2974. All characters in headers are 8-bit characters in the local variant of
  2975. ASCII. Each field in the header is contiguous; that is, there is no
  2976. padding in the header format.
  2977. Data representing the contents of files is not translated in any way
  2978. and is not constrained to represent characters in any character set.
  2979. @code{tar} does not distinguish between text files and binary files.
  2980. The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
  2981. @code{gname} fields contain null-terminated character strings. All
  2982. other fields contain zero-filled octal numbers in ASCII. Each numeric
  2983. field of width @var{w} contains @var{w} @minus{} 2 digits, a space, and a
  2984. null, except @code{size} and @code{mtime}, which do not contain the
  2985. trailing null.
  2986. @node Header Fields, Sparse File Handling, Header Data, Data Format Details
  2987. @appendixsec The Meaning of Header Fields
  2988. The @code{name} field contains the name of the file.
  2989. <<< how big a name before field overflows?
  2990. The @code{mode} field contains nine bits which specify file
  2991. permissions, and three bits which specify the Set UID, Set GID, and
  2992. Save Text (``stick'') modes. Values for these bits are defined above.
  2993. @xref{File Writing Options}, for information on how file permissions
  2994. and modes are used by @code{tar}.
  2995. The @code{uid} and @code{gid} fields contain the numeric user and
  2996. group IDs of the file owners. If the operating system does not
  2997. support numeric user or group IDs, these fields should be ignored.
  2998. @c but are they?
  2999. The @code{size} field contains the size of the file in bytes; this
  3000. field contains a zero if the header describes a link to a file.
  3001. The @code{mtime} field contains the modification time of the file.
  3002. This is the ASCII representation of the octal value of the last time
  3003. the file was modified, represented as an integer number of seconds
  3004. since January 1, 1970, 00:00 Coordinated Universal Time.
  3005. @xref{File Writing Options}, for a description of how @code{tar} uses
  3006. this information.
  3007. The @code{chksum} field contains the ASCII representation of the octal
  3008. value of the simple sum of all bytes in the header record. To
  3009. generate this sum, each 8-bit byte in the header is added to an
  3010. unsigned integer, which has been initialized to zero. The precision
  3011. of the integer is seventeen bits. When calculating the checksum, the
  3012. @code{chksum} field itself is treated as blank.
  3013. The @code{atime} and @code{ctime} fields are used when making
  3014. incremental backups; they store, respectively, the file's access time
  3015. and last inode-change time.
  3016. The value in the @code{offset} field is used when making a
  3017. multi-volume archive. The offset is number of bytes into the file
  3018. that we need to go to pick up where we left off in the previous
  3019. volume, i.e the location that a continued file is continued from.
  3020. The @code{longnames} field supports a feature that is not yet
  3021. implemented. This field should be empty.
  3022. The @code{magic} field indicates that this archive was output in the
  3023. P1003 archive format. If this field contains @code{TMAGIC}, the
  3024. @code{uname} and @code{gname} fields will contain the ASCII
  3025. representation of the owner and group of the file respectively. If
  3026. found, the user and group IDs are used rather than the values in the
  3027. @code{uid} and @code{gid} fields.
  3028. The @code{sp} field is used to archive sparse files efficiently.
  3029. @xref{Sparse File Handling}, for a description of this field, and
  3030. other fields it may imply.
  3031. The @code{typeflag} field specifies the file's type. If a particular
  3032. implementation does not recognize or permit the specified type,
  3033. @code{tar} extracts the file as if it were a regular file, and reports
  3034. the discrepancy on the standard error. @xref{File Types}. @xref{GNU
  3035. File Types}.
  3036. @menu
  3037. * File Types:: File Types
  3038. * GNU File Types:: Additional File Types Supported by GNU
  3039. @end menu
  3040. @node File Types, GNU File Types, Header Fields, Header Fields
  3041. @appendixsubsec File Types
  3042. The following flags are used to describe file types:
  3043. @table @code
  3044. @item LF_NORMAL
  3045. @itemx LF_OLDNORMAL
  3046. Indicates a regular file. In order to be compatible with older
  3047. versions of @code{tar}, a @code{typeflag} value of @code{LF_OLDNORMAL}
  3048. should be silently recognized as a regular file. New archives should
  3049. be created using @code{LF_NORMAL} for regular files. For backward
  3050. compatibility, @code{tar} treats a regular file whose name ends with a
  3051. slash as a directory.
  3052. @item LF_LINK
  3053. Indicates a link to another file, of any type, which has been
  3054. previously archived. @code{tar} identifies linked files in Unix by
  3055. matching device and inode numbers. The linked-to name is specified in
  3056. the @code{linkname} field with a trailing null.
  3057. @item LF_SYMLINK
  3058. Indicates a symbolic link to another file. The linked-to
  3059. name is specified in the @code{linkname} field with a trailing null.
  3060. @xref{File Writing Options}, for information on archiving files
  3061. referenced by a symbolic link.
  3062. @item LF_CHR
  3063. @itemx LF_BLK
  3064. Indicate character special files and block special files,
  3065. respectively. In this case the @code{devmajor} and @code{devminor}
  3066. fields will contain the major and minor device numbers. Operating
  3067. systems may map the device specifications to their own local
  3068. specification, or may ignore the entry.
  3069. @item LF_DIR
  3070. Indicates a directory or sub-directory. The directory name in the
  3071. @code{name} field should end with a slash. On systems where disk
  3072. allocation is performed on a directory basis, the @code{size} field
  3073. will contain the maximum number of bytes (which may be rounded to the
  3074. nearest disk block allocation unit) that the directory can hold. A
  3075. @code{size} field of zero indicates no size limitations. Systems that
  3076. do not support size limiting in this manner should ignore the
  3077. @code{size} field.
  3078. @item LF_FIFO
  3079. Indicates a FIFO special file. Note that archiving a FIFO file
  3080. archives the existence of the file and not its contents.
  3081. @item LF_CONTIG
  3082. Indicates a contiguous file. Contiguous files are the same as normal
  3083. files except that, in operating systems that support it, all the
  3084. files' disk space is allocated contiguously. Operating systems which
  3085. do not allow contiguous allocation should silently treat this type as
  3086. a normal file.
  3087. @item 'A' @dots{}
  3088. @itemx 'Z'
  3089. These are reserved for custom implementations. Some of these are used
  3090. in the GNU modified format, which is described below. @xref{GNU File
  3091. Types}.
  3092. @end table
  3093. Certain other flag values are reserved for specification in future
  3094. revisions of the P1003 standard, and should not be used by any
  3095. @code{tar} program.
  3096. @node GNU File Types, , File Types, Header Fields
  3097. @appendixsubsec Additional File Types Supported by GNU
  3098. GNU @code{tar} uses additional file types to describe new types of
  3099. files in an archive. These are listed below.
  3100. @table @code
  3101. @item LF_DUMPDIR
  3102. @itemx 'D'
  3103. Indicates a directory and a list of files created by the
  3104. @samp{--incremental} option. The @code{size} field gives the total
  3105. size of the associated list of files. Each file name is preceded by
  3106. either a @code{'Y'} (the file should be in this archive) or an
  3107. @code{'N'} (the file is a directory, or is not stored in the archive).
  3108. Each file name is terminated by a null. There is an additional null
  3109. after the last file name.
  3110. @item LF_MULTIVOL
  3111. @itemx 'M'
  3112. Indicates a file continued from another volume of a multi-volume
  3113. archive (@pxref{Multi-Volume Archives}). The original type of the file is not
  3114. given here. The @code{size} field gives the maximum size of this
  3115. piece of the file (assuming the volume does not end before the file is
  3116. written out). The @code{offset} field gives the offset from the
  3117. beginning of the file where this part of the file begins. Thus
  3118. @code{size} plus @code{offset} should equal the original size of the
  3119. file.
  3120. @item LF_SPARSE
  3121. @itemx 'S'
  3122. Indicates a sparse file. @xref{Sparse Files}. @xref{Sparse File
  3123. Handling}.
  3124. @item LF_VOLHDR
  3125. @itemx 'V'
  3126. Marks an archive label that was created using the @samp{--label} option
  3127. when the archive was created (@pxref{Archive Label}. The @code{name}
  3128. field contains the argument to the option. The @code{size} field is
  3129. zero. Only the first file in each volume of an archive should have
  3130. this type.
  3131. @end table
  3132. @node Sparse File Handling, , Header Fields, Data Format Details
  3133. @appendixsec Fields to Handle Sparse Files
  3134. The following header information was added to deal with sparse files
  3135. (@pxref{Sparse Files}):
  3136. @c TALK TO MIB
  3137. The @code{sp} field (fields? something else?) is an array of
  3138. @code{struct sparse}. Each @code{struct sparse} contains two
  3139. 12-character strings, which represent the offset into the file and the
  3140. number of bytes to be written at that offset. The offset is absolute,
  3141. and not relative to the offset in preceding array elements.
  3142. The header can contain four of these @code{struct sparse}; if more are
  3143. needed, they are not stored in the header, instead, the flag
  3144. @code{isextended} is set and the next record is an
  3145. @code{extended_header}.
  3146. @c @code{extended_header} or @dfn{extended_header} ??? the next
  3147. @c record after the header, or in the middle of it.
  3148. The @code{isextended} flag is only set for sparse files, and then only
  3149. if extended header records are needed when archiving the file.
  3150. Each extended header record can contain an array of 21 sparse
  3151. structures, as well as another @code{isextended} flag. There is no
  3152. limit (except that implied by the archive media) on the number of
  3153. extended header records that can be used to describe a sparse file.
  3154. @c so is @code{extended_header} the right way to write this?
  3155. @node Concept Index, , Data Format Details, Top
  3156. @unnumbered Concept Index
  3157. @printindex cp
  3158. @summarycontents
  3159. @contents
  3160. @bye