tar.texi 418 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380
  1. \input texinfo @c -*-texinfo-*-
  2. @comment %**start of header
  3. @setfilename tar.info
  4. @include version.texi
  5. @settitle GNU tar @value{VERSION}
  6. @setchapternewpage odd
  7. @finalout
  8. @smallbook
  9. @c %**end of header
  10. @c Maintenance notes:
  11. @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
  12. @c 2. Before creating final variant:
  13. @c 2.1. Run `make check-options' to make sure all options are properly
  14. @c documented;
  15. @c 2.2. Run `make master-menu' (see comment before the master menu).
  16. @include rendition.texi
  17. @include value.texi
  18. @defcodeindex op
  19. @c Put everything in one index (arbitrarily chosen to be the concept index).
  20. @syncodeindex fn cp
  21. @syncodeindex ky cp
  22. @syncodeindex pg cp
  23. @syncodeindex vr cp
  24. @copying
  25. This manual is for @acronym{GNU} @command{tar} (version
  26. @value{VERSION}, @value{UPDATED}), which creates and extracts files
  27. from archives.
  28. Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
  29. 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
  30. @quotation
  31. Permission is granted to copy, distribute and/or modify this document
  32. under the terms of the GNU Free Documentation License, Version 1.1 or
  33. any later version published by the Free Software Foundation; with no
  34. Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
  35. and with the Back-Cover Texts as in (a) below. A copy of the license
  36. is included in the section entitled "GNU Free Documentation License".
  37. (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
  38. this GNU Manual. Buying copies from GNU Press supports the FSF in
  39. developing GNU and promoting software freedom.''
  40. @end quotation
  41. @end copying
  42. @dircategory Archiving
  43. @direntry
  44. * Tar: (tar). Making tape (or disk) archives.
  45. @end direntry
  46. @dircategory Individual utilities
  47. @direntry
  48. * tar: (tar)tar invocation. Invoking @GNUTAR{}.
  49. @end direntry
  50. @shorttitlepage @acronym{GNU} @command{tar}
  51. @titlepage
  52. @title @acronym{GNU} tar: an archiver tool
  53. @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
  54. @author John Gilmore, Jay Fenlason et al.
  55. @page
  56. @vskip 0pt plus 1filll
  57. @insertcopying
  58. @end titlepage
  59. @ifnottex
  60. @node Top
  61. @top @acronym{GNU} tar: an archiver tool
  62. @insertcopying
  63. @cindex file archival
  64. @cindex archiving files
  65. The first part of this master menu lists the major nodes in this Info
  66. document. The rest of the menu lists all the lower level nodes.
  67. @end ifnottex
  68. @c The master menu goes here.
  69. @c
  70. @c NOTE: To update it from within Emacs, make sure mastermenu.el is
  71. @c loaded and run texinfo-master-menu.
  72. @c To update it from the command line, run
  73. @c
  74. @c make master-menu
  75. @menu
  76. * Introduction::
  77. * Tutorial::
  78. * tar invocation::
  79. * operations::
  80. * Backups::
  81. * Choosing::
  82. * Date input formats::
  83. * Formats::
  84. * Media::
  85. Appendices
  86. * Changes::
  87. * Configuring Help Summary::
  88. * Fixing Snapshot Files::
  89. * Tar Internals::
  90. * Genfile::
  91. * Free Software Needs Free Documentation::
  92. * Copying This Manual::
  93. * Index of Command Line Options::
  94. * Index::
  95. @detailmenu
  96. --- The Detailed Node Listing ---
  97. Introduction
  98. * Book Contents:: What this Book Contains
  99. * Definitions:: Some Definitions
  100. * What tar Does:: What @command{tar} Does
  101. * Naming tar Archives:: How @command{tar} Archives are Named
  102. * Authors:: @GNUTAR{} Authors
  103. * Reports:: Reporting bugs or suggestions
  104. Tutorial Introduction to @command{tar}
  105. * assumptions::
  106. * stylistic conventions::
  107. * basic tar options:: Basic @command{tar} Operations and Options
  108. * frequent operations::
  109. * Two Frequent Options::
  110. * create:: How to Create Archives
  111. * list:: How to List Archives
  112. * extract:: How to Extract Members from an Archive
  113. * going further::
  114. Two Frequently Used Options
  115. * file tutorial::
  116. * verbose tutorial::
  117. * help tutorial::
  118. How to Create Archives
  119. * prepare for examples::
  120. * Creating the archive::
  121. * create verbose::
  122. * short create::
  123. * create dir::
  124. How to List Archives
  125. * list dir::
  126. How to Extract Members from an Archive
  127. * extracting archives::
  128. * extracting files::
  129. * extract dir::
  130. * extracting untrusted archives::
  131. * failing commands::
  132. Invoking @GNUTAR{}
  133. * Synopsis::
  134. * using tar options::
  135. * Styles::
  136. * All Options::
  137. * help::
  138. * defaults::
  139. * verbose::
  140. * checkpoints::
  141. * interactive::
  142. The Three Option Styles
  143. * Long Options:: Long Option Style
  144. * Short Options:: Short Option Style
  145. * Old Options:: Old Option Style
  146. * Mixing:: Mixing Option Styles
  147. All @command{tar} Options
  148. * Operation Summary::
  149. * Option Summary::
  150. * Short Option Summary::
  151. @GNUTAR{} Operations
  152. * Basic tar::
  153. * Advanced tar::
  154. * create options::
  155. * extract options::
  156. * backup::
  157. * Applications::
  158. * looking ahead::
  159. Advanced @GNUTAR{} Operations
  160. * Operations::
  161. * append::
  162. * update::
  163. * concatenate::
  164. * delete::
  165. * compare::
  166. How to Add Files to Existing Archives: @option{--append}
  167. * appending files:: Appending Files to an Archive
  168. * multiple::
  169. Updating an Archive
  170. * how to update::
  171. Options Used by @option{--create}
  172. * override:: Overriding File Metadata.
  173. * Ignore Failed Read::
  174. Options Used by @option{--extract}
  175. * Reading:: Options to Help Read Archives
  176. * Writing:: Changing How @command{tar} Writes Files
  177. * Scarce:: Coping with Scarce Resources
  178. Options to Help Read Archives
  179. * read full records::
  180. * Ignore Zeros::
  181. Changing How @command{tar} Writes Files
  182. * Dealing with Old Files::
  183. * Overwrite Old Files::
  184. * Keep Old Files::
  185. * Keep Newer Files::
  186. * Unlink First::
  187. * Recursive Unlink::
  188. * Data Modification Times::
  189. * Setting Access Permissions::
  190. * Directory Modification Times and Permissions::
  191. * Writing to Standard Output::
  192. * Writing to an External Program::
  193. * remove files::
  194. Coping with Scarce Resources
  195. * Starting File::
  196. * Same Order::
  197. Performing Backups and Restoring Files
  198. * Full Dumps:: Using @command{tar} to Perform Full Dumps
  199. * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
  200. * Backup Levels:: Levels of Backups
  201. * Backup Parameters:: Setting Parameters for Backups and Restoration
  202. * Scripted Backups:: Using the Backup Scripts
  203. * Scripted Restoration:: Using the Restore Script
  204. Setting Parameters for Backups and Restoration
  205. * General-Purpose Variables::
  206. * Magnetic Tape Control::
  207. * User Hooks::
  208. * backup-specs example:: An Example Text of @file{Backup-specs}
  209. Choosing Files and Names for @command{tar}
  210. * file:: Choosing the Archive's Name
  211. * Selecting Archive Members::
  212. * files:: Reading Names from a File
  213. * exclude:: Excluding Some Files
  214. * wildcards:: Wildcards Patterns and Matching
  215. * quoting styles:: Ways of Quoting Special Characters in Names
  216. * transform:: Modifying File and Member Names
  217. * after:: Operating Only on New Files
  218. * recurse:: Descending into Directories
  219. * one:: Crossing File System Boundaries
  220. Reading Names from a File
  221. * nul::
  222. Excluding Some Files
  223. * problems with exclude::
  224. Wildcards Patterns and Matching
  225. * controlling pattern-matching::
  226. Crossing File System Boundaries
  227. * directory:: Changing Directory
  228. * absolute:: Absolute File Names
  229. Date input formats
  230. * General date syntax:: Common rules.
  231. * Calendar date items:: 19 Dec 1994.
  232. * Time of day items:: 9:20pm.
  233. * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
  234. * Day of week items:: Monday and others.
  235. * Relative items in date strings:: next tuesday, 2 years ago.
  236. * Pure numbers in date strings:: 19931219, 1440.
  237. * Seconds since the Epoch:: @@1078100502.
  238. * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
  239. * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
  240. Controlling the Archive Format
  241. * Compression:: Using Less Space through Compression
  242. * Attributes:: Handling File Attributes
  243. * Portability:: Making @command{tar} Archives More Portable
  244. * cpio:: Comparison of @command{tar} and @command{cpio}
  245. Using Less Space through Compression
  246. * gzip:: Creating and Reading Compressed Archives
  247. * sparse:: Archiving Sparse Files
  248. Making @command{tar} Archives More Portable
  249. * Portable Names:: Portable Names
  250. * dereference:: Symbolic Links
  251. * hard links:: Hard Links
  252. * old:: Old V7 Archives
  253. * ustar:: Ustar Archives
  254. * gnu:: GNU and old GNU format archives.
  255. * posix:: @acronym{POSIX} archives
  256. * Checksumming:: Checksumming Problems
  257. * Large or Negative Values:: Large files, negative time stamps, etc.
  258. * Other Tars:: How to Extract GNU-Specific Data Using
  259. Other @command{tar} Implementations
  260. @GNUTAR{} and @acronym{POSIX} @command{tar}
  261. * PAX keywords:: Controlling Extended Header Keywords.
  262. How to Extract GNU-Specific Data Using Other @command{tar} Implementations
  263. * Split Recovery:: Members Split Between Volumes
  264. * Sparse Recovery:: Sparse Members
  265. Tapes and Other Archive Media
  266. * Device:: Device selection and switching
  267. * Remote Tape Server::
  268. * Common Problems and Solutions::
  269. * Blocking:: Blocking
  270. * Many:: Many archives on one tape
  271. * Using Multiple Tapes:: Using Multiple Tapes
  272. * label:: Including a Label in the Archive
  273. * verify::
  274. * Write Protection::
  275. Blocking
  276. * Format Variations:: Format Variations
  277. * Blocking Factor:: The Blocking Factor of an Archive
  278. Many Archives on One Tape
  279. * Tape Positioning:: Tape Positions and Tape Marks
  280. * mt:: The @command{mt} Utility
  281. Using Multiple Tapes
  282. * Multi-Volume Archives:: Archives Longer than One Tape or Disk
  283. * Tape Files:: Tape Files
  284. * Tarcat:: Concatenate Volumes into a Single Archive
  285. Tar Internals
  286. * Standard:: Basic Tar Format
  287. * Extensions:: @acronym{GNU} Extensions to the Archive Format
  288. * Sparse Formats:: Storing Sparse Files
  289. * Snapshot Files::
  290. * Dumpdir::
  291. Storing Sparse Files
  292. * Old GNU Format::
  293. * PAX 0:: PAX Format, Versions 0.0 and 0.1
  294. * PAX 1:: PAX Format, Version 1.0
  295. Genfile
  296. * Generate Mode:: File Generation Mode.
  297. * Status Mode:: File Status Mode.
  298. * Exec Mode:: Synchronous Execution mode.
  299. Copying This Manual
  300. * GNU Free Documentation License:: License for copying this manual
  301. @end detailmenu
  302. @end menu
  303. @node Introduction
  304. @chapter Introduction
  305. @GNUTAR{} creates
  306. and manipulates @dfn{archives} which are actually collections of
  307. many other files; the program provides users with an organized and
  308. systematic method for controlling a large amount of data.
  309. The name ``tar'' originally came from the phrase ``Tape ARchive'', but
  310. archives need not (and these days, typically do not) reside on tapes.
  311. @menu
  312. * Book Contents:: What this Book Contains
  313. * Definitions:: Some Definitions
  314. * What tar Does:: What @command{tar} Does
  315. * Naming tar Archives:: How @command{tar} Archives are Named
  316. * Authors:: @GNUTAR{} Authors
  317. * Reports:: Reporting bugs or suggestions
  318. @end menu
  319. @node Book Contents
  320. @section What this Book Contains
  321. The first part of this chapter introduces you to various terms that will
  322. recur throughout the book. It also tells you who has worked on @GNUTAR{}
  323. and its documentation, and where you should send bug reports
  324. or comments.
  325. The second chapter is a tutorial (@pxref{Tutorial}) which provides a
  326. gentle introduction for people who are new to using @command{tar}. It is
  327. meant to be self contained, not requiring any reading from subsequent
  328. chapters to make sense. It moves from topic to topic in a logical,
  329. progressive order, building on information already explained.
  330. Although the tutorial is paced and structured to allow beginners to
  331. learn how to use @command{tar}, it is not intended solely for beginners.
  332. The tutorial explains how to use the three most frequently used
  333. operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
  334. two frequently used options (@samp{file} and @samp{verbose}). The other
  335. chapters do not refer to the tutorial frequently; however, if a section
  336. discusses something which is a complex variant of a basic concept, there
  337. may be a cross reference to that basic concept. (The entire book,
  338. including the tutorial, assumes that the reader understands some basic
  339. concepts of using a Unix-type operating system; @pxref{Tutorial}.)
  340. The third chapter presents the remaining five operations, and
  341. information about using @command{tar} options and option syntax.
  342. @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
  343. than the reality. should think about whether this makes sense to say
  344. here, or not.} The other chapters are meant to be used as a
  345. reference. Each chapter presents everything that needs to be said
  346. about a specific topic.
  347. One of the chapters (@pxref{Date input formats}) exists in its
  348. entirety in other @acronym{GNU} manuals, and is mostly self-contained.
  349. In addition, one section of this manual (@pxref{Standard}) contains a
  350. big quote which is taken directly from @command{tar} sources.
  351. In general, we give both long and short (abbreviated) option names
  352. at least once in each section where the relevant option is covered, so
  353. that novice readers will become familiar with both styles. (A few
  354. options have no short versions, and the relevant sections will
  355. indicate this.)
  356. @node Definitions
  357. @section Some Definitions
  358. @cindex archive
  359. @cindex tar archive
  360. The @command{tar} program is used to create and manipulate @command{tar}
  361. archives. An @dfn{archive} is a single file which contains the contents
  362. of many files, while still identifying the names of the files, their
  363. owner(s), and so forth. (In addition, archives record access
  364. permissions, user and group, size in bytes, and data modification time.
  365. Some archives also record the file names in each archived directory, as
  366. well as other file and directory information.) You can use @command{tar}
  367. to @dfn{create} a new archive in a specified directory.
  368. @cindex member
  369. @cindex archive member
  370. @cindex file name
  371. @cindex member name
  372. The files inside an archive are called @dfn{members}. Within this
  373. manual, we use the term @dfn{file} to refer only to files accessible in
  374. the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
  375. @dfn{member} to refer only to the members of an archive. Similarly, a
  376. @dfn{file name} is the name of a file, as it resides in the file system,
  377. and a @dfn{member name} is the name of an archive member within the
  378. archive.
  379. @cindex extraction
  380. @cindex unpacking
  381. The term @dfn{extraction} refers to the process of copying an archive
  382. member (or multiple members) into a file in the file system. Extracting
  383. all the members of an archive is often called @dfn{extracting the
  384. archive}. The term @dfn{unpack} can also be used to refer to the
  385. extraction of many or all the members of an archive. Extracting an
  386. archive does not destroy the archive's structure, just as creating an
  387. archive does not destroy the copies of the files that exist outside of
  388. the archive. You may also @dfn{list} the members in a given archive
  389. (this is often thought of as ``printing'' them to the standard output,
  390. or the command line), or @dfn{append} members to a pre-existing archive.
  391. All of these operations can be performed using @command{tar}.
  392. @node What tar Does
  393. @section What @command{tar} Does
  394. @cindex tar
  395. The @command{tar} program provides the ability to create @command{tar}
  396. archives, as well as various other kinds of manipulation. For example,
  397. you can use @command{tar} on previously created archives to extract files,
  398. to store additional files, or to update or list files which were already
  399. stored.
  400. Initially, @command{tar} archives were used to store files conveniently on
  401. magnetic tape. The name @command{tar} comes from this use; it stands for
  402. @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
  403. direct its output to available devices, files, or other programs (using
  404. pipes). @command{tar} may even access remote devices or files (as archives).
  405. You can use @command{tar} archives in many ways. We want to stress a few
  406. of them: storage, backup, and transportation.
  407. @FIXME{the following table entries need a bit of work.}
  408. @table @asis
  409. @item Storage
  410. Often, @command{tar} archives are used to store related files for
  411. convenient file transfer over a network. For example, the
  412. @acronym{GNU} Project distributes its software bundled into
  413. @command{tar} archives, so that all the files relating to a particular
  414. program (or set of related programs) can be transferred as a single
  415. unit.
  416. A magnetic tape can store several files in sequence. However, the tape
  417. has no names for these files; it only knows their relative position on
  418. the tape. One way to store several files on one tape and retain their
  419. names is by creating a @command{tar} archive. Even when the basic transfer
  420. mechanism can keep track of names, as FTP can, the nuisance of handling
  421. multiple files, directories, and multiple links makes @command{tar}
  422. archives useful.
  423. Archive files are also used for long-term storage. You can think of
  424. this as transportation from the present into the future. (It is a
  425. science-fiction idiom that you can move through time as well as in
  426. space; the idea here is that @command{tar} can be used to move archives in
  427. all dimensions, even time!)
  428. @item Backup
  429. Because the archive created by @command{tar} is capable of preserving
  430. file information and directory structure, @command{tar} is commonly
  431. used for performing full and incremental backups of disks. A backup
  432. puts a collection of files (possibly pertaining to many users and
  433. projects) together on a disk or a tape. This guards against
  434. accidental destruction of the information in those files.
  435. @GNUTAR{} has special features that allow it to be
  436. used to make incremental and full dumps of all the files in a
  437. file system.
  438. @item Transportation
  439. You can create an archive on one system, transfer it to another system,
  440. and extract the contents there. This allows you to transport a group of
  441. files from one system to another.
  442. @end table
  443. @node Naming tar Archives
  444. @section How @command{tar} Archives are Named
  445. Conventionally, @command{tar} archives are given names ending with
  446. @samp{.tar}. This is not necessary for @command{tar} to operate properly,
  447. but this manual follows that convention in order to accustom readers to
  448. it and to make examples more clear.
  449. @cindex tar file
  450. @cindex entry
  451. @cindex tar entry
  452. Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
  453. archive members as ``files'' or ``entries''. For people familiar with
  454. the operation of @command{tar}, this causes no difficulty. However, in
  455. this manual, we consistently refer to ``archives'' and ``archive
  456. members'' to make learning to use @command{tar} easier for novice users.
  457. @node Authors
  458. @section @GNUTAR{} Authors
  459. @GNUTAR{} was originally written by John Gilmore,
  460. and modified by many people. The @acronym{GNU} enhancements were
  461. written by Jay Fenlason, then Joy Kendall, and the whole package has
  462. been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
  463. Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
  464. numerous and kind users.
  465. We wish to stress that @command{tar} is a collective work, and owes much to
  466. all those people who reported problems, offered solutions and other
  467. insights, or shared their thoughts and suggestions. An impressive, yet
  468. partial list of those contributors can be found in the @file{THANKS}
  469. file from the @GNUTAR{} distribution.
  470. @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
  471. sure i want to spell out the history in this detail, at least not for
  472. the printed book. i'm just not sure it needs to be said this way.
  473. i'll think about it.}
  474. @FIXME{History is more important, and surely more interesting, than
  475. actual names. Quoting names without history would be meaningless. FP}
  476. Jay Fenlason put together a draft of a @GNUTAR{}
  477. manual, borrowing notes from the original man page from John Gilmore.
  478. This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
  479. Gorin worked on a tutorial and manual for @GNUTAR{}.
  480. Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
  481. taking information from all these sources and merging them. Melissa
  482. Weisshaus finally edited and redesigned the book to create version
  483. 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
  484. by the current maintainer, Sergey Poznyakoff.
  485. For version 1.12, Daniel Hagerty contributed a great deal of technical
  486. consulting. In particular, he is the primary author of @ref{Backups}.
  487. In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
  488. (see @url{http://savannah.gnu.org/projects/tar}), and
  489. active development and maintenance work has started
  490. again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
  491. Poznyakoff and Jeff Bailey.
  492. Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
  493. @node Reports
  494. @section Reporting bugs or suggestions
  495. @cindex bug reports
  496. @cindex reporting bugs
  497. If you find problems or have suggestions about this program or manual,
  498. please report them to @file{bug-tar@@gnu.org}.
  499. When reporting a bug, please be sure to include as much detail as
  500. possible, in order to reproduce it. @FIXME{Be more specific, I'd
  501. like to make this node as detailed as 'Bug reporting' node in Emacs
  502. manual}.
  503. @node Tutorial
  504. @chapter Tutorial Introduction to @command{tar}
  505. This chapter guides you through some basic examples of three @command{tar}
  506. operations: @option{--create}, @option{--list}, and @option{--extract}. If
  507. you already know how to use some other version of @command{tar}, then you
  508. may not need to read this chapter. This chapter omits most complicated
  509. details about how @command{tar} works.
  510. @menu
  511. * assumptions::
  512. * stylistic conventions::
  513. * basic tar options:: Basic @command{tar} Operations and Options
  514. * frequent operations::
  515. * Two Frequent Options::
  516. * create:: How to Create Archives
  517. * list:: How to List Archives
  518. * extract:: How to Extract Members from an Archive
  519. * going further::
  520. @end menu
  521. @node assumptions
  522. @section Assumptions this Tutorial Makes
  523. This chapter is paced to allow beginners to learn about @command{tar}
  524. slowly. At the same time, we will try to cover all the basic aspects of
  525. these three operations. In order to accomplish both of these tasks, we
  526. have made certain assumptions about your knowledge before reading this
  527. manual, and the hardware you will be using:
  528. @itemize @bullet
  529. @item
  530. Before you start to work through this tutorial, you should understand
  531. what the terms ``archive'' and ``archive member'' mean
  532. (@pxref{Definitions}). In addition, you should understand something
  533. about how Unix-type operating systems work, and you should know how to
  534. use some basic utilities. For example, you should know how to create,
  535. list, copy, rename, edit, and delete files and directories; how to
  536. change between directories; and how to figure out where you are in the
  537. file system. You should have some basic understanding of directory
  538. structure and how files are named according to which directory they are
  539. in. You should understand concepts such as standard output and standard
  540. input, what various definitions of the term ``argument'' mean, and the
  541. differences between relative and absolute file names. @FIXME{and what
  542. else?}
  543. @item
  544. This manual assumes that you are working from your own home directory
  545. (unless we state otherwise). In this tutorial, you will create a
  546. directory to practice @command{tar} commands in. When we show file names,
  547. we will assume that those names are relative to your home directory.
  548. For example, my home directory is @file{/home/fsf/melissa}. All of
  549. my examples are in a subdirectory of the directory named by that file
  550. name; the subdirectory is called @file{practice}.
  551. @item
  552. In general, we show examples of archives which exist on (or can be
  553. written to, or worked with from) a directory on a hard disk. In most
  554. cases, you could write those archives to, or work with them on any other
  555. device, such as a tape drive. However, some of the later examples in
  556. the tutorial and next chapter will not work on tape drives.
  557. Additionally, working with tapes is much more complicated than working
  558. with hard disks. For these reasons, the tutorial does not cover working
  559. with tape drives. @xref{Media}, for complete information on using
  560. @command{tar} archives with tape drives.
  561. @FIXME{this is a cop out. need to add some simple tape drive info.}
  562. @end itemize
  563. @node stylistic conventions
  564. @section Stylistic Conventions
  565. In the examples, @samp{$} represents a typical shell prompt. It
  566. precedes lines you should type; to make this more clear, those lines are
  567. shown in @kbd{this font}, as opposed to lines which represent the
  568. computer's response; those lines are shown in @code{this font}, or
  569. sometimes @samp{like this}.
  570. @c When we have lines which are too long to be
  571. @c displayed in any other way, we will show them like this:
  572. @node basic tar options
  573. @section Basic @command{tar} Operations and Options
  574. @command{tar} can take a wide variety of arguments which specify and define
  575. the actions it will have on the particular set of files or the archive.
  576. The main types of arguments to @command{tar} fall into one of two classes:
  577. operations, and options.
  578. Some arguments fall into a class called @dfn{operations}; exactly one of
  579. these is both allowed and required for any instance of using @command{tar};
  580. you may @emph{not} specify more than one. People sometimes speak of
  581. @dfn{operating modes}. You are in a particular operating mode when you
  582. have specified the operation which specifies it; there are eight
  583. operations in total, and thus there are eight operating modes.
  584. The other arguments fall into the class known as @dfn{options}. You are
  585. not required to specify any options, and you are allowed to specify more
  586. than one at a time (depending on the way you are using @command{tar} at
  587. that time). Some options are used so frequently, and are so useful for
  588. helping you type commands more carefully that they are effectively
  589. ``required''. We will discuss them in this chapter.
  590. You can write most of the @command{tar} operations and options in any
  591. of three forms: long (mnemonic) form, short form, and old style. Some
  592. of the operations and options have no short or ``old'' forms; however,
  593. the operations and options which we will cover in this tutorial have
  594. corresponding abbreviations. @FIXME{make sure this is still the case,
  595. at the end}We will indicate those abbreviations appropriately to get
  596. you used to seeing them. (Note that the ``old style'' option forms
  597. exist in @GNUTAR{} for compatibility with Unix
  598. @command{tar}. In this book we present a full discussion of this way
  599. of writing options and operations (@pxref{Old Options}), and we discuss
  600. the other two styles of writing options (@xref{Long Options}, and
  601. @pxref{Short Options}).
  602. In the examples and in the text of this tutorial, we usually use the
  603. long forms of operations and options; but the ``short'' forms produce
  604. the same result and can make typing long @command{tar} commands easier.
  605. For example, instead of typing
  606. @smallexample
  607. @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
  608. @end smallexample
  609. @noindent
  610. you can type
  611. @smallexample
  612. @kbd{tar -c -v -f afiles.tar apple angst aspic}
  613. @end smallexample
  614. @noindent
  615. or even
  616. @smallexample
  617. @kbd{tar -cvf afiles.tar apple angst aspic}
  618. @end smallexample
  619. @noindent
  620. For more information on option syntax, see @ref{Advanced tar}. In
  621. discussions in the text, when we name an option by its long form, we
  622. also give the corresponding short option in parentheses.
  623. The term, ``option'', can be confusing at times, since ``operations''
  624. are often lumped in with the actual, @emph{optional} ``options'' in certain
  625. general class statements. For example, we just talked about ``short and
  626. long forms of options and operations''. However, experienced @command{tar}
  627. users often refer to these by shorthand terms such as, ``short and long
  628. options''. This term assumes that the ``operations'' are included, also.
  629. Context will help you determine which definition of ``options'' to use.
  630. Similarly, the term ``command'' can be confusing, as it is often used in
  631. two different ways. People sometimes refer to @command{tar} ``commands''.
  632. A @command{tar} @dfn{command} is the entire command line of user input
  633. which tells @command{tar} what to do --- including the operation, options,
  634. and any arguments (file names, pipes, other commands, etc.). However,
  635. you will also sometimes hear the term ``the @command{tar} command''. When
  636. the word ``command'' is used specifically like this, a person is usually
  637. referring to the @command{tar} @emph{operation}, not the whole line.
  638. Again, use context to figure out which of the meanings the speaker
  639. intends.
  640. @node frequent operations
  641. @section The Three Most Frequently Used Operations
  642. Here are the three most frequently used operations (both short and long
  643. forms), as well as a brief description of their meanings. The rest of
  644. this chapter will cover how to use these operations in detail. We will
  645. present the rest of the operations in the next chapter.
  646. @table @option
  647. @item --create
  648. @itemx -c
  649. Create a new @command{tar} archive.
  650. @item --list
  651. @itemx -t
  652. List the contents of an archive.
  653. @item --extract
  654. @itemx -x
  655. Extract one or more members from an archive.
  656. @end table
  657. @node Two Frequent Options
  658. @section Two Frequently Used Options
  659. To understand how to run @command{tar} in the three operating modes listed
  660. previously, you also need to understand how to use two of the options to
  661. @command{tar}: @option{--file} (which takes an archive file as an argument)
  662. and @option{--verbose}. (You are usually not @emph{required} to specify
  663. either of these options when you run @command{tar}, but they can be very
  664. useful in making things more clear and helping you avoid errors.)
  665. @menu
  666. * file tutorial::
  667. * verbose tutorial::
  668. * help tutorial::
  669. @end menu
  670. @node file tutorial
  671. @unnumberedsubsec The @option{--file} Option
  672. @table @option
  673. @xopindex{file, tutorial}
  674. @item --file=@var{archive-name}
  675. @itemx -f @var{archive-name}
  676. Specify the name of an archive file.
  677. @end table
  678. You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
  679. use @command{tar}; this option determines the name of the archive file
  680. that @command{tar} will work on.
  681. @vrindex TAPE
  682. If you don't specify this argument, then @command{tar} will examine
  683. the environment variable @env{TAPE}. If it is set, its value will be
  684. used as the archive name. Otherwise, @command{tar} will use the
  685. default archive, determined at the compile time. Usually it is
  686. standard output or some physical tape drive attached to your machine
  687. (you can verify what the default is by running @kbd{tar
  688. --show-defaults}, @pxref{defaults}). If there is no tape drive
  689. attached, or the default is not meaningful, then @command{tar} will
  690. print an error message. The error message might look roughly like one
  691. of the following:
  692. @smallexample
  693. tar: can't open /dev/rmt8 : No such device or address
  694. tar: can't open /dev/rsmt0 : I/O error
  695. @end smallexample
  696. @noindent
  697. To avoid confusion, we recommend that you always specify an archive file
  698. name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
  699. For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
  700. @ref{file}.
  701. @node verbose tutorial
  702. @unnumberedsubsec The @option{--verbose} Option
  703. @table @option
  704. @xopindex{verbose, introduced}
  705. @item --verbose
  706. @itemx -v
  707. Show the files being worked on as @command{tar} is running.
  708. @end table
  709. @option{--verbose} (@option{-v}) shows details about the results of running
  710. @command{tar}. This can be especially useful when the results might not be
  711. obvious. For example, if you want to see the progress of @command{tar} as
  712. it writes files into the archive, you can use the @option{--verbose}
  713. option. In the beginning, you may find it useful to use
  714. @option{--verbose} at all times; when you are more accustomed to
  715. @command{tar}, you will likely want to use it at certain times but not at
  716. others. We will use @option{--verbose} at times to help make something
  717. clear, and we will give many examples both using and not using
  718. @option{--verbose} to show the differences.
  719. Each instance of @option{--verbose} on the command line increases the
  720. verbosity level by one, so if you need more details on the output,
  721. specify it twice.
  722. When reading archives (@option{--list}, @option{--extract},
  723. @option{--diff}), @command{tar} by default prints only the names of
  724. the members being extracted. Using @option{--verbose} will show a full,
  725. @command{ls} style member listing.
  726. In contrast, when writing archives (@option{--create}, @option{--append},
  727. @option{--update}), @command{tar} does not print file names by
  728. default. So, a single @option{--verbose} option shows the file names
  729. being added to the archive, while two @option{--verbose} options
  730. enable the full listing.
  731. For example, to create an archive in verbose mode:
  732. @smallexample
  733. $ @kbd{tar -cvf afiles.tar apple angst aspic}
  734. apple
  735. angst
  736. aspic
  737. @end smallexample
  738. @noindent
  739. Creating the same archive with the verbosity level 2 could give:
  740. @smallexample
  741. $ @kbd{tar -cvvf afiles.tar apple angst aspic}
  742. -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
  743. -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
  744. -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
  745. @end smallexample
  746. @noindent
  747. This works equally well using short or long forms of options. Using
  748. long forms, you would simply write out the mnemonic form of the option
  749. twice, like this:
  750. @smallexample
  751. $ @kbd{tar --create --verbose --verbose @dots{}}
  752. @end smallexample
  753. @noindent
  754. Note that you must double the hyphens properly each time.
  755. Later in the tutorial, we will give examples using @w{@option{--verbose
  756. --verbose}}.
  757. @anchor{verbose member listing}
  758. The full output consists of six fields:
  759. @itemize @bullet
  760. @item File type and permissions in symbolic form.
  761. These are displayed in the same format as the first column of
  762. @command{ls -l} output (@pxref{What information is listed,
  763. format=verbose, Verbose listing, fileutils, GNU file utilities}).
  764. @item Owner name and group separated by a slash character.
  765. If these data are not available (for example, when listing a @samp{v7} format
  766. archive), numeric @acronym{ID} values are printed instead.
  767. @item Size of the file, in bytes.
  768. @item File modification date in ISO 8601 format.
  769. @item File modification time.
  770. @item File name.
  771. If the name contains any special characters (white space, newlines,
  772. etc.) these are displayed in an unambiguous form using so called
  773. @dfn{quoting style}. For the detailed discussion of available styles
  774. and on how to use them, see @ref{quoting styles}.
  775. Depending on the file type, the name can be followed by some
  776. additional information, described in the following table:
  777. @table @samp
  778. @item -> @var{link-name}
  779. The file or archive member is a @dfn{symbolic link} and
  780. @var{link-name} is the name of file it links to.
  781. @item link to @var{link-name}
  782. The file or archive member is a @dfn{hard link} and @var{link-name} is
  783. the name of file it links to.
  784. @item --Long Link--
  785. The archive member is an old GNU format long link. You will normally
  786. not encounter this.
  787. @item --Long Name--
  788. The archive member is an old GNU format long name. You will normally
  789. not encounter this.
  790. @item --Volume Header--
  791. The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
  792. @item --Continued at byte @var{n}--
  793. Encountered only at the beginning of a multi-volume archive
  794. (@pxref{Using Multiple Tapes}). This archive member is a continuation
  795. from the previous volume. The number @var{n} gives the offset where
  796. the original file was split.
  797. @item unknown file type @var{c}
  798. An archive member of unknown type. @var{c} is the type character from
  799. the archive header. If you encounter such a message, it means that
  800. either your archive contains proprietary member types @GNUTAR{} is not
  801. able to handle, or the archive is corrupted.
  802. @end table
  803. @end itemize
  804. For example, here is an archive listing containing most of the special
  805. suffixes explained above:
  806. @smallexample
  807. @group
  808. V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
  809. -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
  810. byte 32456--
  811. -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
  812. lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
  813. -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
  814. hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
  815. @end group
  816. @end smallexample
  817. @smallexample
  818. @end smallexample
  819. @node help tutorial
  820. @unnumberedsubsec Getting Help: Using the @option{--help} Option
  821. @table @option
  822. @opindex help
  823. @item --help
  824. The @option{--help} option to @command{tar} prints out a very brief list of
  825. all operations and option available for the current version of
  826. @command{tar} available on your system.
  827. @end table
  828. @node create
  829. @section How to Create Archives
  830. @UNREVISED
  831. @cindex Creation of the archive
  832. @cindex Archive, creation of
  833. One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
  834. you use to create a @command{tar} archive. We will explain
  835. @option{--create} first because, in order to learn about the other
  836. operations, you will find it useful to have an archive available to
  837. practice on.
  838. To make this easier, in this section you will first create a directory
  839. containing three files. Then, we will show you how to create an
  840. @emph{archive} (inside the new directory). Both the directory, and
  841. the archive are specifically for you to practice on. The rest of this
  842. chapter and the next chapter will show many examples using this
  843. directory and the files you will create: some of those files may be
  844. other directories and other archives.
  845. The three files you will archive in this example are called
  846. @file{blues}, @file{folk}, and @file{jazz}. The archive is called
  847. @file{collection.tar}.
  848. This section will proceed slowly, detailing how to use @option{--create}
  849. in @code{verbose} mode, and showing examples using both short and long
  850. forms. In the rest of the tutorial, and in the examples in the next
  851. chapter, we will proceed at a slightly quicker pace. This section
  852. moves more slowly to allow beginning users to understand how
  853. @command{tar} works.
  854. @menu
  855. * prepare for examples::
  856. * Creating the archive::
  857. * create verbose::
  858. * short create::
  859. * create dir::
  860. @end menu
  861. @node prepare for examples
  862. @subsection Preparing a Practice Directory for Examples
  863. To follow along with this and future examples, create a new directory
  864. called @file{practice} containing files called @file{blues}, @file{folk}
  865. and @file{jazz}. The files can contain any information you like:
  866. ideally, they should contain information which relates to their names,
  867. and be of different lengths. Our examples assume that @file{practice}
  868. is a subdirectory of your home directory.
  869. Now @command{cd} to the directory named @file{practice}; @file{practice}
  870. is now your @dfn{working directory}. (@emph{Please note}: Although
  871. the full file name of this directory is
  872. @file{/@var{homedir}/practice}, in our examples we will refer to
  873. this directory as @file{practice}; the @var{homedir} is presumed.
  874. In general, you should check that the files to be archived exist where
  875. you think they do (in the working directory) by running @command{ls}.
  876. Because you just created the directory and the files and have changed to
  877. that directory, you probably don't need to do that this time.
  878. It is very important to make sure there isn't already a file in the
  879. working directory with the archive name you intend to use (in this case,
  880. @samp{collection.tar}), or that you don't care about its contents.
  881. Whenever you use @samp{create}, @command{tar} will erase the current
  882. contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
  883. will not tell you if you are about to overwrite an archive unless you
  884. specify an option which does this (@pxref{backup}, for the
  885. information on how to do so). To add files to an existing archive,
  886. you need to use a different option, such as @option{--append} (@option{-r}); see
  887. @ref{append} for information on how to do this.
  888. @node Creating the archive
  889. @subsection Creating the Archive
  890. @xopindex{create, introduced}
  891. To place the files @file{blues}, @file{folk}, and @file{jazz} into an
  892. archive named @file{collection.tar}, use the following command:
  893. @smallexample
  894. $ @kbd{tar --create --file=collection.tar blues folk jazz}
  895. @end smallexample
  896. The order of the arguments is not very important, @emph{when using long
  897. option forms}. You could also say:
  898. @smallexample
  899. $ @kbd{tar blues --create folk --file=collection.tar jazz}
  900. @end smallexample
  901. @noindent
  902. However, you can see that this order is harder to understand; this is
  903. why we will list the arguments in the order that makes the commands
  904. easiest to understand (and we encourage you to do the same when you use
  905. @command{tar}, to avoid errors).
  906. Note that the sequence
  907. @option{--file=@-collection.tar} is considered to be @emph{one} argument.
  908. If you substituted any other string of characters for
  909. @kbd{collection.tar}, then that string would become the name of the
  910. archive file you create.
  911. The order of the options becomes more important when you begin to use
  912. short forms. With short forms, if you type commands in the wrong order
  913. (even if you type them correctly in all other ways), you may end up with
  914. results you don't expect. For this reason, it is a good idea to get
  915. into the habit of typing options in the order that makes inherent sense.
  916. @xref{short create}, for more information on this.
  917. In this example, you type the command as shown above: @option{--create}
  918. is the operation which creates the new archive
  919. (@file{collection.tar}), and @option{--file} is the option which lets
  920. you give it the name you chose. The files, @file{blues}, @file{folk},
  921. and @file{jazz}, are now members of the archive, @file{collection.tar}
  922. (they are @dfn{file name arguments} to the @option{--create} operation.
  923. @xref{Choosing}, for the detailed discussion on these.) Now that they are
  924. in the archive, they are called @emph{archive members}, not files.
  925. (@pxref{Definitions,members}).
  926. When you create an archive, you @emph{must} specify which files you
  927. want placed in the archive. If you do not specify any archive
  928. members, @GNUTAR{} will complain.
  929. If you now list the contents of the working directory (@command{ls}), you will
  930. find the archive file listed as well as the files you saw previously:
  931. @smallexample
  932. blues folk jazz collection.tar
  933. @end smallexample
  934. @noindent
  935. Creating the archive @samp{collection.tar} did not destroy the copies of
  936. the files in the directory.
  937. Keep in mind that if you don't indicate an operation, @command{tar} will not
  938. run and will prompt you for one. If you don't name any files, @command{tar}
  939. will complain. You must have write access to the working directory,
  940. or else you will not be able to create an archive in that directory.
  941. @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
  942. an existing archive; it will delete the archive and write a new one.
  943. Use @option{--append} (@option{-r}) instead. @xref{append}.
  944. @node create verbose
  945. @subsection Running @option{--create} with @option{--verbose}
  946. @xopindex{create, using with @option{--verbose}}
  947. @xopindex{verbose, using with @option{--create}}
  948. If you include the @option{--verbose} (@option{-v}) option on the command line,
  949. @command{tar} will list the files it is acting on as it is working. In
  950. verbose mode, the @code{create} example above would appear as:
  951. @smallexample
  952. $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
  953. blues
  954. folk
  955. jazz
  956. @end smallexample
  957. This example is just like the example we showed which did not use
  958. @option{--verbose}, except that @command{tar} generated the remaining lines
  959. @iftex
  960. (note the different font styles).
  961. @end iftex
  962. @ifinfo
  963. .
  964. @end ifinfo
  965. In the rest of the examples in this chapter, we will frequently use
  966. @code{verbose} mode so we can show actions or @command{tar} responses that
  967. you would otherwise not see, and which are important for you to
  968. understand.
  969. @node short create
  970. @subsection Short Forms with @samp{create}
  971. As we said before, the @option{--create} (@option{-c}) operation is one of the most
  972. basic uses of @command{tar}, and you will use it countless times.
  973. Eventually, you will probably want to use abbreviated (or ``short'')
  974. forms of options. A full discussion of the three different forms that
  975. options can take appears in @ref{Styles}; for now, here is what the
  976. previous example (including the @option{--verbose} (@option{-v}) option) looks like
  977. using short option forms:
  978. @smallexample
  979. $ @kbd{tar -cvf collection.tar blues folk jazz}
  980. blues
  981. folk
  982. jazz
  983. @end smallexample
  984. @noindent
  985. As you can see, the system responds the same no matter whether you use
  986. long or short option forms.
  987. @FIXME{i don't like how this is worded:} One difference between using
  988. short and long option forms is that, although the exact placement of
  989. arguments following options is no more specific when using short forms,
  990. it is easier to become confused and make a mistake when using short
  991. forms. For example, suppose you attempted the above example in the
  992. following way:
  993. @smallexample
  994. $ @kbd{tar -cfv collection.tar blues folk jazz}
  995. @end smallexample
  996. @noindent
  997. In this case, @command{tar} will make an archive file called @file{v},
  998. containing the files @file{blues}, @file{folk}, and @file{jazz}, because
  999. the @samp{v} is the closest ``file name'' to the @option{-f} option, and
  1000. is thus taken to be the chosen archive file name. @command{tar} will try
  1001. to add a file called @file{collection.tar} to the @file{v} archive file;
  1002. if the file @file{collection.tar} did not already exist, @command{tar} will
  1003. report an error indicating that this file does not exist. If the file
  1004. @file{collection.tar} does already exist (e.g., from a previous command
  1005. you may have run), then @command{tar} will add this file to the archive.
  1006. Because the @option{-v} option did not get registered, @command{tar} will not
  1007. run under @samp{verbose} mode, and will not report its progress.
  1008. The end result is that you may be quite confused about what happened,
  1009. and possibly overwrite a file. To illustrate this further, we will show
  1010. you how an example we showed previously would look using short forms.
  1011. This example,
  1012. @smallexample
  1013. $ @kbd{tar blues --create folk --file=collection.tar jazz}
  1014. @end smallexample
  1015. @noindent
  1016. is confusing as it is. When shown using short forms, however, it
  1017. becomes much more so:
  1018. @smallexample
  1019. $ @kbd{tar blues -c folk -f collection.tar jazz}
  1020. @end smallexample
  1021. @noindent
  1022. It would be very easy to put the wrong string of characters
  1023. immediately following the @option{-f}, but doing that could sacrifice
  1024. valuable data.
  1025. For this reason, we recommend that you pay very careful attention to
  1026. the order of options and placement of file and archive names,
  1027. especially when using short option forms. Not having the option name
  1028. written out mnemonically can affect how well you remember which option
  1029. does what, and therefore where different names have to be placed.
  1030. @node create dir
  1031. @subsection Archiving Directories
  1032. @cindex Archiving Directories
  1033. @cindex Directories, Archiving
  1034. You can archive a directory by specifying its directory name as a
  1035. file name argument to @command{tar}. The files in the directory will be
  1036. archived relative to the working directory, and the directory will be
  1037. re-created along with its contents when the archive is extracted.
  1038. To archive a directory, first move to its superior directory. If you
  1039. have followed the previous instructions in this tutorial, you should
  1040. type:
  1041. @smallexample
  1042. $ @kbd{cd ..}
  1043. $
  1044. @end smallexample
  1045. @noindent
  1046. This will put you into the directory which contains @file{practice},
  1047. i.e., your home directory. Once in the superior directory, you can
  1048. specify the subdirectory, @file{practice}, as a file name argument. To
  1049. store @file{practice} in the new archive file @file{music.tar}, type:
  1050. @smallexample
  1051. $ @kbd{tar --create --verbose --file=music.tar practice}
  1052. @end smallexample
  1053. @noindent
  1054. @command{tar} should output:
  1055. @smallexample
  1056. practice/
  1057. practice/blues
  1058. practice/folk
  1059. practice/jazz
  1060. practice/collection.tar
  1061. @end smallexample
  1062. Note that the archive thus created is not in the subdirectory
  1063. @file{practice}, but rather in the current working directory---the
  1064. directory from which @command{tar} was invoked. Before trying to archive a
  1065. directory from its superior directory, you should make sure you have
  1066. write access to the superior directory itself, not only the directory
  1067. you are trying archive with @command{tar}. For example, you will probably
  1068. not be able to store your home directory in an archive by invoking
  1069. @command{tar} from the root directory; @xref{absolute}. (Note
  1070. also that @file{collection.tar}, the original archive file, has itself
  1071. been archived. @command{tar} will accept any file as a file to be
  1072. archived, regardless of its content. When @file{music.tar} is
  1073. extracted, the archive file @file{collection.tar} will be re-written
  1074. into the file system).
  1075. If you give @command{tar} a command such as
  1076. @smallexample
  1077. $ @kbd{tar --create --file=foo.tar .}
  1078. @end smallexample
  1079. @noindent
  1080. @command{tar} will report @samp{tar: ./foo.tar is the archive; not
  1081. dumped}. This happens because @command{tar} creates the archive
  1082. @file{foo.tar} in the current directory before putting any files into
  1083. it. Then, when @command{tar} attempts to add all the files in the
  1084. directory @file{.} to the archive, it notices that the file
  1085. @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
  1086. it. (It makes no sense to put an archive into itself.) @GNUTAR{}
  1087. will continue in this case, and create the archive
  1088. normally, except for the exclusion of that one file. (@emph{Please
  1089. note:} Other implementations of @command{tar} may not be so clever;
  1090. they will enter an infinite loop when this happens, so you should not
  1091. depend on this behavior unless you are certain you are running
  1092. @GNUTAR{}. In general, it is wise to always place the archive outside
  1093. of the directory being dumped.
  1094. @node list
  1095. @section How to List Archives
  1096. @opindex list
  1097. Frequently, you will find yourself wanting to determine exactly what a
  1098. particular archive contains. You can use the @option{--list}
  1099. (@option{-t}) operation to get the member names as they currently
  1100. appear in the archive, as well as various attributes of the files at
  1101. the time they were archived. For example, you can examine the archive
  1102. @file{collection.tar} that you created in the last section with the
  1103. command,
  1104. @smallexample
  1105. $ @kbd{tar --list --file=collection.tar}
  1106. @end smallexample
  1107. @noindent
  1108. The output of @command{tar} would then be:
  1109. @smallexample
  1110. blues
  1111. folk
  1112. jazz
  1113. @end smallexample
  1114. @noindent
  1115. The archive @file{bfiles.tar} would list as follows:
  1116. @smallexample
  1117. ./birds
  1118. baboon
  1119. ./box
  1120. @end smallexample
  1121. @noindent
  1122. Be sure to use a @option{--file=@var{archive-name}} (@option{-f
  1123. @var{archive-name}}) option just as with @option{--create}
  1124. (@option{-c}) to specify the name of the archive.
  1125. @xopindex{list, using with @option{--verbose}}
  1126. @xopindex{verbose, using with @option{--list}}
  1127. If you use the @option{--verbose} (@option{-v}) option with
  1128. @option{--list}, then @command{tar} will print out a listing
  1129. reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
  1130. forth. This output is described in detail in @ref{verbose member listing}.
  1131. If you had used @option{--verbose} (@option{-v}) mode, the example
  1132. above would look like:
  1133. @smallexample
  1134. $ @kbd{tar --list --verbose --file=collection.tar folk}
  1135. -rw-r--r-- myself user 62 1990-05-23 10:55 folk
  1136. @end smallexample
  1137. @cindex listing member and file names
  1138. @anchor{listing member and file names}
  1139. It is important to notice that the output of @kbd{tar --list
  1140. --verbose} does not necessarily match that produced by @kbd{tar
  1141. --create --verbose} while creating the archive. It is because
  1142. @GNUTAR{}, unless told explicitly not to do so, removes some directory
  1143. prefixes from file names before storing them in the archive
  1144. (@xref{absolute}, for more information). In other
  1145. words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
  1146. an archive and @dfn{member names} when listing it. Consider this
  1147. example:
  1148. @smallexample
  1149. @group
  1150. $ @kbd{tar cfv archive /etc/mail}
  1151. tar: Removing leading `/' from member names
  1152. /etc/mail/
  1153. /etc/mail/sendmail.cf
  1154. /etc/mail/aliases
  1155. $ @kbd{tar tf archive}
  1156. etc/mail/
  1157. etc/mail/sendmail.cf
  1158. etc/mail/aliases
  1159. @end group
  1160. @end smallexample
  1161. @opindex show-stored-names
  1162. This default behavior can sometimes be inconvenient. You can force
  1163. @GNUTAR{} show member names when creating archive by supplying
  1164. @option{--show-stored-names} option.
  1165. @table @option
  1166. @item --show-stored-names
  1167. Print member (as opposed to @emph{file}) names when creating the archive.
  1168. @end table
  1169. @cindex File name arguments, using @option{--list} with
  1170. @xopindex{list, using with file name arguments}
  1171. You can specify one or more individual member names as arguments when
  1172. using @samp{list}. In this case, @command{tar} will only list the
  1173. names of members you identify. For example, @w{@kbd{tar --list
  1174. --file=afiles.tar apple}} would only print @file{apple}.
  1175. Because @command{tar} preserves file names, these must be specified as
  1176. they appear in the archive (i.e., relative to the directory from which
  1177. the archive was created). Therefore, it is essential when specifying
  1178. member names to @command{tar} that you give the exact member names.
  1179. For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
  1180. error message something like @samp{tar: birds: Not found in archive},
  1181. because there is no member named @file{birds}, only one named
  1182. @file{./birds}. While the names @file{birds} and @file{./birds} name
  1183. the same file, @emph{member} names by default are compared verbatim.
  1184. However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
  1185. with @file{baboon}, because this exact member name is in the archive file
  1186. @file{bfiles.tar}. If you are not sure of the exact file name,
  1187. use @dfn{globbing patterns}, for example:
  1188. @smallexample
  1189. $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
  1190. @end smallexample
  1191. @noindent
  1192. will list all members whose name contains @samp{b}. @xref{wildcards},
  1193. for a detailed discussion of globbing patterns and related
  1194. @command{tar} command line options.
  1195. @menu
  1196. * list dir::
  1197. @end menu
  1198. @node list dir
  1199. @unnumberedsubsec Listing the Contents of a Stored Directory
  1200. To get information about the contents of an archived directory,
  1201. use the directory name as a file name argument in conjunction with
  1202. @option{--list} (@option{-t}). To find out file attributes, include the
  1203. @option{--verbose} (@option{-v}) option.
  1204. For example, to find out about files in the directory @file{practice}, in
  1205. the archive file @file{music.tar}, type:
  1206. @smallexample
  1207. $ @kbd{tar --list --verbose --file=music.tar practice}
  1208. @end smallexample
  1209. @command{tar} responds:
  1210. @smallexample
  1211. drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
  1212. -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
  1213. -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
  1214. -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
  1215. -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
  1216. @end smallexample
  1217. When you use a directory name as a file name argument, @command{tar} acts on
  1218. all the files (including sub-directories) in that directory.
  1219. @node extract
  1220. @section How to Extract Members from an Archive
  1221. @UNREVISED
  1222. @cindex Extraction
  1223. @cindex Retrieving files from an archive
  1224. @cindex Resurrecting files from an archive
  1225. @opindex extract
  1226. Creating an archive is only half the job---there is no point in storing
  1227. files in an archive if you can't retrieve them. The act of retrieving
  1228. members from an archive so they can be used and manipulated as
  1229. unarchived files again is called @dfn{extraction}. To extract files
  1230. from an archive, use the @option{--extract} (@option{--get} or
  1231. @option{-x}) operation. As with @option{--create}, specify the name
  1232. of the archive with @option{--file} (@option{-f}) option. Extracting
  1233. an archive does not modify the archive in any way; you can extract it
  1234. multiple times if you want or need to.
  1235. Using @option{--extract}, you can extract an entire archive, or specific
  1236. files. The files can be directories containing other files, or not. As
  1237. with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
  1238. long form of the operation without affecting the performance.
  1239. @menu
  1240. * extracting archives::
  1241. * extracting files::
  1242. * extract dir::
  1243. * extracting untrusted archives::
  1244. * failing commands::
  1245. @end menu
  1246. @node extracting archives
  1247. @subsection Extracting an Entire Archive
  1248. To extract an entire archive, specify the archive file name only, with
  1249. no individual file names as arguments. For example,
  1250. @smallexample
  1251. $ @kbd{tar -xvf collection.tar}
  1252. @end smallexample
  1253. @noindent
  1254. produces this:
  1255. @smallexample
  1256. -rw-r--r-- me user 28 1996-10-18 16:31 jazz
  1257. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  1258. -rw-r--r-- me user 20 1996-09-23 16:44 folk
  1259. @end smallexample
  1260. @node extracting files
  1261. @subsection Extracting Specific Files
  1262. To extract specific archive members, give their exact member names as
  1263. arguments, as printed by @option{--list} (@option{-t}). If you had
  1264. mistakenly deleted one of the files you had placed in the archive
  1265. @file{collection.tar} earlier (say, @file{blues}), you can extract it
  1266. from the archive without changing the archive's structure. Its
  1267. contents will be identical to the original file @file{blues} that you
  1268. deleted.
  1269. First, make sure you are in the @file{practice} directory, and list the
  1270. files in the directory. Now, delete the file, @samp{blues}, and list
  1271. the files in the directory again.
  1272. You can now extract the member @file{blues} from the archive file
  1273. @file{collection.tar} like this:
  1274. @smallexample
  1275. $ @kbd{tar --extract --file=collection.tar blues}
  1276. @end smallexample
  1277. @noindent
  1278. If you list the files in the directory again, you will see that the file
  1279. @file{blues} has been restored, with its original permissions, data
  1280. modification times, and owner.@footnote{This is only accidentally
  1281. true, but not in general. Whereas modification times are always
  1282. restored, in most cases, one has to be root for restoring the owner,
  1283. and use a special option for restoring permissions. Here, it just
  1284. happens that the restoring user is also the owner of the archived
  1285. members, and that the current @code{umask} is compatible with original
  1286. permissions.} (These parameters will be identical to those which
  1287. the file had when you originally placed it in the archive; any changes
  1288. you may have made before deleting the file from the file system,
  1289. however, will @emph{not} have been made to the archive member.) The
  1290. archive file, @samp{collection.tar}, is the same as it was before you
  1291. extracted @samp{blues}. You can confirm this by running @command{tar} with
  1292. @option{--list} (@option{-t}).
  1293. Remember that as with other operations, specifying the exact member
  1294. name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
  1295. will fail, because there is no member named @file{birds}. To extract
  1296. the member named @file{./birds}, you must specify @w{@kbd{tar
  1297. --extract --file=bfiles.tar ./birds}}. If you don't remember the
  1298. exact member names, use @option{--list} (@option{-t}) option
  1299. (@pxref{list}). You can also extract those members that match a
  1300. specific @dfn{globbing pattern}. For example, to extract from
  1301. @file{bfiles.tar} all files that begin with @samp{b}, no matter their
  1302. directory prefix, you could type:
  1303. @smallexample
  1304. $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
  1305. @end smallexample
  1306. @noindent
  1307. Here, @option{--wildcards} instructs @command{tar} to treat
  1308. command line arguments as globbing patterns and @option{--no-anchored}
  1309. informs it that the patterns apply to member names after any @samp{/}
  1310. delimiter. The use of globbing patterns is discussed in detail in
  1311. @xref{wildcards}.
  1312. You can extract a file to standard output by combining the above options
  1313. with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
  1314. Output}).
  1315. If you give the @option{--verbose} option, then @option{--extract}
  1316. will print the names of the archive members as it extracts them.
  1317. @node extract dir
  1318. @subsection Extracting Files that are Directories
  1319. Extracting directories which are members of an archive is similar to
  1320. extracting other files. The main difference to be aware of is that if
  1321. the extracted directory has the same name as any directory already in
  1322. the working directory, then files in the extracted directory will be
  1323. placed into the directory of the same name. Likewise, if there are
  1324. files in the pre-existing directory with the same names as the members
  1325. which you extract, the files from the extracted archive will replace
  1326. the files already in the working directory (and possible
  1327. subdirectories). This will happen regardless of whether or not the
  1328. files in the working directory were more recent than those extracted
  1329. (there exist, however, special options that alter this behavior
  1330. @pxref{Writing}).
  1331. However, if a file was stored with a directory name as part of its file
  1332. name, and that directory does not exist under the working directory when
  1333. the file is extracted, @command{tar} will create the directory.
  1334. We can demonstrate how to use @option{--extract} to extract a directory
  1335. file with an example. Change to the @file{practice} directory if you
  1336. weren't there, and remove the files @file{folk} and @file{jazz}. Then,
  1337. go back to the parent directory and extract the archive
  1338. @file{music.tar}. You may either extract the entire archive, or you may
  1339. extract only the files you just deleted. To extract the entire archive,
  1340. don't give any file names as arguments after the archive name
  1341. @file{music.tar}. To extract only the files you deleted, use the
  1342. following command:
  1343. @smallexample
  1344. $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
  1345. practice/folk
  1346. practice/jazz
  1347. @end smallexample
  1348. @noindent
  1349. If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
  1350. would have displayed more detail about the extracted files, as shown
  1351. in the example below:
  1352. @smallexample
  1353. $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
  1354. -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
  1355. -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
  1356. @end smallexample
  1357. @noindent
  1358. Because you created the directory with @file{practice} as part of the
  1359. file names of each of the files by archiving the @file{practice}
  1360. directory as @file{practice}, you must give @file{practice} as part
  1361. of the file names when you extract those files from the archive.
  1362. @node extracting untrusted archives
  1363. @subsection Extracting Archives from Untrusted Sources
  1364. Extracting files from archives can overwrite files that already exist.
  1365. If you receive an archive from an untrusted source, you should make a
  1366. new directory and extract into that directory, so that you don't have
  1367. to worry about the extraction overwriting one of your existing files.
  1368. For example, if @file{untrusted.tar} came from somewhere else on the
  1369. Internet, and you don't necessarily trust its contents, you can
  1370. extract it as follows:
  1371. @smallexample
  1372. $ @kbd{mkdir newdir}
  1373. $ @kbd{cd newdir}
  1374. $ @kbd{tar -xvf ../untrusted.tar}
  1375. @end smallexample
  1376. It is also a good practice to examine contents of the archive
  1377. before extracting it, using @option{--list} (@option{-t}) option, possibly combined
  1378. with @option{--verbose} (@option{-v}).
  1379. @node failing commands
  1380. @subsection Commands That Will Fail
  1381. Here are some sample commands you might try which will not work, and why
  1382. they won't work.
  1383. If you try to use this command,
  1384. @smallexample
  1385. $ @kbd{tar -xvf music.tar folk jazz}
  1386. @end smallexample
  1387. @noindent
  1388. you will get the following response:
  1389. @smallexample
  1390. tar: folk: Not found in archive
  1391. tar: jazz: Not found in archive
  1392. $
  1393. @end smallexample
  1394. @noindent
  1395. This is because these files were not originally @emph{in} the parent
  1396. directory @file{..}, where the archive is located; they were in the
  1397. @file{practice} directory, and their file names reflect this:
  1398. @smallexample
  1399. $ @kbd{tar -tvf music.tar}
  1400. practice/folk
  1401. practice/jazz
  1402. practice/rock
  1403. @end smallexample
  1404. @FIXME{make sure the above works when going through the examples in
  1405. order...}
  1406. @noindent
  1407. Likewise, if you try to use this command,
  1408. @smallexample
  1409. $ @kbd{tar -tvf music.tar folk jazz}
  1410. @end smallexample
  1411. @noindent
  1412. you would get a similar response. Members with those names are not in the
  1413. archive. You must use the correct member names, or wildcards, in order
  1414. to extract the files from the archive.
  1415. If you have forgotten the correct names of the files in the archive,
  1416. use @w{@kbd{tar --list --verbose}} to list them correctly.
  1417. @FIXME{more examples, here? hag thinks it's a good idea.}
  1418. @node going further
  1419. @section Going Further Ahead in this Manual
  1420. @FIXME{need to write up a node here about the things that are going to
  1421. be in the rest of the manual.}
  1422. @node tar invocation
  1423. @chapter Invoking @GNUTAR{}
  1424. @UNREVISED
  1425. This chapter is about how one invokes the @GNUTAR{}
  1426. command, from the command synopsis (@pxref{Synopsis}). There are
  1427. numerous options, and many styles for writing them. One mandatory
  1428. option specifies the operation @command{tar} should perform
  1429. (@pxref{Operation Summary}), other options are meant to detail how
  1430. this operation should be performed (@pxref{Option Summary}).
  1431. Non-option arguments are not always interpreted the same way,
  1432. depending on what the operation is.
  1433. You will find in this chapter everything about option styles and rules for
  1434. writing them (@pxref{Styles}). On the other hand, operations and options
  1435. are fully described elsewhere, in other chapters. Here, you will find
  1436. only synthetic descriptions for operations and options, together with
  1437. pointers to other parts of the @command{tar} manual.
  1438. Some options are so special they are fully described right in this
  1439. chapter. They have the effect of inhibiting the normal operation of
  1440. @command{tar} or else, they globally alter the amount of feedback the user
  1441. receives about what is going on. These are the @option{--help} and
  1442. @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
  1443. and @option{--interactive} options (@pxref{interactive}).
  1444. @menu
  1445. * Synopsis::
  1446. * using tar options::
  1447. * Styles::
  1448. * All Options::
  1449. * help::
  1450. * defaults::
  1451. * verbose::
  1452. * checkpoints::
  1453. * interactive::
  1454. @end menu
  1455. @node Synopsis
  1456. @section General Synopsis of @command{tar}
  1457. The @GNUTAR{} program is invoked as either one of:
  1458. @smallexample
  1459. @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
  1460. @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
  1461. @end smallexample
  1462. The second form is for when old options are being used.
  1463. You can use @command{tar} to store files in an archive, to extract them from
  1464. an archive, and to do other types of archive manipulation. The primary
  1465. argument to @command{tar}, which is called the @dfn{operation}, specifies
  1466. which action to take. The other arguments to @command{tar} are either
  1467. @dfn{options}, which change the way @command{tar} performs an operation,
  1468. or file names or archive members, which specify the files or members
  1469. @command{tar} is to act on.
  1470. You can actually type in arguments in any order, even if in this manual
  1471. the options always precede the other arguments, to make examples easier
  1472. to understand. Further, the option stating the main operation mode
  1473. (the @command{tar} main command) is usually given first.
  1474. Each @var{name} in the synopsis above is interpreted as an archive member
  1475. name when the main command is one of @option{--compare}
  1476. (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
  1477. (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
  1478. @option{--update} (@option{-u}). When naming archive members, you
  1479. must give the exact name of the member in the archive, as it is
  1480. printed by @option{--list}. For @option{--append} (@option{-r}) and
  1481. @option{--create} (@option{-c}), these @var{name} arguments specify
  1482. the names of either files or directory hierarchies to place in the archive.
  1483. These files or hierarchies should already exist in the file system,
  1484. prior to the execution of the @command{tar} command.
  1485. @command{tar} interprets relative file names as being relative to the
  1486. working directory. @command{tar} will make all file names relative
  1487. (by removing leading slashes when archiving or restoring files),
  1488. unless you specify otherwise (using the @option{--absolute-names}
  1489. option). @xref{absolute}, for more information about
  1490. @option{--absolute-names}.
  1491. If you give the name of a directory as either a file name or a member
  1492. name, then @command{tar} acts recursively on all the files and directories
  1493. beneath that directory. For example, the name @file{/} identifies all
  1494. the files in the file system to @command{tar}.
  1495. The distinction between file names and archive member names is especially
  1496. important when shell globbing is used, and sometimes a source of confusion
  1497. for newcomers. @xref{wildcards}, for more information about globbing.
  1498. The problem is that shells may only glob using existing files in the
  1499. file system. Only @command{tar} itself may glob on archive members, so when
  1500. needed, you must ensure that wildcard characters reach @command{tar} without
  1501. being interpreted by the shell first. Using a backslash before @samp{*}
  1502. or @samp{?}, or putting the whole argument between quotes, is usually
  1503. sufficient for this.
  1504. Even if @var{name}s are often specified on the command line, they
  1505. can also be read from a text file in the file system, using the
  1506. @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
  1507. If you don't use any file name arguments, @option{--append} (@option{-r}),
  1508. @option{--delete} and @option{--concatenate} (@option{--catenate},
  1509. @option{-A}) will do nothing, while @option{--create} (@option{-c})
  1510. will usually yield a diagnostic and inhibit @command{tar} execution.
  1511. The other operations of @command{tar} (@option{--list},
  1512. @option{--extract}, @option{--compare}, and @option{--update})
  1513. will act on the entire contents of the archive.
  1514. @cindex exit status
  1515. @cindex return status
  1516. Besides successful exits, @GNUTAR{} may fail for
  1517. many reasons. Some reasons correspond to bad usage, that is, when the
  1518. @command{tar} command is improperly written. Errors may be
  1519. encountered later, while encountering an error processing the archive
  1520. or the files. Some errors are recoverable, in which case the failure
  1521. is delayed until @command{tar} has completed all its work. Some
  1522. errors are such that it would not meaningful, or at least risky, to
  1523. continue processing: @command{tar} then aborts processing immediately.
  1524. All abnormal exits, whether immediate or delayed, should always be
  1525. clearly diagnosed on @code{stderr}, after a line stating the nature of
  1526. the error.
  1527. Possible exit codes of @GNUTAR{} are summarized in the following
  1528. table:
  1529. @table @asis
  1530. @item 0
  1531. @samp{Successful termination}.
  1532. @item 1
  1533. @samp{Some files differ}. If tar was invoked with @option{--compare}
  1534. (@option{--diff}, @option{-d}) command line option, this means that
  1535. some files in the archive differ from their disk counterparts
  1536. (@pxref{compare}). If tar was given @option{--create},
  1537. @option{--append} or @option{--update} option, this exit code means
  1538. that some files were changed while being archived and so the resulting
  1539. archive does not contain the exact copy of the file set.
  1540. @item 2
  1541. @samp{Fatal error}. This means that some fatal, unrecoverable error
  1542. occurred.
  1543. @end table
  1544. If @command{tar} has invoked a subprocess and that subprocess exited with a
  1545. nonzero exit code, @command{tar} exits with that code as well.
  1546. This can happen, for example, if @command{tar} was given some
  1547. compression option (@pxref{gzip}) and the external compressor program
  1548. failed. Another example is @command{rmt} failure during backup to the
  1549. remote device (@pxref{Remote Tape Server}).
  1550. @node using tar options
  1551. @section Using @command{tar} Options
  1552. @GNUTAR{} has a total of eight operating modes which
  1553. allow you to perform a variety of tasks. You are required to choose
  1554. one operating mode each time you employ the @command{tar} program by
  1555. specifying one, and only one operation as an argument to the
  1556. @command{tar} command (two lists of four operations each may be found
  1557. at @ref{frequent operations} and @ref{Operations}). Depending on
  1558. circumstances, you may also wish to customize how the chosen operating
  1559. mode behaves. For example, you may wish to change the way the output
  1560. looks, or the format of the files that you wish to archive may require
  1561. you to do something special in order to make the archive look right.
  1562. You can customize and control @command{tar}'s performance by running
  1563. @command{tar} with one or more options (such as @option{--verbose}
  1564. (@option{-v}), which we used in the tutorial). As we said in the
  1565. tutorial, @dfn{options} are arguments to @command{tar} which are (as
  1566. their name suggests) optional. Depending on the operating mode, you
  1567. may specify one or more options. Different options will have different
  1568. effects, but in general they all change details of the operation, such
  1569. as archive format, archive name, or level of user interaction. Some
  1570. options make sense with all operating modes, while others are
  1571. meaningful only with particular modes. You will likely use some
  1572. options frequently, while you will only use others infrequently, or
  1573. not at all. (A full list of options is available in @pxref{All Options}.)
  1574. @vrindex TAR_OPTIONS, environment variable
  1575. @anchor{TAR_OPTIONS}
  1576. The @env{TAR_OPTIONS} environment variable specifies default options to
  1577. be placed in front of any explicit options. For example, if
  1578. @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
  1579. if the two options @option{-v} and @option{--unlink-first} had been
  1580. specified before any explicit options. Option specifications are
  1581. separated by whitespace. A backslash escapes the next character, so it
  1582. can be used to specify an option containing whitespace or a backslash.
  1583. Note that @command{tar} options are case sensitive. For example, the
  1584. options @option{-T} and @option{-t} are different; the first requires an
  1585. argument for stating the name of a file providing a list of @var{name}s,
  1586. while the second does not require an argument and is another way to
  1587. write @option{--list} (@option{-t}).
  1588. In addition to the eight operations, there are many options to
  1589. @command{tar}, and three different styles for writing both: long (mnemonic)
  1590. form, short form, and old style. These styles are discussed below.
  1591. Both the options and the operations can be written in any of these three
  1592. styles.
  1593. @FIXME{menu at end of this node. need to think of an actual outline
  1594. for this chapter; probably do that after stuff from chapter 4 is
  1595. incorporated.}
  1596. @node Styles
  1597. @section The Three Option Styles
  1598. There are three styles for writing operations and options to the command
  1599. line invoking @command{tar}. The different styles were developed at
  1600. different times during the history of @command{tar}. These styles will be
  1601. presented below, from the most recent to the oldest.
  1602. Some options must take an argument. (For example, @option{--file}
  1603. (@option{-f})) takes the name of an archive file as an argument. If
  1604. you do not supply an archive file name, @command{tar} will use a
  1605. default, but this can be confusing; thus, we recommend that you always
  1606. supply a specific archive file name.) Where you @emph{place} the
  1607. arguments generally depends on which style of options you choose. We
  1608. will detail specific information relevant to each option style in the
  1609. sections on the different option styles, below. The differences are
  1610. subtle, yet can often be very important; incorrect option placement
  1611. can cause you to overwrite a number of important files. We urge you
  1612. to note these differences, and only use the option style(s) which
  1613. makes the most sense to you until you feel comfortable with the others.
  1614. Some options @emph{may} take an argument. Such options may have at
  1615. most long and short forms, they do not have old style equivalent. The
  1616. rules for specifying an argument for such options are stricter than
  1617. those for specifying mandatory arguments. Please, pay special
  1618. attention to them.
  1619. @menu
  1620. * Long Options:: Long Option Style
  1621. * Short Options:: Short Option Style
  1622. * Old Options:: Old Option Style
  1623. * Mixing:: Mixing Option Styles
  1624. @end menu
  1625. @node Long Options
  1626. @subsection Long Option Style
  1627. Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
  1628. dashes in a row, e.g., @option{--list}. The long names are more clear than
  1629. their corresponding short or old names. It sometimes happens that a
  1630. single long option has many different names which are
  1631. synonymous, such as @option{--compare} and @option{--diff}. In addition,
  1632. long option names can be given unique abbreviations. For example,
  1633. @option{--cre} can be used in place of @option{--create} because there is no
  1634. other long option which begins with @samp{cre}. (One way to find
  1635. this out is by trying it and seeing what happens; if a particular
  1636. abbreviation could represent more than one option, @command{tar} will tell
  1637. you that that abbreviation is ambiguous and you'll know that that
  1638. abbreviation won't work. You may also choose to run @samp{tar --help}
  1639. to see a list of options. Be aware that if you run @command{tar} with a
  1640. unique abbreviation for the long name of an option you didn't want to
  1641. use, you are stuck; @command{tar} will perform the command as ordered.)
  1642. Long options are meant to be obvious and easy to remember, and their
  1643. meanings are generally easier to discern than those of their
  1644. corresponding short options (see below). For example:
  1645. @smallexample
  1646. $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
  1647. @end smallexample
  1648. @noindent
  1649. gives a fairly good set of hints about what the command does, even
  1650. for those not fully acquainted with @command{tar}.
  1651. Long options which require arguments take those arguments
  1652. immediately following the option name. There are two ways of
  1653. specifying a mandatory argument. It can be separated from the
  1654. option name either by an equal sign, or by any amount of
  1655. white space characters. For example, the @option{--file} option (which
  1656. tells the name of the @command{tar} archive) is given a file such as
  1657. @file{archive.tar} as argument by using any of the following notations:
  1658. @option{--file=archive.tar} or @option{--file archive.tar}.
  1659. In contrast, optional arguments must always be introduced using
  1660. an equal sign. For example, the @option{--backup} option takes
  1661. an optional argument specifying backup type. It must be used
  1662. as @option{--backup=@var{backup-type}}.
  1663. @node Short Options
  1664. @subsection Short Option Style
  1665. Most options also have a @dfn{short option} name. Short options start with
  1666. a single dash, and are followed by a single character, e.g., @option{-t}
  1667. (which is equivalent to @option{--list}). The forms are absolutely
  1668. identical in function; they are interchangeable.
  1669. The short option names are faster to type than long option names.
  1670. Short options which require arguments take their arguments immediately
  1671. following the option, usually separated by white space. It is also
  1672. possible to stick the argument right after the short option name, using
  1673. no intervening space. For example, you might write @w{@option{-f
  1674. archive.tar}} or @option{-farchive.tar} instead of using
  1675. @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
  1676. @w{@option{-f @var{archive-name}}} denote the option which indicates a
  1677. specific archive, here named @file{archive.tar}.
  1678. Short options which take optional arguments take their arguments
  1679. immediately following the option letter, @emph{without any intervening
  1680. white space characters}.
  1681. Short options' letters may be clumped together, but you are not
  1682. required to do this (as compared to old options; see below). When
  1683. short options are clumped as a set, use one (single) dash for them
  1684. all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
  1685. such a set is allowed to have an argument@footnote{Clustering many
  1686. options, the last of which has an argument, is a rather opaque way to
  1687. write options. Some wonder if @acronym{GNU} @code{getopt} should not
  1688. even be made helpful enough for considering such usages as invalid.}.
  1689. When the options are separated, the argument for each option which requires
  1690. an argument directly follows that option, as is usual for Unix programs.
  1691. For example:
  1692. @smallexample
  1693. $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
  1694. @end smallexample
  1695. If you reorder short options' locations, be sure to move any arguments
  1696. that belong to them. If you do not move the arguments properly, you may
  1697. end up overwriting files.
  1698. @node Old Options
  1699. @subsection Old Option Style
  1700. @UNREVISED
  1701. Like short options, @dfn{old options} are single letters. However, old options
  1702. must be written together as a single clumped set, without spaces separating
  1703. them or dashes preceding them@footnote{Beware that if you precede options
  1704. with a dash, you are announcing the short option style instead of the
  1705. old option style; short options are decoded differently.}. This set
  1706. of letters must be the first to appear on the command line, after the
  1707. @command{tar} program name and some white space; old options cannot appear
  1708. anywhere else. The letter of an old option is exactly the same letter as
  1709. the corresponding short option. For example, the old option @samp{t} is
  1710. the same as the short option @option{-t}, and consequently, the same as the
  1711. long option @option{--list}. So for example, the command @w{@samp{tar
  1712. cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
  1713. When options that need arguments are given together with the command,
  1714. all the associated arguments follow, in the same order as the options.
  1715. Thus, the example given previously could also be written in the old
  1716. style as follows:
  1717. @smallexample
  1718. $ @kbd{tar cvbf 20 /dev/rmt0}
  1719. @end smallexample
  1720. @noindent
  1721. Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
  1722. the argument of @option{-f}.
  1723. On the other hand, this old style syntax makes it difficult to match
  1724. option letters with their corresponding arguments, and is often
  1725. confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
  1726. @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
  1727. argument for @option{-f}, and @option{-v} does not have a corresponding
  1728. argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
  1729. /dev/rmt0}} is clearer, putting all arguments next to the option they
  1730. pertain to.
  1731. If you want to reorder the letters in the old option argument, be
  1732. sure to reorder any corresponding argument appropriately.
  1733. This old way of writing @command{tar} options can surprise even experienced
  1734. users. For example, the two commands:
  1735. @smallexample
  1736. @kbd{tar cfz archive.tar.gz file}
  1737. @kbd{tar -cfz archive.tar.gz file}
  1738. @end smallexample
  1739. @noindent
  1740. are quite different. The first example uses @file{archive.tar.gz} as
  1741. the value for option @samp{f} and recognizes the option @samp{z}. The
  1742. second example, however, uses @file{z} as the value for option
  1743. @samp{f} --- probably not what was intended.
  1744. Old options are kept for compatibility with old versions of @command{tar}.
  1745. This second example could be corrected in many ways, among which the
  1746. following are equivalent:
  1747. @smallexample
  1748. @kbd{tar -czf archive.tar.gz file}
  1749. @kbd{tar -cf archive.tar.gz -z file}
  1750. @kbd{tar cf archive.tar.gz -z file}
  1751. @end smallexample
  1752. @cindex option syntax, traditional
  1753. As far as we know, all @command{tar} programs, @acronym{GNU} and
  1754. non-@acronym{GNU}, support old options. @GNUTAR{}
  1755. supports them not only for historical reasons, but also because many
  1756. people are used to them. For compatibility with Unix @command{tar},
  1757. the first argument is always treated as containing command and option
  1758. letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
  1759. equivalent to @w{@samp{tar -c}:} both of them specify the
  1760. @option{--create} (@option{-c}) command to create an archive.
  1761. @node Mixing
  1762. @subsection Mixing Option Styles
  1763. All three styles may be intermixed in a single @command{tar} command,
  1764. so long as the rules for each style are fully
  1765. respected@footnote{Before @GNUTAR{} version 1.11.6,
  1766. a bug prevented intermixing old style options with long options in
  1767. some cases.}. Old style options and either of the modern styles of
  1768. options may be mixed within a single @command{tar} command. However,
  1769. old style options must be introduced as the first arguments only,
  1770. following the rule for old options (old options must appear directly
  1771. after the @command{tar} command and some white space). Modern options
  1772. may be given only after all arguments to the old options have been
  1773. collected. If this rule is not respected, a modern option might be
  1774. falsely interpreted as the value of the argument to one of the old
  1775. style options.
  1776. For example, all the following commands are wholly equivalent, and
  1777. illustrate the many combinations and orderings of option styles.
  1778. @smallexample
  1779. @kbd{tar --create --file=archive.tar}
  1780. @kbd{tar --create -f archive.tar}
  1781. @kbd{tar --create -farchive.tar}
  1782. @kbd{tar --file=archive.tar --create}
  1783. @kbd{tar --file=archive.tar -c}
  1784. @kbd{tar -c --file=archive.tar}
  1785. @kbd{tar -c -f archive.tar}
  1786. @kbd{tar -c -farchive.tar}
  1787. @kbd{tar -cf archive.tar}
  1788. @kbd{tar -cfarchive.tar}
  1789. @kbd{tar -f archive.tar --create}
  1790. @kbd{tar -f archive.tar -c}
  1791. @kbd{tar -farchive.tar --create}
  1792. @kbd{tar -farchive.tar -c}
  1793. @kbd{tar c --file=archive.tar}
  1794. @kbd{tar c -f archive.tar}
  1795. @kbd{tar c -farchive.tar}
  1796. @kbd{tar cf archive.tar}
  1797. @kbd{tar f archive.tar --create}
  1798. @kbd{tar f archive.tar -c}
  1799. @kbd{tar fc archive.tar}
  1800. @end smallexample
  1801. On the other hand, the following commands are @emph{not} equivalent to
  1802. the previous set:
  1803. @smallexample
  1804. @kbd{tar -f -c archive.tar}
  1805. @kbd{tar -fc archive.tar}
  1806. @kbd{tar -fcarchive.tar}
  1807. @kbd{tar -farchive.tarc}
  1808. @kbd{tar cfarchive.tar}
  1809. @end smallexample
  1810. @noindent
  1811. These last examples mean something completely different from what the
  1812. user intended (judging based on the example in the previous set which
  1813. uses long options, whose intent is therefore very clear). The first
  1814. four specify that the @command{tar} archive would be a file named
  1815. @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
  1816. respectively. The first two examples also specify a single non-option,
  1817. @var{name} argument having the value @samp{archive.tar}. The last
  1818. example contains only old style option letters (repeating option
  1819. @samp{c} twice), not all of which are meaningful (eg., @samp{.},
  1820. @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
  1821. the first sentence of this paragraph..}
  1822. @node All Options
  1823. @section All @command{tar} Options
  1824. The coming manual sections contain an alphabetical listing of all
  1825. @command{tar} operations and options, with brief descriptions and cross
  1826. references to more in-depth explanations in the body of the manual.
  1827. They also contain an alphabetically arranged table of the short option
  1828. forms with their corresponding long option. You can use this table as
  1829. a reference for deciphering @command{tar} commands in scripts.
  1830. @menu
  1831. * Operation Summary::
  1832. * Option Summary::
  1833. * Short Option Summary::
  1834. @end menu
  1835. @node Operation Summary
  1836. @subsection Operations
  1837. @table @option
  1838. @opsummary{append}
  1839. @item --append
  1840. @itemx -r
  1841. Appends files to the end of the archive. @xref{append}.
  1842. @opsummary{catenate}
  1843. @item --catenate
  1844. @itemx -A
  1845. Same as @option{--concatenate}. @xref{concatenate}.
  1846. @opsummary{compare}
  1847. @item --compare
  1848. @itemx -d
  1849. Compares archive members with their counterparts in the file
  1850. system, and reports differences in file size, mode, owner,
  1851. modification date and contents. @xref{compare}.
  1852. @opsummary{concatenate}
  1853. @item --concatenate
  1854. @itemx -A
  1855. Appends other @command{tar} archives to the end of the archive.
  1856. @xref{concatenate}.
  1857. @opsummary{create}
  1858. @item --create
  1859. @itemx -c
  1860. Creates a new @command{tar} archive. @xref{create}.
  1861. @opsummary{delete}
  1862. @item --delete
  1863. Deletes members from the archive. Don't try this on a archive on a
  1864. tape! @xref{delete}.
  1865. @opsummary{diff}
  1866. @item --diff
  1867. @itemx -d
  1868. Same @option{--compare}. @xref{compare}.
  1869. @opsummary{extract}
  1870. @item --extract
  1871. @itemx -x
  1872. Extracts members from the archive into the file system. @xref{extract}.
  1873. @opsummary{get}
  1874. @item --get
  1875. @itemx -x
  1876. Same as @option{--extract}. @xref{extract}.
  1877. @opsummary{list}
  1878. @item --list
  1879. @itemx -t
  1880. Lists the members in an archive. @xref{list}.
  1881. @opsummary{update}
  1882. @item --update
  1883. @itemx -u
  1884. Adds files to the end of the archive, but only if they are newer than
  1885. their counterparts already in the archive, or if they do not already
  1886. exist in the archive. @xref{update}.
  1887. @end table
  1888. @node Option Summary
  1889. @subsection @command{tar} Options
  1890. @table @option
  1891. @opsummary{absolute-names}
  1892. @item --absolute-names
  1893. @itemx -P
  1894. Normally when creating an archive, @command{tar} strips an initial
  1895. @samp{/} from member names. This option disables that behavior.
  1896. @xref{absolute}.
  1897. @opsummary{after-date}
  1898. @item --after-date
  1899. (See @option{--newer}, @pxref{after})
  1900. @opsummary{anchored}
  1901. @item --anchored
  1902. A pattern must match an initial subsequence of the name's components.
  1903. @xref{controlling pattern-matching}.
  1904. @opsummary{atime-preserve}
  1905. @item --atime-preserve
  1906. @itemx --atime-preserve=replace
  1907. @itemx --atime-preserve=system
  1908. Attempt to preserve the access time of files when reading them. This
  1909. option currently is effective only on files that you own, unless you
  1910. have superuser privileges.
  1911. @option{--atime-preserve=replace} remembers the access time of a file
  1912. before reading it, and then restores the access time afterwards. This
  1913. may cause problems if other programs are reading the file at the same
  1914. time, as the times of their accesses will be lost. On most platforms
  1915. restoring the access time also requires @command{tar} to restore the
  1916. data modification time too, so this option may also cause problems if
  1917. other programs are writing the file at the same time. (Tar attempts
  1918. to detect this situation, but cannot do so reliably due to race
  1919. conditions.) Worse, on most platforms restoring the access time also
  1920. updates the status change time, which means that this option is
  1921. incompatible with incremental backups.
  1922. @option{--atime-preserve=system} avoids changing time stamps on files,
  1923. without interfering with time stamp updates
  1924. caused by other programs, so it works better with incremental backups.
  1925. However, it requires a special @code{O_NOATIME} option from the
  1926. underlying operating and file system implementation, and it also requires
  1927. that searching directories does not update their access times. As of
  1928. this writing (November 2005) this works only with Linux, and only with
  1929. Linux kernels 2.6.8 and later. Worse, there is currently no reliable
  1930. way to know whether this feature actually works. Sometimes
  1931. @command{tar} knows that it does not work, and if you use
  1932. @option{--atime-preserve=system} then @command{tar} complains and
  1933. exits right away. But other times @command{tar} might think that the
  1934. option works when it actually does not.
  1935. Currently @option{--atime-preserve} with no operand defaults to
  1936. @option{--atime-preserve=replace}, but this may change in the future
  1937. as support for @option{--atime-preserve=system} improves.
  1938. If your operating system does not support
  1939. @option{--atime-preserve=@-system}, you might be able to preserve access
  1940. times reliably by by using the @command{mount} command. For example,
  1941. you can mount the file system read-only, or access the file system via
  1942. a read-only loopback mount, or use the @samp{noatime} mount option
  1943. available on some systems. However, mounting typically requires
  1944. superuser privileges and can be a pain to manage.
  1945. @opsummary{auto-compress}
  1946. @item --auto-compress
  1947. @itemx -a
  1948. During a @option{--create} operation, enables automatic compressed
  1949. format recognition based on the archive suffix. @xref{gzip}.
  1950. @opsummary{backup}
  1951. @item --backup=@var{backup-type}
  1952. Rather than deleting files from the file system, @command{tar} will
  1953. back them up using simple or numbered backups, depending upon
  1954. @var{backup-type}. @xref{backup}.
  1955. @opsummary{block-number}
  1956. @item --block-number
  1957. @itemx -R
  1958. With this option present, @command{tar} prints error messages for read errors
  1959. with the block number in the archive file. @xref{block-number}.
  1960. @opsummary{blocking-factor}
  1961. @item --blocking-factor=@var{blocking}
  1962. @itemx -b @var{blocking}
  1963. Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
  1964. record. @xref{Blocking Factor}.
  1965. @opsummary{bzip2}
  1966. @item --bzip2
  1967. @itemx -j
  1968. This option tells @command{tar} to read or write archives through
  1969. @code{bzip2}. @xref{gzip}.
  1970. @opsummary{checkpoint}
  1971. @item --checkpoint[=@var{number}]
  1972. This option directs @command{tar} to print periodic checkpoint
  1973. messages as it reads through the archive. It is intended for when you
  1974. want a visual indication that @command{tar} is still running, but
  1975. don't want to see @option{--verbose} output. You can also instruct
  1976. @command{tar} to execute a list of actions on each checkpoint, see
  1977. @option{--checklist-action} below. For a detailed description, see
  1978. @ref{checkpoints}.
  1979. @opsummary{checkpoint-action}
  1980. @item --checkpoint-action=@var{action}
  1981. Instruct @command{tar} to execute an action upon hitting a
  1982. breakpoint. Here we give only a brief outline. @xref{checkpoints},
  1983. for a complete description.
  1984. The @var{action} argument can be one of the following:
  1985. @table @asis
  1986. @item echo
  1987. Display a textual message on the standard error, with the status and
  1988. number of the checkpoint. This is the default.
  1989. @item echo=@var{string}
  1990. Display @var{string} on the standard error. Before output, the string
  1991. is subject to meta-character expansion.
  1992. @item dot
  1993. @itemx .
  1994. Print a single dot on the standard listing stream.
  1995. @item sleep=@var{time}
  1996. Wait for @var{time} seconds.
  1997. @item exec=@var{command}
  1998. Execute the given @var{command}.
  1999. @end table
  2000. Several @option{--checkpoint-action} options can be specified. The
  2001. supplied actions will be executed in order of their appearance in the
  2002. command line.
  2003. Using @option{--checkpoint-action} without @option{--checkpoint}
  2004. assumes default checkpoint frequency of one checkpoint per 10 records.
  2005. @opsummary{check-links}
  2006. @item --check-links
  2007. @itemx -l
  2008. If this option was given, @command{tar} will check the number of links
  2009. dumped for each processed file. If this number does not match the
  2010. total number of hard links for the file, a warning message will be
  2011. output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
  2012. synonym for @option{--one-file-system}. The current semantics, which
  2013. complies to UNIX98, was introduced with version
  2014. 1.15.91. @xref{Changes}, for more information.}.
  2015. @xref{hard links}.
  2016. @opsummary{compress}
  2017. @opsummary{uncompress}
  2018. @item --compress
  2019. @itemx --uncompress
  2020. @itemx -Z
  2021. @command{tar} will use the @command{compress} program when reading or
  2022. writing the archive. This allows you to directly act on archives
  2023. while saving space. @xref{gzip}.
  2024. @opsummary{confirmation}
  2025. @item --confirmation
  2026. (See @option{--interactive}.) @xref{interactive}.
  2027. @opsummary{delay-directory-restore}
  2028. @item --delay-directory-restore
  2029. Delay setting modification times and permissions of extracted
  2030. directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
  2031. @opsummary{dereference}
  2032. @item --dereference
  2033. @itemx -h
  2034. When creating a @command{tar} archive, @command{tar} will archive the
  2035. file that a symbolic link points to, rather than archiving the
  2036. symlink. @xref{dereference}.
  2037. @opsummary{directory}
  2038. @item --directory=@var{dir}
  2039. @itemx -C @var{dir}
  2040. When this option is specified, @command{tar} will change its current directory
  2041. to @var{dir} before performing any operations. When this option is used
  2042. during archive creation, it is order sensitive. @xref{directory}.
  2043. @opsummary{exclude}
  2044. @item --exclude=@var{pattern}
  2045. When performing operations, @command{tar} will skip files that match
  2046. @var{pattern}. @xref{exclude}.
  2047. @opsummary{exclude-from}
  2048. @item --exclude-from=@var{file}
  2049. @itemx -X @var{file}
  2050. Similar to @option{--exclude}, except @command{tar} will use the list of
  2051. patterns in the file @var{file}. @xref{exclude}.
  2052. @opsummary{exclude-caches}
  2053. @item --exclude-caches
  2054. Exclude from dump any directory containing a valid cache directory
  2055. tag file, but still dump the directory node and the tag file itself.
  2056. @xref{exclude}.
  2057. @opsummary{exclude-caches-under}
  2058. @item --exclude-caches-under
  2059. Exclude from dump any directory containing a valid cache directory
  2060. tag file, but still dump the directory node itself.
  2061. @xref{exclude}.
  2062. @opsummary{exclude-caches-all}
  2063. @item --exclude-caches-all
  2064. Exclude from dump any directory containing a valid cache directory
  2065. tag file. @xref{exclude}.
  2066. @opsummary{exclude-tag}
  2067. @item --exclude-tag=@var{file}
  2068. Exclude from dump any directory containing file named @var{file}, but
  2069. dump the directory node and @var{file} itself. @xref{exclude}.
  2070. @opsummary{exclude-tag-under}
  2071. @item --exclude-tag-under=@var{file}
  2072. Exclude from dump the contents of any directory containing file
  2073. named @var{file}, but dump the directory node itself. @xref{exclude}.
  2074. @opsummary{exclude-tag-all}
  2075. @item --exclude-tag-all=@var{file}
  2076. Exclude from dump any directory containing file named @var{file}.
  2077. @xref{exclude}.
  2078. @opsummary{exclude-vcs}
  2079. @item --exclude-vcs
  2080. Exclude from dump directories and files, that are internal for some
  2081. widely used version control systems.
  2082. @xref{exclude}.
  2083. @opsummary{file}
  2084. @item --file=@var{archive}
  2085. @itemx -f @var{archive}
  2086. @command{tar} will use the file @var{archive} as the @command{tar} archive it
  2087. performs operations on, rather than @command{tar}'s compilation dependent
  2088. default. @xref{file tutorial}.
  2089. @opsummary{files-from}
  2090. @item --files-from=@var{file}
  2091. @itemx -T @var{file}
  2092. @command{tar} will use the contents of @var{file} as a list of archive members
  2093. or files to operate on, in addition to those specified on the
  2094. command-line. @xref{files}.
  2095. @opsummary{force-local}
  2096. @item --force-local
  2097. Forces @command{tar} to interpret the file name given to @option{--file}
  2098. as a local file, even if it looks like a remote tape drive name.
  2099. @xref{local and remote archives}.
  2100. @opsummary{format}
  2101. @item --format=@var{format}
  2102. @itemx -H @var{format}
  2103. Selects output archive format. @var{Format} may be one of the
  2104. following:
  2105. @table @samp
  2106. @item v7
  2107. Creates an archive that is compatible with Unix V7 @command{tar}.
  2108. @item oldgnu
  2109. Creates an archive that is compatible with GNU @command{tar} version
  2110. 1.12 or earlier.
  2111. @item gnu
  2112. Creates archive in GNU tar 1.13 format. Basically it is the same as
  2113. @samp{oldgnu} with the only difference in the way it handles long
  2114. numeric fields.
  2115. @item ustar
  2116. Creates a @acronym{POSIX.1-1988} compatible archive.
  2117. @item posix
  2118. Creates a @acronym{POSIX.1-2001 archive}.
  2119. @end table
  2120. @xref{Formats}, for a detailed discussion of these formats.
  2121. @opsummary{group}
  2122. @item --group=@var{group}
  2123. Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
  2124. rather than the group from the source file. @var{group} is first decoded
  2125. as a group symbolic name, but if this interpretation fails, it has to be
  2126. a decimal numeric group @acronym{ID}. @xref{override}.
  2127. Also see the comments for the @option{--owner=@var{user}} option.
  2128. @opsummary{gzip}
  2129. @opsummary{gunzip}
  2130. @opsummary{ungzip}
  2131. @item --gzip
  2132. @itemx --gunzip
  2133. @itemx --ungzip
  2134. @itemx -z
  2135. This option tells @command{tar} to read or write archives through
  2136. @command{gzip}, allowing @command{tar} to directly operate on several
  2137. kinds of compressed archives transparently. @xref{gzip}.
  2138. @opsummary{hard-dereference}
  2139. @item --hard-dereference
  2140. When creating an archive, dereference hard links and store the files
  2141. they refer to, instead of creating usual hard link members.
  2142. @xref{hard links}.
  2143. @opsummary{help}
  2144. @item --help
  2145. @itemx -?
  2146. @command{tar} will print out a short message summarizing the operations and
  2147. options to @command{tar} and exit. @xref{help}.
  2148. @opsummary{ignore-case}
  2149. @item --ignore-case
  2150. Ignore case when matching member or file names with
  2151. patterns. @xref{controlling pattern-matching}.
  2152. @opsummary{ignore-command-error}
  2153. @item --ignore-command-error
  2154. Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
  2155. @opsummary{ignore-failed-read}
  2156. @item --ignore-failed-read
  2157. Do not exit unsuccessfully merely because an unreadable file was encountered.
  2158. @xref{Reading}.
  2159. @opsummary{ignore-zeros}
  2160. @item --ignore-zeros
  2161. @itemx -i
  2162. With this option, @command{tar} will ignore zeroed blocks in the
  2163. archive, which normally signals EOF. @xref{Reading}.
  2164. @opsummary{incremental}
  2165. @item --incremental
  2166. @itemx -G
  2167. Informs @command{tar} that it is working with an old
  2168. @acronym{GNU}-format incremental backup archive. It is intended
  2169. primarily for backwards compatibility only. @xref{Incremental Dumps},
  2170. for a detailed discussion of incremental archives.
  2171. @opsummary{index-file}
  2172. @item --index-file=@var{file}
  2173. Send verbose output to @var{file} instead of to standard output.
  2174. @opsummary{info-script}
  2175. @opsummary{new-volume-script}
  2176. @item --info-script=@var{script-file}
  2177. @itemx --new-volume-script=@var{script-file}
  2178. @itemx -F @var{script-file}
  2179. When @command{tar} is performing multi-tape backups, @var{script-file} is run
  2180. at the end of each tape. If @var{script-file} exits with nonzero status,
  2181. @command{tar} fails immediately. @xref{info-script}, for a detailed
  2182. discussion of @var{script-file}.
  2183. @opsummary{interactive}
  2184. @item --interactive
  2185. @itemx --confirmation
  2186. @itemx -w
  2187. Specifies that @command{tar} should ask the user for confirmation before
  2188. performing potentially destructive options, such as overwriting files.
  2189. @xref{interactive}.
  2190. @opsummary{keep-newer-files}
  2191. @item --keep-newer-files
  2192. Do not replace existing files that are newer than their archive copies
  2193. when extracting files from an archive.
  2194. @opsummary{keep-old-files}
  2195. @item --keep-old-files
  2196. @itemx -k
  2197. Do not overwrite existing files when extracting files from an archive.
  2198. @xref{Keep Old Files}.
  2199. @opsummary{label}
  2200. @item --label=@var{name}
  2201. @itemx -V @var{name}
  2202. When creating an archive, instructs @command{tar} to write @var{name}
  2203. as a name record in the archive. When extracting or listing archives,
  2204. @command{tar} will only operate on archives that have a label matching
  2205. the pattern specified in @var{name}. @xref{Tape Files}.
  2206. @opsummary{listed-incremental}
  2207. @item --listed-incremental=@var{snapshot-file}
  2208. @itemx -g @var{snapshot-file}
  2209. During a @option{--create} operation, specifies that the archive that
  2210. @command{tar} creates is a new @acronym{GNU}-format incremental
  2211. backup, using @var{snapshot-file} to determine which files to backup.
  2212. With other operations, informs @command{tar} that the archive is in
  2213. incremental format. @xref{Incremental Dumps}.
  2214. @opsummary{lzma}
  2215. @item --lzma
  2216. This option tells @command{tar} to read or write archives through
  2217. @command{lzma}. @xref{gzip}.
  2218. @opsummary{mode}
  2219. @item --mode=@var{permissions}
  2220. When adding files to an archive, @command{tar} will use
  2221. @var{permissions} for the archive members, rather than the permissions
  2222. from the files. @var{permissions} can be specified either as an octal
  2223. number or as symbolic permissions, like with
  2224. @command{chmod}. @xref{override}.
  2225. @opsummary{mtime}
  2226. @item --mtime=@var{date}
  2227. When adding files to an archive, @command{tar} will use @var{date} as
  2228. the modification time of members when creating archives, instead of
  2229. their actual modification times. The value of @var{date} can be
  2230. either a textual date representation (@pxref{Date input formats}) or a
  2231. name of the existing file, starting with @samp{/} or @samp{.}. In the
  2232. latter case, the modification time of that file is used. @xref{override}.
  2233. @opsummary{multi-volume}
  2234. @item --multi-volume
  2235. @itemx -M
  2236. Informs @command{tar} that it should create or otherwise operate on a
  2237. multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
  2238. @opsummary{new-volume-script}
  2239. @item --new-volume-script
  2240. (see --info-script)
  2241. @opsummary{newer}
  2242. @item --newer=@var{date}
  2243. @itemx --after-date=@var{date}
  2244. @itemx -N
  2245. When creating an archive, @command{tar} will only add files that have changed
  2246. since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
  2247. is taken to be the name of a file whose data modification time specifies
  2248. the date. @xref{after}.
  2249. @opsummary{newer-mtime}
  2250. @item --newer-mtime=@var{date}
  2251. Like @option{--newer}, but add only files whose
  2252. contents have changed (as opposed to just @option{--newer}, which will
  2253. also back up files for which any status information has
  2254. changed). @xref{after}.
  2255. @opsummary{no-anchored}
  2256. @item --no-anchored
  2257. An exclude pattern can match any subsequence of the name's components.
  2258. @xref{controlling pattern-matching}.
  2259. @opsummary{no-delay-directory-restore}
  2260. @item --no-delay-directory-restore
  2261. Modification times and permissions of extracted
  2262. directories are set when all files from this directory have been
  2263. extracted. This is the default.
  2264. @xref{Directory Modification Times and Permissions}.
  2265. @opsummary{no-ignore-case}
  2266. @item --no-ignore-case
  2267. Use case-sensitive matching.
  2268. @xref{controlling pattern-matching}.
  2269. @opsummary{no-ignore-command-error}
  2270. @item --no-ignore-command-error
  2271. Print warnings about subprocesses that terminated with a nonzero exit
  2272. code. @xref{Writing to an External Program}.
  2273. @opsummary{no-overwrite-dir}
  2274. @item --no-overwrite-dir
  2275. Preserve metadata of existing directories when extracting files
  2276. from an archive. @xref{Overwrite Old Files}.
  2277. @opsummary{no-quote-chars}
  2278. @item --no-quote-chars=@var{string}
  2279. Remove characters listed in @var{string} from the list of quoted
  2280. characters set by the previous @option{--quote-chars} option
  2281. (@pxref{quoting styles}).
  2282. @opsummary{no-recursion}
  2283. @item --no-recursion
  2284. With this option, @command{tar} will not recurse into directories.
  2285. @xref{recurse}.
  2286. @opsummary{no-same-owner}
  2287. @item --no-same-owner
  2288. @itemx -o
  2289. When extracting an archive, do not attempt to preserve the owner
  2290. specified in the @command{tar} archive. This the default behavior
  2291. for ordinary users.
  2292. @opsummary{no-same-permissions}
  2293. @item --no-same-permissions
  2294. When extracting an archive, subtract the user's umask from files from
  2295. the permissions specified in the archive. This is the default behavior
  2296. for ordinary users.
  2297. @opsummary{no-unquote}
  2298. @item --no-unquote
  2299. Treat all input file or member names literally, do not interpret
  2300. escape sequences. @xref{input name quoting}.
  2301. @opsummary{no-wildcards}
  2302. @item --no-wildcards
  2303. Do not use wildcards.
  2304. @xref{controlling pattern-matching}.
  2305. @opsummary{no-wildcards-match-slash}
  2306. @item --no-wildcards-match-slash
  2307. Wildcards do not match @samp{/}.
  2308. @xref{controlling pattern-matching}.
  2309. @opsummary{null}
  2310. @item --null
  2311. When @command{tar} is using the @option{--files-from} option, this option
  2312. instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
  2313. @command{tar} can correctly work with file names that contain newlines.
  2314. @xref{nul}.
  2315. @opsummary{numeric-owner}
  2316. @item --numeric-owner
  2317. This option will notify @command{tar} that it should use numeric user
  2318. and group IDs when creating a @command{tar} file, rather than names.
  2319. @xref{Attributes}.
  2320. @item -o
  2321. The function of this option depends on the action @command{tar} is
  2322. performing. When extracting files, @option{-o} is a synonym for
  2323. @option{--no-same-owner}, i.e., it prevents @command{tar} from
  2324. restoring ownership of files being extracted.
  2325. When creating an archive, it is a synonym for
  2326. @option{--old-archive}. This behavior is for compatibility
  2327. with previous versions of @GNUTAR{}, and will be
  2328. removed in future releases.
  2329. @xref{Changes}, for more information.
  2330. @opsummary{occurrence}
  2331. @item --occurrence[=@var{number}]
  2332. This option can be used in conjunction with one of the subcommands
  2333. @option{--delete}, @option{--diff}, @option{--extract} or
  2334. @option{--list} when a list of files is given either on the command
  2335. line or via @option{-T} option.
  2336. This option instructs @command{tar} to process only the @var{number}th
  2337. occurrence of each named file. @var{Number} defaults to 1, so
  2338. @smallexample
  2339. tar -x -f archive.tar --occurrence filename
  2340. @end smallexample
  2341. @noindent
  2342. will extract the first occurrence of the member @file{filename} from @file{archive.tar}
  2343. and will terminate without scanning to the end of the archive.
  2344. @opsummary{old-archive}
  2345. @item --old-archive
  2346. Synonym for @option{--format=v7}.
  2347. @opsummary{one-file-system}
  2348. @item --one-file-system
  2349. Used when creating an archive. Prevents @command{tar} from recursing into
  2350. directories that are on different file systems from the current
  2351. directory.
  2352. @opsummary{overwrite}
  2353. @item --overwrite
  2354. Overwrite existing files and directory metadata when extracting files
  2355. from an archive. @xref{Overwrite Old Files}.
  2356. @opsummary{overwrite-dir}
  2357. @item --overwrite-dir
  2358. Overwrite the metadata of existing directories when extracting files
  2359. from an archive. @xref{Overwrite Old Files}.
  2360. @opsummary{owner}
  2361. @item --owner=@var{user}
  2362. Specifies that @command{tar} should use @var{user} as the owner of members
  2363. when creating archives, instead of the user associated with the source
  2364. file. @var{user} is first decoded as a user symbolic name, but if
  2365. this interpretation fails, it has to be a decimal numeric user @acronym{ID}.
  2366. @xref{override}.
  2367. This option does not affect extraction from archives.
  2368. @opsummary{pax-option}
  2369. @item --pax-option=@var{keyword-list}
  2370. This option is meaningful only with @acronym{POSIX.1-2001} archives
  2371. (@pxref{posix}). It modifies the way @command{tar} handles the
  2372. extended header keywords. @var{Keyword-list} is a comma-separated
  2373. list of keyword options. @xref{PAX keywords}, for a detailed
  2374. discussion.
  2375. @opsummary{portability}
  2376. @item --portability
  2377. @itemx --old-archive
  2378. Synonym for @option{--format=v7}.
  2379. @opsummary{posix}
  2380. @item --posix
  2381. Same as @option{--format=posix}.
  2382. @opsummary{preserve}
  2383. @item --preserve
  2384. Synonymous with specifying both @option{--preserve-permissions} and
  2385. @option{--same-order}. @xref{Setting Access Permissions}.
  2386. @opsummary{preserve-order}
  2387. @item --preserve-order
  2388. (See @option{--same-order}; @pxref{Reading}.)
  2389. @opsummary{preserve-permissions}
  2390. @opsummary{same-permissions}
  2391. @item --preserve-permissions
  2392. @itemx --same-permissions
  2393. @itemx -p
  2394. When @command{tar} is extracting an archive, it normally subtracts the
  2395. users' umask from the permissions specified in the archive and uses
  2396. that number as the permissions to create the destination file.
  2397. Specifying this option instructs @command{tar} that it should use the
  2398. permissions directly from the archive. @xref{Setting Access Permissions}.
  2399. @opsummary{quote-chars}
  2400. @item --quote-chars=@var{string}
  2401. Always quote characters from @var{string}, even if the selected
  2402. quoting style would not quote them (@pxref{quoting styles}).
  2403. @opsummary{quoting-style}
  2404. @item --quoting-style=@var{style}
  2405. Set quoting style to use when printing member and file names
  2406. (@pxref{quoting styles}). Valid @var{style} values are:
  2407. @code{literal}, @code{shell}, @code{shell-always}, @code{c},
  2408. @code{escape}, @code{locale}, and @code{clocale}. Default quoting
  2409. style is @code{escape}, unless overridden while configuring the
  2410. package.
  2411. @opsummary{read-full-records}
  2412. @item --read-full-records
  2413. @itemx -B
  2414. Specifies that @command{tar} should reblock its input, for reading
  2415. from pipes on systems with buggy implementations. @xref{Reading}.
  2416. @opsummary{record-size}
  2417. @item --record-size=@var{size}
  2418. Instructs @command{tar} to use @var{size} bytes per record when accessing the
  2419. archive. @xref{Blocking Factor}.
  2420. @opsummary{recursion}
  2421. @item --recursion
  2422. With this option, @command{tar} recurses into directories (default).
  2423. @xref{recurse}.
  2424. @opsummary{recursive-unlink}
  2425. @item --recursive-unlink
  2426. Remove existing
  2427. directory hierarchies before extracting directories of the same name
  2428. from the archive. @xref{Recursive Unlink}.
  2429. @opsummary{remove-files}
  2430. @item --remove-files
  2431. Directs @command{tar} to remove the source file from the file system after
  2432. appending it to an archive. @xref{remove files}.
  2433. @opsummary{restrict}
  2434. @item --restrict
  2435. Disable use of some potentially harmful @command{tar} options.
  2436. Currently this option disables shell invocation from multi-volume menu
  2437. (@pxref{Using Multiple Tapes}).
  2438. @opsummary{rmt-command}
  2439. @item --rmt-command=@var{cmd}
  2440. Notifies @command{tar} that it should use @var{cmd} instead of
  2441. the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
  2442. @opsummary{rsh-command}
  2443. @item --rsh-command=@var{cmd}
  2444. Notifies @command{tar} that is should use @var{cmd} to communicate with remote
  2445. devices. @xref{Device}.
  2446. @opsummary{same-order}
  2447. @item --same-order
  2448. @itemx --preserve-order
  2449. @itemx -s
  2450. This option is an optimization for @command{tar} when running on machines with
  2451. small amounts of memory. It informs @command{tar} that the list of file
  2452. arguments has already been sorted to match the order of files in the
  2453. archive. @xref{Reading}.
  2454. @opsummary{same-owner}
  2455. @item --same-owner
  2456. When extracting an archive, @command{tar} will attempt to preserve the owner
  2457. specified in the @command{tar} archive with this option present.
  2458. This is the default behavior for the superuser; this option has an
  2459. effect only for ordinary users. @xref{Attributes}.
  2460. @opsummary{same-permissions}
  2461. @item --same-permissions
  2462. (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
  2463. @opsummary{seek}
  2464. @item --seek
  2465. @itemx -n
  2466. Assume that the archive media supports seeks to arbitrary
  2467. locations. Usually @command{tar} determines automatically whether
  2468. the archive can be seeked or not. This option is intended for use
  2469. in cases when such recognition fails.
  2470. @opsummary{show-defaults}
  2471. @item --show-defaults
  2472. Displays the default options used by @command{tar} and exits
  2473. successfully. This option is intended for use in shell scripts.
  2474. Here is an example of what you can see using this option:
  2475. @smallexample
  2476. $ tar --show-defaults
  2477. --format=gnu -f- -b20 --quoting-style=escape \
  2478. --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
  2479. @end smallexample
  2480. @opsummary{show-omitted-dirs}
  2481. @item --show-omitted-dirs
  2482. Instructs @command{tar} to mention the directories it is skipping when
  2483. operating on a @command{tar} archive. @xref{show-omitted-dirs}.
  2484. @opsummary{show-transformed-names}
  2485. @opsummary{show-stored-names}
  2486. @item --show-transformed-names
  2487. @itemx --show-stored-names
  2488. Display file or member names after applying any transformations
  2489. (@pxref{transform}). In particular, when used in conjunction with one of
  2490. the archive creation operations it instructs @command{tar} to list the
  2491. member names stored in the archive, as opposed to the actual file
  2492. names. @xref{listing member and file names}.
  2493. @opsummary{sparse}
  2494. @item --sparse
  2495. @itemx -S
  2496. Invokes a @acronym{GNU} extension when adding files to an archive that handles
  2497. sparse files efficiently. @xref{sparse}.
  2498. @opsummary{sparse-version}
  2499. @item --sparse-version=@var{version}
  2500. Specifies the @dfn{format version} to use when archiving sparse
  2501. files. Implies @option{--sparse}. @xref{sparse}. For the description
  2502. of the supported sparse formats, @xref{Sparse Formats}.
  2503. @opsummary{starting-file}
  2504. @item --starting-file=@var{name}
  2505. @itemx -K @var{name}
  2506. This option affects extraction only; @command{tar} will skip extracting
  2507. files in the archive until it finds one that matches @var{name}.
  2508. @xref{Scarce}.
  2509. @opsummary{strip-components}
  2510. @item --strip-components=@var{number}
  2511. Strip given @var{number} of leading components from file names before
  2512. extraction. For example, if archive @file{archive.tar} contained
  2513. @file{/some/file/name}, then running
  2514. @smallexample
  2515. tar --extract --file archive.tar --strip-components=2
  2516. @end smallexample
  2517. @noindent
  2518. would extract this file to file @file{name}.
  2519. @opsummary{suffix}, summary
  2520. @item --suffix=@var{suffix}
  2521. Alters the suffix @command{tar} uses when backing up files from the default
  2522. @samp{~}. @xref{backup}.
  2523. @opsummary{tape-length}
  2524. @item --tape-length=@var{num}
  2525. @itemx -L @var{num}
  2526. Specifies the length of tapes that @command{tar} is writing as being
  2527. @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
  2528. @opsummary{test-label}
  2529. @item --test-label
  2530. Reads the volume label. If an argument is specified, test whether it
  2531. matches the volume label. @xref{--test-label option}.
  2532. @opsummary{to-command}
  2533. @item --to-command=@var{command}
  2534. During extraction @command{tar} will pipe extracted files to the
  2535. standard input of @var{command}. @xref{Writing to an External Program}.
  2536. @opsummary{to-stdout}
  2537. @item --to-stdout
  2538. @itemx -O
  2539. During extraction, @command{tar} will extract files to stdout rather
  2540. than to the file system. @xref{Writing to Standard Output}.
  2541. @opsummary{totals}
  2542. @item --totals[=@var{signo}]
  2543. Displays the total number of bytes transferred when processing an
  2544. archive. If an argument is given, these data are displayed on
  2545. request, when signal @var{signo} is delivered to @command{tar}.
  2546. @xref{totals}.
  2547. @opsummary{touch}
  2548. @item --touch
  2549. @itemx -m
  2550. Sets the data modification time of extracted files to the extraction time,
  2551. rather than the data modification time stored in the archive.
  2552. @xref{Data Modification Times}.
  2553. @opsummary{transform}
  2554. @item --transform=@var{sed-expr}
  2555. Transform file or member names using @command{sed} replacement expression
  2556. @var{sed-expr}. For example,
  2557. @smallexample
  2558. $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
  2559. @end smallexample
  2560. @noindent
  2561. will add to @file{archive} files from the current working directory,
  2562. replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
  2563. discussion, @xref{transform}.
  2564. To see transformed member names in verbose listings, use
  2565. @option{--show-transformed-names} option
  2566. (@pxref{show-transformed-names}).
  2567. @opsummary{uncompress}
  2568. @item --uncompress
  2569. (See @option{--compress}. @pxref{gzip})
  2570. @opsummary{ungzip}
  2571. @item --ungzip
  2572. (See @option{--gzip}. @pxref{gzip})
  2573. @opsummary{unlink-first}
  2574. @item --unlink-first
  2575. @itemx -U
  2576. Directs @command{tar} to remove the corresponding file from the file
  2577. system before extracting it from the archive. @xref{Unlink First}.
  2578. @opsummary{unquote}
  2579. @item --unquote
  2580. Enable unquoting input file or member names (default). @xref{input
  2581. name quoting}.
  2582. @opsummary{use-compress-program}
  2583. @item --use-compress-program=@var{prog}
  2584. Instructs @command{tar} to access the archive through @var{prog}, which is
  2585. presumed to be a compression program of some sort. @xref{gzip}.
  2586. @opsummary{utc}
  2587. @item --utc
  2588. Display file modification dates in @acronym{UTC}. This option implies
  2589. @option{--verbose}.
  2590. @opsummary{verbose}
  2591. @item --verbose
  2592. @itemx -v
  2593. Specifies that @command{tar} should be more verbose about the
  2594. operations it is performing. This option can be specified multiple
  2595. times for some operations to increase the amount of information displayed.
  2596. @xref{verbose}.
  2597. @opsummary{verify}
  2598. @item --verify
  2599. @itemx -W
  2600. Verifies that the archive was correctly written when creating an
  2601. archive. @xref{verify}.
  2602. @opsummary{version}
  2603. @item --version
  2604. Print information about the program's name, version, origin and legal
  2605. status, all on standard output, and then exit successfully.
  2606. @xref{help}.
  2607. @opsummary{volno-file}
  2608. @item --volno-file=@var{file}
  2609. Used in conjunction with @option{--multi-volume}. @command{tar} will
  2610. keep track of which volume of a multi-volume archive it is working in
  2611. @var{file}. @xref{volno-file}.
  2612. @opsummary{wildcards}
  2613. @item --wildcards
  2614. Use wildcards when matching member names with patterns.
  2615. @xref{controlling pattern-matching}.
  2616. @opsummary{wildcards-match-slash}
  2617. @item --wildcards-match-slash
  2618. Wildcards match @samp{/}.
  2619. @xref{controlling pattern-matching}.
  2620. @end table
  2621. @node Short Option Summary
  2622. @subsection Short Options Cross Reference
  2623. Here is an alphabetized list of all of the short option forms, matching
  2624. them with the equivalent long option.
  2625. @multitable @columnfractions 0.20 0.80
  2626. @headitem Short Option @tab Reference
  2627. @item -A @tab @ref{--concatenate}.
  2628. @item -B @tab @ref{--read-full-records}.
  2629. @item -C @tab @ref{--directory}.
  2630. @item -F @tab @ref{--info-script}.
  2631. @item -G @tab @ref{--incremental}.
  2632. @item -K @tab @ref{--starting-file}.
  2633. @item -L @tab @ref{--tape-length}.
  2634. @item -M @tab @ref{--multi-volume}.
  2635. @item -N @tab @ref{--newer}.
  2636. @item -O @tab @ref{--to-stdout}.
  2637. @item -P @tab @ref{--absolute-names}.
  2638. @item -R @tab @ref{--block-number}.
  2639. @item -S @tab @ref{--sparse}.
  2640. @item -T @tab @ref{--files-from}.
  2641. @item -U @tab @ref{--unlink-first}.
  2642. @item -V @tab @ref{--label}.
  2643. @item -W @tab @ref{--verify}.
  2644. @item -X @tab @ref{--exclude-from}.
  2645. @item -Z @tab @ref{--compress}.
  2646. @item -b @tab @ref{--blocking-factor}.
  2647. @item -c @tab @ref{--create}.
  2648. @item -d @tab @ref{--compare}.
  2649. @item -f @tab @ref{--file}.
  2650. @item -g @tab @ref{--listed-incremental}.
  2651. @item -h @tab @ref{--dereference}.
  2652. @item -i @tab @ref{--ignore-zeros}.
  2653. @item -j @tab @ref{--bzip2}.
  2654. @item -k @tab @ref{--keep-old-files}.
  2655. @item -l @tab @ref{--check-links}.
  2656. @item -m @tab @ref{--touch}.
  2657. @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
  2658. @ref{--portability}.
  2659. The later usage is deprecated. It is retained for compatibility with
  2660. the earlier versions of @GNUTAR{}. In future releases
  2661. @option{-o} will be equivalent to @option{--no-same-owner} only.
  2662. @item -p @tab @ref{--preserve-permissions}.
  2663. @item -r @tab @ref{--append}.
  2664. @item -s @tab @ref{--same-order}.
  2665. @item -t @tab @ref{--list}.
  2666. @item -u @tab @ref{--update}.
  2667. @item -v @tab @ref{--verbose}.
  2668. @item -w @tab @ref{--interactive}.
  2669. @item -x @tab @ref{--extract}.
  2670. @item -z @tab @ref{--gzip}.
  2671. @end multitable
  2672. @node help
  2673. @section @GNUTAR{} documentation
  2674. @cindex Getting program version number
  2675. @opindex version
  2676. @cindex Version of the @command{tar} program
  2677. Being careful, the first thing is really checking that you are using
  2678. @GNUTAR{}, indeed. The @option{--version} option
  2679. causes @command{tar} to print information about its name, version,
  2680. origin and legal status, all on standard output, and then exit
  2681. successfully. For example, @w{@samp{tar --version}} might print:
  2682. @smallexample
  2683. tar (GNU tar) @value{VERSION}
  2684. Copyright (C) 2006 Free Software Foundation, Inc.
  2685. This is free software. You may redistribute copies of it under the terms
  2686. of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
  2687. There is NO WARRANTY, to the extent permitted by law.
  2688. Written by John Gilmore and Jay Fenlason.
  2689. @end smallexample
  2690. @noindent
  2691. The first occurrence of @samp{tar} in the result above is the program
  2692. name in the package (for example, @command{rmt} is another program),
  2693. while the second occurrence of @samp{tar} is the name of the package
  2694. itself, containing possibly many programs. The package is currently
  2695. named @samp{tar}, after the name of the main program it
  2696. contains@footnote{There are plans to merge the @command{cpio} and
  2697. @command{tar} packages into a single one which would be called
  2698. @code{paxutils}. So, who knows if, one of this days, the
  2699. @option{--version} would not output @w{@samp{tar (@acronym{GNU}
  2700. paxutils) 3.2}}}.
  2701. @cindex Obtaining help
  2702. @cindex Listing all @command{tar} options
  2703. @xopindex{help, introduction}
  2704. Another thing you might want to do is checking the spelling or meaning
  2705. of some particular @command{tar} option, without resorting to this
  2706. manual, for once you have carefully read it. @GNUTAR{}
  2707. has a short help feature, triggerable through the
  2708. @option{--help} option. By using this option, @command{tar} will
  2709. print a usage message listing all available options on standard
  2710. output, then exit successfully, without doing anything else and
  2711. ignoring all other options. Even if this is only a brief summary, it
  2712. may be several screens long. So, if you are not using some kind of
  2713. scrollable window, you might prefer to use something like:
  2714. @smallexample
  2715. $ @kbd{tar --help | less}
  2716. @end smallexample
  2717. @noindent
  2718. presuming, here, that you like using @command{less} for a pager. Other
  2719. popular pagers are @command{more} and @command{pg}. If you know about some
  2720. @var{keyword} which interests you and do not want to read all the
  2721. @option{--help} output, another common idiom is doing:
  2722. @smallexample
  2723. tar --help | grep @var{keyword}
  2724. @end smallexample
  2725. @noindent
  2726. for getting only the pertinent lines. Notice, however, that some
  2727. @command{tar} options have long description lines and the above
  2728. command will list only the first of them.
  2729. The exact look of the option summary displayed by @kbd{tar --help} is
  2730. configurable. @xref{Configuring Help Summary}, for a detailed description.
  2731. @opindex usage
  2732. If you only wish to check the spelling of an option, running @kbd{tar
  2733. --usage} may be a better choice. This will display a terse list of
  2734. @command{tar} option without accompanying explanations.
  2735. The short help output is quite succinct, and you might have to get
  2736. back to the full documentation for precise points. If you are reading
  2737. this paragraph, you already have the @command{tar} manual in some
  2738. form. This manual is available in a variety of forms from
  2739. @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
  2740. distribution, provided you have @TeX{} already installed somewhere,
  2741. and a laser printer around. Just configure the distribution, execute
  2742. the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
  2743. usual way (contact your local guru to know how). If @GNUTAR{}
  2744. has been conveniently installed at your place, this
  2745. manual is also available in interactive, hypertextual form as an Info
  2746. file. Just call @w{@samp{info tar}} or, if you do not have the
  2747. @command{info} program handy, use the Info reader provided within
  2748. @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
  2749. There is currently no @code{man} page for @GNUTAR{}.
  2750. If you observe such a @code{man} page on the system you are running,
  2751. either it does not belong to @GNUTAR{}, or it has not
  2752. been produced by @acronym{GNU}. Some package maintainers convert
  2753. @kbd{tar --help} output to a man page, using @command{help2man}. In
  2754. any case, please bear in mind that the authoritative source of
  2755. information about @GNUTAR{} is this Texinfo documentation.
  2756. @node defaults
  2757. @section Obtaining @GNUTAR{} default values
  2758. @opindex show-defaults
  2759. @GNUTAR{} has some predefined defaults that are used when you do not
  2760. explicitly specify another values. To obtain a list of such
  2761. defaults, use @option{--show-defaults} option. This will output the
  2762. values in the form of @command{tar} command line options:
  2763. @smallexample
  2764. @group
  2765. @kbd{tar --show-defaults}
  2766. --format=gnu -f- -b20 --quoting-style=escape
  2767. --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
  2768. @end group
  2769. @end smallexample
  2770. @noindent
  2771. Notice, that this option outputs only one line. The example output above
  2772. has been split to fit page boundaries.
  2773. @noindent
  2774. The above output shows that this version of @GNUTAR{} defaults to
  2775. using @samp{gnu} archive format (@pxref{Formats}), it uses standard
  2776. output as the archive, if no @option{--file} option has been given
  2777. (@pxref{file tutorial}), the default blocking factor is 20
  2778. (@pxref{Blocking Factor}). It also shows the default locations where
  2779. @command{tar} will look for @command{rmt} and @command{rsh} binaries.
  2780. @node verbose
  2781. @section Checking @command{tar} progress
  2782. Typically, @command{tar} performs most operations without reporting any
  2783. information to the user except error messages. When using @command{tar}
  2784. with many options, particularly ones with complicated or
  2785. difficult-to-predict behavior, it is possible to make serious mistakes.
  2786. @command{tar} provides several options that make observing @command{tar}
  2787. easier. These options cause @command{tar} to print information as it
  2788. progresses in its job, and you might want to use them just for being
  2789. more careful about what is going on, or merely for entertaining
  2790. yourself. If you have encountered a problem when operating on an
  2791. archive, however, you may need more information than just an error
  2792. message in order to solve the problem. The following options can be
  2793. helpful diagnostic tools.
  2794. @cindex Verbose operation
  2795. @opindex verbose
  2796. Normally, the @option{--list} (@option{-t}) command to list an archive
  2797. prints just the file names (one per line) and the other commands are
  2798. silent. When used with most operations, the @option{--verbose}
  2799. (@option{-v}) option causes @command{tar} to print the name of each
  2800. file or archive member as it is processed. This and the other options
  2801. which make @command{tar} print status information can be useful in
  2802. monitoring @command{tar}.
  2803. With @option{--create} or @option{--extract}, @option{--verbose} used
  2804. once just prints the names of the files or members as they are processed.
  2805. Using it twice causes @command{tar} to print a longer listing
  2806. (@xref{verbose member listing}, for the description) for each member.
  2807. Since @option{--list} already prints the names of the members,
  2808. @option{--verbose} used once with @option{--list} causes @command{tar}
  2809. to print an @samp{ls -l} type listing of the files in the archive.
  2810. The following examples both extract members with long list output:
  2811. @smallexample
  2812. $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
  2813. $ @kbd{tar xvvf archive.tar}
  2814. @end smallexample
  2815. Verbose output appears on the standard output except when an archive is
  2816. being written to the standard output, as with @samp{tar --create
  2817. --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
  2818. installer let standard output be the default archive). In that case
  2819. @command{tar} writes verbose output to the standard error stream.
  2820. If @option{--index-file=@var{file}} is specified, @command{tar} sends
  2821. verbose output to @var{file} rather than to standard output or standard
  2822. error.
  2823. @anchor{totals}
  2824. @cindex Obtaining total status information
  2825. @opindex totals
  2826. The @option{--totals} option causes @command{tar} to print on the
  2827. standard error the total amount of bytes transferred when processing
  2828. an archive. When creating or appending to an archive, this option
  2829. prints the number of bytes written to the archive and the average
  2830. speed at which they have been written, e.g.:
  2831. @smallexample
  2832. @group
  2833. $ @kbd{tar -c -f archive.tar --totals /home}
  2834. Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
  2835. @end group
  2836. @end smallexample
  2837. When reading an archive, this option displays the number of bytes
  2838. read:
  2839. @smallexample
  2840. @group
  2841. $ @kbd{tar -x -f archive.tar --totals}
  2842. Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
  2843. @end group
  2844. @end smallexample
  2845. Finally, when deleting from an archive, the @option{--totals} option
  2846. displays both numbers plus number of bytes removed from the archive:
  2847. @smallexample
  2848. @group
  2849. $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
  2850. Total bytes read: 9543680 (9.2MiB, 201MiB/s)
  2851. Total bytes written: 3829760 (3.7MiB, 81MiB/s)
  2852. Total bytes deleted: 1474048
  2853. @end group
  2854. @end smallexample
  2855. You can also obtain this information on request. When
  2856. @option{--totals} is used with an argument, this argument is
  2857. interpreted as a symbolic name of a signal, upon delivery of which the
  2858. statistics is to be printed:
  2859. @table @option
  2860. @item --totals=@var{signo}
  2861. Print statistics upon delivery of signal @var{signo}. Valid arguments
  2862. are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
  2863. @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
  2864. accepted.
  2865. @end table
  2866. Both forms of @option{--totals} option can be used simultaneously.
  2867. Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
  2868. extract all members from its default archive and print statistics
  2869. after finishing the extraction, as well as when receiving signal
  2870. @code{SIGUSR1}.
  2871. @anchor{Progress information}
  2872. @cindex Progress information
  2873. The @option{--checkpoint} option prints an occasional message
  2874. as @command{tar} reads or writes the archive. It is designed for
  2875. those who don't need the more detailed (and voluminous) output of
  2876. @option{--block-number} (@option{-R}), but do want visual confirmation
  2877. that @command{tar} is actually making forward progress. By default it
  2878. prints a message each 10 records read or written. This can be changed
  2879. by giving it a numeric argument after an equal sign:
  2880. @smallexample
  2881. $ @kbd{tar -c --checkpoint=1000} /var
  2882. tar: Write checkpoint 1000
  2883. tar: Write checkpoint 2000
  2884. tar: Write checkpoint 3000
  2885. @end smallexample
  2886. This example shows the default checkpoint message used by
  2887. @command{tar}. If you place a dot immediately after the equal
  2888. sign, it will print a @samp{.} at each checkpoint@footnote{This is
  2889. actually a shortcut for @option{--checkpoint=@var{n}
  2890. --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
  2891. @smallexample
  2892. $ @kbd{tar -c --checkpoint=.1000} /var
  2893. ...
  2894. @end smallexample
  2895. The @option{--checkpoint} option provides a flexible mechanism for
  2896. executing arbitrary actions upon hitting checkpoints, see the next
  2897. section (@pxref{checkpoints}), for more information on it.
  2898. @opindex show-omitted-dirs
  2899. @anchor{show-omitted-dirs}
  2900. The @option{--show-omitted-dirs} option, when reading an archive---with
  2901. @option{--list} or @option{--extract}, for example---causes a message
  2902. to be printed for each directory in the archive which is skipped.
  2903. This happens regardless of the reason for skipping: the directory might
  2904. not have been named on the command line (implicitly or explicitly),
  2905. it might be excluded by the use of the
  2906. @option{--exclude=@var{pattern}} option, or some other reason.
  2907. @opindex block-number
  2908. @cindex Block number where error occurred
  2909. @anchor{block-number}
  2910. If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
  2911. every message it would normally produce, the block number within the
  2912. archive where the message was triggered. Also, supplementary messages
  2913. are triggered when reading blocks full of NULs, or when hitting end of
  2914. file on the archive. As of now, if the archive if properly terminated
  2915. with a NUL block, the reading of the file may stop before end of file
  2916. is met, so the position of end of file will not usually show when
  2917. @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
  2918. drains the archive before exiting when reading the
  2919. archive from a pipe.
  2920. @cindex Error message, block number of
  2921. This option is especially useful when reading damaged archives, since
  2922. it helps pinpoint the damaged sections. It can also be used with
  2923. @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
  2924. choose among several backup tapes when retrieving a file later, in
  2925. favor of the tape where the file appears earliest (closest to the
  2926. front of the tape). @xref{backup}.
  2927. @node checkpoints
  2928. @section Checkpoints
  2929. @cindex checkpoints, defined
  2930. @opindex checkpoint
  2931. @opindex checkpoint-action
  2932. A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
  2933. the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
  2934. from the archive (a @dfn{read checkpoint}). Checkpoints allow to
  2935. periodically execute arbitrary actions.
  2936. The checkpoint facility is enabled using the following option:
  2937. @table @option
  2938. @xopindex{checkpoint, defined}
  2939. @item --checkpoint[=@var{n}]
  2940. Schedule checkpoints before writing or reading each @var{n}th record.
  2941. The default value for @var{n} is 10.
  2942. @end table
  2943. A list of arbitrary @dfn{actions} can be executed at each checkpoint.
  2944. These actions include: pausing, displaying textual messages, and
  2945. executing arbitrary external programs. Actions are defined using
  2946. the @option{--checkpoint-action} option.
  2947. @table @option
  2948. @xopindex{checkpoint-action, defined}
  2949. @item --checkpoint-action=@var{action}
  2950. Execute an @var{action} at each checkpoint.
  2951. @end table
  2952. @cindex @code{echo}, checkpoint action
  2953. The simplest value of @var{action} is @samp{echo}. It instructs
  2954. @command{tar} to display the default message on the standard error
  2955. stream upon arriving at each checkpoint. The default message is (in
  2956. @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
  2957. checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
  2958. Here, @var{n} represents ordinal number of the checkpoint.
  2959. In another locales, translated versions of this message are used.
  2960. This is the default action, so running:
  2961. @smallexample
  2962. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
  2963. @end smallexample
  2964. @noindent
  2965. is equivalent to:
  2966. @smallexample
  2967. $ @kbd{tar -c --checkpoint=1000} /var
  2968. @end smallexample
  2969. The @samp{echo} action also allows to supply a customized message.
  2970. You do so by placing an equals sign and the message right after it,
  2971. e.g.:
  2972. @smallexample
  2973. --checkpoint-action="echo=Hit %s checkpoint #%u"
  2974. @end smallexample
  2975. The @samp{%s} and @samp{%u} in the above example are
  2976. @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
  2977. the @dfn{type} of the checkpoint: @samp{write} or
  2978. @samp{read} (or a corresponding translated version in locales other
  2979. than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
  2980. the ordinal number of the checkpoint. Thus, the above example could
  2981. produce the following output when used with the @option{--create}
  2982. option:
  2983. @smallexample
  2984. tar: Hit write checkpoint #10
  2985. tar: Hit write checkpoint #20
  2986. tar: Hit write checkpoint #30
  2987. @end smallexample
  2988. Aside from meta-character expansion, the message string is subject to
  2989. @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
  2990. replaced with their corresponding @acronym{ASCII} characters
  2991. (@pxref{escape sequences}). E.g. the following action will produce an
  2992. audible bell and the message described above at each checkpoint:
  2993. @smallexample
  2994. --checkpoint-action='echo=\aHit %s checkpoint #%u'
  2995. @end smallexample
  2996. @cindex @code{dot}, checkpoint action
  2997. Another available checkpoint action is @samp{dot} (or @samp{.}). It
  2998. instructs @command{tar} to print a single dot on the standard listing
  2999. stream, e.g.:
  3000. @smallexample
  3001. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
  3002. ...
  3003. @end smallexample
  3004. For compatibility with previous @GNUTAR{} versions, this action can
  3005. be abbreviated by placing a dot in front of the checkpoint frequency,
  3006. as shown in the previous section.
  3007. @cindex @code{sleep}, checkpoint action
  3008. Yet another action, @samp{sleep}, pauses @command{tar} for a specified
  3009. amount of seconds. The following example will stop for 30 seconds at each
  3010. checkpoint:
  3011. @smallexample
  3012. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
  3013. @end smallexample
  3014. @cindex @code{exec}, checkpoint action
  3015. Finally, the @code{exec} action executes a given external program.
  3016. For example:
  3017. @smallexample
  3018. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
  3019. @end smallexample
  3020. This program is executed using @command{/bin/sh -c}, with no
  3021. additional arguments. Its exit code is ignored. It gets a copy of
  3022. @command{tar}'s environment plus the following variables:
  3023. @table @env
  3024. @vrindex TAR_VERSION, checkpoint script environment
  3025. @item TAR_VERSION
  3026. @GNUTAR{} version number.
  3027. @vrindex TAR_ARCHIVE, checkpoint script environment
  3028. @item TAR_ARCHIVE
  3029. The name of the archive @command{tar} is processing.
  3030. @vrindex TAR_CHECKPOINT, checkpoint script environment
  3031. @item TAR_CHECKPOINT
  3032. The checkpoint number.
  3033. @vrindex TAR_SUBCOMMAND, checkpoint script environment
  3034. @item TAR_SUBCOMMAND
  3035. A short option describing the operation @command{tar} is executing
  3036. @xref{Operations}, for a complete list of subcommand options.
  3037. @vrindex TAR_FORMAT, checkpoint script environment
  3038. @item TAR_FORMAT
  3039. Format of the archive being processed. @xref{Formats}, for a complete
  3040. list of archive format names.
  3041. @end table
  3042. Any number of actions can be defined, by supplying several
  3043. @option{--checkpoint-action} options in the command line. For
  3044. example, the command below displays two messages, pauses
  3045. execution for 30 seconds and executes the @file{/sbin/cpoint} script:
  3046. @example
  3047. @group
  3048. $ @kbd{tar -c -f arc.tar \
  3049. --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
  3050. --checkpoint-action='echo=Sleeping for 30 seconds' \
  3051. --checkpoint-action='sleep=30' \
  3052. --checkpoint-action='exec=/sbin/cpoint'}
  3053. @end group
  3054. @end example
  3055. This example also illustrates the fact that
  3056. @option{--checkpoint-action} can be used without
  3057. @option{--checkpoint}. In this case, the default checkpoint frequency
  3058. (at each 10th record) is assumed.
  3059. @node interactive
  3060. @section Asking for Confirmation During Operations
  3061. @cindex Interactive operation
  3062. Typically, @command{tar} carries out a command without stopping for
  3063. further instructions. In some situations however, you may want to
  3064. exclude some files and archive members from the operation (for instance
  3065. if disk or storage space is tight). You can do this by excluding
  3066. certain files automatically (@pxref{Choosing}), or by performing
  3067. an operation interactively, using the @option{--interactive} (@option{-w}) option.
  3068. @command{tar} also accepts @option{--confirmation} for this option.
  3069. @opindex interactive
  3070. When the @option{--interactive} (@option{-w}) option is specified, before
  3071. reading, writing, or deleting files, @command{tar} first prints a message
  3072. for each such file, telling what operation it intends to take, then asks
  3073. for confirmation on the terminal. The actions which require
  3074. confirmation include adding a file to the archive, extracting a file
  3075. from the archive, deleting a file from the archive, and deleting a file
  3076. from disk. To confirm the action, you must type a line of input
  3077. beginning with @samp{y}. If your input line begins with anything other
  3078. than @samp{y}, @command{tar} skips that file.
  3079. If @command{tar} is reading the archive from the standard input,
  3080. @command{tar} opens the file @file{/dev/tty} to support the interactive
  3081. communications.
  3082. Verbose output is normally sent to standard output, separate from
  3083. other error messages. However, if the archive is produced directly
  3084. on standard output, then verbose output is mixed with errors on
  3085. @code{stderr}. Producing the archive on standard output may be used
  3086. as a way to avoid using disk space, when the archive is soon to be
  3087. consumed by another process reading it, say. Some people felt the need
  3088. of producing an archive on stdout, still willing to segregate between
  3089. verbose output and error output. A possible approach would be using a
  3090. named pipe to receive the archive, and having the consumer process to
  3091. read from that named pipe. This has the advantage of letting standard
  3092. output free to receive verbose output, all separate from errors.
  3093. @node operations
  3094. @chapter @GNUTAR{} Operations
  3095. @menu
  3096. * Basic tar::
  3097. * Advanced tar::
  3098. * create options::
  3099. * extract options::
  3100. * backup::
  3101. * Applications::
  3102. * looking ahead::
  3103. @end menu
  3104. @node Basic tar
  3105. @section Basic @GNUTAR{} Operations
  3106. The basic @command{tar} operations, @option{--create} (@option{-c}),
  3107. @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
  3108. @option{-x}), are currently presented and described in the tutorial
  3109. chapter of this manual. This section provides some complementary notes
  3110. for these operations.
  3111. @table @option
  3112. @xopindex{create, complementary notes}
  3113. @item --create
  3114. @itemx -c
  3115. Creating an empty archive would have some kind of elegance. One can
  3116. initialize an empty archive and later use @option{--append}
  3117. (@option{-r}) for adding all members. Some applications would not
  3118. welcome making an exception in the way of adding the first archive
  3119. member. On the other hand, many people reported that it is
  3120. dangerously too easy for @command{tar} to destroy a magnetic tape with
  3121. an empty archive@footnote{This is well described in @cite{Unix-haters
  3122. Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
  3123. Books, ISBN 1-56884-203-1.}. The two most common errors are:
  3124. @enumerate
  3125. @item
  3126. Mistakingly using @code{create} instead of @code{extract}, when the
  3127. intent was to extract the full contents of an archive. This error
  3128. is likely: keys @kbd{c} and @kbd{x} are right next to each other on
  3129. the QWERTY keyboard. Instead of being unpacked, the archive then
  3130. gets wholly destroyed. When users speak about @dfn{exploding} an
  3131. archive, they usually mean something else :-).
  3132. @item
  3133. Forgetting the argument to @code{file}, when the intent was to create
  3134. an archive with a single file in it. This error is likely because a
  3135. tired user can easily add the @kbd{f} key to the cluster of option
  3136. letters, by the mere force of habit, without realizing the full
  3137. consequence of doing so. The usual consequence is that the single
  3138. file, which was meant to be saved, is rather destroyed.
  3139. @end enumerate
  3140. So, recognizing the likelihood and the catastrophic nature of these
  3141. errors, @GNUTAR{} now takes some distance from elegance, and
  3142. cowardly refuses to create an archive when @option{--create} option is
  3143. given, there are no arguments besides options, and
  3144. @option{--files-from} (@option{-T}) option is @emph{not} used. To get
  3145. around the cautiousness of @GNUTAR{} and nevertheless create an
  3146. archive with nothing in it, one may still use, as the value for the
  3147. @option{--files-from} option, a file with no names in it, as shown in
  3148. the following commands:
  3149. @smallexample
  3150. @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
  3151. @kbd{tar cfT empty-archive.tar /dev/null}
  3152. @end smallexample
  3153. @xopindex{extract, complementary notes}
  3154. @item --extract
  3155. @itemx --get
  3156. @itemx -x
  3157. A socket is stored, within a @GNUTAR{} archive, as a pipe.
  3158. @item @option{--list} (@option{-t})
  3159. @GNUTAR{} now shows dates as @samp{1996-08-30},
  3160. while it used to show them as @samp{Aug 30 1996}. Preferably,
  3161. people should get used to ISO 8601 dates. Local American dates should
  3162. be made available again with full date localization support, once
  3163. ready. In the meantime, programs not being localizable for dates
  3164. should prefer international dates, that's really the way to go.
  3165. Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
  3166. are curious, it contains a detailed explanation of the ISO 8601 standard.
  3167. @end table
  3168. @node Advanced tar
  3169. @section Advanced @GNUTAR{} Operations
  3170. Now that you have learned the basics of using @GNUTAR{}, you may want
  3171. to learn about further ways in which @command{tar} can help you.
  3172. This chapter presents five, more advanced operations which you probably
  3173. won't use on a daily basis, but which serve more specialized functions.
  3174. We also explain the different styles of options and why you might want
  3175. to use one or another, or a combination of them in your @command{tar}
  3176. commands. Additionally, this chapter includes options which allow you to
  3177. define the output from @command{tar} more carefully, and provide help and
  3178. error correction in special circumstances.
  3179. @FIXME{check this after the chapter is actually revised to make sure
  3180. it still introduces the info in the chapter correctly : ).}
  3181. @menu
  3182. * Operations::
  3183. * append::
  3184. * update::
  3185. * concatenate::
  3186. * delete::
  3187. * compare::
  3188. @end menu
  3189. @node Operations
  3190. @subsection The Five Advanced @command{tar} Operations
  3191. @UNREVISED
  3192. In the last chapter, you learned about the first three operations to
  3193. @command{tar}. This chapter presents the remaining five operations to
  3194. @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
  3195. @option{--delete}, and @option{--compare}.
  3196. You are not likely to use these operations as frequently as those
  3197. covered in the last chapter; however, since they perform specialized
  3198. functions, they are quite useful when you do need to use them. We
  3199. will give examples using the same directory and files that you created
  3200. in the last chapter. As you may recall, the directory is called
  3201. @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
  3202. @samp{rock}, and the two archive files you created are
  3203. @samp{collection.tar} and @samp{music.tar}.
  3204. We will also use the archive files @samp{afiles.tar} and
  3205. @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
  3206. @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
  3207. @samp{./birds}, @samp{baboon}, and @samp{./box}.
  3208. Unless we state otherwise, all practicing you do and examples you follow
  3209. in this chapter will take place in the @file{practice} directory that
  3210. you created in the previous chapter; see @ref{prepare for examples}.
  3211. (Below in this section, we will remind you of the state of the examples
  3212. where the last chapter left them.)
  3213. The five operations that we will cover in this chapter are:
  3214. @table @option
  3215. @item --append
  3216. @itemx -r
  3217. Add new entries to an archive that already exists.
  3218. @item --update
  3219. @itemx -r
  3220. Add more recent copies of archive members to the end of an archive, if
  3221. they exist.
  3222. @item --concatenate
  3223. @itemx --catenate
  3224. @itemx -A
  3225. Add one or more pre-existing archives to the end of another archive.
  3226. @item --delete
  3227. Delete items from an archive (does not work on tapes).
  3228. @item --compare
  3229. @itemx --diff
  3230. @itemx -d
  3231. Compare archive members to their counterparts in the file system.
  3232. @end table
  3233. @node append
  3234. @subsection How to Add Files to Existing Archives: @option{--append}
  3235. @UNREVISED
  3236. @opindex append
  3237. If you want to add files to an existing archive, you don't need to
  3238. create a new archive; you can use @option{--append} (@option{-r}).
  3239. The archive must already exist in order to use @option{--append}. (A
  3240. related operation is the @option{--update} operation; you can use this
  3241. to add newer versions of archive members to an existing archive. To learn how to
  3242. do this with @option{--update}, @pxref{update}.)
  3243. If you use @option{--append} to add a file that has the same name as an
  3244. archive member to an archive containing that archive member, then the
  3245. old member is not deleted. What does happen, however, is somewhat
  3246. complex. @command{tar} @emph{allows} you to have infinite number of files
  3247. with the same name. Some operations treat these same-named members no
  3248. differently than any other set of archive members: for example, if you
  3249. view an archive with @option{--list} (@option{-t}), you will see all
  3250. of those members listed, with their data modification times, owners, etc.
  3251. Other operations don't deal with these members as perfectly as you might
  3252. prefer; if you were to use @option{--extract} to extract the archive,
  3253. only the most recently added copy of a member with the same name as four
  3254. other members would end up in the working directory. This is because
  3255. @option{--extract} extracts an archive in the order the members appeared
  3256. in the archive; the most recently archived members will be extracted
  3257. last. Additionally, an extracted member will @emph{replace} a file of
  3258. the same name which existed in the directory already, and @command{tar}
  3259. will not prompt you about this@footnote{Unless you give it
  3260. @option{--keep-old-files} option, or the disk copy is newer than the
  3261. the one in the archive and you invoke @command{tar} with
  3262. @option{--keep-newer-files} option}. Thus, only the most recently archived
  3263. member will end up being extracted, as it will replace the one
  3264. extracted before it, and so on.
  3265. There exists a special option that allows you to get around this
  3266. behavior and extract (or list) only a particular copy of the file.
  3267. This is @option{--occurrence} option. If you run @command{tar} with
  3268. this option, it will extract only the first copy of the file. You
  3269. may also give this option an argument specifying the number of
  3270. copy to be extracted. Thus, for example if the archive
  3271. @file{archive.tar} contained three copies of file @file{myfile}, then
  3272. the command
  3273. @smallexample
  3274. tar --extract --file archive.tar --occurrence=2 myfile
  3275. @end smallexample
  3276. @noindent
  3277. would extract only the second copy. @xref{Option
  3278. Summary,---occurrence}, for the description of @option{--occurrence}
  3279. option.
  3280. @FIXME{ hag -- you might want to incorporate some of the above into the
  3281. MMwtSN node; not sure. i didn't know how to make it simpler...
  3282. There are a few ways to get around this. (maybe xref Multiple Members
  3283. with the Same Name.}
  3284. @cindex Members, replacing with other members
  3285. @cindex Replacing members with other members
  3286. If you want to replace an archive member, use @option{--delete} to
  3287. delete the member you want to remove from the archive, , and then use
  3288. @option{--append} to add the member you want to be in the archive. Note
  3289. that you can not change the order of the archive; the most recently
  3290. added member will still appear last. In this sense, you cannot truly
  3291. ``replace'' one member with another. (Replacing one member with another
  3292. will not work on certain types of media, such as tapes; see @ref{delete}
  3293. and @ref{Media}, for more information.)
  3294. @menu
  3295. * appending files:: Appending Files to an Archive
  3296. * multiple::
  3297. @end menu
  3298. @node appending files
  3299. @subsubsection Appending Files to an Archive
  3300. @UNREVISED
  3301. @cindex Adding files to an Archive
  3302. @cindex Appending files to an Archive
  3303. @cindex Archives, Appending files to
  3304. The simplest way to add a file to an already existing archive is the
  3305. @option{--append} (@option{-r}) operation, which writes specified
  3306. files into the archive whether or not they are already among the
  3307. archived files.
  3308. When you use @option{--append}, you @emph{must} specify file name
  3309. arguments, as there is no default. If you specify a file that already
  3310. exists in the archive, another copy of the file will be added to the
  3311. end of the archive. As with other operations, the member names of the
  3312. newly added files will be exactly the same as their names given on the
  3313. command line. The @option{--verbose} (@option{-v}) option will print
  3314. out the names of the files as they are written into the archive.
  3315. @option{--append} cannot be performed on some tape drives, unfortunately,
  3316. due to deficiencies in the formats those tape drives use. The archive
  3317. must be a valid @command{tar} archive, or else the results of using this
  3318. operation will be unpredictable. @xref{Media}.
  3319. To demonstrate using @option{--append} to add a file to an archive,
  3320. create a file called @file{rock} in the @file{practice} directory.
  3321. Make sure you are in the @file{practice} directory. Then, run the
  3322. following @command{tar} command to add @file{rock} to
  3323. @file{collection.tar}:
  3324. @smallexample
  3325. $ @kbd{tar --append --file=collection.tar rock}
  3326. @end smallexample
  3327. @noindent
  3328. If you now use the @option{--list} (@option{-t}) operation, you will see that
  3329. @file{rock} has been added to the archive:
  3330. @smallexample
  3331. $ @kbd{tar --list --file=collection.tar}
  3332. -rw-r--r-- me user 28 1996-10-18 16:31 jazz
  3333. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  3334. -rw-r--r-- me user 20 1996-09-23 16:44 folk
  3335. -rw-r--r-- me user 20 1996-09-23 16:44 rock
  3336. @end smallexample
  3337. @node multiple
  3338. @subsubsection Multiple Members with the Same Name
  3339. You can use @option{--append} (@option{-r}) to add copies of files
  3340. which have been updated since the archive was created. (However, we
  3341. do not recommend doing this since there is another @command{tar}
  3342. option called @option{--update}; @xref{update}, for more information.
  3343. We describe this use of @option{--append} here for the sake of
  3344. completeness.) When you extract the archive, the older version will
  3345. be effectively lost. This works because files are extracted from an
  3346. archive in the order in which they were archived. Thus, when the
  3347. archive is extracted, a file archived later in time will replace a
  3348. file of the same name which was archived earlier, even though the
  3349. older version of the file will remain in the archive unless you delete
  3350. all versions of the file.
  3351. Supposing you change the file @file{blues} and then append the changed
  3352. version to @file{collection.tar}. As you saw above, the original
  3353. @file{blues} is in the archive @file{collection.tar}. If you change the
  3354. file and append the new version of the file to the archive, there will
  3355. be two copies in the archive. When you extract the archive, the older
  3356. version of the file will be extracted first, and then replaced by the
  3357. newer version when it is extracted.
  3358. You can append the new, changed copy of the file @file{blues} to the
  3359. archive in this way:
  3360. @smallexample
  3361. $ @kbd{tar --append --verbose --file=collection.tar blues}
  3362. blues
  3363. @end smallexample
  3364. @noindent
  3365. Because you specified the @option{--verbose} option, @command{tar} has
  3366. printed the name of the file being appended as it was acted on. Now
  3367. list the contents of the archive:
  3368. @smallexample
  3369. $ @kbd{tar --list --verbose --file=collection.tar}
  3370. -rw-r--r-- me user 28 1996-10-18 16:31 jazz
  3371. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  3372. -rw-r--r-- me user 20 1996-09-23 16:44 folk
  3373. -rw-r--r-- me user 20 1996-09-23 16:44 rock
  3374. -rw-r--r-- me user 58 1996-10-24 18:30 blues
  3375. @end smallexample
  3376. @noindent
  3377. The newest version of @file{blues} is now at the end of the archive
  3378. (note the different creation dates and file sizes). If you extract
  3379. the archive, the older version of the file @file{blues} will be
  3380. replaced by the newer version. You can confirm this by extracting
  3381. the archive and running @samp{ls} on the directory.
  3382. If you wish to extract the first occurrence of the file @file{blues}
  3383. from the archive, use @option{--occurrence} option, as shown in
  3384. the following example:
  3385. @smallexample
  3386. $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
  3387. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  3388. @end smallexample
  3389. @xref{Writing}, for more information on @option{--extract} and
  3390. @xref{Option Summary, --occurrence}, for the description of
  3391. @option{--occurrence} option.
  3392. @node update
  3393. @subsection Updating an Archive
  3394. @UNREVISED
  3395. @cindex Updating an archive
  3396. @opindex update
  3397. In the previous section, you learned how to use @option{--append} to
  3398. add a file to an existing archive. A related operation is
  3399. @option{--update} (@option{-u}). The @option{--update} operation
  3400. updates a @command{tar} archive by comparing the date of the specified
  3401. archive members against the date of the file with the same name. If
  3402. the file has been modified more recently than the archive member, then
  3403. the newer version of the file is added to the archive (as with
  3404. @option{--append}).
  3405. Unfortunately, you cannot use @option{--update} with magnetic tape drives.
  3406. The operation will fail.
  3407. @FIXME{other examples of media on which --update will fail? need to ask
  3408. charles and/or mib/thomas/dave shevett..}
  3409. Both @option{--update} and @option{--append} work by adding to the end
  3410. of the archive. When you extract a file from the archive, only the
  3411. version stored last will wind up in the file system, unless you use
  3412. the @option{--backup} option. @xref{multiple}, for a detailed discussion.
  3413. @menu
  3414. * how to update::
  3415. @end menu
  3416. @node how to update
  3417. @subsubsection How to Update an Archive Using @option{--update}
  3418. You must use file name arguments with the @option{--update}
  3419. (@option{-u}) operation. If you don't specify any files,
  3420. @command{tar} won't act on any files and won't tell you that it didn't
  3421. do anything (which may end up confusing you).
  3422. @c note: the above parenthetical added because in fact, this
  3423. @c behavior just confused the author. :-)
  3424. To see the @option{--update} option at work, create a new file,
  3425. @file{classical}, in your practice directory, and some extra text to the
  3426. file @file{blues}, using any text editor. Then invoke @command{tar} with
  3427. the @samp{update} operation and the @option{--verbose} (@option{-v})
  3428. option specified, using the names of all the files in the practice
  3429. directory as file name arguments:
  3430. @smallexample
  3431. $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
  3432. blues
  3433. classical
  3434. $
  3435. @end smallexample
  3436. @noindent
  3437. Because we have specified verbose mode, @command{tar} prints out the names
  3438. of the files it is working on, which in this case are the names of the
  3439. files that needed to be updated. If you run @samp{tar --list} and look
  3440. at the archive, you will see @file{blues} and @file{classical} at its
  3441. end. There will be a total of two versions of the member @samp{blues};
  3442. the one at the end will be newer and larger, since you added text before
  3443. updating it.
  3444. (The reason @command{tar} does not overwrite the older file when updating
  3445. it is because writing to the middle of a section of tape is a difficult
  3446. process. Tapes are not designed to go backward. @xref{Media}, for more
  3447. information about tapes.
  3448. @option{--update} (@option{-u}) is not suitable for performing backups for two
  3449. reasons: it does not change directory content entries, and it
  3450. lengthens the archive every time it is used. The @GNUTAR{}
  3451. options intended specifically for backups are more
  3452. efficient. If you need to run backups, please consult @ref{Backups}.
  3453. @node concatenate
  3454. @subsection Combining Archives with @option{--concatenate}
  3455. @cindex Adding archives to an archive
  3456. @cindex Concatenating Archives
  3457. @opindex concatenate
  3458. @opindex catenate
  3459. @c @cindex @option{-A} described
  3460. Sometimes it may be convenient to add a second archive onto the end of
  3461. an archive rather than adding individual files to the archive. To add
  3462. one or more archives to the end of another archive, you should use the
  3463. @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
  3464. To use @option{--concatenate}, give the first archive with
  3465. @option{--file} option and name the rest of archives to be
  3466. concatenated on the command line. The members, and their member
  3467. names, will be copied verbatim from those archives to the first one.
  3468. @footnote{This can cause multiple members to have the same name, for
  3469. information on how this affects reading the archive, @ref{multiple}.}
  3470. The new, concatenated archive will be called by the same name as the
  3471. one given with the @option{--file} option. As usual, if you omit
  3472. @option{--file}, @command{tar} will use the value of the environment
  3473. variable @env{TAPE}, or, if this has not been set, the default archive name.
  3474. @FIXME{There is no way to specify a new name...}
  3475. To demonstrate how @option{--concatenate} works, create two small archives
  3476. called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
  3477. files from @file{practice}:
  3478. @smallexample
  3479. $ @kbd{tar -cvf bluesrock.tar blues rock}
  3480. blues
  3481. rock
  3482. $ @kbd{tar -cvf folkjazz.tar folk jazz}
  3483. folk
  3484. jazz
  3485. @end smallexample
  3486. @noindent
  3487. If you like, You can run @samp{tar --list} to make sure the archives
  3488. contain what they are supposed to:
  3489. @smallexample
  3490. $ @kbd{tar -tvf bluesrock.tar}
  3491. -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
  3492. -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
  3493. $ @kbd{tar -tvf jazzfolk.tar}
  3494. -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
  3495. -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
  3496. @end smallexample
  3497. We can concatenate these two archives with @command{tar}:
  3498. @smallexample
  3499. $ @kbd{cd ..}
  3500. $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
  3501. @end smallexample
  3502. If you now list the contents of the @file{bluesrock.tar}, you will see
  3503. that now it also contains the archive members of @file{jazzfolk.tar}:
  3504. @smallexample
  3505. $ @kbd{tar --list --file=bluesrock.tar}
  3506. blues
  3507. rock
  3508. folk
  3509. jazz
  3510. @end smallexample
  3511. When you use @option{--concatenate}, the source and target archives must
  3512. already exist and must have been created using compatible format
  3513. parameters. Notice, that @command{tar} does not check whether the
  3514. archives it concatenates have compatible formats, it does not
  3515. even check if the files are really tar archives.
  3516. Like @option{--append} (@option{-r}), this operation cannot be performed on some
  3517. tape drives, due to deficiencies in the formats those tape drives use.
  3518. @cindex @code{concatenate} vs @command{cat}
  3519. @cindex @command{cat} vs @code{concatenate}
  3520. It may seem more intuitive to you to want or try to use @command{cat} to
  3521. concatenate two archives instead of using the @option{--concatenate}
  3522. operation; after all, @command{cat} is the utility for combining files.
  3523. However, @command{tar} archives incorporate an end-of-file marker which
  3524. must be removed if the concatenated archives are to be read properly as
  3525. one archive. @option{--concatenate} removes the end-of-archive marker
  3526. from the target archive before each new archive is appended. If you use
  3527. @command{cat} to combine the archives, the result will not be a valid
  3528. @command{tar} format archive. If you need to retrieve files from an
  3529. archive that was added to using the @command{cat} utility, use the
  3530. @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
  3531. information on dealing with archives improperly combined using the
  3532. @command{cat} shell utility.
  3533. @node delete
  3534. @subsection Removing Archive Members Using @option{--delete}
  3535. @UNREVISED
  3536. @cindex Deleting files from an archive
  3537. @cindex Removing files from an archive
  3538. @opindex delete
  3539. You can remove members from an archive by using the @option{--delete}
  3540. option. Specify the name of the archive with @option{--file}
  3541. (@option{-f}) and then specify the names of the members to be deleted;
  3542. if you list no member names, nothing will be deleted. The
  3543. @option{--verbose} option will cause @command{tar} to print the names
  3544. of the members as they are deleted. As with @option{--extract}, you
  3545. must give the exact member names when using @samp{tar --delete}.
  3546. @option{--delete} will remove all versions of the named file from the
  3547. archive. The @option{--delete} operation can run very slowly.
  3548. Unlike other operations, @option{--delete} has no short form.
  3549. @cindex Tapes, using @option{--delete} and
  3550. @cindex Deleting from tape archives
  3551. This operation will rewrite the archive. You can only use
  3552. @option{--delete} on an archive if the archive device allows you to
  3553. write to any point on the media, such as a disk; because of this, it
  3554. does not work on magnetic tapes. Do not try to delete an archive member
  3555. from a magnetic tape; the action will not succeed, and you will be
  3556. likely to scramble the archive and damage your tape. There is no safe
  3557. way (except by completely re-writing the archive) to delete files from
  3558. most kinds of magnetic tape. @xref{Media}.
  3559. To delete all versions of the file @file{blues} from the archive
  3560. @file{collection.tar} in the @file{practice} directory, make sure you
  3561. are in that directory, and then,
  3562. @smallexample
  3563. $ @kbd{tar --list --file=collection.tar}
  3564. blues
  3565. folk
  3566. jazz
  3567. rock
  3568. $ @kbd{tar --delete --file=collection.tar blues}
  3569. $ @kbd{tar --list --file=collection.tar}
  3570. folk
  3571. jazz
  3572. rock
  3573. $
  3574. @end smallexample
  3575. @FIXME{Check if the above listing is actually produced after running
  3576. all the examples on collection.tar.}
  3577. The @option{--delete} option has been reported to work properly when
  3578. @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
  3579. @node compare
  3580. @subsection Comparing Archive Members with the File System
  3581. @cindex Verifying the currency of an archive
  3582. @UNREVISED
  3583. @opindex compare
  3584. The @option{--compare} (@option{-d}), or @option{--diff} operation compares
  3585. specified archive members against files with the same names, and then
  3586. reports differences in file size, mode, owner, modification date and
  3587. contents. You should @emph{only} specify archive member names, not file
  3588. names. If you do not name any members, then @command{tar} will compare the
  3589. entire archive. If a file is represented in the archive but does not
  3590. exist in the file system, @command{tar} reports a difference.
  3591. You have to specify the record size of the archive when modifying an
  3592. archive with a non-default record size.
  3593. @command{tar} ignores files in the file system that do not have
  3594. corresponding members in the archive.
  3595. The following example compares the archive members @file{rock},
  3596. @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
  3597. files of the same name in the file system. (Note that there is no file,
  3598. @file{funk}; @command{tar} will report an error message.)
  3599. @smallexample
  3600. $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
  3601. rock
  3602. blues
  3603. tar: funk not found in archive
  3604. @end smallexample
  3605. The spirit behind the @option{--compare} (@option{--diff},
  3606. @option{-d}) option is to check whether the archive represents the
  3607. current state of files on disk, more than validating the integrity of
  3608. the archive media. For this later goal, @xref{verify}.
  3609. @node create options
  3610. @section Options Used by @option{--create}
  3611. @xopindex{create, additional options}
  3612. The previous chapter described the basics of how to use
  3613. @option{--create} (@option{-c}) to create an archive from a set of files.
  3614. @xref{create}. This section described advanced options to be used with
  3615. @option{--create}.
  3616. @menu
  3617. * override:: Overriding File Metadata.
  3618. * Ignore Failed Read::
  3619. @end menu
  3620. @node override
  3621. @subsection Overriding File Metadata
  3622. As described above, a @command{tar} archive keeps, for each member it contains,
  3623. its @dfn{metadata}, such as modification time, mode and ownership of
  3624. the file. @GNUTAR{} allows to replace these data with other values
  3625. when adding files to the archive. The options described in this
  3626. section affect creation of archives of any type. For POSIX archives,
  3627. see also @ref{PAX keywords}, for additional ways of controlling
  3628. metadata, stored in the archive.
  3629. @table @option
  3630. @opindex mode
  3631. @item --mode=@var{permissions}
  3632. When adding files to an archive, @command{tar} will use
  3633. @var{permissions} for the archive members, rather than the permissions
  3634. from the files. @var{permissions} can be specified either as an octal
  3635. number or as symbolic permissions, like with
  3636. @command{chmod} (@xref{File permissions, Permissions, File
  3637. permissions, fileutils, @acronym{GNU} file utilities}. This reference
  3638. also has useful information for those not being overly familiar with
  3639. the UNIX permission system). Using latter syntax allows for
  3640. more flexibility. For example, the value @samp{a+rw} adds read and write
  3641. permissions for everybody, while retaining executable bits on directories
  3642. or on any other file already marked as executable:
  3643. @smallexample
  3644. $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
  3645. @end smallexample
  3646. @item --mtime=@var{date}
  3647. @opindex mtime
  3648. When adding files to an archive, @command{tar} will use @var{date} as
  3649. the modification time of members when creating archives, instead of
  3650. their actual modification times. The argument @var{date} can be
  3651. either a textual date representation in almost arbitrary format
  3652. (@pxref{Date input formats}) or a name of the existing file, starting
  3653. with @samp{/} or @samp{.}. In the latter case, the modification time
  3654. of that file will be used.
  3655. The following example will set the modification date to 00:00:00 UTC,
  3656. January 1, 1970:
  3657. @smallexample
  3658. $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
  3659. @end smallexample
  3660. @noindent
  3661. When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
  3662. will try to convert the specified date back to its textual
  3663. representation and compare it with the one given with
  3664. @option{--mtime} options. If the two dates differ, @command{tar} will
  3665. print a warning saying what date it will use. This is to help user
  3666. ensure he is using the right date.
  3667. For example:
  3668. @smallexample
  3669. $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
  3670. tar: Option --mtime: Treating date `yesterday' as 2006-06-20
  3671. 13:06:29.152478
  3672. @dots{}
  3673. @end smallexample
  3674. @item --owner=@var{user}
  3675. @opindex owner
  3676. Specifies that @command{tar} should use @var{user} as the owner of members
  3677. when creating archives, instead of the user associated with the source
  3678. file. The argument @var{user} can be either an existing user symbolic
  3679. name, or a decimal numeric user @acronym{ID}.
  3680. There is no value indicating a missing number, and @samp{0} usually means
  3681. @code{root}. Some people like to force @samp{0} as the value to offer in
  3682. their distributions for the owner of files, because the @code{root} user is
  3683. anonymous anyway, so that might as well be the owner of anonymous
  3684. archives. For example:
  3685. @smallexample
  3686. @group
  3687. $ @kbd{tar -c -f archive.tar --owner=0 .}
  3688. # @r{Or:}
  3689. $ @kbd{tar -c -f archive.tar --owner=root .}
  3690. @end group
  3691. @end smallexample
  3692. @item --group=@var{group}
  3693. @opindex group
  3694. Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
  3695. rather than the group from the source file. The argument @var{group}
  3696. can be either an existing group symbolic name, or a decimal numeric group @acronym{ID}.
  3697. @end table
  3698. @node Ignore Failed Read
  3699. @subsection Ignore Fail Read
  3700. @table @option
  3701. @item --ignore-failed-read
  3702. @opindex ignore-failed-read
  3703. Do not exit with nonzero on unreadable files or directories.
  3704. @end table
  3705. @node extract options
  3706. @section Options Used by @option{--extract}
  3707. @UNREVISED
  3708. @xopindex{extract, additional options}
  3709. The previous chapter showed how to use @option{--extract} to extract
  3710. an archive into the file system. Various options cause @command{tar} to
  3711. extract more information than just file contents, such as the owner,
  3712. the permissions, the modification date, and so forth. This section
  3713. presents options to be used with @option{--extract} when certain special
  3714. considerations arise. You may review the information presented in
  3715. @ref{extract} for more basic information about the
  3716. @option{--extract} operation.
  3717. @menu
  3718. * Reading:: Options to Help Read Archives
  3719. * Writing:: Changing How @command{tar} Writes Files
  3720. * Scarce:: Coping with Scarce Resources
  3721. @end menu
  3722. @node Reading
  3723. @subsection Options to Help Read Archives
  3724. @cindex Options when reading archives
  3725. @UNREVISED
  3726. @cindex Reading incomplete records
  3727. @cindex Records, incomplete
  3728. @opindex read-full-records
  3729. Normally, @command{tar} will request data in full record increments from
  3730. an archive storage device. If the device cannot return a full record,
  3731. @command{tar} will report an error. However, some devices do not always
  3732. return full records, or do not require the last record of an archive to
  3733. be padded out to the next record boundary. To keep reading until you
  3734. obtain a full record, or to accept an incomplete record if it contains
  3735. an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
  3736. in conjunction with the @option{--extract} or @option{--list} operations.
  3737. @xref{Blocking}.
  3738. The @option{--read-full-records} (@option{-B}) option is turned on by default when
  3739. @command{tar} reads an archive from standard input, or from a remote
  3740. machine. This is because on @acronym{BSD} Unix systems, attempting to read a
  3741. pipe returns however much happens to be in the pipe, even if it is
  3742. less than was requested. If this option were not enabled, @command{tar}
  3743. would fail as soon as it read an incomplete record from the pipe.
  3744. If you're not sure of the blocking factor of an archive, you can
  3745. read the archive by specifying @option{--read-full-records} (@option{-B}) and
  3746. @option{--blocking-factor=@var{512-size}} (@option{-b
  3747. @var{512-size}}), using a blocking factor larger than what the archive
  3748. uses. This lets you avoid having to determine the blocking factor
  3749. of an archive. @xref{Blocking Factor}.
  3750. @menu
  3751. * read full records::
  3752. * Ignore Zeros::
  3753. @end menu
  3754. @node read full records
  3755. @unnumberedsubsubsec Reading Full Records
  3756. @FIXME{need sentence or so of intro here}
  3757. @table @option
  3758. @opindex read-full-records
  3759. @item --read-full-records
  3760. @item -B
  3761. Use in conjunction with @option{--extract} (@option{--get},
  3762. @option{-x}) to read an archive which contains incomplete records, or
  3763. one which has a blocking factor less than the one specified.
  3764. @end table
  3765. @node Ignore Zeros
  3766. @unnumberedsubsubsec Ignoring Blocks of Zeros
  3767. @cindex End-of-archive blocks, ignoring
  3768. @cindex Ignoring end-of-archive blocks
  3769. @opindex ignore-zeros
  3770. Normally, @command{tar} stops reading when it encounters a block of zeros
  3771. between file entries (which usually indicates the end of the archive).
  3772. @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
  3773. completely read an archive which contains a block of zeros before the
  3774. end (i.e., a damaged archive, or one that was created by concatenating
  3775. several archives together).
  3776. The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
  3777. versions of @command{tar} write garbage after the end-of-archive entry,
  3778. since that part of the media is never supposed to be read. @GNUTAR{}
  3779. does not write after the end of an archive, but seeks to
  3780. maintain compatibility among archiving utilities.
  3781. @table @option
  3782. @item --ignore-zeros
  3783. @itemx -i
  3784. To ignore blocks of zeros (i.e., end-of-archive entries) which may be
  3785. encountered while reading an archive. Use in conjunction with
  3786. @option{--extract} or @option{--list}.
  3787. @end table
  3788. @node Writing
  3789. @subsection Changing How @command{tar} Writes Files
  3790. @UNREVISED
  3791. @FIXME{Introductory paragraph}
  3792. @menu
  3793. * Dealing with Old Files::
  3794. * Overwrite Old Files::
  3795. * Keep Old Files::
  3796. * Keep Newer Files::
  3797. * Unlink First::
  3798. * Recursive Unlink::
  3799. * Data Modification Times::
  3800. * Setting Access Permissions::
  3801. * Directory Modification Times and Permissions::
  3802. * Writing to Standard Output::
  3803. * Writing to an External Program::
  3804. * remove files::
  3805. @end menu
  3806. @node Dealing with Old Files
  3807. @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
  3808. @xopindex{overwrite-dir, introduced}
  3809. When extracting files, if @command{tar} discovers that the extracted
  3810. file already exists, it normally replaces the file by removing it before
  3811. extracting it, to prevent confusion in the presence of hard or symbolic
  3812. links. (If the existing file is a symbolic link, it is removed, not
  3813. followed.) However, if a directory cannot be removed because it is
  3814. nonempty, @command{tar} normally overwrites its metadata (ownership,
  3815. permission, etc.). The @option{--overwrite-dir} option enables this
  3816. default behavior. To be more cautious and preserve the metadata of
  3817. such a directory, use the @option{--no-overwrite-dir} option.
  3818. @cindex Overwriting old files, prevention
  3819. @xopindex{keep-old-files, introduced}
  3820. To be even more cautious and prevent existing files from being replaced, use
  3821. the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
  3822. to replace or update a file that already exists, i.e., a file with the
  3823. same name as an archive member prevents extraction of that archive
  3824. member. Instead, it reports an error.
  3825. @xopindex{overwrite, introduced}
  3826. To be more aggressive about altering existing files, use the
  3827. @option{--overwrite} option. It causes @command{tar} to overwrite
  3828. existing files and to follow existing symbolic links when extracting.
  3829. @cindex Protecting old files
  3830. Some people argue that @GNUTAR{} should not hesitate
  3831. to overwrite files with other files when extracting. When extracting
  3832. a @command{tar} archive, they expect to see a faithful copy of the
  3833. state of the file system when the archive was created. It is debatable
  3834. that this would always be a proper behavior. For example, suppose one
  3835. has an archive in which @file{usr/local} is a link to
  3836. @file{usr/local2}. Since then, maybe the site removed the link and
  3837. renamed the whole hierarchy from @file{/usr/local2} to
  3838. @file{/usr/local}. Such things happen all the time. I guess it would
  3839. not be welcome at all that @GNUTAR{} removes the
  3840. whole hierarchy just to make room for the link to be reinstated
  3841. (unless it @emph{also} simultaneously restores the full
  3842. @file{/usr/local2}, of course!) @GNUTAR{} is indeed
  3843. able to remove a whole hierarchy to reestablish a symbolic link, for
  3844. example, but @emph{only if} @option{--recursive-unlink} is specified
  3845. to allow this behavior. In any case, single files are silently
  3846. removed.
  3847. @xopindex{unlink-first, introduced}
  3848. Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
  3849. some cases by causing @command{tar} to remove files unconditionally
  3850. before extracting them.
  3851. @node Overwrite Old Files
  3852. @unnumberedsubsubsec Overwrite Old Files
  3853. @table @option
  3854. @opindex overwrite
  3855. @item --overwrite
  3856. Overwrite existing files and directory metadata when extracting files
  3857. from an archive.
  3858. This causes @command{tar} to write extracted files into the file system without
  3859. regard to the files already on the system; i.e., files with the same
  3860. names as archive members are overwritten when the archive is extracted.
  3861. It also causes @command{tar} to extract the ownership, permissions,
  3862. and time stamps onto any preexisting files or directories.
  3863. If the name of a corresponding file name is a symbolic link, the file
  3864. pointed to by the symbolic link will be overwritten instead of the
  3865. symbolic link itself (if this is possible). Moreover, special devices,
  3866. empty directories and even symbolic links are automatically removed if
  3867. they are in the way of extraction.
  3868. Be careful when using the @option{--overwrite} option, particularly when
  3869. combined with the @option{--absolute-names} (@option{-P}) option, as this combination
  3870. can change the contents, ownership or permissions of any file on your
  3871. system. Also, many systems do not take kindly to overwriting files that
  3872. are currently being executed.
  3873. @opindex overwrite-dir
  3874. @item --overwrite-dir
  3875. Overwrite the metadata of directories when extracting files from an
  3876. archive, but remove other files before extracting.
  3877. @end table
  3878. @node Keep Old Files
  3879. @unnumberedsubsubsec Keep Old Files
  3880. @table @option
  3881. @opindex keep-old-files
  3882. @item --keep-old-files
  3883. @itemx -k
  3884. Do not replace existing files from archive. The
  3885. @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
  3886. from replacing existing files with files with the same name from the
  3887. archive. The @option{--keep-old-files} option is meaningless with
  3888. @option{--list} (@option{-t}). Prevents @command{tar} from replacing
  3889. files in the file system during extraction.
  3890. @end table
  3891. @node Keep Newer Files
  3892. @unnumberedsubsubsec Keep Newer Files
  3893. @table @option
  3894. @opindex keep-newer-files
  3895. @item --keep-newer-files
  3896. Do not replace existing files that are newer than their archive
  3897. copies. This option is meaningless with @option{--list} (@option{-t}).
  3898. @end table
  3899. @node Unlink First
  3900. @unnumberedsubsubsec Unlink First
  3901. @table @option
  3902. @opindex unlink-first
  3903. @item --unlink-first
  3904. @itemx -U
  3905. Remove files before extracting over them.
  3906. This can make @command{tar} run a bit faster if you know in advance
  3907. that the extracted files all need to be removed. Normally this option
  3908. slows @command{tar} down slightly, so it is disabled by default.
  3909. @end table
  3910. @node Recursive Unlink
  3911. @unnumberedsubsubsec Recursive Unlink
  3912. @table @option
  3913. @opindex recursive-unlink
  3914. @item --recursive-unlink
  3915. When this option is specified, try removing files and directory hierarchies
  3916. before extracting over them. @emph{This is a dangerous option!}
  3917. @end table
  3918. If you specify the @option{--recursive-unlink} option,
  3919. @command{tar} removes @emph{anything} that keeps you from extracting a file
  3920. as far as current permissions will allow it. This could include removal
  3921. of the contents of a full directory hierarchy.
  3922. @node Data Modification Times
  3923. @unnumberedsubsubsec Setting Data Modification Times
  3924. @cindex Data modification times of extracted files
  3925. @cindex Modification times of extracted files
  3926. Normally, @command{tar} sets the data modification times of extracted
  3927. files to the corresponding times recorded for the files in the archive, but
  3928. limits the permissions of extracted files by the current @code{umask}
  3929. setting.
  3930. To set the data modification times of extracted files to the time when
  3931. the files were extracted, use the @option{--touch} (@option{-m}) option in
  3932. conjunction with @option{--extract} (@option{--get}, @option{-x}).
  3933. @table @option
  3934. @opindex touch
  3935. @item --touch
  3936. @itemx -m
  3937. Sets the data modification time of extracted archive members to the time
  3938. they were extracted, not the time recorded for them in the archive.
  3939. Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
  3940. @end table
  3941. @node Setting Access Permissions
  3942. @unnumberedsubsubsec Setting Access Permissions
  3943. @cindex Permissions of extracted files
  3944. @cindex Modes of extracted files
  3945. To set the modes (access permissions) of extracted files to those
  3946. recorded for those files in the archive, use @option{--same-permissions}
  3947. in conjunction with the @option{--extract} (@option{--get},
  3948. @option{-x}) operation.
  3949. @table @option
  3950. @opindex preserve-permissions
  3951. @opindex same-permissions
  3952. @item --preserve-permissions
  3953. @itemx --same-permissions
  3954. @c @itemx --ignore-umask
  3955. @itemx -p
  3956. Set modes of extracted archive members to those recorded in the
  3957. archive, instead of current umask settings. Use in conjunction with
  3958. @option{--extract} (@option{--get}, @option{-x}).
  3959. @end table
  3960. @node Directory Modification Times and Permissions
  3961. @unnumberedsubsubsec Directory Modification Times and Permissions
  3962. After successfully extracting a file member, @GNUTAR{} normally
  3963. restores its permissions and modification times, as described in the
  3964. previous sections. This cannot be done for directories, because
  3965. after extracting a directory @command{tar} will almost certainly
  3966. extract files into that directory and this will cause the directory
  3967. modification time to be updated. Moreover, restoring that directory
  3968. permissions may not permit file creation within it. Thus, restoring
  3969. directory permissions and modification times must be delayed at least
  3970. until all files have been extracted into that directory. @GNUTAR{}
  3971. restores directories using the following approach.
  3972. The extracted directories are created with the mode specified in the
  3973. archive, as modified by the umask of the user, which gives sufficient
  3974. permissions to allow file creation. The meta-information about the
  3975. directory is recorded in the temporary list of directories. When
  3976. preparing to extract next archive member, @GNUTAR{} checks if the
  3977. directory prefix of this file contains the remembered directory. If
  3978. it does not, the program assumes that all files have been extracted
  3979. into that directory, restores its modification time and permissions
  3980. and removes its entry from the internal list. This approach allows
  3981. to correctly restore directory meta-information in the majority of
  3982. cases, while keeping memory requirements sufficiently small. It is
  3983. based on the fact, that most @command{tar} archives use the predefined
  3984. order of members: first the directory, then all the files and
  3985. subdirectories in that directory.
  3986. However, this is not always true. The most important exception are
  3987. incremental archives (@pxref{Incremental Dumps}). The member order in
  3988. an incremental archive is reversed: first all directory members are
  3989. stored, followed by other (non-directory) members. So, when extracting
  3990. from incremental archives, @GNUTAR{} alters the above procedure. It
  3991. remembers all restored directories, and restores their meta-data
  3992. only after the entire archive has been processed. Notice, that you do
  3993. not need to specify any special options for that, as @GNUTAR{}
  3994. automatically detects archives in incremental format.
  3995. There may be cases, when such processing is required for normal archives
  3996. too. Consider the following example:
  3997. @smallexample
  3998. @group
  3999. $ @kbd{tar --no-recursion -cvf archive \
  4000. foo foo/file1 bar bar/file foo/file2}
  4001. foo/
  4002. foo/file1
  4003. bar/
  4004. bar/file
  4005. foo/file2
  4006. @end group
  4007. @end smallexample
  4008. During the normal operation, after encountering @file{bar}
  4009. @GNUTAR{} will assume that all files from the directory @file{foo}
  4010. were already extracted and will therefore restore its timestamp and
  4011. permission bits. However, after extracting @file{foo/file2} the
  4012. directory timestamp will be offset again.
  4013. To correctly restore directory meta-information in such cases, use
  4014. @option{delay-directory-restore} command line option:
  4015. @table @option
  4016. @opindex delay-directory-restore
  4017. @item --delay-directory-restore
  4018. Delays restoring of the modification times and permissions of extracted
  4019. directories until the end of extraction. This way, correct
  4020. meta-information is restored even if the archive has unusual member
  4021. ordering.
  4022. @opindex no-delay-directory-restore
  4023. @item --no-delay-directory-restore
  4024. Cancel the effect of the previous @option{--delay-directory-restore}.
  4025. Use this option if you have used @option{--delay-directory-restore} in
  4026. @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
  4027. temporarily disable it.
  4028. @end table
  4029. @node Writing to Standard Output
  4030. @unnumberedsubsubsec Writing to Standard Output
  4031. @cindex Writing extracted files to standard output
  4032. @cindex Standard output, writing extracted files to
  4033. To write the extracted files to the standard output, instead of
  4034. creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
  4035. conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
  4036. extracting files to send them through a pipe, and do not need to
  4037. preserve them in the file system. If you extract multiple members,
  4038. they appear on standard output concatenated, in the order they are
  4039. found in the archive.
  4040. @table @option
  4041. @opindex to-stdout
  4042. @item --to-stdout
  4043. @itemx -O
  4044. Writes files to the standard output. Use only in conjunction with
  4045. @option{--extract} (@option{--get}, @option{-x}). When this option is
  4046. used, instead of creating the files specified, @command{tar} writes
  4047. the contents of the files extracted to its standard output. This may
  4048. be useful if you are only extracting the files in order to send them
  4049. through a pipe. This option is meaningless with @option{--list}
  4050. (@option{-t}).
  4051. @end table
  4052. This can be useful, for example, if you have a tar archive containing
  4053. a big file and don't want to store the file on disk before processing
  4054. it. You can use a command like this:
  4055. @smallexample
  4056. tar -xOzf foo.tgz bigfile | process
  4057. @end smallexample
  4058. or even like this if you want to process the concatenation of the files:
  4059. @smallexample
  4060. tar -xOzf foo.tgz bigfile1 bigfile2 | process
  4061. @end smallexample
  4062. However, @option{--to-command} may be more convenient for use with
  4063. multiple files. See the next section.
  4064. @node Writing to an External Program
  4065. @unnumberedsubsubsec Writing to an External Program
  4066. You can instruct @command{tar} to send the contents of each extracted
  4067. file to the standard input of an external program:
  4068. @table @option
  4069. @opindex to-command
  4070. @item --to-command=@var{command}
  4071. Extract files and pipe their contents to the standard input of
  4072. @var{command}. When this option is used, instead of creating the
  4073. files specified, @command{tar} invokes @var{command} and pipes the
  4074. contents of the files to its standard output. @var{Command} may
  4075. contain command line arguments. The program is executed via
  4076. @code{sh -c}. Notice, that @var{command} is executed once for each regular file
  4077. extracted. Non-regular files (directories, etc.) are ignored when this
  4078. option is used.
  4079. @end table
  4080. The command can obtain the information about the file it processes
  4081. from the following environment variables:
  4082. @table @env
  4083. @vrindex TAR_FILETYPE, to-command environment
  4084. @item TAR_FILETYPE
  4085. Type of the file. It is a single letter with the following meaning:
  4086. @multitable @columnfractions 0.10 0.90
  4087. @item f @tab Regular file
  4088. @item d @tab Directory
  4089. @item l @tab Symbolic link
  4090. @item h @tab Hard link
  4091. @item b @tab Block device
  4092. @item c @tab Character device
  4093. @end multitable
  4094. Currently only regular files are supported.
  4095. @vrindex TAR_MODE, to-command environment
  4096. @item TAR_MODE
  4097. File mode, an octal number.
  4098. @vrindex TAR_FILENAME, to-command environment
  4099. @item TAR_FILENAME
  4100. The name of the file.
  4101. @vrindex TAR_REALNAME, to-command environment
  4102. @item TAR_REALNAME
  4103. Name of the file as stored in the archive.
  4104. @vrindex TAR_UNAME, to-command environment
  4105. @item TAR_UNAME
  4106. Name of the file owner.
  4107. @vrindex TAR_GNAME, to-command environment
  4108. @item TAR_GNAME
  4109. Name of the file owner group.
  4110. @vrindex TAR_ATIME, to-command environment
  4111. @item TAR_ATIME
  4112. Time of last access. It is a decimal number, representing seconds
  4113. since the epoch. If the archive provides times with nanosecond
  4114. precision, the nanoseconds are appended to the timestamp after a
  4115. decimal point.
  4116. @vrindex TAR_MTIME, to-command environment
  4117. @item TAR_MTIME
  4118. Time of last modification.
  4119. @vrindex TAR_CTIME, to-command environment
  4120. @item TAR_CTIME
  4121. Time of last status change.
  4122. @vrindex TAR_SIZE, to-command environment
  4123. @item TAR_SIZE
  4124. Size of the file.
  4125. @vrindex TAR_UID, to-command environment
  4126. @item TAR_UID
  4127. UID of the file owner.
  4128. @vrindex TAR_GID, to-command environment
  4129. @item TAR_GID
  4130. GID of the file owner.
  4131. @end table
  4132. In addition to these variables, @env{TAR_VERSION} contains the
  4133. @GNUTAR{} version number.
  4134. If @var{command} exits with a non-0 status, @command{tar} will print
  4135. an error message similar to the following:
  4136. @smallexample
  4137. tar: 2345: Child returned status 1
  4138. @end smallexample
  4139. Here, @samp{2345} is the PID of the finished process.
  4140. If this behavior is not wanted, use @option{--ignore-command-error}:
  4141. @table @option
  4142. @opindex ignore-command-error
  4143. @item --ignore-command-error
  4144. Ignore exit codes of subprocesses. Notice that if the program
  4145. exits on signal or otherwise terminates abnormally, the error message
  4146. will be printed even if this option is used.
  4147. @opindex no-ignore-command-error
  4148. @item --no-ignore-command-error
  4149. Cancel the effect of any previous @option{--ignore-command-error}
  4150. option. This option is useful if you have set
  4151. @option{--ignore-command-error} in @env{TAR_OPTIONS}
  4152. (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
  4153. @end table
  4154. @node remove files
  4155. @unnumberedsubsubsec Removing Files
  4156. @FIXME{The section is too terse. Something more to add? An example,
  4157. maybe?}
  4158. @table @option
  4159. @opindex remove-files
  4160. @item --remove-files
  4161. Remove files after adding them to the archive.
  4162. @end table
  4163. @node Scarce
  4164. @subsection Coping with Scarce Resources
  4165. @UNREVISED
  4166. @cindex Small memory
  4167. @cindex Running out of space
  4168. @menu
  4169. * Starting File::
  4170. * Same Order::
  4171. @end menu
  4172. @node Starting File
  4173. @unnumberedsubsubsec Starting File
  4174. @table @option
  4175. @opindex starting-file
  4176. @item --starting-file=@var{name}
  4177. @itemx -K @var{name}
  4178. Starts an operation in the middle of an archive. Use in conjunction
  4179. with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
  4180. @end table
  4181. @cindex Middle of the archive, starting in the
  4182. If a previous attempt to extract files failed due to lack of disk
  4183. space, you can use @option{--starting-file=@var{name}} (@option{-K
  4184. @var{name}}) to start extracting only after member @var{name} of the
  4185. archive. This assumes, of course, that there is now free space, or
  4186. that you are now extracting into a different file system. (You could
  4187. also choose to suspend @command{tar}, remove unnecessary files from
  4188. the file system, and then restart the same @command{tar} operation.
  4189. In this case, @option{--starting-file} is not necessary.
  4190. @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
  4191. @node Same Order
  4192. @unnumberedsubsubsec Same Order
  4193. @table @option
  4194. @cindex Large lists of file names on small machines
  4195. @opindex same-order
  4196. @opindex preserve-order
  4197. @item --same-order
  4198. @itemx --preserve-order
  4199. @itemx -s
  4200. To process large lists of file names on machines with small amounts of
  4201. memory. Use in conjunction with @option{--compare} (@option{--diff},
  4202. @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
  4203. (@option{--get}, @option{-x}).
  4204. @end table
  4205. The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
  4206. names to be listed or extracted is sorted in the same order as the
  4207. files in the archive. This allows a large list of names to be used,
  4208. even on a small machine that would not otherwise be able to hold all
  4209. the names in memory at the same time. Such a sorted list can easily be
  4210. created by running @samp{tar -t} on the archive and editing its output.
  4211. This option is probably never needed on modern computer systems.
  4212. @node backup
  4213. @section Backup options
  4214. @cindex backup options
  4215. @GNUTAR{} offers options for making backups of files
  4216. before writing new versions. These options control the details of
  4217. these backups. They may apply to the archive itself before it is
  4218. created or rewritten, as well as individual extracted members. Other
  4219. @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
  4220. and @command{mv}, for example) offer similar options.
  4221. Backup options may prove unexpectedly useful when extracting archives
  4222. containing many members having identical name, or when extracting archives
  4223. on systems having file name limitations, making different members appear
  4224. has having similar names through the side-effect of name truncation.
  4225. (This is true only if we have a good scheme for truncated backup names,
  4226. which I'm not sure at all: I suspect work is needed in this area.)
  4227. When any existing file is backed up before being overwritten by extraction,
  4228. then clashing files are automatically be renamed to be unique, and the
  4229. true name is kept for only the last file of a series of clashing files.
  4230. By using verbose mode, users may track exactly what happens.
  4231. At the detail level, some decisions are still experimental, and may
  4232. change in the future, we are waiting comments from our users. So, please
  4233. do not learn to depend blindly on the details of the backup features.
  4234. For example, currently, directories themselves are never renamed through
  4235. using these options, so, extracting a file over a directory still has
  4236. good chances to fail. Also, backup options apply to created archives,
  4237. not only to extracted members. For created archives, backups will not
  4238. be attempted when the archive is a block or character device, or when it
  4239. refers to a remote file.
  4240. For the sake of simplicity and efficiency, backups are made by renaming old
  4241. files prior to creation or extraction, and not by copying. The original
  4242. name is restored if the file creation fails. If a failure occurs after a
  4243. partial extraction of a file, both the backup and the partially extracted
  4244. file are kept.
  4245. @table @samp
  4246. @item --backup[=@var{method}]
  4247. @opindex backup
  4248. @vindex VERSION_CONTROL
  4249. @cindex backups
  4250. Back up files that are about to be overwritten or removed.
  4251. Without this option, the original versions are destroyed.
  4252. Use @var{method} to determine the type of backups made.
  4253. If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
  4254. environment variable. And if @env{VERSION_CONTROL} is not set,
  4255. use the @samp{existing} method.
  4256. @vindex version-control @r{Emacs variable}
  4257. This option corresponds to the Emacs variable @samp{version-control};
  4258. the same values for @var{method} are accepted as in Emacs. This option
  4259. also allows more descriptive names. The valid @var{method}s are:
  4260. @table @samp
  4261. @item t
  4262. @itemx numbered
  4263. @cindex numbered @r{backup method}
  4264. Always make numbered backups.
  4265. @item nil
  4266. @itemx existing
  4267. @cindex existing @r{backup method}
  4268. Make numbered backups of files that already have them, simple backups
  4269. of the others.
  4270. @item never
  4271. @itemx simple
  4272. @cindex simple @r{backup method}
  4273. Always make simple backups.
  4274. @end table
  4275. @item --suffix=@var{suffix}
  4276. @opindex suffix
  4277. @cindex backup suffix
  4278. @vindex SIMPLE_BACKUP_SUFFIX
  4279. Append @var{suffix} to each backup file made with @option{--backup}. If this
  4280. option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
  4281. environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
  4282. set, the default is @samp{~}, just as in Emacs.
  4283. @end table
  4284. @node Applications
  4285. @section Notable @command{tar} Usages
  4286. @UNREVISED
  4287. @FIXME{Using Unix file linking capability to recreate directory
  4288. structures---linking files into one subdirectory and then
  4289. @command{tar}ring that directory.}
  4290. @FIXME{Nice hairy example using absolute-names, newer, etc.}
  4291. @findex uuencode
  4292. You can easily use archive files to transport a group of files from
  4293. one system to another: put all relevant files into an archive on one
  4294. computer system, transfer the archive to another system, and extract
  4295. the contents there. The basic transfer medium might be magnetic tape,
  4296. Internet FTP, or even electronic mail (though you must encode the
  4297. archive with @command{uuencode} in order to transport it properly by
  4298. mail). Both machines do not have to use the same operating system, as
  4299. long as they both support the @command{tar} program.
  4300. For example, here is how you might copy a directory's contents from
  4301. one disk to another, while preserving the dates, modes, owners and
  4302. link-structure of all the files therein. In this case, the transfer
  4303. medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
  4304. @smallexample
  4305. $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
  4306. @end smallexample
  4307. @noindent
  4308. You can avoid subshells by using @option{-C} option:
  4309. @smallexample
  4310. $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
  4311. @end smallexample
  4312. @noindent
  4313. The command also works using short option forms:
  4314. @smallexample
  4315. $ @kbd{(cd sourcedir; tar --create --file=- . ) \
  4316. | (cd targetdir; tar --extract --file=-)}
  4317. # Or:
  4318. $ @kbd{tar --directory sourcedir --create --file=- . ) \
  4319. | tar --directory targetdir --extract --file=-}
  4320. @end smallexample
  4321. @noindent
  4322. This is one of the easiest methods to transfer a @command{tar} archive.
  4323. @node looking ahead
  4324. @section Looking Ahead: The Rest of this Manual
  4325. You have now seen how to use all eight of the operations available to
  4326. @command{tar}, and a number of the possible options. The next chapter
  4327. explains how to choose and change file and archive names, how to use
  4328. files to store names of other files which you can then call as
  4329. arguments to @command{tar} (this can help you save time if you expect to
  4330. archive the same list of files a number of times), and so forth.
  4331. @FIXME{in case it's not obvious, i'm making this up in some sense
  4332. based on my limited memory of what the next chapter *really* does. i
  4333. just wanted to flesh out this final section a little bit so i'd
  4334. remember to stick it in here. :-)}
  4335. If there are too many files to conveniently list on the command line,
  4336. you can list the names in a file, and @command{tar} will read that file.
  4337. @xref{files}.
  4338. There are various ways of causing @command{tar} to skip over some files,
  4339. and not archive them. @xref{Choosing}.
  4340. @node Backups
  4341. @chapter Performing Backups and Restoring Files
  4342. @UNREVISED
  4343. @GNUTAR{} is distributed along with the scripts
  4344. which the Free Software Foundation uses for performing backups. There
  4345. is no corresponding scripts available yet for doing restoration of
  4346. files. Even if there is a good chance those scripts may be satisfying
  4347. to you, they are not the only scripts or methods available for doing
  4348. backups and restore. You may well create your own, or use more
  4349. sophisticated packages dedicated to that purpose.
  4350. Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
  4351. Automatic Network Disk Archiver), a backup system developed by James
  4352. da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
  4353. This is free software, and it is available at these places:
  4354. @smallexample
  4355. http://www.cs.umd.edu/projects/amanda/amanda.html
  4356. ftp://ftp.cs.umd.edu/pub/amanda
  4357. @end smallexample
  4358. @FIXME{
  4359. Here is a possible plan for a future documentation about the backuping
  4360. scripts which are provided within the @GNUTAR{}
  4361. distribution.
  4362. @itemize @bullet
  4363. @item dumps
  4364. @itemize @minus
  4365. @item what are dumps
  4366. @item different levels of dumps
  4367. @itemize +
  4368. @item full dump = dump everything
  4369. @item level 1, level 2 dumps etc
  4370. A level @var{n} dump dumps everything changed since the last level
  4371. @var{n}-1 dump (?)
  4372. @end itemize
  4373. @item how to use scripts for dumps (ie, the concept)
  4374. @itemize +
  4375. @item scripts to run after editing backup specs (details)
  4376. @end itemize
  4377. @item Backup Specs, what is it.
  4378. @itemize +
  4379. @item how to customize
  4380. @item actual text of script [/sp/dump/backup-specs]
  4381. @end itemize
  4382. @item Problems
  4383. @itemize +
  4384. @item rsh doesn't work
  4385. @item rtape isn't installed
  4386. @item (others?)
  4387. @end itemize
  4388. @item the @option{--incremental} option of tar
  4389. @item tapes
  4390. @itemize +
  4391. @item write protection
  4392. @item types of media, different sizes and types, useful for different things
  4393. @item files and tape marks
  4394. one tape mark between files, two at end.
  4395. @item positioning the tape
  4396. MT writes two at end of write,
  4397. backspaces over one when writing again.
  4398. @end itemize
  4399. @end itemize
  4400. @end itemize
  4401. }
  4402. This chapter documents both the provided shell scripts and @command{tar}
  4403. options which are more specific to usage as a backup tool.
  4404. To @dfn{back up} a file system means to create archives that contain
  4405. all the files in that file system. Those archives can then be used to
  4406. restore any or all of those files (for instance if a disk crashes or a
  4407. file is accidentally deleted). File system @dfn{backups} are also
  4408. called @dfn{dumps}.
  4409. @menu
  4410. * Full Dumps:: Using @command{tar} to Perform Full Dumps
  4411. * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
  4412. * Backup Levels:: Levels of Backups
  4413. * Backup Parameters:: Setting Parameters for Backups and Restoration
  4414. * Scripted Backups:: Using the Backup Scripts
  4415. * Scripted Restoration:: Using the Restore Script
  4416. @end menu
  4417. @node Full Dumps
  4418. @section Using @command{tar} to Perform Full Dumps
  4419. @UNREVISED
  4420. @cindex full dumps
  4421. @cindex dumps, full
  4422. @cindex corrupted archives
  4423. Full dumps should only be made when no other people or programs
  4424. are modifying files in the file system. If files are modified while
  4425. @command{tar} is making the backup, they may not be stored properly in
  4426. the archive, in which case you won't be able to restore them if you
  4427. have to. (Files not being modified are written with no trouble, and do
  4428. not corrupt the entire archive.)
  4429. You will want to use the @option{--label=@var{archive-label}}
  4430. (@option{-V @var{archive-label}}) option to give the archive a
  4431. volume label, so you can tell what this archive is even if the label
  4432. falls off the tape, or anything like that.
  4433. Unless the file system you are dumping is guaranteed to fit on
  4434. one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
  4435. Make sure you have enough tapes on hand to complete the backup.
  4436. If you want to dump each file system separately you will need to use
  4437. the @option{--one-file-system} option to prevent
  4438. @command{tar} from crossing file system boundaries when storing
  4439. (sub)directories.
  4440. The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
  4441. option is not needed, since this is a complete copy of everything in
  4442. the file system, and a full restore from this backup would only be
  4443. done onto a completely
  4444. empty disk.
  4445. Unless you are in a hurry, and trust the @command{tar} program (and your
  4446. tapes), it is a good idea to use the @option{--verify} (@option{-W})
  4447. option, to make sure your files really made it onto the dump properly.
  4448. This will also detect cases where the file was modified while (or just
  4449. after) it was being archived. Not all media (notably cartridge tapes)
  4450. are capable of being verified, unfortunately.
  4451. @node Incremental Dumps
  4452. @section Using @command{tar} to Perform Incremental Dumps
  4453. @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
  4454. stores additional metadata so that exact state of the file system
  4455. can be restored when extracting the archive.
  4456. @GNUTAR{} currently offers two options for handling incremental
  4457. backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
  4458. @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
  4459. @opindex listed-incremental
  4460. The option @option{--listed-incremental} instructs tar to operate on
  4461. an incremental archive with additional metadata stored in a standalone
  4462. file, called a @dfn{snapshot file}. The purpose of this file is to help
  4463. determine which files have been changed, added or deleted since the
  4464. last backup, so that the next incremental backup will contain only
  4465. modified files. The name of the snapshot file is given as an argument
  4466. to the option:
  4467. @table @option
  4468. @item --listed-incremental=@var{file}
  4469. @itemx -g @var{file}
  4470. Handle incremental backups with snapshot data in @var{file}.
  4471. @end table
  4472. To create an incremental backup, you would use
  4473. @option{--listed-incremental} together with @option{--create}
  4474. (@pxref{create}). For example:
  4475. @smallexample
  4476. $ @kbd{tar --create \
  4477. --file=archive.1.tar \
  4478. --listed-incremental=/var/log/usr.snar \
  4479. /usr}
  4480. @end smallexample
  4481. This will create in @file{archive.1.tar} an incremental backup of
  4482. the @file{/usr} file system, storing additional metadata in the file
  4483. @file{/var/log/usr.snar}. If this file does not exist, it will be
  4484. created. The created archive will then be a @dfn{level 0 backup};
  4485. please see the next section for more on backup levels.
  4486. Otherwise, if the file @file{/var/log/usr.snar} exists, it
  4487. determines which files are modified. In this case only these files will be
  4488. stored in the archive. Suppose, for example, that after running the
  4489. above command, you delete file @file{/usr/doc/old} and create
  4490. directory @file{/usr/local/db} with the following contents:
  4491. @smallexample
  4492. $ @kbd{ls /usr/local/db}
  4493. /usr/local/db/data
  4494. /usr/local/db/index
  4495. @end smallexample
  4496. Some time later you create another incremental backup. You will
  4497. then see:
  4498. @smallexample
  4499. $ @kbd{tar --create \
  4500. --file=archive.2.tar \
  4501. --listed-incremental=/var/log/usr.snar \
  4502. /usr}
  4503. tar: usr/local/db: Directory is new
  4504. usr/local/db/
  4505. usr/local/db/data
  4506. usr/local/db/index
  4507. @end smallexample
  4508. @noindent
  4509. The created archive @file{archive.2.tar} will contain only these
  4510. three members. This archive is called a @dfn{level 1 backup}. Notice
  4511. that @file{/var/log/usr.snar} will be updated with the new data, so if
  4512. you plan to create more @samp{level 1} backups, it is necessary to
  4513. create a working copy of the snapshot file before running
  4514. @command{tar}. The above example will then be modified as follows:
  4515. @smallexample
  4516. $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
  4517. $ @kbd{tar --create \
  4518. --file=archive.2.tar \
  4519. --listed-incremental=/var/log/usr.snar-1 \
  4520. /usr}
  4521. @end smallexample
  4522. Incremental dumps depend crucially on time stamps, so the results are
  4523. unreliable if you modify a file's time stamps during dumping (e.g.,
  4524. with the @option{--atime-preserve=replace} option), or if you set the clock
  4525. backwards.
  4526. @cindex Device numbers, using in incremental backups
  4527. Metadata stored in snapshot files include device numbers, which,
  4528. obviously is supposed to be a non-volatile value. However, it turns
  4529. out that NFS devices have undependable values when an automounter
  4530. gets in the picture. This can lead to a great deal of spurious
  4531. redumping in incremental dumps, so it is somewhat useless to compare
  4532. two NFS devices numbers over time. The solution implemented currently
  4533. is to considers all NFS devices as being equal when it comes to
  4534. comparing directories; this is fairly gross, but there does not seem
  4535. to be a better way to go.
  4536. If you are using the @i{Linux} kernel, the device numbers can also
  4537. change when upgrading to some newer versions of the kernel. This can
  4538. cause the next backup to be full backup on the affected filesystems.
  4539. @xref{Fixing Snapshot Files}, for the information on how to handle this case.
  4540. Note that incremental archives use @command{tar} extensions and may
  4541. not be readable by non-@acronym{GNU} versions of the @command{tar} program.
  4542. @xopindex{listed-incremental, using with @option{--extract}}
  4543. @xopindex{extract, using with @option{--listed-incremental}}
  4544. To extract from the incremental dumps, use
  4545. @option{--listed-incremental} together with @option{--extract}
  4546. option (@pxref{extracting files}). In this case, @command{tar} does
  4547. not need to access snapshot file, since all the data necessary for
  4548. extraction are stored in the archive itself. So, when extracting, you
  4549. can give whatever argument to @option{--listed-incremental}, the usual
  4550. practice is to use @option{--listed-incremental=/dev/null}.
  4551. Alternatively, you can use @option{--incremental}, which needs no
  4552. arguments. In general, @option{--incremental} (@option{-G}) can be
  4553. used as a shortcut for @option{--listed-incremental} when listing or
  4554. extracting incremental backups (for more information, regarding this
  4555. option, @pxref{incremental-op}).
  4556. When extracting from the incremental backup @GNUTAR{} attempts to
  4557. restore the exact state the file system had when the archive was
  4558. created. In particular, it will @emph{delete} those files in the file
  4559. system that did not exist in their directories when the archive was
  4560. created. If you have created several levels of incremental files,
  4561. then in order to restore the exact contents the file system had when
  4562. the last level was created, you will need to restore from all backups
  4563. in turn. Continuing our example, to restore the state of @file{/usr}
  4564. file system, one would do@footnote{Notice, that since both archives
  4565. were created without @option{-P} option (@pxref{absolute}), these
  4566. commands should be run from the root file system.}:
  4567. @smallexample
  4568. $ @kbd{tar --extract \
  4569. --listed-incremental=/dev/null \
  4570. --file archive.1.tar}
  4571. $ @kbd{tar --extract \
  4572. --listed-incremental=/dev/null \
  4573. --file archive.2.tar}
  4574. @end smallexample
  4575. To list the contents of an incremental archive, use @option{--list}
  4576. (@pxref{list}), as usual. To obtain more information about the
  4577. archive, use @option{--listed-incremental} or @option{--incremental}
  4578. combined with two @option{--verbose} options@footnote{Two
  4579. @option{--verbose} options were selected to avoid breaking usual
  4580. verbose listing output (@option{--list --verbose}) when using in
  4581. scripts.
  4582. @xopindex{incremental, using with @option{--list}}
  4583. @xopindex{listed-incremental, using with @option{--list}}
  4584. @xopindex{list, using with @option{--incremental}}
  4585. @xopindex{list, using with @option{--listed-incremental}}
  4586. Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
  4587. contents of the DUMPDIR header (with terminating nulls) when
  4588. @option{--incremental} or @option{--listed-incremental} option was
  4589. given, no matter what the verbosity level. This behavior, and,
  4590. especially, the binary output it produced were considered inconvenient
  4591. and were changed in version 1.16}:
  4592. @smallexample
  4593. @kbd{tar --list --incremental --verbose --verbose archive.tar}
  4594. @end smallexample
  4595. This command will print, for each directory in the archive, the list
  4596. of files in that directory at the time the archive was created. This
  4597. information is put out in a format which is both human-readable and
  4598. unambiguous for a program: each file name is printed as
  4599. @smallexample
  4600. @var{x} @var{file}
  4601. @end smallexample
  4602. @noindent
  4603. where @var{x} is a letter describing the status of the file: @samp{Y}
  4604. if the file is present in the archive, @samp{N} if the file is not
  4605. included in the archive, or a @samp{D} if the file is a directory (and
  4606. is included in the archive). @xref{Dumpdir}, for the detailed
  4607. description of dumpdirs and status codes. Each such
  4608. line is terminated by a newline character. The last line is followed
  4609. by an additional newline to indicate the end of the data.
  4610. @anchor{incremental-op}The option @option{--incremental} (@option{-G})
  4611. gives the same behavior as @option{--listed-incremental} when used
  4612. with @option{--list} and @option{--extract} options. When used with
  4613. @option{--create} option, it creates an incremental archive without
  4614. creating snapshot file. Thus, it is impossible to create several
  4615. levels of incremental backups with @option{--incremental} option.
  4616. @node Backup Levels
  4617. @section Levels of Backups
  4618. An archive containing all the files in the file system is called a
  4619. @dfn{full backup} or @dfn{full dump}. You could insure your data by
  4620. creating a full dump every day. This strategy, however, would waste a
  4621. substantial amount of archive media and user time, as unchanged files
  4622. are daily re-archived.
  4623. It is more efficient to do a full dump only occasionally. To back up
  4624. files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
  4625. one} dump archives all the files that have changed since the last full
  4626. dump.
  4627. A typical dump strategy would be to perform a full dump once a week,
  4628. and a level one dump once a day. This means some versions of files
  4629. will in fact be archived more than once, but this dump strategy makes
  4630. it possible to restore a file system to within one day of accuracy by
  4631. only extracting two archives---the last weekly (full) dump and the
  4632. last daily (level one) dump. The only information lost would be in
  4633. files changed or created since the last daily backup. (Doing dumps
  4634. more than once a day is usually not worth the trouble).
  4635. @GNUTAR{} comes with scripts you can use to do full
  4636. and level-one (actually, even level-two and so on) dumps. Using
  4637. scripts (shell programs) to perform backups and restoration is a
  4638. convenient and reliable alternative to typing out file name lists
  4639. and @command{tar} commands by hand.
  4640. Before you use these scripts, you need to edit the file
  4641. @file{backup-specs}, which specifies parameters used by the backup
  4642. scripts and by the restore script. This file is usually located
  4643. in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
  4644. detailed description. Once the backup parameters are set, you can
  4645. perform backups or restoration by running the appropriate script.
  4646. The name of the backup script is @code{backup}. The name of the
  4647. restore script is @code{restore}. The following sections describe
  4648. their use in detail.
  4649. @emph{Please Note:} The backup and restoration scripts are
  4650. designed to be used together. While it is possible to restore files by
  4651. hand from an archive which was created using a backup script, and to create
  4652. an archive by hand which could then be extracted using the restore script,
  4653. it is easier to use the scripts. @xref{Incremental Dumps}, before
  4654. making such an attempt.
  4655. @node Backup Parameters
  4656. @section Setting Parameters for Backups and Restoration
  4657. The file @file{backup-specs} specifies backup parameters for the
  4658. backup and restoration scripts provided with @command{tar}. You must
  4659. edit @file{backup-specs} to fit your system configuration and schedule
  4660. before using these scripts.
  4661. Syntactically, @file{backup-specs} is a shell script, containing
  4662. mainly variable assignments. However, any valid shell construct
  4663. is allowed in this file. Particularly, you may wish to define
  4664. functions within that script (e.g., see @code{RESTORE_BEGIN} below).
  4665. For more information about shell script syntax, please refer to
  4666. @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
  4667. g_02, the definition of the Shell Command Language}. See also
  4668. @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
  4669. The shell variables controlling behavior of @code{backup} and
  4670. @code{restore} are described in the following subsections.
  4671. @menu
  4672. * General-Purpose Variables::
  4673. * Magnetic Tape Control::
  4674. * User Hooks::
  4675. * backup-specs example:: An Example Text of @file{Backup-specs}
  4676. @end menu
  4677. @node General-Purpose Variables
  4678. @subsection General-Purpose Variables
  4679. @defvr {Backup variable} ADMINISTRATOR
  4680. The user name of the backup administrator. @code{Backup} scripts
  4681. sends a backup report to this address.
  4682. @end defvr
  4683. @defvr {Backup variable} BACKUP_HOUR
  4684. The hour at which the backups are done. This can be a number from 0
  4685. to 23, or the time specification in form @var{hours}:@var{minutes},
  4686. or the string @samp{now}.
  4687. This variable is used by @code{backup}. Its value may be overridden
  4688. using @option{--time} option (@pxref{Scripted Backups}).
  4689. @end defvr
  4690. @defvr {Backup variable} TAPE_FILE
  4691. The device @command{tar} writes the archive to. If @var{TAPE_FILE}
  4692. is a remote archive (@pxref{remote-dev}), backup script will suppose
  4693. that your @command{mt} is able to access remote devices. If @var{RSH}
  4694. (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
  4695. invocations of @command{mt}.
  4696. @end defvr
  4697. @defvr {Backup variable} BLOCKING
  4698. The blocking factor @command{tar} will use when writing the dump archive.
  4699. @xref{Blocking Factor}.
  4700. @end defvr
  4701. @defvr {Backup variable} BACKUP_DIRS
  4702. A list of file systems to be dumped (for @code{backup}), or restored
  4703. (for @code{restore}). You can include any directory
  4704. name in the list --- subdirectories on that file system will be
  4705. included, regardless of how they may look to other networked machines.
  4706. Subdirectories on other file systems will be ignored.
  4707. The host name specifies which host to run @command{tar} on, and should
  4708. normally be the host that actually contains the file system. However,
  4709. the host machine must have @GNUTAR{} installed, and
  4710. must be able to access the directory containing the backup scripts and
  4711. their support files using the same file name that is used on the
  4712. machine where the scripts are run (i.e., what @command{pwd} will print
  4713. when in that directory on that machine). If the host that contains
  4714. the file system does not have this capability, you can specify another
  4715. host as long as it can access the file system through NFS.
  4716. If the list of file systems is very long you may wish to put it
  4717. in a separate file. This file is usually named
  4718. @file{/etc/backup/dirs}, but this name may be overridden in
  4719. @file{backup-specs} using @code{DIRLIST} variable.
  4720. @end defvr
  4721. @defvr {Backup variable} DIRLIST
  4722. The name of the file that contains a list of file systems to backup
  4723. or restore. By default it is @file{/etc/backup/dirs}.
  4724. @end defvr
  4725. @defvr {Backup variable} BACKUP_FILES
  4726. A list of individual files to be dumped (for @code{backup}), or restored
  4727. (for @code{restore}). These should be accessible from the machine on
  4728. which the backup script is run.
  4729. If the list of file systems is very long you may wish to store it
  4730. in a separate file. This file is usually named
  4731. @file{/etc/backup/files}, but this name may be overridden in
  4732. @file{backup-specs} using @code{FILELIST} variable.
  4733. @end defvr
  4734. @defvr {Backup variable} FILELIST
  4735. The name of the file that contains a list of individual files to backup
  4736. or restore. By default it is @file{/etc/backup/files}.
  4737. @end defvr
  4738. @defvr {Backup variable} MT
  4739. Full file name of @command{mt} binary.
  4740. @end defvr
  4741. @defvr {Backup variable} RSH
  4742. @anchor{RSH}
  4743. Full file name of @command{rsh} binary or its equivalent. You may wish to
  4744. set it to @code{ssh}, to improve security. In this case you will have
  4745. to use public key authentication.
  4746. @end defvr
  4747. @defvr {Backup variable} RSH_COMMAND
  4748. Full file name of @command{rsh} binary on remote machines. This will
  4749. be passed via @option{--rsh-command} option to the remote invocation
  4750. of @GNUTAR{}.
  4751. @end defvr
  4752. @defvr {Backup variable} VOLNO_FILE
  4753. Name of temporary file to hold volume numbers. This needs to be accessible
  4754. by all the machines which have file systems to be dumped.
  4755. @end defvr
  4756. @defvr {Backup variable} XLIST
  4757. Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
  4758. located on the remote machine and containing the list of files to
  4759. be excluded from the backup. Exclude file lists are searched in
  4760. /etc/tar-backup directory. A common use for exclude file lists
  4761. is to exclude files containing security-sensitive information
  4762. (e.g., @file{/etc/shadow} from backups).
  4763. This variable affects only @code{backup}.
  4764. @end defvr
  4765. @defvr {Backup variable} SLEEP_TIME
  4766. Time to sleep between dumps of any two successive file systems
  4767. This variable affects only @code{backup}.
  4768. @end defvr
  4769. @defvr {Backup variable} DUMP_REMIND_SCRIPT
  4770. Script to be run when it's time to insert a new tape in for the next
  4771. volume. Administrators may want to tailor this script for their site.
  4772. If this variable isn't set, @GNUTAR{} will display its built-in
  4773. prompt, and will expect confirmation from the console. For the
  4774. description of the default prompt, see @ref{change volume prompt}.
  4775. @end defvr
  4776. @defvr {Backup variable} SLEEP_MESSAGE
  4777. Message to display on the terminal while waiting for dump time. Usually
  4778. this will just be some literal text.
  4779. @end defvr
  4780. @defvr {Backup variable} TAR
  4781. Full file name of the @GNUTAR{} executable. If this is not set, backup
  4782. scripts will search @command{tar} in the current shell path.
  4783. @end defvr
  4784. @node Magnetic Tape Control
  4785. @subsection Magnetic Tape Control
  4786. Backup scripts access tape device using special @dfn{hook functions}.
  4787. These functions take a single argument -- the name of the tape
  4788. device. Their names are kept in the following variables:
  4789. @defvr {Backup variable} MT_BEGIN
  4790. The name of @dfn{begin} function. This function is called before
  4791. accessing the drive. By default it retensions the tape:
  4792. @smallexample
  4793. MT_BEGIN=mt_begin
  4794. mt_begin() @{
  4795. mt -f "$1" retension
  4796. @}
  4797. @end smallexample
  4798. @end defvr
  4799. @defvr {Backup variable} MT_REWIND
  4800. The name of @dfn{rewind} function. The default definition is as
  4801. follows:
  4802. @smallexample
  4803. MT_REWIND=mt_rewind
  4804. mt_rewind() @{
  4805. mt -f "$1" rewind
  4806. @}
  4807. @end smallexample
  4808. @end defvr
  4809. @defvr {Backup variable} MT_OFFLINE
  4810. The name of the function switching the tape off line. By default
  4811. it is defined as follows:
  4812. @smallexample
  4813. MT_OFFLINE=mt_offline
  4814. mt_offline() @{
  4815. mt -f "$1" offl
  4816. @}
  4817. @end smallexample
  4818. @end defvr
  4819. @defvr {Backup variable} MT_STATUS
  4820. The name of the function used to obtain the status of the archive device,
  4821. including error count. Default definition:
  4822. @smallexample
  4823. MT_STATUS=mt_status
  4824. mt_status() @{
  4825. mt -f "$1" status
  4826. @}
  4827. @end smallexample
  4828. @end defvr
  4829. @node User Hooks
  4830. @subsection User Hooks
  4831. @dfn{User hooks} are shell functions executed before and after
  4832. each @command{tar} invocation. Thus, there are @dfn{backup
  4833. hooks}, which are executed before and after dumping each file
  4834. system, and @dfn{restore hooks}, executed before and
  4835. after restoring a file system. Each user hook is a shell function
  4836. taking four arguments:
  4837. @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
  4838. Its arguments are:
  4839. @table @var
  4840. @item level
  4841. Current backup or restore level.
  4842. @item host
  4843. Name or IP address of the host machine being dumped or restored.
  4844. @item fs
  4845. Full file name of the file system being dumped or restored.
  4846. @item fsname
  4847. File system name with directory separators replaced with colons. This
  4848. is useful, e.g., for creating unique files.
  4849. @end table
  4850. @end deffn
  4851. Following variables keep the names of user hook functions
  4852. @defvr {Backup variable} DUMP_BEGIN
  4853. Dump begin function. It is executed before dumping the file system.
  4854. @end defvr
  4855. @defvr {Backup variable} DUMP_END
  4856. Executed after dumping the file system.
  4857. @end defvr
  4858. @defvr {Backup variable} RESTORE_BEGIN
  4859. Executed before restoring the file system.
  4860. @end defvr
  4861. @defvr {Backup variable} RESTORE_END
  4862. Executed after restoring the file system.
  4863. @end defvr
  4864. @node backup-specs example
  4865. @subsection An Example Text of @file{Backup-specs}
  4866. The following is an example of @file{backup-specs}:
  4867. @smallexample
  4868. # site-specific parameters for file system backup.
  4869. ADMINISTRATOR=friedman
  4870. BACKUP_HOUR=1
  4871. TAPE_FILE=/dev/nrsmt0
  4872. # Use @code{ssh} instead of the less secure @code{rsh}
  4873. RSH=/usr/bin/ssh
  4874. RSH_COMMAND=/usr/bin/ssh
  4875. # Override MT_STATUS function:
  4876. my_status() @{
  4877. mts -t $TAPE_FILE
  4878. @}
  4879. MT_STATUS=my_status
  4880. # Disable MT_OFFLINE function
  4881. MT_OFFLINE=:
  4882. BLOCKING=124
  4883. BACKUP_DIRS="
  4884. albert:/fs/fsf
  4885. apple-gunkies:/gd
  4886. albert:/fs/gd2
  4887. albert:/fs/gp
  4888. geech:/usr/jla
  4889. churchy:/usr/roland
  4890. albert:/
  4891. albert:/usr
  4892. apple-gunkies:/
  4893. apple-gunkies:/usr
  4894. gnu:/hack
  4895. gnu:/u
  4896. apple-gunkies:/com/mailer/gnu
  4897. apple-gunkies:/com/archive/gnu"
  4898. BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
  4899. @end smallexample
  4900. @node Scripted Backups
  4901. @section Using the Backup Scripts
  4902. The syntax for running a backup script is:
  4903. @smallexample
  4904. backup --level=@var{level} --time=@var{time}
  4905. @end smallexample
  4906. The @option{level} option requests the dump level. Thus, to produce
  4907. a full dump, specify @code{--level=0} (this is the default, so
  4908. @option{--level} may be omitted if its value is @code{0}).
  4909. @footnote{For backward compatibility, the @code{backup} will also
  4910. try to deduce the requested dump level from the name of the
  4911. script itself. If the name consists of a string @samp{level-}
  4912. followed by a single decimal digit, that digit is taken as
  4913. the dump level number. Thus, you may create a link from @code{backup}
  4914. to @code{level-1} and then run @code{level-1} whenever you need to
  4915. create a level one dump.}
  4916. The @option{--time} option determines when should the backup be
  4917. run. @var{Time} may take three forms:
  4918. @table @asis
  4919. @item @var{hh}:@var{mm}
  4920. The dump must be run at @var{hh} hours @var{mm} minutes.
  4921. @item @var{hh}
  4922. The dump must be run at @var{hh} hours
  4923. @item now
  4924. The dump must be run immediately.
  4925. @end table
  4926. You should start a script with a tape or disk mounted. Once you
  4927. start a script, it prompts you for new tapes or disks as it
  4928. needs them. Media volumes don't have to correspond to archive
  4929. files --- a multi-volume archive can be started in the middle of a
  4930. tape that already contains the end of another multi-volume archive.
  4931. The @code{restore} script prompts for media by its archive volume,
  4932. so to avoid an error message you should keep track of which tape
  4933. (or disk) contains which volume of the archive (@pxref{Scripted
  4934. Restoration}).
  4935. The backup scripts write two files on the file system. The first is a
  4936. record file in @file{/etc/tar-backup/}, which is used by the scripts
  4937. to store and retrieve information about which files were dumped. This
  4938. file is not meant to be read by humans, and should not be deleted by
  4939. them. @xref{Snapshot Files}, for a more detailed explanation of this
  4940. file.
  4941. The second file is a log file containing the names of the file systems
  4942. and files dumped, what time the backup was made, and any error
  4943. messages that were generated, as well as how much space was left in
  4944. the media volume after the last volume of the archive was written.
  4945. You should check this log file after every backup. The file name is
  4946. @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
  4947. represents current date, and @var{n} represents current dump level number.
  4948. The script also prints the name of each system being dumped to the
  4949. standard output.
  4950. Following is the full list of options accepted by @code{backup}
  4951. script:
  4952. @table @option
  4953. @item -l @var{level}
  4954. @itemx --level=@var{level}
  4955. Do backup level @var{level} (default 0).
  4956. @item -f
  4957. @itemx --force
  4958. Force backup even if today's log file already exists.
  4959. @item -v[@var{level}]
  4960. @itemx --verbose[=@var{level}]
  4961. Set verbosity level. The higher the level is, the more debugging
  4962. information will be output during execution. Default @var{level}
  4963. is 100, which means the highest debugging level.
  4964. @item -t @var{start-time}
  4965. @itemx --time=@var{start-time}
  4966. Wait till @var{time}, then do backup.
  4967. @item -h
  4968. @itemx --help
  4969. Display short help message and exit.
  4970. @item -V
  4971. @itemx --version
  4972. Display information about the program's name, version, origin and legal
  4973. status, all on standard output, and then exit successfully.
  4974. @end table
  4975. @node Scripted Restoration
  4976. @section Using the Restore Script
  4977. To restore files that were archived using a scripted backup, use the
  4978. @code{restore} script. Its usage is quite straightforward. In the
  4979. simplest form, invoke @code{restore --all}, it will
  4980. then restore all the file systems and files specified in
  4981. @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
  4982. You may select the file systems (and/or files) to restore by
  4983. giving @code{restore} list of @dfn{patterns} in its command
  4984. line. For example, running
  4985. @smallexample
  4986. restore 'albert:*'
  4987. @end smallexample
  4988. @noindent
  4989. will restore all file systems on the machine @samp{albert}. A more
  4990. complicated example:
  4991. @smallexample
  4992. restore 'albert:*' '*:/var'
  4993. @end smallexample
  4994. @noindent
  4995. This command will restore all file systems on the machine @samp{albert}
  4996. as well as @file{/var} file system on all machines.
  4997. By default @code{restore} will start restoring files from the lowest
  4998. available dump level (usually zero) and will continue through
  4999. all available dump levels. There may be situations where such a
  5000. thorough restore is not necessary. For example, you may wish to
  5001. restore only files from the recent level one backup. To do so,
  5002. use @option{--level} option, as shown in the example below:
  5003. @smallexample
  5004. restore --level=1
  5005. @end smallexample
  5006. The full list of options accepted by @code{restore} follows:
  5007. @table @option
  5008. @item -a
  5009. @itemx --all
  5010. Restore all file systems and files specified in @file{backup-specs}
  5011. @item -l @var{level}
  5012. @itemx --level=@var{level}
  5013. Start restoring from the given backup level, instead of the default 0.
  5014. @item -v[@var{level}]
  5015. @itemx --verbose[=@var{level}]
  5016. Set verbosity level. The higher the level is, the more debugging
  5017. information will be output during execution. Default @var{level}
  5018. is 100, which means the highest debugging level.
  5019. @item -h
  5020. @itemx --help
  5021. Display short help message and exit.
  5022. @item -V
  5023. @itemx --version
  5024. Display information about the program's name, version, origin and legal
  5025. status, all on standard output, and then exit successfully.
  5026. @end table
  5027. You should start the restore script with the media containing the
  5028. first volume of the archive mounted. The script will prompt for other
  5029. volumes as they are needed. If the archive is on tape, you don't need
  5030. to rewind the tape to to its beginning---if the tape head is
  5031. positioned past the beginning of the archive, the script will rewind
  5032. the tape as needed. @xref{Tape Positioning}, for a discussion of tape
  5033. positioning.
  5034. @quotation
  5035. @strong{Warning:} The script will delete files from the active file
  5036. system if they were not in the file system when the archive was made.
  5037. @end quotation
  5038. @xref{Incremental Dumps}, for an explanation of how the script makes
  5039. that determination.
  5040. @node Choosing
  5041. @chapter Choosing Files and Names for @command{tar}
  5042. @UNREVISED
  5043. Certain options to @command{tar} enable you to specify a name for your
  5044. archive. Other options let you decide which files to include or exclude
  5045. from the archive, based on when or whether files were modified, whether
  5046. the file names do or don't match specified patterns, or whether files
  5047. are in specified directories.
  5048. This chapter discusses these options in detail.
  5049. @menu
  5050. * file:: Choosing the Archive's Name
  5051. * Selecting Archive Members::
  5052. * files:: Reading Names from a File
  5053. * exclude:: Excluding Some Files
  5054. * wildcards:: Wildcards Patterns and Matching
  5055. * quoting styles:: Ways of Quoting Special Characters in Names
  5056. * transform:: Modifying File and Member Names
  5057. * after:: Operating Only on New Files
  5058. * recurse:: Descending into Directories
  5059. * one:: Crossing File System Boundaries
  5060. @end menu
  5061. @node file
  5062. @section Choosing and Naming Archive Files
  5063. @UNREVISED
  5064. @cindex Naming an archive
  5065. @cindex Archive Name
  5066. @cindex Choosing an archive file
  5067. @cindex Where is the archive?
  5068. By default, @command{tar} uses an archive file name that was compiled when
  5069. it was built on the system; usually this name refers to some physical
  5070. tape drive on the machine. However, the person who installed @command{tar}
  5071. on the system may not have set the default to a meaningful value as far as
  5072. most users are concerned. As a result, you will usually want to tell
  5073. @command{tar} where to find (or create) the archive. The
  5074. @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
  5075. option allows you to either specify or name a file to use as the archive
  5076. instead of the default archive file location.
  5077. @table @option
  5078. @xopindex{file, short description}
  5079. @item --file=@var{archive-name}
  5080. @itemx -f @var{archive-name}
  5081. Name the archive to create or operate on. Use in conjunction with
  5082. any operation.
  5083. @end table
  5084. For example, in this @command{tar} command,
  5085. @smallexample
  5086. $ @kbd{tar -cvf collection.tar blues folk jazz}
  5087. @end smallexample
  5088. @noindent
  5089. @file{collection.tar} is the name of the archive. It must directly
  5090. follow the @option{-f} option, since whatever directly follows @option{-f}
  5091. @emph{will} end up naming the archive. If you neglect to specify an
  5092. archive name, you may end up overwriting a file in the working directory
  5093. with the archive you create since @command{tar} will use this file's name
  5094. for the archive name.
  5095. An archive can be saved as a file in the file system, sent through a
  5096. pipe or over a network, or written to an I/O device such as a tape,
  5097. floppy disk, or CD write drive.
  5098. @cindex Writing new archives
  5099. @cindex Archive creation
  5100. If you do not name the archive, @command{tar} uses the value of the
  5101. environment variable @env{TAPE} as the file name for the archive. If
  5102. that is not available, @command{tar} uses a default, compiled-in archive
  5103. name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
  5104. @cindex Standard input and output
  5105. @cindex tar to standard input and output
  5106. If you use @file{-} as an @var{archive-name}, @command{tar} reads the
  5107. archive from standard input (when listing or extracting files), or
  5108. writes it to standard output (when creating an archive). If you use
  5109. @file{-} as an @var{archive-name} when modifying an archive,
  5110. @command{tar} reads the original archive from its standard input and
  5111. writes the entire new archive to its standard output.
  5112. The following example is a convenient way of copying directory
  5113. hierarchy from @file{sourcedir} to @file{targetdir}.
  5114. @smallexample
  5115. $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
  5116. @end smallexample
  5117. The @option{-C} option allows to avoid using subshells:
  5118. @smallexample
  5119. $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
  5120. @end smallexample
  5121. In both examples above, the leftmost @command{tar} invocation archives
  5122. the contents of @file{sourcedir} to the standard output, while the
  5123. rightmost one reads this archive from its standard input and
  5124. extracts it. The @option{-p} option tells it to restore permissions
  5125. of the extracted files.
  5126. @cindex Remote devices
  5127. @cindex tar to a remote device
  5128. @anchor{remote-dev}
  5129. To specify an archive file on a device attached to a remote machine,
  5130. use the following:
  5131. @smallexample
  5132. @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
  5133. @end smallexample
  5134. @noindent
  5135. @command{tar} will complete the remote connection, if possible, and
  5136. prompt you for a username and password. If you use
  5137. @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
  5138. will complete the remote connection, if possible, using your username
  5139. as the username on the remote machine.
  5140. @cindex Local and remote archives
  5141. @anchor{local and remote archives}
  5142. If the archive file name includes a colon (@samp{:}), then it is assumed
  5143. to be a file on another machine. If the archive file is
  5144. @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
  5145. host @var{host}. The remote host is accessed using the @command{rsh}
  5146. program, with a username of @var{user}. If the username is omitted
  5147. (along with the @samp{@@} sign), then your user name will be used.
  5148. (This is the normal @command{rsh} behavior.) It is necessary for the
  5149. remote machine, in addition to permitting your @command{rsh} access, to
  5150. have the @file{rmt} program installed (This command is included in
  5151. the @GNUTAR{} distribution and by default is installed under
  5152. @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
  5153. installation prefix). If you need to use a file whose name includes a
  5154. colon, then the remote tape drive behavior
  5155. can be inhibited by using the @option{--force-local} option.
  5156. When the archive is being created to @file{/dev/null}, @GNUTAR{}
  5157. tries to minimize input and output operations. The Amanda backup
  5158. system, when used with @GNUTAR{}, has an initial sizing pass which
  5159. uses this feature.
  5160. @node Selecting Archive Members
  5161. @section Selecting Archive Members
  5162. @cindex Specifying files to act on
  5163. @cindex Specifying archive members
  5164. @dfn{File Name arguments} specify which files in the file system
  5165. @command{tar} operates on, when creating or adding to an archive, or which
  5166. archive members @command{tar} operates on, when reading or deleting from
  5167. an archive. @xref{Operations}.
  5168. To specify file names, you can include them as the last arguments on
  5169. the command line, as follows:
  5170. @smallexample
  5171. @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
  5172. @end smallexample
  5173. If a file name begins with dash (@samp{-}), precede it with
  5174. @option{--add-file} option to prevent it from being treated as an
  5175. option.
  5176. @anchor{input name quoting}
  5177. By default @GNUTAR{} attempts to @dfn{unquote} each file or member
  5178. name, replacing @dfn{escape sequences} according to the following
  5179. table:
  5180. @multitable @columnfractions 0.20 0.60
  5181. @headitem Escape @tab Replaced with
  5182. @item \a @tab Audible bell (@acronym{ASCII} 7)
  5183. @item \b @tab Backspace (@acronym{ASCII} 8)
  5184. @item \f @tab Form feed (@acronym{ASCII} 12)
  5185. @item \n @tab New line (@acronym{ASCII} 10)
  5186. @item \r @tab Carriage return (@acronym{ASCII} 13)
  5187. @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
  5188. @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
  5189. @item \? @tab @acronym{ASCII} 127
  5190. @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
  5191. of up to 3 digits)
  5192. @end multitable
  5193. A backslash followed by any other symbol is retained.
  5194. This default behavior is controlled by the following command line
  5195. option:
  5196. @table @option
  5197. @opindex unquote
  5198. @item --unquote
  5199. Enable unquoting input file or member names (default).
  5200. @opindex no-unquote
  5201. @item --no-unquote
  5202. Disable unquoting input file or member names.
  5203. @end table
  5204. If you specify a directory name as a file name argument, all the files
  5205. in that directory are operated on by @command{tar}.
  5206. If you do not specify files, @command{tar} behavior differs depending
  5207. on the operation mode as described below:
  5208. When @command{tar} is invoked with @option{--create} (@option{-c}),
  5209. @command{tar} will stop immediately, reporting the following:
  5210. @smallexample
  5211. @group
  5212. $ @kbd{tar cf a.tar}
  5213. tar: Cowardly refusing to create an empty archive
  5214. Try `tar --help' or `tar --usage' for more information.
  5215. @end group
  5216. @end smallexample
  5217. If you specify either @option{--list} (@option{-t}) or
  5218. @option{--extract} (@option{--get}, @option{-x}), @command{tar}
  5219. operates on all the archive members in the archive.
  5220. If run with @option{--diff} option, tar will compare the archive with
  5221. the contents of the current working directory.
  5222. If you specify any other operation, @command{tar} does nothing.
  5223. By default, @command{tar} takes file names from the command line. However,
  5224. there are other ways to specify file or member names, or to modify the
  5225. manner in which @command{tar} selects the files or members upon which to
  5226. operate. In general, these methods work both for specifying the names
  5227. of files and archive members.
  5228. @node files
  5229. @section Reading Names from a File
  5230. @cindex Reading file names from a file
  5231. @cindex Lists of file names
  5232. @cindex File Name arguments, alternatives
  5233. Instead of giving the names of files or archive members on the command
  5234. line, you can put the names into a file, and then use the
  5235. @option{--files-from=@var{file-of-names}} (@option{-T
  5236. @var{file-of-names}}) option to @command{tar}. Give the name of the
  5237. file which contains the list of files to include as the argument to
  5238. @option{--files-from}. In the list, the file names should be separated by
  5239. newlines. You will frequently use this option when you have generated
  5240. the list of files to archive with the @command{find} utility.
  5241. @table @option
  5242. @opindex files-from
  5243. @item --files-from=@var{file-name}
  5244. @itemx -T @var{file-name}
  5245. Get names to extract or create from file @var{file-name}.
  5246. @end table
  5247. If you give a single dash as a file name for @option{--files-from}, (i.e.,
  5248. you specify either @code{--files-from=-} or @code{-T -}), then the file
  5249. names are read from standard input.
  5250. Unless you are running @command{tar} with @option{--create}, you can not use
  5251. both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
  5252. command.
  5253. Any number of @option{-T} options can be given in the command line.
  5254. The following example shows how to use @command{find} to generate a list of
  5255. files smaller than 400K in length and put that list into a file
  5256. called @file{small-files}. You can then use the @option{-T} option to
  5257. @command{tar} to specify the files from that file, @file{small-files}, to
  5258. create the archive @file{little.tgz}. (The @option{-z} option to
  5259. @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
  5260. more information.)
  5261. @smallexample
  5262. $ @kbd{find . -size -400 -print > small-files}
  5263. $ @kbd{tar -c -v -z -T small-files -f little.tgz}
  5264. @end smallexample
  5265. @noindent
  5266. In the file list given by @option{-T} option, any file name beginning
  5267. with @samp{-} character is considered a @command{tar} option and is
  5268. processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
  5269. recognized only @option{-C} option in file lists, and only if the
  5270. option and its argument occupied two consecutive lines.} For example,
  5271. the common use of this feature is to change to another directory by
  5272. specifying @option{-C} option:
  5273. @smallexample
  5274. @group
  5275. $ @kbd{cat list}
  5276. -C/etc
  5277. passwd
  5278. hosts
  5279. -C/lib
  5280. libc.a
  5281. $ @kbd{tar -c -f foo.tar --files-from list}
  5282. @end group
  5283. @end smallexample
  5284. @noindent
  5285. In this example, @command{tar} will first switch to @file{/etc}
  5286. directory and add files @file{passwd} and @file{hosts} to the
  5287. archive. Then it will change to @file{/lib} directory and will archive
  5288. the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
  5289. contain:
  5290. @smallexample
  5291. @group
  5292. $ @kbd{tar tf foo.tar}
  5293. passwd
  5294. hosts
  5295. libc.a
  5296. @end group
  5297. @end smallexample
  5298. @noindent
  5299. @xopindex{directory, using in @option{--files-from} argument}
  5300. Notice that the option parsing algorithm used with @option{-T} is
  5301. stricter than the one used by shell. Namely, when specifying option
  5302. arguments, you should observe the following rules:
  5303. @itemize @bullet
  5304. @item
  5305. When using short (single-letter) option form, its argument must
  5306. immediately follow the option letter, without any intervening
  5307. whitespace. For example: @code{-Cdir}.
  5308. @item
  5309. When using long option form, the option argument must be separated
  5310. from the option by a single equal sign. No whitespace is allowed on
  5311. any side of the equal sign. For example: @code{--directory=dir}.
  5312. @item
  5313. For both short and long option forms, the option argument can be given
  5314. on the next line after the option name, e.g.:
  5315. @smallexample
  5316. @group
  5317. --directory
  5318. dir
  5319. @end group
  5320. @end smallexample
  5321. @noindent
  5322. and
  5323. @smallexample
  5324. @group
  5325. -C
  5326. dir
  5327. @end group
  5328. @end smallexample
  5329. @end itemize
  5330. @opindex add-file
  5331. If you happen to have a file whose name starts with @samp{-},
  5332. precede it with @option{--add-file} option to prevent it from
  5333. being recognized as an option. For example: @code{--add-file=--my-file}.
  5334. @menu
  5335. * nul::
  5336. @end menu
  5337. @node nul
  5338. @subsection @code{NUL} Terminated File Names
  5339. @cindex File names, terminated by @code{NUL}
  5340. @cindex @code{NUL} terminated file names
  5341. The @option{--null} option causes
  5342. @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
  5343. to read file names terminated by a @code{NUL} instead of a newline, so
  5344. files whose names contain newlines can be archived using
  5345. @option{--files-from}.
  5346. @table @option
  5347. @opindex null
  5348. @item --null
  5349. Only consider @code{NUL} terminated file names, instead of files that
  5350. terminate in a newline.
  5351. @end table
  5352. The @option{--null} option is just like the one in @acronym{GNU}
  5353. @command{xargs} and @command{cpio}, and is useful with the
  5354. @option{-print0} predicate of @acronym{GNU} @command{find}. In
  5355. @command{tar}, @option{--null} also disables special handling for
  5356. file names that begin with dash.
  5357. This example shows how to use @command{find} to generate a list of files
  5358. larger than 800K in length and put that list into a file called
  5359. @file{long-files}. The @option{-print0} option to @command{find} is just
  5360. like @option{-print}, except that it separates files with a @code{NUL}
  5361. rather than with a newline. You can then run @command{tar} with both the
  5362. @option{--null} and @option{-T} options to specify that @command{tar} get the
  5363. files from that file, @file{long-files}, to create the archive
  5364. @file{big.tgz}. The @option{--null} option to @command{tar} will cause
  5365. @command{tar} to recognize the @code{NUL} separator between files.
  5366. @smallexample
  5367. $ @kbd{find . -size +800 -print0 > long-files}
  5368. $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
  5369. @end smallexample
  5370. @FIXME{say anything else here to conclude the section?}
  5371. @node exclude
  5372. @section Excluding Some Files
  5373. @UNREVISED
  5374. @cindex File names, excluding files by
  5375. @cindex Excluding files by name and pattern
  5376. @cindex Excluding files by file system
  5377. To avoid operating on files whose names match a particular pattern,
  5378. use the @option{--exclude} or @option{--exclude-from} options.
  5379. @table @option
  5380. @opindex exclude
  5381. @item --exclude=@var{pattern}
  5382. Causes @command{tar} to ignore files that match the @var{pattern}.
  5383. @end table
  5384. @findex exclude
  5385. The @option{--exclude=@var{pattern}} option prevents any file or
  5386. member whose name matches the shell wildcard (@var{pattern}) from
  5387. being operated on.
  5388. For example, to create an archive with all the contents of the directory
  5389. @file{src} except for files whose names end in @file{.o}, use the
  5390. command @samp{tar -cf src.tar --exclude='*.o' src}.
  5391. You may give multiple @option{--exclude} options.
  5392. @table @option
  5393. @opindex exclude-from
  5394. @item --exclude-from=@var{file}
  5395. @itemx -X @var{file}
  5396. Causes @command{tar} to ignore files that match the patterns listed in
  5397. @var{file}.
  5398. @end table
  5399. @findex exclude-from
  5400. Use the @option{--exclude-from} option to read a
  5401. list of patterns, one per line, from @var{file}; @command{tar} will
  5402. ignore files matching those patterns. Thus if @command{tar} is
  5403. called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
  5404. single line @file{*.o}, no files whose names end in @file{.o} will be
  5405. added to the archive.
  5406. Notice, that lines from @var{file} are read verbatim. One of the
  5407. frequent errors is leaving some extra whitespace after a file name,
  5408. which is difficult to catch using text editors.
  5409. However, empty lines are OK.
  5410. @cindex version control system, excluding files
  5411. @cindex VCS, excluding files
  5412. @cindex SCCS, excluding files
  5413. @cindex RCS, excluding files
  5414. @cindex CVS, excluding files
  5415. @cindex SVN, excluding files
  5416. @cindex git, excluding files
  5417. @table @option
  5418. @opindex exclude-vcs
  5419. @item --exclude-vcs
  5420. Exclude files and directories used by some version control systems.
  5421. @end table
  5422. As of version @value{VERSION}, the following files are excluded:
  5423. @itemize @bullet
  5424. @item @file{CVS/}, and everything under it
  5425. @item @file{RCS/}, and everything under it
  5426. @item @file{SCCS/}, and everything under it
  5427. @item @file{.git/}, and everything under it
  5428. @item @file{.gitignore}
  5429. @item @file{.cvsignore}
  5430. @item @file{.svn/}, and everything under it
  5431. @item @file{.arch-ids/}, and everything under it
  5432. @item @file{@{arch@}/}, and everything under it
  5433. @item @file{=RELEASE-ID}
  5434. @item @file{=meta-update}
  5435. @item @file{=update}
  5436. @end itemize
  5437. @findex exclude-caches
  5438. When creating an archive, the @option{--exclude-caches} option family
  5439. causes @command{tar} to exclude all directories that contain a @dfn{cache
  5440. directory tag}. A cache directory tag is a short file with the
  5441. well-known name @file{CACHEDIR.TAG} and having a standard header
  5442. specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
  5443. Various applications write cache directory tags into directories they
  5444. use to hold regenerable, non-precious data, so that such data can be
  5445. more easily excluded from backups.
  5446. There are three @samp{exclude-caches} options, each providing a different
  5447. exclusion semantics:
  5448. @table @option
  5449. @opindex exclude-caches
  5450. @item --exclude-caches
  5451. Do not archive the contents of the directory, but archive the
  5452. directory itself and the @file{CACHEDIR.TAG} file.
  5453. @opindex exclude-caches-under
  5454. @item --exclude-caches-under
  5455. Do not archive the contents of the directory, nor the
  5456. @file{CACHEDIR.TAG} file, archive only the directory itself.
  5457. @opindex exclude-caches-all
  5458. @item --exclude-caches-all
  5459. Omit directories containing @file{CACHEDIR.TAG} file entirely.
  5460. @end table
  5461. @findex exclude-tag
  5462. Another option family, @option{--exclude-tag}, provides a generalization of
  5463. this concept. It takes a single argument, a file name to look for.
  5464. Any directory that contains this file will be excluded from the dump.
  5465. Similarly to @samp{exclude-caches}, there are three options in this
  5466. option family:
  5467. @table @option
  5468. @opindex exclude-tag
  5469. @item --exclude-tag=@var{file}
  5470. Do not dump the contents of the directory, but dump the
  5471. directory itself and the @var{file}.
  5472. @opindex exclude-tag-under
  5473. @item --exclude-tag-under=@var{file}
  5474. Do not dump the contents of the directory, nor the
  5475. @var{file}, archive only the directory itself.
  5476. @opindex exclude-tag-all
  5477. @item --exclude-tag-all=@var{file}
  5478. Omit directories containing @var{file} file entirely.
  5479. @end table
  5480. Multiple @option{--exclude-tag*} options can be given.
  5481. For example, given this directory:
  5482. @smallexample
  5483. @group
  5484. $ @kbd{find dir}
  5485. dir
  5486. dir/blues
  5487. dir/jazz
  5488. dir/folk
  5489. dir/folk/tagfile
  5490. dir/folk/sanjuan
  5491. dir/folk/trote
  5492. @end group
  5493. @end smallexample
  5494. The @option{--exclude-tag} will produce the following:
  5495. @smallexample
  5496. $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
  5497. dir/
  5498. dir/blues
  5499. dir/jazz
  5500. dir/folk/
  5501. tar: dir/folk/: contains a cache directory tag tagfile;
  5502. contents not dumped
  5503. dir/folk/tagfile
  5504. @end smallexample
  5505. Both the @file{dir/folk} directory and its tagfile are preserved in
  5506. the archive, however the rest of files in this directory are not.
  5507. Now, using the @option{--exclude-tag-under} option will exclude
  5508. @file{tagfile} from the dump, while still preserving the directory
  5509. itself, as shown in this example:
  5510. @smallexample
  5511. $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
  5512. dir/
  5513. dir/blues
  5514. dir/jazz
  5515. dir/folk/
  5516. ./tar: dir/folk/: contains a cache directory tag tagfile;
  5517. contents not dumped
  5518. @end smallexample
  5519. Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
  5520. directory entirely:
  5521. @smallexample
  5522. $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
  5523. dir/
  5524. dir/blues
  5525. dir/jazz
  5526. ./tar: dir/folk/: contains a cache directory tag tagfile;
  5527. directory not dumped
  5528. @end smallexample
  5529. @menu
  5530. * problems with exclude::
  5531. @end menu
  5532. @node problems with exclude
  5533. @unnumberedsubsec Problems with Using the @code{exclude} Options
  5534. @xopindex{exclude, potential problems with}
  5535. Some users find @samp{exclude} options confusing. Here are some common
  5536. pitfalls:
  5537. @itemize @bullet
  5538. @item
  5539. The main operating mode of @command{tar} does not act on a file name
  5540. explicitly listed on the command line, if one of its file name
  5541. components is excluded. In the example above, if
  5542. you create an archive and exclude files that end with @samp{*.o}, but
  5543. explicitly name the file @samp{dir.o/foo} after all the options have been
  5544. listed, @samp{dir.o/foo} will be excluded from the archive.
  5545. @item
  5546. You can sometimes confuse the meanings of @option{--exclude} and
  5547. @option{--exclude-from}. Be careful: use @option{--exclude} when files
  5548. to be excluded are given as a pattern on the command line. Use
  5549. @option{--exclude-from} to introduce the name of a file which contains
  5550. a list of patterns, one per line; each of these patterns can exclude
  5551. zero, one, or many files.
  5552. @item
  5553. When you use @option{--exclude=@var{pattern}}, be sure to quote the
  5554. @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
  5555. like @samp{*}. If you do not do this, the shell might expand the
  5556. @samp{*} itself using files at hand, so @command{tar} might receive a
  5557. list of files instead of one pattern, or none at all, making the
  5558. command somewhat illegal. This might not correspond to what you want.
  5559. For example, write:
  5560. @smallexample
  5561. $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
  5562. @end smallexample
  5563. @noindent
  5564. rather than:
  5565. @smallexample
  5566. # @emph{Wrong!}
  5567. $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
  5568. @end smallexample
  5569. @item
  5570. You must use use shell syntax, or globbing, rather than @code{regexp}
  5571. syntax, when using exclude options in @command{tar}. If you try to use
  5572. @code{regexp} syntax to describe files to be excluded, your command
  5573. might fail.
  5574. @item
  5575. @FIXME{The change in semantics must have occurred before 1.11,
  5576. so I doubt if it is worth mentioning at all. Anyway, should at
  5577. least specify in which version the semantics changed.}
  5578. In earlier versions of @command{tar}, what is now the
  5579. @option{--exclude-from} option was called @option{--exclude} instead.
  5580. Now, @option{--exclude} applies to patterns listed on the command
  5581. line and @option{--exclude-from} applies to patterns listed in a
  5582. file.
  5583. @end itemize
  5584. @node wildcards
  5585. @section Wildcards Patterns and Matching
  5586. @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
  5587. @samp{*} or @samp{?} for example, are replaced and expanded into all
  5588. existing files matching the given pattern. @GNUTAR{} can use wildcard
  5589. patterns for matching (or globbing) archive members when extracting
  5590. from or listing an archive. Wildcard patterns are also used for
  5591. verifying volume labels of @command{tar} archives. This section has the
  5592. purpose of explaining wildcard syntax for @command{tar}.
  5593. @FIXME{the next few paragraphs need work.}
  5594. A @var{pattern} should be written according to shell syntax, using wildcard
  5595. characters to effect globbing. Most characters in the pattern stand
  5596. for themselves in the matched string, and case is significant: @samp{a}
  5597. will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
  5598. pattern matches any single character in the matched string. The character
  5599. @samp{*} in the pattern matches zero, one, or more single characters in
  5600. the matched string. The character @samp{\} says to take the following
  5601. character of the pattern @emph{literally}; it is useful when one needs to
  5602. match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
  5603. The character @samp{[}, up to the matching @samp{]}, introduces a character
  5604. class. A @dfn{character class} is a list of acceptable characters
  5605. for the next single character of the matched string. For example,
  5606. @samp{[abcde]} would match any of the first five letters of the alphabet.
  5607. Note that within a character class, all of the ``special characters''
  5608. listed above other than @samp{\} lose their special meaning; for example,
  5609. @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
  5610. @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
  5611. the characters @samp{-} and @samp{]} must either come @emph{first} or
  5612. @emph{last} in a character class.)
  5613. @cindex Excluding characters from a character class
  5614. @cindex Character class, excluding characters from
  5615. If the first character of the class after the opening @samp{[}
  5616. is @samp{!} or @samp{^}, then the meaning of the class is reversed.
  5617. Rather than listing character to match, it lists those characters which
  5618. are @emph{forbidden} as the next single character of the matched string.
  5619. Other characters of the class stand for themselves. The special
  5620. construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
  5621. letters, is meant to represent all characters between @var{a} and
  5622. @var{e}, inclusive.
  5623. @FIXME{need to add a sentence or so here to make this clear for those
  5624. who don't have dan around.}
  5625. Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
  5626. special for wildcard matches. However, if a pattern completely matches
  5627. a directory prefix of a matched string, then it matches the full matched
  5628. string: thus, excluding a directory also excludes all the files beneath it.
  5629. @menu
  5630. * controlling pattern-matching::
  5631. @end menu
  5632. @node controlling pattern-matching
  5633. @unnumberedsubsec Controlling Pattern-Matching
  5634. For the purposes of this section, we call @dfn{exclusion members} all
  5635. member names obtained while processing @option{--exclude} and
  5636. @option{--exclude-from} options, and @dfn{inclusion members} those
  5637. member names that were given in the command line or read from the file
  5638. specified with @option{--files-from} option.
  5639. These two pairs of member lists are used in the following operations:
  5640. @option{--diff}, @option{--extract}, @option{--list},
  5641. @option{--update}.
  5642. There are no inclusion members in create mode (@option{--create} and
  5643. @option{--append}), since in this mode the names obtained from the
  5644. command line refer to @emph{files}, not archive members.
  5645. By default, inclusion members are compared with archive members
  5646. literally @footnote{Notice that earlier @GNUTAR{} versions used
  5647. globbing for inclusion members, which contradicted to UNIX98
  5648. specification and was not documented. @xref{Changes}, for more
  5649. information on this and other changes.} and exclusion members are
  5650. treated as globbing patterns. For example:
  5651. @smallexample
  5652. @group
  5653. $ @kbd{tar tf foo.tar}
  5654. a.c
  5655. b.c
  5656. a.txt
  5657. [remarks]
  5658. # @i{Member names are used verbatim:}
  5659. $ @kbd{tar -xf foo.tar -v '[remarks]'}
  5660. [remarks]
  5661. # @i{Exclude member names are globbed:}
  5662. $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
  5663. a.txt
  5664. [remarks]
  5665. @end group
  5666. @end smallexample
  5667. This behavior can be altered by using the following options:
  5668. @table @option
  5669. @opindex wildcards
  5670. @item --wildcards
  5671. Treat all member names as wildcards.
  5672. @opindex no-wildcards
  5673. @item --no-wildcards
  5674. Treat all member names as literal strings.
  5675. @end table
  5676. Thus, to extract files whose names end in @samp{.c}, you can use:
  5677. @smallexample
  5678. $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
  5679. a.c
  5680. b.c
  5681. @end smallexample
  5682. @noindent
  5683. Notice quoting of the pattern to prevent the shell from interpreting
  5684. it.
  5685. The effect of @option{--wildcards} option is canceled by
  5686. @option{--no-wildcards}. This can be used to pass part of
  5687. the command line arguments verbatim and other part as globbing
  5688. patterns. For example, the following invocation:
  5689. @smallexample
  5690. $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
  5691. @end smallexample
  5692. @noindent
  5693. instructs @command{tar} to extract from @file{foo.tar} all files whose
  5694. names end in @samp{.txt} and the file named @file{[remarks]}.
  5695. Normally, a pattern matches a name if an initial subsequence of the
  5696. name's components matches the pattern, where @samp{*}, @samp{?}, and
  5697. @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
  5698. and wildcards can match @samp{/}.
  5699. Other than optionally stripping leading @samp{/} from names
  5700. (@pxref{absolute}), patterns and names are used as-is. For
  5701. example, trailing @samp{/} is not trimmed from a user-specified name
  5702. before deciding whether to exclude it.
  5703. However, this matching procedure can be altered by the options listed
  5704. below. These options accumulate. For example:
  5705. @smallexample
  5706. --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
  5707. @end smallexample
  5708. @noindent
  5709. ignores case when excluding @samp{makefile}, but not when excluding
  5710. @samp{readme}.
  5711. @table @option
  5712. @opindex anchored
  5713. @opindex no-anchored
  5714. @item --anchored
  5715. @itemx --no-anchored
  5716. If anchored, a pattern must match an initial subsequence
  5717. of the name's components. Otherwise, the pattern can match any
  5718. subsequence. Default is @option{--no-anchored} for exclusion members
  5719. and @option{--anchored} inclusion members.
  5720. @opindex ignore-case
  5721. @opindex no-ignore-case
  5722. @item --ignore-case
  5723. @itemx --no-ignore-case
  5724. When ignoring case, upper-case patterns match lower-case names and vice versa.
  5725. When not ignoring case (the default), matching is case-sensitive.
  5726. @opindex wildcards-match-slash
  5727. @opindex no-wildcards-match-slash
  5728. @item --wildcards-match-slash
  5729. @itemx --no-wildcards-match-slash
  5730. When wildcards match slash (the default for exclusion members), a
  5731. wildcard like @samp{*} in the pattern can match a @samp{/} in the
  5732. name. Otherwise, @samp{/} is matched only by @samp{/}.
  5733. @end table
  5734. The @option{--recursion} and @option{--no-recursion} options
  5735. (@pxref{recurse}) also affect how member patterns are interpreted. If
  5736. recursion is in effect, a pattern matches a name if it matches any of
  5737. the name's parent directories.
  5738. The following table summarizes pattern-matching default values:
  5739. @multitable @columnfractions .3 .7
  5740. @headitem Members @tab Default settings
  5741. @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
  5742. @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
  5743. @end multitable
  5744. @node quoting styles
  5745. @section Quoting Member Names
  5746. When displaying member names, @command{tar} takes care to avoid
  5747. ambiguities caused by certain characters. This is called @dfn{name
  5748. quoting}. The characters in question are:
  5749. @itemize @bullet
  5750. @item Non-printable control characters:
  5751. @anchor{escape sequences}
  5752. @multitable @columnfractions 0.20 0.10 0.60
  5753. @headitem Character @tab @acronym{ASCII} @tab Character name
  5754. @item \a @tab 7 @tab Audible bell
  5755. @item \b @tab 8 @tab Backspace
  5756. @item \f @tab 12 @tab Form feed
  5757. @item \n @tab 10 @tab New line
  5758. @item \r @tab 13 @tab Carriage return
  5759. @item \t @tab 9 @tab Horizontal tabulation
  5760. @item \v @tab 11 @tab Vertical tabulation
  5761. @end multitable
  5762. @item Space (@acronym{ASCII} 32)
  5763. @item Single and double quotes (@samp{'} and @samp{"})
  5764. @item Backslash (@samp{\})
  5765. @end itemize
  5766. The exact way @command{tar} uses to quote these characters depends on
  5767. the @dfn{quoting style}. The default quoting style, called
  5768. @dfn{escape} (see below), uses backslash notation to represent control
  5769. characters, space and backslash. Using this quoting style, control
  5770. characters are represented as listed in column @samp{Character} in the
  5771. above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
  5772. @GNUTAR{} offers seven distinct quoting styles, which can be selected
  5773. using @option{--quoting-style} option:
  5774. @table @option
  5775. @item --quoting-style=@var{style}
  5776. @opindex quoting-style
  5777. Sets quoting style. Valid values for @var{style} argument are:
  5778. literal, shell, shell-always, c, escape, locale, clocale.
  5779. @end table
  5780. These styles are described in detail below. To illustrate their
  5781. effect, we will use an imaginary tar archive @file{arch.tar}
  5782. containing the following members:
  5783. @smallexample
  5784. @group
  5785. # 1. Contains horizontal tabulation character.
  5786. a tab
  5787. # 2. Contains newline character
  5788. a
  5789. newline
  5790. # 3. Contains a space
  5791. a space
  5792. # 4. Contains double quotes
  5793. a"double"quote
  5794. # 5. Contains single quotes
  5795. a'single'quote
  5796. # 6. Contains a backslash character:
  5797. a\backslash
  5798. @end group
  5799. @end smallexample
  5800. Here is how usual @command{ls} command would have listed them, if they
  5801. had existed in the current working directory:
  5802. @smallexample
  5803. @group
  5804. $ @kbd{ls}
  5805. a\ttab
  5806. a\nnewline
  5807. a\ space
  5808. a"double"quote
  5809. a'single'quote
  5810. a\\backslash
  5811. @end group
  5812. @end smallexample
  5813. Quoting styles:
  5814. @table @samp
  5815. @item literal
  5816. No quoting, display each character as is:
  5817. @smallexample
  5818. @group
  5819. $ @kbd{tar tf arch.tar --quoting-style=literal}
  5820. ./
  5821. ./a space
  5822. ./a'single'quote
  5823. ./a"double"quote
  5824. ./a\backslash
  5825. ./a tab
  5826. ./a
  5827. newline
  5828. @end group
  5829. @end smallexample
  5830. @item shell
  5831. Display characters the same way Bourne shell does:
  5832. control characters, except @samp{\t} and @samp{\n}, are printed using
  5833. backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
  5834. single quote is printed as @samp{\'}. If a name contains any quoted
  5835. characters, it is enclosed in single quotes. In particular, if a name
  5836. contains single quotes, it is printed as several single-quoted strings:
  5837. @smallexample
  5838. @group
  5839. $ @kbd{tar tf arch.tar --quoting-style=shell}
  5840. ./
  5841. './a space'
  5842. './a'\''single'\''quote'
  5843. './a"double"quote'
  5844. './a\backslash'
  5845. './a tab'
  5846. './a
  5847. newline'
  5848. @end group
  5849. @end smallexample
  5850. @item shell-always
  5851. Same as @samp{shell}, but the names are always enclosed in single
  5852. quotes:
  5853. @smallexample
  5854. @group
  5855. $ @kbd{tar tf arch.tar --quoting-style=shell-always}
  5856. './'
  5857. './a space'
  5858. './a'\''single'\''quote'
  5859. './a"double"quote'
  5860. './a\backslash'
  5861. './a tab'
  5862. './a
  5863. newline'
  5864. @end group
  5865. @end smallexample
  5866. @item c
  5867. Use the notation of the C programming language. All names are
  5868. enclosed in double quotes. Control characters are quoted using
  5869. backslash notations, double quotes are represented as @samp{\"},
  5870. backslash characters are represented as @samp{\\}. Single quotes and
  5871. spaces are not quoted:
  5872. @smallexample
  5873. @group
  5874. $ @kbd{tar tf arch.tar --quoting-style=c}
  5875. "./"
  5876. "./a space"
  5877. "./a'single'quote"
  5878. "./a\"double\"quote"
  5879. "./a\\backslash"
  5880. "./a\ttab"
  5881. "./a\nnewline"
  5882. @end group
  5883. @end smallexample
  5884. @item escape
  5885. Control characters are printed using backslash notation, a space is
  5886. printed as @samp{\ } and a backslash as @samp{\\}. This is the
  5887. default quoting style, unless it was changed when configured the
  5888. package.
  5889. @smallexample
  5890. @group
  5891. $ @kbd{tar tf arch.tar --quoting-style=escape}
  5892. ./
  5893. ./a space
  5894. ./a'single'quote
  5895. ./a"double"quote
  5896. ./a\\backslash
  5897. ./a\ttab
  5898. ./a\nnewline
  5899. @end group
  5900. @end smallexample
  5901. @item locale
  5902. Control characters, single quote and backslash are printed using
  5903. backslash notation. All names are quoted using left and right
  5904. quotation marks, appropriate to the current locale. If it does not
  5905. define quotation marks, use @samp{`} as left and @samp{'} as right
  5906. quotation marks. Any occurrences of the right quotation mark in a
  5907. name are escaped with @samp{\}, for example:
  5908. For example:
  5909. @smallexample
  5910. @group
  5911. $ @kbd{tar tf arch.tar --quoting-style=locale}
  5912. `./'
  5913. `./a space'
  5914. `./a\'single\'quote'
  5915. `./a"double"quote'
  5916. `./a\\backslash'
  5917. `./a\ttab'
  5918. `./a\nnewline'
  5919. @end group
  5920. @end smallexample
  5921. @item clocale
  5922. Same as @samp{locale}, but @samp{"} is used for both left and right
  5923. quotation marks, if not provided by the currently selected locale:
  5924. @smallexample
  5925. @group
  5926. $ @kbd{tar tf arch.tar --quoting-style=clocale}
  5927. "./"
  5928. "./a space"
  5929. "./a'single'quote"
  5930. "./a\"double\"quote"
  5931. "./a\\backslash"
  5932. "./a\ttab"
  5933. "./a\nnewline"
  5934. @end group
  5935. @end smallexample
  5936. @end table
  5937. You can specify which characters should be quoted in addition to those
  5938. implied by the current quoting style:
  5939. @table @option
  5940. @item --quote-chars=@var{string}
  5941. Always quote characters from @var{string}, even if the selected
  5942. quoting style would not quote them.
  5943. @end table
  5944. For example, using @samp{escape} quoting (compare with the usual
  5945. escape listing above):
  5946. @smallexample
  5947. @group
  5948. $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
  5949. ./
  5950. ./a\ space
  5951. ./a'single'quote
  5952. ./a\"double\"quote
  5953. ./a\\backslash
  5954. ./a\ttab
  5955. ./a\nnewline
  5956. @end group
  5957. @end smallexample
  5958. To disable quoting of such additional characters, use the following
  5959. option:
  5960. @table @option
  5961. @item --no-quote-chars=@var{string}
  5962. Remove characters listed in @var{string} from the list of quoted
  5963. characters set by the previous @option{--quote-chars} option.
  5964. @end table
  5965. This option is particularly useful if you have added
  5966. @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
  5967. and wish to disable it for the current invocation.
  5968. Note, that @option{--no-quote-chars} does @emph{not} disable those
  5969. characters that are quoted by default in the selected quoting style.
  5970. @node transform
  5971. @section Modifying File and Member Names
  5972. @command{Tar} archives contain detailed information about files stored
  5973. in them and full file names are part of that information. When
  5974. storing file to an archive, its file name is recorded in the archive
  5975. along with the actual file contents. When restoring from an archive,
  5976. a file is created on disk with exactly the same name as that stored
  5977. in the archive. In the majority of cases this is the desired behavior
  5978. of a file archiver. However, there are some cases when it is not.
  5979. First of all, it is often unsafe to extract archive members with
  5980. absolute file names or those that begin with a @file{../}. @GNUTAR{}
  5981. takes special precautions when extracting such names and provides a
  5982. special option for handling them, which is described in
  5983. @ref{absolute}.
  5984. Secondly, you may wish to extract file names without some leading
  5985. directory components, or with otherwise modified names. In other
  5986. cases it is desirable to store files under differing names in the
  5987. archive.
  5988. @GNUTAR{} provides two options for these needs.
  5989. @table @option
  5990. @opindex strip-components
  5991. @item --strip-components=@var{number}
  5992. Strip given @var{number} of leading components from file names before
  5993. extraction.
  5994. @end table
  5995. For example, suppose you have archived whole @file{/usr} hierarchy to
  5996. a tar archive named @file{usr.tar}. Among other files, this archive
  5997. contains @file{usr/include/stdlib.h}, which you wish to extract to
  5998. the current working directory. To do so, you type:
  5999. @smallexample
  6000. $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
  6001. @end smallexample
  6002. The option @option{--strip=2} instructs @command{tar} to strip the
  6003. two leading components (@file{usr/} and @file{include/}) off the file
  6004. name.
  6005. If you add to the above invocation @option{--verbose} (@option{-v})
  6006. option, you will note that the verbose listing still contains the
  6007. full file name, with the two removed components still in place. This
  6008. can be inconvenient, so @command{tar} provides a special option for
  6009. altering this behavior:
  6010. @anchor{show-transformed-names}
  6011. @table @option
  6012. @opindex show-transformed-names
  6013. @item --show-transformed-names
  6014. Display file or member names with all requested transformations
  6015. applied.
  6016. @end table
  6017. @noindent
  6018. For example:
  6019. @smallexample
  6020. @group
  6021. $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
  6022. usr/include/stdlib.h
  6023. $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
  6024. stdlib.h
  6025. @end group
  6026. @end smallexample
  6027. Notice that in both cases the file is @file{stdlib.h} extracted to the
  6028. current working directory, @option{--show-transformed-names} affects
  6029. only the way its name is displayed.
  6030. This option is especially useful for verifying whether the invocation
  6031. will have the desired effect. Thus, before running
  6032. @smallexample
  6033. $ @kbd{tar -x --strip=@var{n}}
  6034. @end smallexample
  6035. @noindent
  6036. it is often advisable to run
  6037. @smallexample
  6038. $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
  6039. @end smallexample
  6040. @noindent
  6041. to make sure the command will produce the intended results.
  6042. In case you need to apply more complex modifications to the file name,
  6043. @GNUTAR{} provides a general-purpose transformation option:
  6044. @table @option
  6045. @opindex transform
  6046. @item --transform=@var{expression}
  6047. Modify file names using supplied @var{expression}.
  6048. @end table
  6049. @noindent
  6050. The @var{expression} is a @command{sed}-like replace expression of the
  6051. form:
  6052. @smallexample
  6053. s/@var{regexp}/@var{replace}/[@var{flags}]
  6054. @end smallexample
  6055. @noindent
  6056. where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
  6057. replacement for each file name part that matches @var{regexp}. Both
  6058. @var{regexp} and @var{replace} are described in detail in
  6059. @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
  6060. Supported @var{flags} are:
  6061. @table @samp
  6062. @item g
  6063. Apply the replacement to @emph{all} matches to the @var{regexp}, not
  6064. just the first.
  6065. @item i
  6066. Use case-insensitive matching
  6067. @item x
  6068. @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
  6069. regexps, Extended regular expressions, Extended regular expressions,
  6070. sed, GNU sed}).
  6071. @item @var{number}
  6072. Only replace the @var{number}th match of the @var{regexp}.
  6073. Note: the @var{posix} standard does not specify what should happen
  6074. when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
  6075. follows the GNU @command{sed} implementation in this regard, so
  6076. the interaction is defined to be: ignore matches before the
  6077. @var{number}th, and then match and replace all matches from the
  6078. @var{number}th on.
  6079. @end table
  6080. Any delimiter can be used in lieue of @samp{/}, the only requirement being
  6081. that it be used consistently throughout the expression. For example,
  6082. the following two expressions are equivalent:
  6083. @smallexample
  6084. @group
  6085. s/one/two/
  6086. s,one,two,
  6087. @end group
  6088. @end smallexample
  6089. Changing delimiters is often useful when the @var{regex} contains
  6090. slashes. For example, it is more convenient to write @code{s,/,-,} than
  6091. @code{s/\//-/}.
  6092. Here are several examples of @option{--transform} usage:
  6093. @enumerate
  6094. @item Extract @file{usr/} hierarchy into @file{usr/local/}:
  6095. @smallexample
  6096. $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
  6097. @end smallexample
  6098. @item Strip two leading directory components (equivalent to
  6099. @option{--strip-components=2}):
  6100. @smallexample
  6101. $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
  6102. @end smallexample
  6103. @item Prepend @file{/prefix/} to each file name:
  6104. @smallexample
  6105. $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
  6106. @end smallexample
  6107. @item Convert each file name to lower case:
  6108. @smallexample
  6109. $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
  6110. @end smallexample
  6111. @end enumerate
  6112. Unlike @option{--strip-components}, @option{--transform} can be used
  6113. in any @GNUTAR{} operation mode. For example, the following command
  6114. adds files to the archive while replacing the leading @file{usr/}
  6115. component with @file{var/}:
  6116. @smallexample
  6117. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
  6118. @end smallexample
  6119. To test @option{--transform} effect we suggest using
  6120. @option{--show-transformed-names} option:
  6121. @smallexample
  6122. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
  6123. --verbose --show-transformed-names /}
  6124. @end smallexample
  6125. If both @option{--strip-components} and @option{--transform} are used
  6126. together, then @option{--transform} is applied first, and the required
  6127. number of components is then stripped from its result.
  6128. @node after
  6129. @section Operating Only on New Files
  6130. @UNREVISED
  6131. @cindex Excluding file by age
  6132. @cindex Data Modification time, excluding files by
  6133. @cindex Modification time, excluding files by
  6134. @cindex Age, excluding files by
  6135. The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
  6136. @option{-N @var{date}}) option causes @command{tar} to only work on
  6137. files whose data modification or status change times are newer than
  6138. the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
  6139. it is taken to be a file name; the data modification time of that file
  6140. is used as the date. If you use this option when creating or appending
  6141. to an archive, the archive will only include new files. If you use
  6142. @option{--after-date} when extracting an archive, @command{tar} will
  6143. only extract files newer than the @var{date} you specify.
  6144. If you only want @command{tar} to make the date comparison based on
  6145. modification of the file's data (rather than status
  6146. changes), then use the @option{--newer-mtime=@var{date}} option.
  6147. You may use these options with any operation. Note that these options
  6148. differ from the @option{--update} (@option{-u}) operation in that they
  6149. allow you to specify a particular date against which @command{tar} can
  6150. compare when deciding whether or not to archive the files.
  6151. @table @option
  6152. @opindex after-date
  6153. @opindex newer
  6154. @item --after-date=@var{date}
  6155. @itemx --newer=@var{date}
  6156. @itemx -N @var{date}
  6157. Only store files newer than @var{date}.
  6158. Acts on files only if their data modification or status change times are
  6159. later than @var{date}. Use in conjunction with any operation.
  6160. If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
  6161. name; the data modification time of that file is used as the date.
  6162. @opindex newer-mtime
  6163. @item --newer-mtime=@var{date}
  6164. Acts like @option{--after-date}, but only looks at data modification times.
  6165. @end table
  6166. These options limit @command{tar} to operate only on files which have
  6167. been modified after the date specified. A file's status is considered to have
  6168. changed if its contents have been modified, or if its owner,
  6169. permissions, and so forth, have been changed. (For more information on
  6170. how to specify a date, see @ref{Date input formats}; remember that the
  6171. entire date argument must be quoted if it contains any spaces.)
  6172. Gurus would say that @option{--after-date} tests both the data
  6173. modification time (@code{mtime}, the time the contents of the file
  6174. were last modified) and the status change time (@code{ctime}, the time
  6175. the file's status was last changed: owner, permissions, etc.@:)
  6176. fields, while @option{--newer-mtime} tests only the @code{mtime}
  6177. field.
  6178. To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
  6179. @code{ctime} and processes the file if either one is more recent than
  6180. @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
  6181. disregards @code{ctime}. Neither does it use @code{atime} (the last time the
  6182. contents of the file were looked at).
  6183. Date specifiers can have embedded spaces. Because of this, you may need
  6184. to quote date arguments to keep the shell from parsing them as separate
  6185. arguments. For example, the following command will add to the archive
  6186. all the files modified less than two days ago:
  6187. @smallexample
  6188. $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
  6189. @end smallexample
  6190. When any of these options is used with the option @option{--verbose}
  6191. (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
  6192. date back to its textual representation and compare that with the
  6193. one given with the option. If the two dates differ, @command{tar} will
  6194. print a warning saying what date it will use. This is to help user
  6195. ensure he is using the right date. For example:
  6196. @smallexample
  6197. @group
  6198. $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
  6199. tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
  6200. 13:19:37.232434
  6201. @end group
  6202. @end smallexample
  6203. @quotation
  6204. @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
  6205. should not be used for incremental backups. @xref{Incremental Dumps},
  6206. for proper way of creating incremental backups.
  6207. @end quotation
  6208. @node recurse
  6209. @section Descending into Directories
  6210. @UNREVISED
  6211. @cindex Avoiding recursion in directories
  6212. @cindex Descending directories, avoiding
  6213. @cindex Directories, avoiding recursion
  6214. @cindex Recursion in directories, avoiding
  6215. @FIXME{arrggh! this is still somewhat confusing to me. :-< }
  6216. Usually, @command{tar} will recursively explore all directories (either
  6217. those given on the command line or through the @option{--files-from}
  6218. option) for the various files they contain. However, you may not always
  6219. want @command{tar} to act this way.
  6220. @opindex no-recursion
  6221. The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
  6222. into specified directories. If you specify @option{--no-recursion}, you can
  6223. use the @command{find} utility for hunting through levels of directories to
  6224. construct a list of file names which you could then pass to @command{tar}.
  6225. @command{find} allows you to be more selective when choosing which files to
  6226. archive; see @ref{files}, for more information on using @command{find} with
  6227. @command{tar}, or look.
  6228. @table @option
  6229. @item --no-recursion
  6230. Prevents @command{tar} from recursively descending directories.
  6231. @opindex recursion
  6232. @item --recursion
  6233. Requires @command{tar} to recursively descend directories.
  6234. This is the default.
  6235. @end table
  6236. When you use @option{--no-recursion}, @GNUTAR{} grabs
  6237. directory entries themselves, but does not descend on them
  6238. recursively. Many people use @command{find} for locating files they
  6239. want to back up, and since @command{tar} @emph{usually} recursively
  6240. descends on directories, they have to use the @samp{@w{-not -type d}}
  6241. test in their @command{find} invocation (@pxref{Type, Type, Type test,
  6242. find, Finding Files}), as they usually do not want all the files in a
  6243. directory. They then use the @option{--files-from} option to archive
  6244. the files located via @command{find}.
  6245. The problem when restoring files archived in this manner is that the
  6246. directories themselves are not in the archive; so the
  6247. @option{--same-permissions} (@option{--preserve-permissions},
  6248. @option{-p}) option does not affect them---while users might really
  6249. like it to. Specifying @option{--no-recursion} is a way to tell
  6250. @command{tar} to grab only the directory entries given to it, adding
  6251. no new files on its own. To summarize, if you use @command{find} to
  6252. create a list of files to be stored in an archive, use it as follows:
  6253. @smallexample
  6254. @group
  6255. $ @kbd{find @var{dir} @var{tests} | \
  6256. tar -cf @var{archive} -T - --no-recursion}
  6257. @end group
  6258. @end smallexample
  6259. The @option{--no-recursion} option also applies when extracting: it
  6260. causes @command{tar} to extract only the matched directory entries, not
  6261. the files under those directories.
  6262. The @option{--no-recursion} option also affects how globbing patterns
  6263. are interpreted (@pxref{controlling pattern-matching}).
  6264. The @option{--no-recursion} and @option{--recursion} options apply to
  6265. later options and operands, and can be overridden by later occurrences
  6266. of @option{--no-recursion} and @option{--recursion}. For example:
  6267. @smallexample
  6268. $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
  6269. @end smallexample
  6270. @noindent
  6271. creates an archive with one entry for @file{grape}, and the recursive
  6272. contents of @file{grape/concord}, but no entries under @file{grape}
  6273. other than @file{grape/concord}.
  6274. @node one
  6275. @section Crossing File System Boundaries
  6276. @cindex File system boundaries, not crossing
  6277. @UNREVISED
  6278. @command{tar} will normally automatically cross file system boundaries in
  6279. order to archive files which are part of a directory tree. You can
  6280. change this behavior by running @command{tar} and specifying
  6281. @option{--one-file-system}. This option only affects files that are
  6282. archived because they are in a directory that is being archived;
  6283. @command{tar} will still archive files explicitly named on the command line
  6284. or through @option{--files-from}, regardless of where they reside.
  6285. @table @option
  6286. @opindex one-file-system
  6287. @item --one-file-system
  6288. Prevents @command{tar} from crossing file system boundaries when
  6289. archiving. Use in conjunction with any write operation.
  6290. @end table
  6291. The @option{--one-file-system} option causes @command{tar} to modify its
  6292. normal behavior in archiving the contents of directories. If a file in
  6293. a directory is not on the same file system as the directory itself, then
  6294. @command{tar} will not archive that file. If the file is a directory
  6295. itself, @command{tar} will not archive anything beneath it; in other words,
  6296. @command{tar} will not cross mount points.
  6297. This option is useful for making full or incremental archival backups of
  6298. a file system. If this option is used in conjunction with
  6299. @option{--verbose} (@option{-v}), files that are excluded are
  6300. mentioned by name on the standard error.
  6301. @menu
  6302. * directory:: Changing Directory
  6303. * absolute:: Absolute File Names
  6304. @end menu
  6305. @node directory
  6306. @subsection Changing the Working Directory
  6307. @FIXME{need to read over this node now for continuity; i've switched
  6308. things around some.}
  6309. @cindex Changing directory mid-stream
  6310. @cindex Directory, changing mid-stream
  6311. @cindex Working directory, specifying
  6312. To change the working directory in the middle of a list of file names,
  6313. either on the command line or in a file specified using
  6314. @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
  6315. This will change the working directory to the specified directory
  6316. after that point in the list.
  6317. @table @option
  6318. @opindex directory
  6319. @item --directory=@var{directory}
  6320. @itemx -C @var{directory}
  6321. Changes the working directory in the middle of a command line.
  6322. @end table
  6323. For example,
  6324. @smallexample
  6325. $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
  6326. @end smallexample
  6327. @noindent
  6328. will place the files @file{grape} and @file{prune} from the current
  6329. directory into the archive @file{jams.tar}, followed by the file
  6330. @file{cherry} from the directory @file{food}. This option is especially
  6331. useful when you have several widely separated files that you want to
  6332. store in the same archive.
  6333. Note that the file @file{cherry} is recorded in the archive under the
  6334. precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
  6335. archive will contain three files that all appear to have come from the
  6336. same directory; if the archive is extracted with plain @samp{tar
  6337. --extract}, all three files will be written in the current directory.
  6338. Contrast this with the command,
  6339. @smallexample
  6340. $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
  6341. @end smallexample
  6342. @noindent
  6343. which records the third file in the archive under the name
  6344. @file{red/cherry} so that, if the archive is extracted using
  6345. @samp{tar --extract}, the third file will be written in a subdirectory
  6346. named @file{orange-colored}.
  6347. You can use the @option{--directory} option to make the archive
  6348. independent of the original name of the directory holding the files.
  6349. The following command places the files @file{/etc/passwd},
  6350. @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
  6351. @file{foo.tar}:
  6352. @smallexample
  6353. $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
  6354. @end smallexample
  6355. @noindent
  6356. However, the names of the archive members will be exactly what they were
  6357. on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
  6358. They will not appear to be related by file name to the original
  6359. directories where those files were located.
  6360. Note that @option{--directory} options are interpreted consecutively. If
  6361. @option{--directory} specifies a relative file name, it is interpreted
  6362. relative to the then current directory, which might not be the same as
  6363. the original current working directory of @command{tar}, due to a previous
  6364. @option{--directory} option.
  6365. When using @option{--files-from} (@pxref{files}), you can put various
  6366. @command{tar} options (including @option{-C}) in the file list. Notice,
  6367. however, that in this case the option and its argument may not be
  6368. separated by whitespace. If you use short option, its argument must
  6369. either follow the option letter immediately, without any intervening
  6370. whitespace, or occupy the next line. Otherwise, if you use long
  6371. option, separate its argument by an equal sign.
  6372. For instance, the file list for the above example will be:
  6373. @smallexample
  6374. @group
  6375. -C/etc
  6376. passwd
  6377. hosts
  6378. --directory=/lib
  6379. libc.a
  6380. @end group
  6381. @end smallexample
  6382. @noindent
  6383. To use it, you would invoke @command{tar} as follows:
  6384. @smallexample
  6385. $ @kbd{tar -c -f foo.tar --files-from list}
  6386. @end smallexample
  6387. The interpretation of @option{--directory} is disabled by
  6388. @option{--null} option.
  6389. @node absolute
  6390. @subsection Absolute File Names
  6391. @UNREVISED
  6392. @table @option
  6393. @opindex absolute-names
  6394. @item --absolute-names
  6395. @itemx -P
  6396. Do not strip leading slashes from file names, and permit file names
  6397. containing a @file{..} file name component.
  6398. @end table
  6399. By default, @GNUTAR{} drops a leading @samp{/} on
  6400. input or output, and complains about file names containing a @file{..}
  6401. component. This option turns off this behavior.
  6402. When @command{tar} extracts archive members from an archive, it strips any
  6403. leading slashes (@samp{/}) from the member name. This causes absolute
  6404. member names in the archive to be treated as relative file names. This
  6405. allows you to have such members extracted wherever you want, instead of
  6406. being restricted to extracting the member in the exact directory named
  6407. in the archive. For example, if the archive member has the name
  6408. @file{/etc/passwd}, @command{tar} will extract it as if the name were
  6409. really @file{etc/passwd}.
  6410. File names containing @file{..} can cause problems when extracting, so
  6411. @command{tar} normally warns you about such files when creating an
  6412. archive, and rejects attempts to extracts such files.
  6413. Other @command{tar} programs do not do this. As a result, if you
  6414. create an archive whose member names start with a slash, they will be
  6415. difficult for other people with a non-@GNUTAR{}
  6416. program to use. Therefore, @GNUTAR{} also strips
  6417. leading slashes from member names when putting members into the
  6418. archive. For example, if you ask @command{tar} to add the file
  6419. @file{/bin/ls} to an archive, it will do so, but the member name will
  6420. be @file{bin/ls}.@footnote{A side effect of this is that when
  6421. @option{--create} is used with @option{--verbose} the resulting output
  6422. is not, generally speaking, the same as the one you'd get running
  6423. @kbd{tar --list} command. This may be important if you use some
  6424. scripts for comparing both outputs. @xref{listing member and file names},
  6425. for the information on how to handle this case.}
  6426. If you use the @option{--absolute-names} (@option{-P}) option,
  6427. @command{tar} will do none of these transformations.
  6428. To archive or extract files relative to the root directory, specify
  6429. the @option{--absolute-names} (@option{-P}) option.
  6430. Normally, @command{tar} acts on files relative to the working
  6431. directory---ignoring superior directory names when archiving, and
  6432. ignoring leading slashes when extracting.
  6433. When you specify @option{--absolute-names} (@option{-P}),
  6434. @command{tar} stores file names including all superior directory
  6435. names, and preserves leading slashes. If you only invoked
  6436. @command{tar} from the root directory you would never need the
  6437. @option{--absolute-names} option, but using this option
  6438. may be more convenient than switching to root.
  6439. @FIXME{Should be an example in the tutorial/wizardry section using this
  6440. to transfer files between systems.}
  6441. @FIXME{Is write access an issue?}
  6442. @table @option
  6443. @item --absolute-names
  6444. Preserves full file names (including superior directory names) when
  6445. archiving files. Preserves leading slash when extracting files.
  6446. @end table
  6447. @FIXME{this is still horrible; need to talk with dan on monday.}
  6448. @command{tar} prints out a message about removing the @samp{/} from
  6449. file names. This message appears once per @GNUTAR{}
  6450. invocation. It represents something which ought to be told; ignoring
  6451. what it means can cause very serious surprises, later.
  6452. Some people, nevertheless, do not want to see this message. Wanting to
  6453. play really dangerously, one may of course redirect @command{tar} standard
  6454. error to the sink. For example, under @command{sh}:
  6455. @smallexample
  6456. $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
  6457. @end smallexample
  6458. @noindent
  6459. Another solution, both nicer and simpler, would be to change to
  6460. the @file{/} directory first, and then avoid absolute notation.
  6461. For example:
  6462. @smallexample
  6463. $ @kbd{(cd / && tar -c -f archive.tar home)}
  6464. # @i{or}:
  6465. $ @kbd{tar -c -f archive.tar -C / home}
  6466. @end smallexample
  6467. @include getdate.texi
  6468. @node Formats
  6469. @chapter Controlling the Archive Format
  6470. @cindex Tar archive formats
  6471. Due to historical reasons, there are several formats of tar archives.
  6472. All of them are based on the same principles, but have some subtle
  6473. differences that often make them incompatible with each other.
  6474. GNU tar is able to create and handle archives in a variety of formats.
  6475. The most frequently used formats are (in alphabetical order):
  6476. @table @asis
  6477. @item gnu
  6478. Format used by @GNUTAR{} versions up to 1.13.25. This format derived
  6479. from an early @acronym{POSIX} standard, adding some improvements such as
  6480. sparse file handling and incremental archives. Unfortunately these
  6481. features were implemented in a way incompatible with other archive
  6482. formats.
  6483. Archives in @samp{gnu} format are able to hold file names of unlimited
  6484. length.
  6485. @item oldgnu
  6486. Format used by @GNUTAR{} of versions prior to 1.12.
  6487. @item v7
  6488. Archive format, compatible with the V7 implementation of tar. This
  6489. format imposes a number of limitations. The most important of them
  6490. are:
  6491. @enumerate
  6492. @item The maximum length of a file name is limited to 99 characters.
  6493. @item The maximum length of a symbolic link is limited to 99 characters.
  6494. @item It is impossible to store special files (block and character
  6495. devices, fifos etc.)
  6496. @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
  6497. octal)
  6498. @item V7 archives do not contain symbolic ownership information (user
  6499. and group name of the file owner).
  6500. @end enumerate
  6501. This format has traditionally been used by Automake when producing
  6502. Makefiles. This practice will change in the future, in the meantime,
  6503. however this means that projects containing file names more than 99
  6504. characters long will not be able to use @GNUTAR{} @value{VERSION} and
  6505. Automake prior to 1.9.
  6506. @item ustar
  6507. Archive format defined by @acronym{POSIX.1-1988} specification. It stores
  6508. symbolic ownership information. It is also able to store
  6509. special files. However, it imposes several restrictions as well:
  6510. @enumerate
  6511. @item The maximum length of a file name is limited to 256 characters,
  6512. provided that the file name can be split at a directory separator in
  6513. two parts, first of them being at most 155 bytes long. So, in most
  6514. cases the maximum file name length will be shorter than 256
  6515. characters.
  6516. @item The maximum length of a symbolic link name is limited to
  6517. 100 characters.
  6518. @item Maximum size of a file the archive is able to accommodate
  6519. is 8GB
  6520. @item Maximum value of UID/GID is 2097151.
  6521. @item Maximum number of bits in device major and minor numbers is 21.
  6522. @end enumerate
  6523. @item star
  6524. Format used by J@"org Schilling @command{star}
  6525. implementation. @GNUTAR{} is able to read @samp{star} archives but
  6526. currently does not produce them.
  6527. @item posix
  6528. Archive format defined by @acronym{POSIX.1-2001} specification. This is the
  6529. most flexible and feature-rich format. It does not impose any
  6530. restrictions on file sizes or file name lengths. This format is quite
  6531. recent, so not all tar implementations are able to handle it properly.
  6532. However, this format is designed in such a way that any tar
  6533. implementation able to read @samp{ustar} archives will be able to read
  6534. most @samp{posix} archives as well, with the only exception that any
  6535. additional information (such as long file names etc.) will in such
  6536. case be extracted as plain text files along with the files it refers to.
  6537. This archive format will be the default format for future versions
  6538. of @GNUTAR{}.
  6539. @end table
  6540. The following table summarizes the limitations of each of these
  6541. formats:
  6542. @multitable @columnfractions .10 .20 .20 .20 .20
  6543. @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
  6544. @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  6545. @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  6546. @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
  6547. @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
  6548. @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
  6549. @end multitable
  6550. The default format for @GNUTAR{} is defined at compilation
  6551. time. You may check it by running @command{tar --help}, and examining
  6552. the last lines of its output. Usually, @GNUTAR{} is configured
  6553. to create archives in @samp{gnu} format, however, future version will
  6554. switch to @samp{posix}.
  6555. @menu
  6556. * Compression:: Using Less Space through Compression
  6557. * Attributes:: Handling File Attributes
  6558. * Portability:: Making @command{tar} Archives More Portable
  6559. * cpio:: Comparison of @command{tar} and @command{cpio}
  6560. @end menu
  6561. @node Compression
  6562. @section Using Less Space through Compression
  6563. @menu
  6564. * gzip:: Creating and Reading Compressed Archives
  6565. * sparse:: Archiving Sparse Files
  6566. @end menu
  6567. @node gzip
  6568. @subsection Creating and Reading Compressed Archives
  6569. @cindex Compressed archives
  6570. @cindex Storing archives in compressed format
  6571. @GNUTAR{} is able to create and read compressed archives. It supports
  6572. @command{gzip}, @command{bzip2} and @command{lzma} compression
  6573. programs. For backward compatibility, it also supports
  6574. @command{compress} command, although we strongly recommend against
  6575. using it, because it is by far less effective than other compression
  6576. programs@footnote{It also had patent problems in the past.}.
  6577. Creating a compressed archive is simple: you just specify a
  6578. @dfn{compression option} along with the usual archive creation
  6579. commands. The compression option is @option{-z} (@option{--gzip}) to
  6580. create a @command{gzip} compressed archive, @option{-j}
  6581. (@option{--bzip2}) to create a @command{bzip2} compressed archive,
  6582. @command{lzma} to create an @asis{LZMA} compressed archive and
  6583. @option{-Z} (@option{--compress}) to use @command{compress} program.
  6584. For example:
  6585. @smallexample
  6586. $ @kbd{tar cfz archive.tar.gz .}
  6587. @end smallexample
  6588. You can also let @GNUTAR{} select the compression program basing on
  6589. the suffix of the archive file name. This is done using
  6590. @option{--auto-compress} (@option{-a}) command line option. For
  6591. example, the following invocation will use @command{bzip2} for
  6592. compression:
  6593. @smallexample
  6594. $ @kbd{tar cfa archive.tar.bz2 .}
  6595. @end smallexample
  6596. @noindent
  6597. whereas the following one will use @command{lzma}:
  6598. @smallexample
  6599. $ @kbd{tar cfa archive.tar.lzma .}
  6600. @end smallexample
  6601. For a complete list of file name suffixes recognized by @GNUTAR{},
  6602. @ref{auto-compress}.
  6603. Reading compressed archive is even simpler: you don't need to specify
  6604. any additional options as @GNUTAR{} recognizes its format
  6605. automatically. Thus, the following commands will list and extract the
  6606. archive created in previous example:
  6607. @smallexample
  6608. # List the compressed archive
  6609. $ @kbd{tar tf archive.tar.gz}
  6610. # Extract the compressed archive
  6611. $ @kbd{tar xf archive.tar.gz}
  6612. @end smallexample
  6613. The only case when you have to specify a decompression option while
  6614. reading the archive is when reading from a pipe or from a tape drive
  6615. that does not support random access. However, in this case @GNUTAR{}
  6616. will indicate which option you should use. For example:
  6617. @smallexample
  6618. $ @kbd{cat archive.tar.gz | tar tf -}
  6619. tar: Archive is compressed. Use -z option
  6620. tar: Error is not recoverable: exiting now
  6621. @end smallexample
  6622. If you see such diagnostics, just add the suggested option to the
  6623. invocation of @GNUTAR{}:
  6624. @smallexample
  6625. $ @kbd{cat archive.tar.gz | tar tfz -}
  6626. @end smallexample
  6627. Notice also, that there are several restrictions on operations on
  6628. compressed archives. First of all, compressed archives cannot be
  6629. modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
  6630. (@option{--delete}) members from them. Likewise, you cannot append
  6631. another @command{tar} archive to a compressed archive using
  6632. @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
  6633. compressed.
  6634. The following table summarizes compression options used by @GNUTAR{}.
  6635. @table @option
  6636. @anchor{auto-compress}
  6637. @opindex auto-compress
  6638. @item --auto-compress
  6639. @itemx -a
  6640. Select a compression program to use by the archive file name
  6641. suffix. The following suffixes are recognized:
  6642. @multitable @columnfractions 0.3 0.6
  6643. @headitem Suffix @tab Compression program
  6644. @item @samp{.gz} @tab @command{gzip}
  6645. @item @samp{.tgz} @tab @command{gzip}
  6646. @item @samp{.taz} @tab @command{gzip}
  6647. @item @samp{.Z} @tab @command{compress}
  6648. @item @samp{.taZ} @tab @command{compress}
  6649. @item @samp{.bz2} @tab @command{bzip2}
  6650. @item @samp{.tz2} @tab @command{bzip2}
  6651. @item @samp{.tbz2} @tab @command{bzip2}
  6652. @item @samp{.tbz} @tab @command{bzip2}
  6653. @item @samp{.lzma} @tab @command{lzma}
  6654. @item @samp{.tlz} @tab @command{lzma}
  6655. @end multitable
  6656. @opindex gzip
  6657. @opindex ungzip
  6658. @item -z
  6659. @itemx --gzip
  6660. @itemx --ungzip
  6661. Filter the archive through @command{gzip}.
  6662. You can use @option{--gzip} and @option{--gunzip} on physical devices
  6663. (tape drives, etc.) and remote files as well as on normal files; data
  6664. to or from such devices or remote files is reblocked by another copy
  6665. of the @command{tar} program to enforce the specified (or default) record
  6666. size. The default compression parameters are used; if you need to
  6667. override them, set @env{GZIP} environment variable, e.g.:
  6668. @smallexample
  6669. $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
  6670. @end smallexample
  6671. @noindent
  6672. Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
  6673. @command{gzip} explicitly:
  6674. @smallexample
  6675. $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
  6676. @end smallexample
  6677. @cindex corrupted archives
  6678. About corrupted compressed archives: @command{gzip}'ed files have no
  6679. redundancy, for maximum compression. The adaptive nature of the
  6680. compression scheme means that the compression tables are implicitly
  6681. spread all over the archive. If you lose a few blocks, the dynamic
  6682. construction of the compression tables becomes unsynchronized, and there
  6683. is little chance that you could recover later in the archive.
  6684. There are pending suggestions for having a per-volume or per-file
  6685. compression in @GNUTAR{}. This would allow for viewing the
  6686. contents without decompression, and for resynchronizing decompression at
  6687. every volume or file, in case of corrupted archives. Doing so, we might
  6688. lose some compressibility. But this would have make recovering easier.
  6689. So, there are pros and cons. We'll see!
  6690. @opindex bzip2
  6691. @item -j
  6692. @itemx --bzip2
  6693. Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
  6694. @opindex lzma
  6695. @item --lzma
  6696. Filter the archive through @command{lzma}. Otherwise like @option{--gzip}.
  6697. @opindex compress
  6698. @opindex uncompress
  6699. @item -Z
  6700. @itemx --compress
  6701. @itemx --uncompress
  6702. Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
  6703. @opindex use-compress-program
  6704. @item --use-compress-program=@var{prog}
  6705. Use external compression program @var{prog}. Use this option if you
  6706. have a compression program that @GNUTAR{} does not support. There
  6707. are two requirements to which @var{prog} should comply:
  6708. First, when called without options, it should read data from standard
  6709. input, compress it and output it on standard output.
  6710. Secondly, if called with @option{-d} argument, it should do exactly
  6711. the opposite, i.e., read the compressed data from the standard input
  6712. and produce uncompressed data on the standard output.
  6713. @end table
  6714. @cindex gpg, using with tar
  6715. @cindex gnupg, using with tar
  6716. @cindex Using encrypted archives
  6717. The @option{--use-compress-program} option, in particular, lets you
  6718. implement your own filters, not necessarily dealing with
  6719. compression/decompression. For example, suppose you wish to implement
  6720. PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
  6721. gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
  6722. Manual}). The following script does that:
  6723. @smallexample
  6724. @group
  6725. #! /bin/sh
  6726. case $1 in
  6727. -d) gpg --decrypt - | gzip -d -c;;
  6728. '') gzip -c | gpg -s ;;
  6729. *) echo "Unknown option $1">&2; exit 1;;
  6730. esac
  6731. @end group
  6732. @end smallexample
  6733. Suppose you name it @file{gpgz} and save it somewhere in your
  6734. @env{PATH}. Then the following command will create a compressed
  6735. archive signed with your private key:
  6736. @smallexample
  6737. $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
  6738. @end smallexample
  6739. @noindent
  6740. Likewise, the following command will list its contents:
  6741. @smallexample
  6742. $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
  6743. @end smallexample
  6744. @ignore
  6745. The above is based on the following discussion:
  6746. I have one question, or maybe it's a suggestion if there isn't a way
  6747. to do it now. I would like to use @option{--gzip}, but I'd also like
  6748. the output to be fed through a program like @acronym{GNU}
  6749. @command{ecc} (actually, right now that's @samp{exactly} what I'd like
  6750. to use :-)), basically adding ECC protection on top of compression.
  6751. It seems as if this should be quite easy to do, but I can't work out
  6752. exactly how to go about it. Of course, I can pipe the standard output
  6753. of @command{tar} through @command{ecc}, but then I lose (though I
  6754. haven't started using it yet, I confess) the ability to have
  6755. @command{tar} use @command{rmt} for it's I/O (I think).
  6756. I think the most straightforward thing would be to let me specify a
  6757. general set of filters outboard of compression (preferably ordered,
  6758. so the order can be automatically reversed on input operations, and
  6759. with the options they require specifiable), but beggars shouldn't be
  6760. choosers and anything you decide on would be fine with me.
  6761. By the way, I like @command{ecc} but if (as the comments say) it can't
  6762. deal with loss of block sync, I'm tempted to throw some time at adding
  6763. that capability. Supposing I were to actually do such a thing and
  6764. get it (apparently) working, do you accept contributed changes to
  6765. utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
  6766. Isn't that exactly the role of the
  6767. @option{--use-compress-prog=@var{program}} option?
  6768. I never tried it myself, but I suspect you may want to write a
  6769. @var{prog} script or program able to filter stdin to stdout to
  6770. way you want. It should recognize the @option{-d} option, for when
  6771. extraction is needed rather than creation.
  6772. It has been reported that if one writes compressed data (through the
  6773. @option{--gzip} or @option{--compress} options) to a DLT and tries to use
  6774. the DLT compression mode, the data will actually get bigger and one will
  6775. end up with less space on the tape.
  6776. @end ignore
  6777. @node sparse
  6778. @subsection Archiving Sparse Files
  6779. @cindex Sparse Files
  6780. Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
  6781. in a file is a section of the file's contents which was never written.
  6782. The contents of a hole reads as all zeros. On many operating systems,
  6783. actual disk storage is not allocated for holes, but they are counted
  6784. in the length of the file. If you archive such a file, @command{tar}
  6785. could create an archive longer than the original. To have @command{tar}
  6786. attempt to recognize the holes in a file, use @option{--sparse}
  6787. (@option{-S}). When you use this option, then, for any file using
  6788. less disk space than would be expected from its length, @command{tar}
  6789. searches the file for consecutive stretches of zeros. It then records
  6790. in the archive for the file where the consecutive stretches of zeros
  6791. are, and only archives the ``real contents'' of the file. On
  6792. extraction (using @option{--sparse} is not needed on extraction) any
  6793. such files have holes created wherever the continuous stretches of zeros
  6794. were found. Thus, if you use @option{--sparse}, @command{tar} archives
  6795. won't take more space than the original.
  6796. @table @option
  6797. @opindex sparse
  6798. @item -S
  6799. @itemx --sparse
  6800. This option instructs @command{tar} to test each file for sparseness
  6801. before attempting to archive it. If the file is found to be sparse it
  6802. is treated specially, thus allowing to decrease the amount of space
  6803. used by its image in the archive.
  6804. This option is meaningful only when creating or updating archives. It
  6805. has no effect on extraction.
  6806. @end table
  6807. Consider using @option{--sparse} when performing file system backups,
  6808. to avoid archiving the expanded forms of files stored sparsely in the
  6809. system.
  6810. Even if your system has no sparse files currently, some may be
  6811. created in the future. If you use @option{--sparse} while making file
  6812. system backups as a matter of course, you can be assured the archive
  6813. will never take more space on the media than the files take on disk
  6814. (otherwise, archiving a disk filled with sparse files might take
  6815. hundreds of tapes). @xref{Incremental Dumps}.
  6816. However, be aware that @option{--sparse} option presents a serious
  6817. drawback. Namely, in order to determine if the file is sparse
  6818. @command{tar} has to read it before trying to archive it, so in total
  6819. the file is read @strong{twice}. So, always bear in mind that the
  6820. time needed to process all files with this option is roughly twice
  6821. the time needed to archive them without it.
  6822. @FIXME{A technical note:
  6823. Programs like @command{dump} do not have to read the entire file; by
  6824. examining the file system directly, they can determine in advance
  6825. exactly where the holes are and thus avoid reading through them. The
  6826. only data it need read are the actual allocated data blocks.
  6827. @GNUTAR{} uses a more portable and straightforward
  6828. archiving approach, it would be fairly difficult that it does
  6829. otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
  6830. 1990-12-10:
  6831. @quotation
  6832. What I did say is that you cannot tell the difference between a hole and an
  6833. equivalent number of nulls without reading raw blocks. @code{st_blocks} at
  6834. best tells you how many holes there are; it doesn't tell you @emph{where}.
  6835. Just as programs may, conceivably, care what @code{st_blocks} is (care
  6836. to name one that does?), they may also care where the holes are (I have
  6837. no examples of this one either, but it's equally imaginable).
  6838. I conclude from this that good archivers are not portable. One can
  6839. arguably conclude that if you want a portable program, you can in good
  6840. conscience restore files with as many holes as possible, since you can't
  6841. get it right.
  6842. @end quotation
  6843. }
  6844. @cindex sparse formats, defined
  6845. When using @samp{POSIX} archive format, @GNUTAR{} is able to store
  6846. sparse files using in three distinct ways, called @dfn{sparse
  6847. formats}. A sparse format is identified by its @dfn{number},
  6848. consisting, as usual of two decimal numbers, delimited by a dot. By
  6849. default, format @samp{1.0} is used. If, for some reason, you wish to
  6850. use an earlier format, you can select it using
  6851. @option{--sparse-version} option.
  6852. @table @option
  6853. @opindex sparse-version
  6854. @item --sparse-version=@var{version}
  6855. Select the format to store sparse files in. Valid @var{version} values
  6856. are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
  6857. for a detailed description of each format.
  6858. @end table
  6859. Using @option{--sparse-format} option implies @option{--sparse}.
  6860. @node Attributes
  6861. @section Handling File Attributes
  6862. @UNREVISED
  6863. When @command{tar} reads files, it updates their access times. To
  6864. avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
  6865. reset the access time retroactively or avoid changing it in the first
  6866. place.
  6867. Handling of file attributes
  6868. @table @option
  6869. @opindex atime-preserve
  6870. @item --atime-preserve
  6871. @itemx --atime-preserve=replace
  6872. @itemx --atime-preserve=system
  6873. Preserve the access times of files that are read. This works only for
  6874. files that you own, unless you have superuser privileges.
  6875. @option{--atime-preserve=replace} works on most systems, but it also
  6876. restores the data modification time and updates the status change
  6877. time. Hence it doesn't interact with incremental dumps nicely
  6878. (@pxref{Incremental Dumps}), and it can set access or data modification times
  6879. incorrectly if other programs access the file while @command{tar} is
  6880. running.
  6881. @option{--atime-preserve=system} avoids changing the access time in
  6882. the first place, if the operating system supports this.
  6883. Unfortunately, this may or may not work on any given operating system
  6884. or file system. If @command{tar} knows for sure it won't work, it
  6885. complains right away.
  6886. Currently @option{--atime-preserve} with no operand defaults to
  6887. @option{--atime-preserve=replace}, but this is intended to change to
  6888. @option{--atime-preserve=system} when the latter is better-supported.
  6889. @opindex touch
  6890. @item -m
  6891. @itemx --touch
  6892. Do not extract data modification time.
  6893. When this option is used, @command{tar} leaves the data modification times
  6894. of the files it extracts as the times when the files were extracted,
  6895. instead of setting it to the times recorded in the archive.
  6896. This option is meaningless with @option{--list} (@option{-t}).
  6897. @opindex same-owner
  6898. @item --same-owner
  6899. Create extracted files with the same ownership they have in the
  6900. archive.
  6901. This is the default behavior for the superuser,
  6902. so this option is meaningful only for non-root users, when @command{tar}
  6903. is executed on those systems able to give files away. This is
  6904. considered as a security flaw by many people, at least because it
  6905. makes quite difficult to correctly account users for the disk space
  6906. they occupy. Also, the @code{suid} or @code{sgid} attributes of
  6907. files are easily and silently lost when files are given away.
  6908. When writing an archive, @command{tar} writes the user @acronym{ID} and user name
  6909. separately. If it can't find a user name (because the user @acronym{ID} is not
  6910. in @file{/etc/passwd}), then it does not write one. When restoring,
  6911. it tries to look the name (if one was written) up in
  6912. @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
  6913. the archive instead.
  6914. @opindex no-same-owner
  6915. @item --no-same-owner
  6916. @itemx -o
  6917. Do not attempt to restore ownership when extracting. This is the
  6918. default behavior for ordinary users, so this option has an effect
  6919. only for the superuser.
  6920. @opindex numeric-owner
  6921. @item --numeric-owner
  6922. The @option{--numeric-owner} option allows (ANSI) archives to be written
  6923. without user/group name information or such information to be ignored
  6924. when extracting. It effectively disables the generation and/or use
  6925. of user/group name information. This option forces extraction using
  6926. the numeric ids from the archive, ignoring the names.
  6927. This is useful in certain circumstances, when restoring a backup from
  6928. an emergency floppy with different passwd/group files for example.
  6929. It is otherwise impossible to extract files with the right ownerships
  6930. if the password file in use during the extraction does not match the
  6931. one belonging to the file system(s) being extracted. This occurs,
  6932. for example, if you are restoring your files after a major crash and
  6933. had booted from an emergency floppy with no password file or put your
  6934. disk into another machine to do the restore.
  6935. The numeric ids are @emph{always} saved into @command{tar} archives.
  6936. The identifying names are added at create time when provided by the
  6937. system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
  6938. used when moving archives between a collection of machines using
  6939. a centralized management for attribution of numeric ids to users
  6940. and groups. This is often made through using the NIS capabilities.
  6941. When making a @command{tar} file for distribution to other sites, it
  6942. is sometimes cleaner to use a single owner for all files in the
  6943. distribution, and nicer to specify the write permission bits of the
  6944. files as stored in the archive independently of their actual value on
  6945. the file system. The way to prepare a clean distribution is usually
  6946. to have some Makefile rule creating a directory, copying all needed
  6947. files in that directory, then setting ownership and permissions as
  6948. wanted (there are a lot of possible schemes), and only then making a
  6949. @command{tar} archive out of this directory, before cleaning
  6950. everything out. Of course, we could add a lot of options to
  6951. @GNUTAR{} for fine tuning permissions and ownership.
  6952. This is not the good way, I think. @GNUTAR{} is
  6953. already crowded with options and moreover, the approach just explained
  6954. gives you a great deal of control already.
  6955. @xopindex{same-permissions, short description}
  6956. @xopindex{preserve-permissions, short description}
  6957. @item -p
  6958. @itemx --same-permissions
  6959. @itemx --preserve-permissions
  6960. Extract all protection information.
  6961. This option causes @command{tar} to set the modes (access permissions) of
  6962. extracted files exactly as recorded in the archive. If this option
  6963. is not used, the current @code{umask} setting limits the permissions
  6964. on extracted files. This option is by default enabled when
  6965. @command{tar} is executed by a superuser.
  6966. This option is meaningless with @option{--list} (@option{-t}).
  6967. @opindex preserve
  6968. @item --preserve
  6969. Same as both @option{--same-permissions} and @option{--same-order}.
  6970. The @option{--preserve} option has no equivalent short option name.
  6971. It is equivalent to @option{--same-permissions} plus @option{--same-order}.
  6972. @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
  6973. Neither do I. --Sergey}
  6974. @end table
  6975. @node Portability
  6976. @section Making @command{tar} Archives More Portable
  6977. Creating a @command{tar} archive on a particular system that is meant to be
  6978. useful later on many other machines and with other versions of @command{tar}
  6979. is more challenging than you might think. @command{tar} archive formats
  6980. have been evolving since the first versions of Unix. Many such formats
  6981. are around, and are not always compatible with each other. This section
  6982. discusses a few problems, and gives some advice about making @command{tar}
  6983. archives more portable.
  6984. One golden rule is simplicity. For example, limit your @command{tar}
  6985. archives to contain only regular files and directories, avoiding
  6986. other kind of special files. Do not attempt to save sparse files or
  6987. contiguous files as such. Let's discuss a few more problems, in turn.
  6988. @FIXME{Discuss GNU extensions (incremental backups, multi-volume
  6989. archives and archive labels) in GNU and PAX formats.}
  6990. @menu
  6991. * Portable Names:: Portable Names
  6992. * dereference:: Symbolic Links
  6993. * hard links:: Hard Links
  6994. * old:: Old V7 Archives
  6995. * ustar:: Ustar Archives
  6996. * gnu:: GNU and old GNU format archives.
  6997. * posix:: @acronym{POSIX} archives
  6998. * Checksumming:: Checksumming Problems
  6999. * Large or Negative Values:: Large files, negative time stamps, etc.
  7000. * Other Tars:: How to Extract GNU-Specific Data Using
  7001. Other @command{tar} Implementations
  7002. @end menu
  7003. @node Portable Names
  7004. @subsection Portable Names
  7005. Use portable file and member names. A name is portable if it contains
  7006. only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
  7007. @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
  7008. contain @samp{/-}. Avoid deep directory nesting. For portability to
  7009. old Unix hosts, limit your file name components to 14 characters or
  7010. less.
  7011. If you intend to have your @command{tar} archives to be read under
  7012. MSDOS, you should not rely on case distinction for file names, and you
  7013. might use the @acronym{GNU} @command{doschk} program for helping you
  7014. further diagnosing illegal MSDOS names, which are even more limited
  7015. than System V's.
  7016. @node dereference
  7017. @subsection Symbolic Links
  7018. @cindex File names, using symbolic links
  7019. @cindex Symbolic link as file name
  7020. @opindex dereference
  7021. Normally, when @command{tar} archives a symbolic link, it writes a
  7022. block to the archive naming the target of the link. In that way, the
  7023. @command{tar} archive is a faithful record of the file system contents.
  7024. @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
  7025. @command{tar} to archive the files symbolic links point to, instead of
  7026. the links themselves. When this option is used, when @command{tar}
  7027. encounters a symbolic link, it will archive the linked-to file,
  7028. instead of simply recording the presence of a symbolic link.
  7029. The name under which the file is stored in the file system is not
  7030. recorded in the archive. To record both the symbolic link name and
  7031. the file name in the system, archive the file under both names. If
  7032. all links were recorded automatically by @command{tar}, an extracted file
  7033. might be linked to a file name that no longer exists in the file
  7034. system.
  7035. If a linked-to file is encountered again by @command{tar} while creating
  7036. the same archive, an entire second copy of it will be stored. (This
  7037. @emph{might} be considered a bug.)
  7038. So, for portable archives, do not archive symbolic links as such,
  7039. and use @option{--dereference} (@option{-h}): many systems do not support
  7040. symbolic links, and moreover, your distribution might be unusable if
  7041. it contains unresolved symbolic links.
  7042. @node hard links
  7043. @subsection Hard Links
  7044. @UNREVISED{}
  7045. @cindex File names, using hard links
  7046. @cindex hard links, dereferencing
  7047. @cindex dereferencing hard links
  7048. Normally, when @command{tar} archives a hard link, it writes a
  7049. block to the archive naming the target of the link (a @samp{1} type
  7050. block). In that way, the actual file contents is stored in file only
  7051. once. For example, consider the following two files:
  7052. @smallexample
  7053. @group
  7054. $ ls
  7055. -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
  7056. -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
  7057. @end group
  7058. @end smallexample
  7059. Here, @file{jeden} is a link to @file{one}. When archiving this
  7060. directory with a verbose level 2, you will get an output similar to
  7061. the following:
  7062. @smallexample
  7063. $ tar cfvv ../archive.tar .
  7064. drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
  7065. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
  7066. hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
  7067. @end smallexample
  7068. The last line shows that, instead of storing two copies of the file,
  7069. @command{tar} stored it only once, under the name @file{jeden}, and
  7070. stored file @file{one} as a hard link to this file.
  7071. It may be important to know that all hard links to the given file are
  7072. stored in the archive. For example, this may be necessary for exact
  7073. reproduction of the file system. The following option does that:
  7074. @table @option
  7075. @xopindex{check-links, described}
  7076. @item --check-links
  7077. @itemx -l
  7078. Check the number of links dumped for each processed file. If this
  7079. number does not match the total number of hard links for the file, print
  7080. a warning message.
  7081. @end table
  7082. For example, trying to archive only file @file{jeden} with this option
  7083. produces the following diagnostics:
  7084. @smallexample
  7085. $ tar -c -f ../archive.tar jeden
  7086. tar: Missing links to `jeden'.
  7087. @end smallexample
  7088. Although creating special records for hard links helps keep a faithful
  7089. record of the file system contents and makes archives more compact, it
  7090. may present some difficulties when extracting individual members from
  7091. the archive. For example, trying to extract file @file{one} from the
  7092. archive created in previous examples produces, in the absense of file
  7093. @file{jeden}:
  7094. @smallexample
  7095. $ tar xf archive.tar ./one
  7096. tar: ./one: Cannot hard link to `./jeden': No such file or directory
  7097. tar: Error exit delayed from previous errors
  7098. @end smallexample
  7099. The reason for this behavior is that @command{tar} cannot seek back in
  7100. the archive to the previous member (in this case, @file{one}), to
  7101. extract it@footnote{There are plans to fix this in future releases.}.
  7102. If you wish to avoid such problems at the cost of a bigger archive,
  7103. use the following option:
  7104. @table @option
  7105. @xopindex{hard-dereference, described}
  7106. @item --hard-dereference
  7107. Dereference hard links and store the files they refer to.
  7108. @end table
  7109. For example, trying this option on our two sample files, we get two
  7110. copies in the archive, each of which can then be extracted
  7111. independently of the other:
  7112. @smallexample
  7113. @group
  7114. $ tar -c -vv -f ../archive.tar --hard-dereference .
  7115. drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
  7116. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
  7117. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
  7118. @end group
  7119. @end smallexample
  7120. @node old
  7121. @subsection Old V7 Archives
  7122. @cindex Format, old style
  7123. @cindex Old style format
  7124. @cindex Old style archives
  7125. @cindex v7 archive format
  7126. Certain old versions of @command{tar} cannot handle additional
  7127. information recorded by newer @command{tar} programs. To create an
  7128. archive in V7 format (not ANSI), which can be read by these old
  7129. versions, specify the @option{--format=v7} option in
  7130. conjunction with the @option{--create} (@option{-c}) (@command{tar} also
  7131. accepts @option{--portability} or @option{--old-archive} for this
  7132. option). When you specify it,
  7133. @command{tar} leaves out information about directories, pipes, fifos,
  7134. contiguous files, and device files, and specifies file ownership by
  7135. group and user IDs instead of group and user names.
  7136. When updating an archive, do not use @option{--format=v7}
  7137. unless the archive was created using this option.
  7138. In most cases, a @emph{new} format archive can be read by an @emph{old}
  7139. @command{tar} program without serious trouble, so this option should
  7140. seldom be needed. On the other hand, most modern @command{tar}s are
  7141. able to read old format archives, so it might be safer for you to
  7142. always use @option{--format=v7} for your distributions. Notice,
  7143. however, that @samp{ustar} format is a better alternative, as it is
  7144. free from many of @samp{v7}'s drawbacks.
  7145. @node ustar
  7146. @subsection Ustar Archive Format
  7147. @cindex ustar archive format
  7148. Archive format defined by @acronym{POSIX}.1-1988 specification is called
  7149. @code{ustar}. Although it is more flexible than the V7 format, it
  7150. still has many restrictions (@xref{Formats,ustar}, for the detailed
  7151. description of @code{ustar} format). Along with V7 format,
  7152. @code{ustar} format is a good choice for archives intended to be read
  7153. with other implementations of @command{tar}.
  7154. To create archive in @code{ustar} format, use @option{--format=ustar}
  7155. option in conjunction with the @option{--create} (@option{-c}).
  7156. @node gnu
  7157. @subsection @acronym{GNU} and old @GNUTAR{} format
  7158. @cindex GNU archive format
  7159. @cindex Old GNU archive format
  7160. @GNUTAR{} was based on an early draft of the
  7161. @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
  7162. @command{tar}, such as the support for file names longer than 100
  7163. characters, use portions of the @command{tar} header record which were
  7164. specified in that @acronym{POSIX} draft as unused. Subsequent changes in
  7165. @acronym{POSIX} have allocated the same parts of the header record for
  7166. other purposes. As a result, @GNUTAR{} format is
  7167. incompatible with the current @acronym{POSIX} specification, and with
  7168. @command{tar} programs that follow it.
  7169. In the majority of cases, @command{tar} will be configured to create
  7170. this format by default. This will change in future releases, since
  7171. we plan to make @samp{POSIX} format the default.
  7172. To force creation a @GNUTAR{} archive, use option
  7173. @option{--format=gnu}.
  7174. @node posix
  7175. @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
  7176. @cindex POSIX archive format
  7177. @cindex PAX archive format
  7178. Starting from version 1.14 @GNUTAR{} features full support for
  7179. @acronym{POSIX.1-2001} archives.
  7180. A @acronym{POSIX} conformant archive will be created if @command{tar}
  7181. was given @option{--format=posix} (@option{--format=pax}) option. No
  7182. special option is required to read and extract from a @acronym{POSIX}
  7183. archive.
  7184. @menu
  7185. * PAX keywords:: Controlling Extended Header Keywords.
  7186. @end menu
  7187. @node PAX keywords
  7188. @subsubsection Controlling Extended Header Keywords
  7189. @table @option
  7190. @opindex pax-option
  7191. @item --pax-option=@var{keyword-list}
  7192. Handle keywords in @acronym{PAX} extended headers. This option is
  7193. equivalent to @option{-o} option of the @command{pax} utility.
  7194. @end table
  7195. @var{Keyword-list} is a comma-separated
  7196. list of keyword options, each keyword option taking one of
  7197. the following forms:
  7198. @table @code
  7199. @item delete=@var{pattern}
  7200. When used with one of archive-creation commands,
  7201. this option instructs @command{tar} to omit from extended header records
  7202. that it produces any keywords matching the string @var{pattern}.
  7203. When used in extract or list mode, this option instructs tar
  7204. to ignore any keywords matching the given @var{pattern} in the extended
  7205. header records. In both cases, matching is performed using the pattern
  7206. matching notation described in @acronym{POSIX 1003.2}, 3.13
  7207. (@pxref{wildcards}). For example:
  7208. @smallexample
  7209. --pax-option delete=security.*
  7210. @end smallexample
  7211. would suppress security-related information.
  7212. @item exthdr.name=@var{string}
  7213. This keyword allows user control over the name that is written into the
  7214. ustar header blocks for the extended headers. The name is obtained
  7215. from @var{string} after making the following substitutions:
  7216. @multitable @columnfractions .25 .55
  7217. @headitem Meta-character @tab Replaced By
  7218. @item %d @tab The directory name of the file, equivalent to the
  7219. result of the @command{dirname} utility on the translated file name.
  7220. @item %f @tab The name of the file with the directory information
  7221. stripped, equivalent to the result of the @command{basename} utility
  7222. on the translated file name.
  7223. @item %p @tab The process @acronym{ID} of the @command{tar} process.
  7224. @item %% @tab A @samp{%} character.
  7225. @end multitable
  7226. Any other @samp{%} characters in @var{string} produce undefined
  7227. results.
  7228. If no option @samp{exthdr.name=string} is specified, @command{tar}
  7229. will use the following default value:
  7230. @smallexample
  7231. %d/PaxHeaders.%p/%f
  7232. @end smallexample
  7233. @item globexthdr.name=@var{string}
  7234. This keyword allows user control over the name that is written into
  7235. the ustar header blocks for global extended header records. The name
  7236. is obtained from the contents of @var{string}, after making
  7237. the following substitutions:
  7238. @multitable @columnfractions .25 .55
  7239. @headitem Meta-character @tab Replaced By
  7240. @item %n @tab An integer that represents the
  7241. sequence number of the global extended header record in the archive,
  7242. starting at 1.
  7243. @item %p @tab The process @acronym{ID} of the @command{tar} process.
  7244. @item %% @tab A @samp{%} character.
  7245. @end multitable
  7246. Any other @samp{%} characters in @var{string} produce undefined results.
  7247. If no option @samp{globexthdr.name=string} is specified, @command{tar}
  7248. will use the following default value:
  7249. @smallexample
  7250. $TMPDIR/GlobalHead.%p.%n
  7251. @end smallexample
  7252. @noindent
  7253. where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
  7254. environment variable. If @var{TMPDIR} is not set, @command{tar}
  7255. uses @samp{/tmp}.
  7256. @item @var{keyword}=@var{value}
  7257. When used with one of archive-creation commands, these keyword/value pairs
  7258. will be included at the beginning of the archive in a global extended
  7259. header record. When used with one of archive-reading commands,
  7260. @command{tar} will behave as if it has encountered these keyword/value
  7261. pairs at the beginning of the archive in a global extended header
  7262. record.
  7263. @item @var{keyword}:=@var{value}
  7264. When used with one of archive-creation commands, these keyword/value pairs
  7265. will be included as records at the beginning of an extended header for
  7266. each file. This is effectively equivalent to @var{keyword}=@var{value}
  7267. form except that it creates no global extended header records.
  7268. When used with one of archive-reading commands, @command{tar} will
  7269. behave as if these keyword/value pairs were included as records at the
  7270. end of each extended header; thus, they will override any global or
  7271. file-specific extended header record keywords of the same names.
  7272. For example, in the command:
  7273. @smallexample
  7274. tar --format=posix --create \
  7275. --file archive --pax-option gname:=user .
  7276. @end smallexample
  7277. the group name will be forced to a new value for all files
  7278. stored in the archive.
  7279. @end table
  7280. @node Checksumming
  7281. @subsection Checksumming Problems
  7282. SunOS and HP-UX @command{tar} fail to accept archives created using
  7283. @GNUTAR{} and containing non-@acronym{ASCII} file names, that
  7284. is, file names having characters with the eight bit set, because they
  7285. use signed checksums, while @GNUTAR{} uses unsigned
  7286. checksums while creating archives, as per @acronym{POSIX} standards. On
  7287. reading, @GNUTAR{} computes both checksums and
  7288. accept any. It is somewhat worrying that a lot of people may go
  7289. around doing backup of their files using faulty (or at least
  7290. non-standard) software, not learning about it until it's time to
  7291. restore their missing files with an incompatible file extractor, or
  7292. vice versa.
  7293. @GNUTAR{} compute checksums both ways, and accept
  7294. any on read, so @acronym{GNU} tar can read Sun tapes even with their
  7295. wrong checksums. @GNUTAR{} produces the standard
  7296. checksum, however, raising incompatibilities with Sun. That is to
  7297. say, @GNUTAR{} has not been modified to
  7298. @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
  7299. I've been told that more recent Sun @command{tar} now read standard
  7300. archives, so maybe Sun did a similar patch, after all?
  7301. The story seems to be that when Sun first imported @command{tar}
  7302. sources on their system, they recompiled it without realizing that
  7303. the checksums were computed differently, because of a change in
  7304. the default signing of @code{char}'s in their compiler. So they
  7305. started computing checksums wrongly. When they later realized their
  7306. mistake, they merely decided to stay compatible with it, and with
  7307. themselves afterwards. Presumably, but I do not really know, HP-UX
  7308. has chosen that their @command{tar} archives to be compatible with Sun's.
  7309. The current standards do not favor Sun @command{tar} format. In any
  7310. case, it now falls on the shoulders of SunOS and HP-UX users to get
  7311. a @command{tar} able to read the good archives they receive.
  7312. @node Large or Negative Values
  7313. @subsection Large or Negative Values
  7314. @cindex large values
  7315. @cindex future time stamps
  7316. @cindex negative time stamps
  7317. @UNREVISED{}
  7318. The above sections suggest to use @samp{oldest possible} archive
  7319. format if in doubt. However, sometimes it is not possible. If you
  7320. attempt to archive a file whose metadata cannot be represented using
  7321. required format, @GNUTAR{} will print error message and ignore such a
  7322. file. You will than have to switch to a format that is able to
  7323. handle such values. The format summary table (@pxref{Formats}) will
  7324. help you to do so.
  7325. In particular, when trying to archive files larger than 8GB or with
  7326. timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
  7327. 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
  7328. @acronym{POSIX} archive formats. When considering which format to
  7329. choose, bear in mind that the @acronym{GNU} format uses
  7330. two's-complement base-256 notation to store values that do not fit
  7331. into standard @acronym{ustar} range. Such archives can generally be
  7332. read only by a @GNUTAR{} implementation. Moreover, they sometimes
  7333. cannot be correctly restored on another hosts even by @GNUTAR{}. For
  7334. example, using two's complement representation for negative time
  7335. stamps that assumes a signed 32-bit @code{time_t} generates archives
  7336. that are not portable to hosts with differing @code{time_t}
  7337. representations.
  7338. On the other hand, @acronym{POSIX} archives, generally speaking, can
  7339. be extracted by any tar implementation that understands older
  7340. @acronym{ustar} format. The only exception are files larger than 8GB.
  7341. @FIXME{Describe how @acronym{POSIX} archives are extracted by non
  7342. POSIX-aware tars.}
  7343. @node Other Tars
  7344. @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
  7345. In previous sections you became acquainted with various quirks
  7346. necessary to make your archives portable. Sometimes you may need to
  7347. extract archives containing GNU-specific members using some
  7348. third-party @command{tar} implementation or an older version of
  7349. @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
  7350. but if it is for some reason impossible, this section will explain
  7351. how to cope without it.
  7352. When we speak about @dfn{GNU-specific} members we mean two classes of
  7353. them: members split between the volumes of a multi-volume archive and
  7354. sparse members. You will be able to always recover such members if
  7355. the archive is in PAX format. In addition split members can be
  7356. recovered from archives in old GNU format. The following subsections
  7357. describe the required procedures in detail.
  7358. @menu
  7359. * Split Recovery:: Members Split Between Volumes
  7360. * Sparse Recovery:: Sparse Members
  7361. @end menu
  7362. @node Split Recovery
  7363. @subsubsection Extracting Members Split Between Volumes
  7364. @cindex Mutli-volume archives, extracting using non-GNU tars
  7365. If a member is split between several volumes of an old GNU format archive
  7366. most third party @command{tar} implementation will fail to extract
  7367. it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
  7368. This program is available from
  7369. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
  7370. home page}. It concatenates several archive volumes into a single
  7371. valid archive. For example, if you have three volumes named from
  7372. @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
  7373. extract them using a third-party @command{tar}:
  7374. @smallexample
  7375. $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
  7376. @end smallexample
  7377. @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
  7378. You could use this approach for most (although not all) PAX
  7379. format archives as well. However, extracting split members from a PAX
  7380. archive is a much easier task, because PAX volumes are constructed in
  7381. such a way that each part of a split member is extracted to a
  7382. different file by @command{tar} implementations that are not aware of
  7383. GNU extensions. More specifically, the very first part retains its
  7384. original name, and all subsequent parts are named using the pattern:
  7385. @smallexample
  7386. %d/GNUFileParts.%p/%f.%n
  7387. @end smallexample
  7388. @noindent
  7389. where symbols preceeded by @samp{%} are @dfn{macro characters} that
  7390. have the following meaning:
  7391. @multitable @columnfractions .25 .55
  7392. @headitem Meta-character @tab Replaced By
  7393. @item %d @tab The directory name of the file, equivalent to the
  7394. result of the @command{dirname} utility on its full name.
  7395. @item %f @tab The file name of the file, equivalent to the result
  7396. of the @command{basename} utility on its full name.
  7397. @item %p @tab The process @acronym{ID} of the @command{tar} process that
  7398. created the archive.
  7399. @item %n @tab Ordinal number of this particular part.
  7400. @end multitable
  7401. For example, if the file @file{var/longfile} was split during archive
  7402. creation between three volumes, and the creator @command{tar} process
  7403. had process @acronym{ID} @samp{27962}, then the member names will be:
  7404. @smallexample
  7405. var/longfile
  7406. var/GNUFileParts.27962/longfile.1
  7407. var/GNUFileParts.27962/longfile.2
  7408. @end smallexample
  7409. When you extract your archive using a third-party @command{tar}, these
  7410. files will be created on your disk, and the only thing you will need
  7411. to do to restore your file in its original form is concatenate them in
  7412. the proper order, for example:
  7413. @smallexample
  7414. @group
  7415. $ @kbd{cd var}
  7416. $ @kbd{cat GNUFileParts.27962/longfile.1 \
  7417. GNUFileParts.27962/longfile.2 >> longfile}
  7418. $ rm -f GNUFileParts.27962
  7419. @end group
  7420. @end smallexample
  7421. Notice, that if the @command{tar} implementation you use supports PAX
  7422. format archives, it will probably emit warnings about unknown keywords
  7423. during extraction. They will look like this:
  7424. @smallexample
  7425. @group
  7426. Tar file too small
  7427. Unknown extended header keyword 'GNU.volume.filename' ignored.
  7428. Unknown extended header keyword 'GNU.volume.size' ignored.
  7429. Unknown extended header keyword 'GNU.volume.offset' ignored.
  7430. @end group
  7431. @end smallexample
  7432. @noindent
  7433. You can safely ignore these warnings.
  7434. If your @command{tar} implementation is not PAX-aware, you will get
  7435. more warnings and more files generated on your disk, e.g.:
  7436. @smallexample
  7437. @group
  7438. $ @kbd{tar xf vol-1.tar}
  7439. var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
  7440. normal file
  7441. Unexpected EOF in archive
  7442. $ @kbd{tar xf vol-2.tar}
  7443. tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
  7444. GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
  7445. 'x', extracted as normal file
  7446. @end group
  7447. @end smallexample
  7448. Ignore these warnings. The @file{PaxHeaders.*} directories created
  7449. will contain files with @dfn{extended header keywords} describing the
  7450. extracted files. You can delete them, unless they describe sparse
  7451. members. Read further to learn more about them.
  7452. @node Sparse Recovery
  7453. @subsubsection Extracting Sparse Members
  7454. @cindex sparse files, extracting with non-GNU tars
  7455. Any @command{tar} implementation will be able to extract sparse members from a
  7456. PAX archive. However, the extracted files will be @dfn{condensed},
  7457. i.e., any zero blocks will be removed from them. When we restore such
  7458. a condensed file to its original form, by adding zero blocks (or
  7459. @dfn{holes}) back to their original locations, we call this process
  7460. @dfn{expanding} a compressed sparse file.
  7461. @pindex xsparse
  7462. To expand a file, you will need a simple auxiliary program called
  7463. @command{xsparse}. It is available in source form from
  7464. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
  7465. home page}.
  7466. @cindex sparse files v.1.0, extracting with non-GNU tars
  7467. Let's begin with archive members in @dfn{sparse format
  7468. version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
  7469. The condensed file will contain both file map and file data, so no
  7470. additional data will be needed to restore it. If the original file
  7471. name was @file{@var{dir}/@var{name}}, then the condensed file will be
  7472. named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
  7473. @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
  7474. @dfn{process @acronym{ID}} of the @command{tar} process which created the
  7475. archive (@pxref{PAX keywords}).}.
  7476. To expand a version 1.0 file, run @command{xsparse} as follows:
  7477. @smallexample
  7478. $ @kbd{xsparse @file{cond-file}}
  7479. @end smallexample
  7480. @noindent
  7481. where @file{cond-file} is the name of the condensed file. The utility
  7482. will deduce the name for the resulting expanded file using the
  7483. following algorithm:
  7484. @enumerate 1
  7485. @item If @file{cond-file} does not contain any directories,
  7486. @file{../cond-file} will be used;
  7487. @item If @file{cond-file} has the form
  7488. @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
  7489. are simple names, with no @samp{/} characters in them, the output file
  7490. name will be @file{@var{dir}/@var{name}}.
  7491. @item Otherwise, if @file{cond-file} has the form
  7492. @file{@var{dir}/@var{name}}, the output file name will be
  7493. @file{@var{name}}.
  7494. @end enumerate
  7495. In the unlikely case when this algorithm does not suit your needs,
  7496. you can explicitly specify output file name as a second argument to
  7497. the command:
  7498. @smallexample
  7499. $ @kbd{xsparse @file{cond-file} @file{out-file}}
  7500. @end smallexample
  7501. It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
  7502. first. In this mode, the command does not actually expand the file,
  7503. but verbosely lists all actions it would be taking to do so. The dry
  7504. run mode is enabled by @option{-n} command line argument:
  7505. @smallexample
  7506. @group
  7507. $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
  7508. Reading v.1.0 sparse map
  7509. Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
  7510. `/home/gray/sparsefile'
  7511. Finished dry run
  7512. @end group
  7513. @end smallexample
  7514. To actually expand the file, you would run:
  7515. @smallexample
  7516. $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
  7517. @end smallexample
  7518. @noindent
  7519. The program behaves the same way all UNIX utilities do: it will keep
  7520. quiet unless it has simething important to tell you (e.g. an error
  7521. condition or something). If you wish it to produce verbose output,
  7522. similar to that from the dry run mode, use @option{-v} option:
  7523. @smallexample
  7524. @group
  7525. $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
  7526. Reading v.1.0 sparse map
  7527. Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
  7528. `/home/gray/sparsefile'
  7529. Done
  7530. @end group
  7531. @end smallexample
  7532. Additionally, if your @command{tar} implementation has extracted the
  7533. @dfn{extended headers} for this file, you can instruct @command{xstar}
  7534. to use them in order to verify the integrity of the expanded file.
  7535. The option @option{-x} sets the name of the extended header file to
  7536. use. Continuing our example:
  7537. @smallexample
  7538. @group
  7539. $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
  7540. /home/gray/GNUSparseFile.6058/sparsefile}
  7541. Reading extended header file
  7542. Found variable GNU.sparse.major = 1
  7543. Found variable GNU.sparse.minor = 0
  7544. Found variable GNU.sparse.name = sparsefile
  7545. Found variable GNU.sparse.realsize = 217481216
  7546. Reading v.1.0 sparse map
  7547. Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
  7548. `/home/gray/sparsefile'
  7549. Done
  7550. @end group
  7551. @end smallexample
  7552. @anchor{extracting sparse v.0.x}
  7553. @cindex sparse files v.0.1, extracting with non-GNU tars
  7554. @cindex sparse files v.0.0, extracting with non-GNU tars
  7555. An @dfn{extended header} is a special @command{tar} archive header
  7556. that precedes an archive member and contains a set of
  7557. @dfn{variables}, describing the member properties that cannot be
  7558. stored in the standard @code{ustar} header. While optional for
  7559. expanding sparse version 1.0 members, the use of extended headers is
  7560. mandatory when expanding sparse members in older sparse formats: v.0.0
  7561. and v.0.1 (The sparse formats are described in detail in @ref{Sparse
  7562. Formats}.) So, for these formats, the question is: how to obtain
  7563. extended headers from the archive?
  7564. If you use a @command{tar} implementation that does not support PAX
  7565. format, extended headers for each member will be extracted as a
  7566. separate file. If we represent the member name as
  7567. @file{@var{dir}/@var{name}}, then the extended header file will be
  7568. named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
  7569. @var{n} is an integer number.
  7570. Things become more difficult if your @command{tar} implementation
  7571. does support PAX headers, because in this case you will have to
  7572. manually extract the headers. We recommend the following algorithm:
  7573. @enumerate 1
  7574. @item
  7575. Consult the documentation of your @command{tar} implementation for an
  7576. option that prints @dfn{block numbers} along with the archive
  7577. listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
  7578. @command{star} has @option{-block-number}.
  7579. @item
  7580. Obtain verbose listing using the @samp{block number} option, and
  7581. find block numbers of the sparse member in question and the member
  7582. immediately following it. For example, running @command{star} on our
  7583. archive we obtain:
  7584. @smallexample
  7585. @group
  7586. $ @kbd{star -t -v -block-number -f arc.tar}
  7587. @dots{}
  7588. star: Unknown extended header keyword 'GNU.sparse.size' ignored.
  7589. star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
  7590. star: Unknown extended header keyword 'GNU.sparse.name' ignored.
  7591. star: Unknown extended header keyword 'GNU.sparse.map' ignored.
  7592. block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
  7593. block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
  7594. @dots{}
  7595. @end group
  7596. @end smallexample
  7597. @noindent
  7598. (as usual, ignore the warnings about unknown keywords.)
  7599. @item
  7600. Let @var{size} be the size of the sparse member, @var{Bs} be its block number
  7601. and @var{Bn} be the block number of the next member.
  7602. Compute:
  7603. @smallexample
  7604. @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
  7605. @end smallexample
  7606. @noindent
  7607. This number gives the size of the extended header part in tar @dfn{blocks}.
  7608. In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
  7609. = 7}.
  7610. @item
  7611. Use @command{dd} to extract the headers:
  7612. @smallexample
  7613. @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
  7614. @end smallexample
  7615. @noindent
  7616. where @var{archive} is the archive name, @var{hname} is a name of the
  7617. file to store the extended header in, @var{Bs} and @var{N} are
  7618. computed in previous steps.
  7619. In our example, this command will be
  7620. @smallexample
  7621. $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
  7622. @end smallexample
  7623. @end enumerate
  7624. Finally, you can expand the condensed file, using the obtained header:
  7625. @smallexample
  7626. @group
  7627. $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
  7628. Reading extended header file
  7629. Found variable GNU.sparse.size = 217481216
  7630. Found variable GNU.sparse.numblocks = 208
  7631. Found variable GNU.sparse.name = sparsefile
  7632. Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
  7633. Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
  7634. Done
  7635. @end group
  7636. @end smallexample
  7637. @node cpio
  7638. @section Comparison of @command{tar} and @command{cpio}
  7639. @UNREVISED
  7640. @FIXME{Reorganize the following material}
  7641. The @command{cpio} archive formats, like @command{tar}, do have maximum
  7642. file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
  7643. length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
  7644. file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
  7645. with arbitrary file name lengths, but other @command{cpio} implementations
  7646. may crash unexplainedly trying to read them.
  7647. @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
  7648. @command{cpio} doesn't handle symbolic links in the form in which it comes
  7649. in System V prior to SVR4, and some vendors may have added symlinks
  7650. to their system without enhancing @command{cpio} to know about them.
  7651. Others may have enhanced it in a way other than the way I did it
  7652. at Sun, and which was adopted by AT&T (and which is, I think, also
  7653. present in the @command{cpio} that Berkeley picked up from AT&T and put
  7654. into a later @acronym{BSD} release---I think I gave them my changes).
  7655. (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
  7656. can handle @command{tar} format input, and write it on output, and it
  7657. probably handles symbolic links. They may not have bothered doing
  7658. anything to enhance @command{tar} as a result.)
  7659. @command{cpio} handles special files; traditional @command{tar} doesn't.
  7660. @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
  7661. @command{cpio} comes only with System III, System V, and later @acronym{BSD}
  7662. (4.3-tahoe and later).
  7663. @command{tar}'s way of handling multiple hard links to a file can handle
  7664. file systems that support 32-bit inumbers (e.g., the @acronym{BSD} file system);
  7665. @command{cpio}s way requires you to play some games (in its ``binary''
  7666. format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
  7667. they're 18 bits---it would have to play games with the "file system @acronym{ID}"
  7668. field of the header to make sure that the file system @acronym{ID}/i-number pairs
  7669. of different files were always different), and I don't know which
  7670. @command{cpio}s, if any, play those games. Those that don't might get
  7671. confused and think two files are the same file when they're not, and
  7672. make hard links between them.
  7673. @command{tar}s way of handling multiple hard links to a file places only
  7674. one copy of the link on the tape, but the name attached to that copy
  7675. is the @emph{only} one you can use to retrieve the file; @command{cpio}s
  7676. way puts one copy for every link, but you can retrieve it using any
  7677. of the names.
  7678. @quotation
  7679. What type of check sum (if any) is used, and how is this calculated.
  7680. @end quotation
  7681. See the attached manual pages for @command{tar} and @command{cpio} format.
  7682. @command{tar} uses a checksum which is the sum of all the bytes in the
  7683. @command{tar} header for a file; @command{cpio} uses no checksum.
  7684. @quotation
  7685. If anyone knows why @command{cpio} was made when @command{tar} was present
  7686. at the unix scene,
  7687. @end quotation
  7688. It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
  7689. generally-available version of UNIX had @command{tar} at the time. I don't
  7690. know whether any version that was generally available @emph{within AT&T}
  7691. had @command{tar}, or, if so, whether the people within AT&T who did
  7692. @command{cpio} knew about it.
  7693. On restore, if there is a corruption on a tape @command{tar} will stop at
  7694. that point, while @command{cpio} will skip over it and try to restore the
  7695. rest of the files.
  7696. The main difference is just in the command syntax and header format.
  7697. @command{tar} is a little more tape-oriented in that everything is blocked
  7698. to start on a record boundary.
  7699. @quotation
  7700. Is there any differences between the ability to recover crashed
  7701. archives between the two of them. (Is there any chance of recovering
  7702. crashed archives at all.)
  7703. @end quotation
  7704. Theoretically it should be easier under @command{tar} since the blocking
  7705. lets you find a header with some variation of @samp{dd skip=@var{nn}}.
  7706. However, modern @command{cpio}'s and variations have an option to just
  7707. search for the next file header after an error with a reasonable chance
  7708. of resyncing. However, lots of tape driver software won't allow you to
  7709. continue past a media error which should be the only reason for getting
  7710. out of sync unless a file changed sizes while you were writing the
  7711. archive.
  7712. @quotation
  7713. If anyone knows why @command{cpio} was made when @command{tar} was present
  7714. at the unix scene, please tell me about this too.
  7715. @end quotation
  7716. Probably because it is more media efficient (by not blocking everything
  7717. and using only the space needed for the headers where @command{tar}
  7718. always uses 512 bytes per file header) and it knows how to archive
  7719. special files.
  7720. You might want to look at the freely available alternatives. The
  7721. major ones are @command{afio}, @GNUTAR{}, and
  7722. @command{pax}, each of which have their own extensions with some
  7723. backwards compatibility.
  7724. Sparse files were @command{tar}red as sparse files (which you can
  7725. easily test, because the resulting archive gets smaller, and
  7726. @acronym{GNU} @command{cpio} can no longer read it).
  7727. @node Media
  7728. @chapter Tapes and Other Archive Media
  7729. @UNREVISED
  7730. A few special cases about tape handling warrant more detailed
  7731. description. These special cases are discussed below.
  7732. Many complexities surround the use of @command{tar} on tape drives. Since
  7733. the creation and manipulation of archives located on magnetic tape was
  7734. the original purpose of @command{tar}, it contains many features making
  7735. such manipulation easier.
  7736. Archives are usually written on dismountable media---tape cartridges,
  7737. mag tapes, or floppy disks.
  7738. The amount of data a tape or disk holds depends not only on its size,
  7739. but also on how it is formatted. A 2400 foot long reel of mag tape
  7740. holds 40 megabytes of data when formatted at 1600 bits per inch. The
  7741. physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
  7742. Magnetic media are re-usable---once the archive on a tape is no longer
  7743. needed, the archive can be erased and the tape or disk used over.
  7744. Media quality does deteriorate with use, however. Most tapes or disks
  7745. should be discarded when they begin to produce data errors. EXABYTE
  7746. tape cartridges should be discarded when they generate an @dfn{error
  7747. count} (number of non-usable bits) of more than 10k.
  7748. Magnetic media are written and erased using magnetic fields, and
  7749. should be protected from such fields to avoid damage to stored data.
  7750. Sticking a floppy disk to a filing cabinet using a magnet is probably
  7751. not a good idea.
  7752. @menu
  7753. * Device:: Device selection and switching
  7754. * Remote Tape Server::
  7755. * Common Problems and Solutions::
  7756. * Blocking:: Blocking
  7757. * Many:: Many archives on one tape
  7758. * Using Multiple Tapes:: Using Multiple Tapes
  7759. * label:: Including a Label in the Archive
  7760. * verify::
  7761. * Write Protection::
  7762. @end menu
  7763. @node Device
  7764. @section Device Selection and Switching
  7765. @UNREVISED
  7766. @table @option
  7767. @item -f [@var{hostname}:]@var{file}
  7768. @itemx --file=[@var{hostname}:]@var{file}
  7769. Use archive file or device @var{file} on @var{hostname}.
  7770. @end table
  7771. This option is used to specify the file name of the archive @command{tar}
  7772. works on.
  7773. If the file name is @samp{-}, @command{tar} reads the archive from standard
  7774. input (when listing or extracting), or writes it to standard output
  7775. (when creating). If the @samp{-} file name is given when updating an
  7776. archive, @command{tar} will read the original archive from its standard
  7777. input, and will write the entire new archive to its standard output.
  7778. If the file name contains a @samp{:}, it is interpreted as
  7779. @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
  7780. sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
  7781. either case, @command{tar} will invoke the command @command{rsh} (or
  7782. @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
  7783. machine. If you give an alternate login name, it will be given to the
  7784. @command{rsh}.
  7785. Naturally, the remote machine must have an executable
  7786. @command{/usr/libexec/rmt}. This program is free software from the
  7787. University of California, and a copy of the source code can be found
  7788. with the sources for @command{tar}; it's compiled and installed by default.
  7789. The exact path to this utility is determined when configuring the package.
  7790. It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
  7791. your installation prefix. This location may also be overridden at
  7792. runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
  7793. ---rmt-command}, for detailed description of this option. @xref{Remote
  7794. Tape Server}, for the description of @command{rmt} command).
  7795. If this option is not given, but the environment variable @env{TAPE}
  7796. is set, its value is used; otherwise, old versions of @command{tar}
  7797. used a default archive name (which was picked when @command{tar} was
  7798. compiled). The default is normally set up to be the @dfn{first} tape
  7799. drive or other transportable I/O medium on the system.
  7800. Starting with version 1.11.5, @GNUTAR{} uses
  7801. standard input and standard output as the default device, and I will
  7802. not try anymore supporting automatic device detection at installation
  7803. time. This was failing really in too many cases, it was hopeless.
  7804. This is now completely left to the installer to override standard
  7805. input and standard output for default device, if this seems
  7806. preferable. Further, I think @emph{most} actual usages of
  7807. @command{tar} are done with pipes or disks, not really tapes,
  7808. cartridges or diskettes.
  7809. Some users think that using standard input and output is running
  7810. after trouble. This could lead to a nasty surprise on your screen if
  7811. you forget to specify an output file name---especially if you are going
  7812. through a network or terminal server capable of buffering large amounts
  7813. of output. We had so many bug reports in that area of configuring
  7814. default tapes automatically, and so many contradicting requests, that
  7815. we finally consider the problem to be portably intractable. We could
  7816. of course use something like @samp{/dev/tape} as a default, but this
  7817. is @emph{also} running after various kind of trouble, going from hung
  7818. processes to accidental destruction of real tapes. After having seen
  7819. all this mess, using standard input and output as a default really
  7820. sounds like the only clean choice left, and a very useful one too.
  7821. @GNUTAR{} reads and writes archive in records, I
  7822. suspect this is the main reason why block devices are preferred over
  7823. character devices. Most probably, block devices are more efficient
  7824. too. The installer could also check for @samp{DEFTAPE} in
  7825. @file{<sys/mtio.h>}.
  7826. @table @option
  7827. @xopindex{force-local, short description}
  7828. @item --force-local
  7829. Archive file is local even if it contains a colon.
  7830. @opindex rsh-command
  7831. @item --rsh-command=@var{command}
  7832. Use remote @var{command} instead of @command{rsh}. This option exists
  7833. so that people who use something other than the standard @command{rsh}
  7834. (e.g., a Kerberized @command{rsh}) can access a remote device.
  7835. When this command is not used, the shell command found when
  7836. the @command{tar} program was installed is used instead. This is
  7837. the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
  7838. @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
  7839. The installer may have overridden this by defining the environment
  7840. variable @env{RSH} @emph{at installation time}.
  7841. @item -[0-7][lmh]
  7842. Specify drive and density.
  7843. @xopindex{multi-volume, short description}
  7844. @item -M
  7845. @itemx --multi-volume
  7846. Create/list/extract multi-volume archive.
  7847. This option causes @command{tar} to write a @dfn{multi-volume} archive---one
  7848. that may be larger than will fit on the medium used to hold it.
  7849. @xref{Multi-Volume Archives}.
  7850. @xopindex{tape-length, short description}
  7851. @item -L @var{num}
  7852. @itemx --tape-length=@var{num}
  7853. Change tape after writing @var{num} x 1024 bytes.
  7854. This option might be useful when your tape drivers do not properly
  7855. detect end of physical tapes. By being slightly conservative on the
  7856. maximum tape length, you might avoid the problem entirely.
  7857. @xopindex{info-script, short description}
  7858. @xopindex{new-volume-script, short description}
  7859. @item -F @var{file}
  7860. @itemx --info-script=@var{file}
  7861. @itemx --new-volume-script=@var{file}
  7862. Execute @file{file} at end of each tape. This implies
  7863. @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
  7864. description of this option.
  7865. @end table
  7866. @node Remote Tape Server
  7867. @section The Remote Tape Server
  7868. @cindex remote tape drive
  7869. @pindex rmt
  7870. In order to access the tape drive on a remote machine, @command{tar}
  7871. uses the remote tape server written at the University of California at
  7872. Berkeley. The remote tape server must be installed as
  7873. @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
  7874. want to use. @command{tar} calls @command{rmt} by running an
  7875. @command{rsh} or @command{remsh} to the remote machine, optionally
  7876. using a different login name if one is supplied.
  7877. A copy of the source for the remote tape server is provided. It is
  7878. Copyright @copyright{} 1983 by the Regents of the University of
  7879. California, but can be freely distributed. It is compiled and
  7880. installed by default.
  7881. @cindex absolute file names
  7882. Unless you use the @option{--absolute-names} (@option{-P}) option,
  7883. @GNUTAR{} will not allow you to create an archive that contains
  7884. absolute file names (a file name beginning with @samp{/}.) If you try,
  7885. @command{tar} will automatically remove the leading @samp{/} from the
  7886. file names it stores in the archive. It will also type a warning
  7887. message telling you what it is doing.
  7888. When reading an archive that was created with a different
  7889. @command{tar} program, @GNUTAR{} automatically
  7890. extracts entries in the archive which have absolute file names as if
  7891. the file names were not absolute. This is an important feature. A
  7892. visitor here once gave a @command{tar} tape to an operator to restore;
  7893. the operator used Sun @command{tar} instead of @GNUTAR{},
  7894. and the result was that it replaced large portions of
  7895. our @file{/bin} and friends with versions from the tape; needless to
  7896. say, we were unhappy about having to recover the file system from
  7897. backup tapes.
  7898. For example, if the archive contained a file @file{/usr/bin/computoy},
  7899. @GNUTAR{} would extract the file to @file{usr/bin/computoy},
  7900. relative to the current directory. If you want to extract the files in
  7901. an archive to the same absolute names that they had when the archive
  7902. was created, you should do a @samp{cd /} before extracting the files
  7903. from the archive, or you should either use the @option{--absolute-names}
  7904. option, or use the command @samp{tar -C / @dots{}}.
  7905. @cindex Ultrix 3.1 and write failure
  7906. Some versions of Unix (Ultrix 3.1 is known to have this problem),
  7907. can claim that a short write near the end of a tape succeeded,
  7908. when it actually failed. This will result in the -M option not
  7909. working correctly. The best workaround at the moment is to use a
  7910. significantly larger blocking factor than the default 20.
  7911. In order to update an archive, @command{tar} must be able to backspace the
  7912. archive in order to reread or rewrite a record that was just read (or
  7913. written). This is currently possible only on two kinds of files: normal
  7914. disk files (or any other file that can be backspaced with @samp{lseek}),
  7915. and industry-standard 9-track magnetic tape (or any other kind of tape
  7916. that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
  7917. This means that the @option{--append}, @option{--concatenate}, and
  7918. @option{--delete} commands will not work on any other kind of file.
  7919. Some media simply cannot be backspaced, which means these commands and
  7920. options will never be able to work on them. These non-backspacing
  7921. media include pipes and cartridge tape drives.
  7922. Some other media can be backspaced, and @command{tar} will work on them
  7923. once @command{tar} is modified to do so.
  7924. Archives created with the @option{--multi-volume}, @option{--label}, and
  7925. @option{--incremental} (@option{-G}) options may not be readable by other version
  7926. of @command{tar}. In particular, restoring a file that was split over
  7927. a volume boundary will require some careful work with @command{dd}, if
  7928. it can be done at all. Other versions of @command{tar} may also create
  7929. an empty file whose name is that of the volume header. Some versions
  7930. of @command{tar} may create normal files instead of directories archived
  7931. with the @option{--incremental} (@option{-G}) option.
  7932. @node Common Problems and Solutions
  7933. @section Some Common Problems and their Solutions
  7934. @ifclear PUBLISH
  7935. @format
  7936. errors from system:
  7937. permission denied
  7938. no such file or directory
  7939. not owner
  7940. errors from @command{tar}:
  7941. directory checksum error
  7942. header format error
  7943. errors from media/system:
  7944. i/o error
  7945. device busy
  7946. @end format
  7947. @end ifclear
  7948. @node Blocking
  7949. @section Blocking
  7950. @UNREVISED
  7951. @dfn{Block} and @dfn{record} terminology is rather confused, and it
  7952. is also confusing to the expert reader. On the other hand, readers
  7953. who are new to the field have a fresh mind, and they may safely skip
  7954. the next two paragraphs, as the remainder of this manual uses those
  7955. two terms in a quite consistent way.
  7956. John Gilmore, the writer of the public domain @command{tar} from which
  7957. @GNUTAR{} was originally derived, wrote (June 1995):
  7958. @quotation
  7959. The nomenclature of tape drives comes from IBM, where I believe
  7960. they were invented for the IBM 650 or so. On IBM mainframes, what
  7961. is recorded on tape are tape blocks. The logical organization of
  7962. data is into records. There are various ways of putting records into
  7963. blocks, including @code{F} (fixed sized records), @code{V} (variable
  7964. sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
  7965. to a block), @code{VB} (variable size records, @var{n} to a block),
  7966. @code{VSB} (variable spanned blocked: variable sized records that can
  7967. occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
  7968. parameter specified this to the operating system.
  7969. The Unix man page on @command{tar} was totally confused about this.
  7970. When I wrote @code{PD TAR}, I used the historically correct terminology
  7971. (@command{tar} writes data records, which are grouped into blocks).
  7972. It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
  7973. here), and now Fran@,{c}ois has migrated that terminology back
  7974. into the source code too.
  7975. @end quotation
  7976. The term @dfn{physical block} means the basic transfer chunk from or
  7977. to a device, after which reading or writing may stop without anything
  7978. being lost. In this manual, the term @dfn{block} usually refers to
  7979. a disk physical block, @emph{assuming} that each disk block is 512
  7980. bytes in length. It is true that some disk devices have different
  7981. physical blocks, but @command{tar} ignore these differences in its own
  7982. format, which is meant to be portable, so a @command{tar} block is always
  7983. 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
  7984. The term @dfn{logical block} often represents the basic chunk of
  7985. allocation of many disk blocks as a single entity, which the operating
  7986. system treats somewhat atomically; this concept is only barely used
  7987. in @GNUTAR{}.
  7988. The term @dfn{physical record} is another way to speak of a physical
  7989. block, those two terms are somewhat interchangeable. In this manual,
  7990. the term @dfn{record} usually refers to a tape physical block,
  7991. @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
  7992. It is true that archives may be put on disk or used with pipes,
  7993. but nevertheless, @command{tar} tries to read and write the archive one
  7994. @dfn{record} at a time, whatever the medium in use. One record is made
  7995. up of an integral number of blocks, and this operation of putting many
  7996. disk blocks into a single tape block is called @dfn{reblocking}, or
  7997. more simply, @dfn{blocking}. The term @dfn{logical record} refers to
  7998. the logical organization of many characters into something meaningful
  7999. to the application. The term @dfn{unit record} describes a small set
  8000. of characters which are transmitted whole to or by the application,
  8001. and often refers to a line of text. Those two last terms are unrelated
  8002. to what we call a @dfn{record} in @GNUTAR{}.
  8003. When writing to tapes, @command{tar} writes the contents of the archive
  8004. in chunks known as @dfn{records}. To change the default blocking
  8005. factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
  8006. @var{512-size}}) option. Each record will then be composed of
  8007. @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
  8008. @xref{Standard}.) Each file written to the archive uses at least one
  8009. full record. As a result, using a larger record size can result in
  8010. more wasted space for small files. On the other hand, a larger record
  8011. size can often be read and written much more efficiently.
  8012. Further complicating the problem is that some tape drives ignore the
  8013. blocking entirely. For these, a larger record size can still improve
  8014. performance (because the software layers above the tape drive still
  8015. honor the blocking), but not as dramatically as on tape drives that
  8016. honor blocking.
  8017. When reading an archive, @command{tar} can usually figure out the
  8018. record size on itself. When this is the case, and a non-standard
  8019. record size was used when the archive was created, @command{tar} will
  8020. print a message about a non-standard blocking factor, and then operate
  8021. normally. On some tape devices, however, @command{tar} cannot figure
  8022. out the record size itself. On most of those, you can specify a
  8023. blocking factor (with @option{--blocking-factor}) larger than the
  8024. actual blocking factor, and then use the @option{--read-full-records}
  8025. (@option{-B}) option. (If you specify a blocking factor with
  8026. @option{--blocking-factor} and don't use the
  8027. @option{--read-full-records} option, then @command{tar} will not
  8028. attempt to figure out the recording size itself.) On some devices,
  8029. you must always specify the record size exactly with
  8030. @option{--blocking-factor} when reading, because @command{tar} cannot
  8031. figure it out. In any case, use @option{--list} (@option{-t}) before
  8032. doing any extractions to see whether @command{tar} is reading the archive
  8033. correctly.
  8034. @command{tar} blocks are all fixed size (512 bytes), and its scheme for
  8035. putting them into records is to put a whole number of them (one or
  8036. more) into each record. @command{tar} records are all the same size;
  8037. at the end of the file there's a block containing all zeros, which
  8038. is how you tell that the remainder of the last record(s) are garbage.
  8039. In a standard @command{tar} file (no options), the block size is 512
  8040. and the record size is 10240, for a blocking factor of 20. What the
  8041. @option{--blocking-factor} option does is sets the blocking factor,
  8042. changing the record size while leaving the block size at 512 bytes.
  8043. 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
  8044. most tape drives these days prefer much bigger records in order to
  8045. stream and not waste tape. When writing tapes for myself, some tend
  8046. to use a factor of the order of 2048, say, giving a record size of
  8047. around one megabyte.
  8048. If you use a blocking factor larger than 20, older @command{tar}
  8049. programs might not be able to read the archive, so we recommend this
  8050. as a limit to use in practice. @GNUTAR{}, however,
  8051. will support arbitrarily large record sizes, limited only by the
  8052. amount of virtual memory or the physical characteristics of the tape
  8053. device.
  8054. @menu
  8055. * Format Variations:: Format Variations
  8056. * Blocking Factor:: The Blocking Factor of an Archive
  8057. @end menu
  8058. @node Format Variations
  8059. @subsection Format Variations
  8060. @cindex Format Parameters
  8061. @cindex Format Options
  8062. @cindex Options, archive format specifying
  8063. @cindex Options, format specifying
  8064. @UNREVISED
  8065. Format parameters specify how an archive is written on the archive
  8066. media. The best choice of format parameters will vary depending on
  8067. the type and number of files being archived, and on the media used to
  8068. store the archive.
  8069. To specify format parameters when accessing or creating an archive,
  8070. you can use the options described in the following sections.
  8071. If you do not specify any format parameters, @command{tar} uses
  8072. default parameters. You cannot modify a compressed archive.
  8073. If you create an archive with the @option{--blocking-factor} option
  8074. specified (@pxref{Blocking Factor}), you must specify that
  8075. blocking-factor when operating on the archive. @xref{Formats}, for other
  8076. examples of format parameter considerations.
  8077. @node Blocking Factor
  8078. @subsection The Blocking Factor of an Archive
  8079. @cindex Blocking Factor
  8080. @cindex Record Size
  8081. @cindex Number of blocks per record
  8082. @cindex Number of bytes per record
  8083. @cindex Bytes per record
  8084. @cindex Blocks per record
  8085. @UNREVISED
  8086. @opindex blocking-factor
  8087. The data in an archive is grouped into blocks, which are 512 bytes.
  8088. Blocks are read and written in whole number multiples called
  8089. @dfn{records}. The number of blocks in a record (i.e., the size of a
  8090. record in units of 512 bytes) is called the @dfn{blocking factor}.
  8091. The @option{--blocking-factor=@var{512-size}} (@option{-b
  8092. @var{512-size}}) option specifies the blocking factor of an archive.
  8093. The default blocking factor is typically 20 (i.e., 10240 bytes), but
  8094. can be specified at installation. To find out the blocking factor of
  8095. an existing archive, use @samp{tar --list --file=@var{archive-name}}.
  8096. This may not work on some devices.
  8097. Records are separated by gaps, which waste space on the archive media.
  8098. If you are archiving on magnetic tape, using a larger blocking factor
  8099. (and therefore larger records) provides faster throughput and allows you
  8100. to fit more data on a tape (because there are fewer gaps). If you are
  8101. archiving on cartridge, a very large blocking factor (say 126 or more)
  8102. greatly increases performance. A smaller blocking factor, on the other
  8103. hand, may be useful when archiving small files, to avoid archiving lots
  8104. of nulls as @command{tar} fills out the archive to the end of the record.
  8105. In general, the ideal record size depends on the size of the
  8106. inter-record gaps on the tape you are using, and the average size of the
  8107. files you are archiving. @xref{create}, for information on
  8108. writing archives.
  8109. @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
  8110. Archives with blocking factors larger than 20 cannot be read
  8111. by very old versions of @command{tar}, or by some newer versions
  8112. of @command{tar} running on old machines with small address spaces.
  8113. With @GNUTAR{}, the blocking factor of an archive is limited
  8114. only by the maximum record size of the device containing the archive,
  8115. or by the amount of available virtual memory.
  8116. Also, on some systems, not using adequate blocking factors, as sometimes
  8117. imposed by the device drivers, may yield unexpected diagnostics. For
  8118. example, this has been reported:
  8119. @smallexample
  8120. Cannot write to /dev/dlt: Invalid argument
  8121. @end smallexample
  8122. @noindent
  8123. In such cases, it sometimes happen that the @command{tar} bundled by
  8124. the system is aware of block size idiosyncrasies, while @GNUTAR{}
  8125. requires an explicit specification for the block size,
  8126. which it cannot guess. This yields some people to consider
  8127. @GNUTAR{} is misbehaving, because by comparison,
  8128. @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
  8129. for example, might resolve the problem.
  8130. If you use a non-default blocking factor when you create an archive, you
  8131. must specify the same blocking factor when you modify that archive. Some
  8132. archive devices will also require you to specify the blocking factor when
  8133. reading that archive, however this is not typically the case. Usually, you
  8134. can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
  8135. reports a non-default record size and then lists the archive members as
  8136. it would normally. To extract files from an archive with a non-standard
  8137. blocking factor (particularly if you're not sure what the blocking factor
  8138. is), you can usually use the @option{--read-full-records} (@option{-B}) option while
  8139. specifying a blocking factor larger then the blocking factor of the archive
  8140. (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
  8141. @xref{list}, for more information on the @option{--list} (@option{-t})
  8142. operation. @xref{Reading}, for a more detailed explanation of that option.
  8143. @table @option
  8144. @item --blocking-factor=@var{number}
  8145. @itemx -b @var{number}
  8146. Specifies the blocking factor of an archive. Can be used with any
  8147. operation, but is usually not necessary with @option{--list} (@option{-t}).
  8148. @end table
  8149. Device blocking
  8150. @table @option
  8151. @item -b @var{blocks}
  8152. @itemx --blocking-factor=@var{blocks}
  8153. Set record size to @math{@var{blocks} * 512} bytes.
  8154. This option is used to specify a @dfn{blocking factor} for the archive.
  8155. When reading or writing the archive, @command{tar}, will do reads and writes
  8156. of the archive in records of @math{@var{block}*512} bytes. This is true
  8157. even when the archive is compressed. Some devices requires that all
  8158. write operations be a multiple of a certain size, and so, @command{tar}
  8159. pads the archive out to the next record boundary.
  8160. The default blocking factor is set when @command{tar} is compiled, and is
  8161. typically 20. Blocking factors larger than 20 cannot be read by very
  8162. old versions of @command{tar}, or by some newer versions of @command{tar}
  8163. running on old machines with small address spaces.
  8164. With a magnetic tape, larger records give faster throughput and fit
  8165. more data on a tape (because there are fewer inter-record gaps).
  8166. If the archive is in a disk file or a pipe, you may want to specify
  8167. a smaller blocking factor, since a large one will result in a large
  8168. number of null bytes at the end of the archive.
  8169. When writing cartridge or other streaming tapes, a much larger
  8170. blocking factor (say 126 or more) will greatly increase performance.
  8171. However, you must specify the same blocking factor when reading or
  8172. updating the archive.
  8173. Apparently, Exabyte drives have a physical block size of 8K bytes.
  8174. If we choose our blocksize as a multiple of 8k bytes, then the problem
  8175. seems to disappear. Id est, we are using block size of 112 right
  8176. now, and we haven't had the problem since we switched@dots{}
  8177. With @GNUTAR{} the blocking factor is limited only
  8178. by the maximum record size of the device containing the archive, or by
  8179. the amount of available virtual memory.
  8180. However, deblocking or reblocking is virtually avoided in a special
  8181. case which often occurs in practice, but which requires all the
  8182. following conditions to be simultaneously true:
  8183. @itemize @bullet
  8184. @item
  8185. the archive is subject to a compression option,
  8186. @item
  8187. the archive is not handled through standard input or output, nor
  8188. redirected nor piped,
  8189. @item
  8190. the archive is directly handled to a local disk, instead of any special
  8191. device,
  8192. @item
  8193. @option{--blocking-factor} is not explicitly specified on the @command{tar}
  8194. invocation.
  8195. @end itemize
  8196. If the output goes directly to a local disk, and not through
  8197. stdout, then the last write is not extended to a full record size.
  8198. Otherwise, reblocking occurs. Here are a few other remarks on this
  8199. topic:
  8200. @itemize @bullet
  8201. @item
  8202. @command{gzip} will complain about trailing garbage if asked to
  8203. uncompress a compressed archive on tape, there is an option to turn
  8204. the message off, but it breaks the regularity of simply having to use
  8205. @samp{@var{prog} -d} for decompression. It would be nice if gzip was
  8206. silently ignoring any number of trailing zeros. I'll ask Jean-loup
  8207. Gailly, by sending a copy of this message to him.
  8208. @item
  8209. @command{compress} does not show this problem, but as Jean-loup pointed
  8210. out to Michael, @samp{compress -d} silently adds garbage after
  8211. the result of decompression, which tar ignores because it already
  8212. recognized its end-of-file indicator. So this bug may be safely
  8213. ignored.
  8214. @item
  8215. @samp{gzip -d -q} will be silent about the trailing zeros indeed,
  8216. but will still return an exit status of 2 which tar reports in turn.
  8217. @command{tar} might ignore the exit status returned, but I hate doing
  8218. that, as it weakens the protection @command{tar} offers users against
  8219. other possible problems at decompression time. If @command{gzip} was
  8220. silently skipping trailing zeros @emph{and} also avoiding setting the
  8221. exit status in this innocuous case, that would solve this situation.
  8222. @item
  8223. @command{tar} should become more solid at not stopping to read a pipe at
  8224. the first null block encountered. This inelegantly breaks the pipe.
  8225. @command{tar} should rather drain the pipe out before exiting itself.
  8226. @end itemize
  8227. @xopindex{ignore-zeros, short description}
  8228. @item -i
  8229. @itemx --ignore-zeros
  8230. Ignore blocks of zeros in archive (means EOF).
  8231. The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
  8232. of zeros in the archive. Normally a block of zeros indicates the
  8233. end of the archive, but when reading a damaged archive, or one which
  8234. was created by concatenating several archives together, this option
  8235. allows @command{tar} to read the entire archive. This option is not on
  8236. by default because many versions of @command{tar} write garbage after
  8237. the zeroed blocks.
  8238. Note that this option causes @command{tar} to read to the end of the
  8239. archive file, which may sometimes avoid problems when multiple files
  8240. are stored on a single physical tape.
  8241. @xopindex{read-full-records, short description}
  8242. @item -B
  8243. @itemx --read-full-records
  8244. Reblock as we read (for reading 4.2@acronym{BSD} pipes).
  8245. If @option{--read-full-records} is used, @command{tar}
  8246. will not panic if an attempt to read a record from the archive does
  8247. not return a full record. Instead, @command{tar} will keep reading
  8248. until it has obtained a full
  8249. record.
  8250. This option is turned on by default when @command{tar} is reading
  8251. an archive from standard input, or from a remote machine. This is
  8252. because on @acronym{BSD} Unix systems, a read of a pipe will return however
  8253. much happens to be in the pipe, even if it is less than @command{tar}
  8254. requested. If this option was not used, @command{tar} would fail as
  8255. soon as it read an incomplete record from the pipe.
  8256. This option is also useful with the commands for updating an archive.
  8257. @end table
  8258. Tape blocking
  8259. @FIXME{Appropriate options should be moved here from elsewhere.}
  8260. @cindex blocking factor
  8261. @cindex tape blocking
  8262. When handling various tapes or cartridges, you have to take care of
  8263. selecting a proper blocking, that is, the number of disk blocks you
  8264. put together as a single tape block on the tape, without intervening
  8265. tape gaps. A @dfn{tape gap} is a small landing area on the tape
  8266. with no information on it, used for decelerating the tape to a
  8267. full stop, and for later regaining the reading or writing speed.
  8268. When the tape driver starts reading a record, the record has to
  8269. be read whole without stopping, as a tape gap is needed to stop the
  8270. tape motion without loosing information.
  8271. @cindex Exabyte blocking
  8272. @cindex DAT blocking
  8273. Using higher blocking (putting more disk blocks per tape block) will use
  8274. the tape more efficiently as there will be less tape gaps. But reading
  8275. such tapes may be more difficult for the system, as more memory will be
  8276. required to receive at once the whole record. Further, if there is a
  8277. reading error on a huge record, this is less likely that the system will
  8278. succeed in recovering the information. So, blocking should not be too
  8279. low, nor it should be too high. @command{tar} uses by default a blocking of
  8280. 20 for historical reasons, and it does not really matter when reading or
  8281. writing to disk. Current tape technology would easily accommodate higher
  8282. blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
  8283. We were told that for some DLT drives, the blocking should be a multiple
  8284. of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
  8285. Other manufacturers may use different recommendations for the same tapes.
  8286. This might also depends of the buffering techniques used inside modern
  8287. tape controllers. Some imposes a minimum blocking, or a maximum blocking.
  8288. Others request blocking to be some exponent of two.
  8289. So, there is no fixed rule for blocking. But blocking at read time
  8290. should ideally be the same as blocking used at write time. At one place
  8291. I know, with a wide variety of equipment, they found it best to use a
  8292. blocking of 32 to guarantee that their tapes are fully interchangeable.
  8293. I was also told that, for recycled tapes, prior erasure (by the same
  8294. drive unit that will be used to create the archives) sometimes lowers
  8295. the error rates observed at rewriting time.
  8296. I might also use @option{--number-blocks} instead of
  8297. @option{--block-number}, so @option{--block} will then expand to
  8298. @option{--blocking-factor} unambiguously.
  8299. @node Many
  8300. @section Many Archives on One Tape
  8301. @FIXME{Appropriate options should be moved here from elsewhere.}
  8302. @findex ntape @r{device}
  8303. Most tape devices have two entries in the @file{/dev} directory, or
  8304. entries that come in pairs, which differ only in the minor number for
  8305. this device. Let's take for example @file{/dev/tape}, which often
  8306. points to the only or usual tape device of a given system. There might
  8307. be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
  8308. name is the @emph{rewinding} version of the device, while the name
  8309. having @samp{nr} in it is the @emph{no rewinding} version of the same
  8310. device.
  8311. A rewinding tape device will bring back the tape to its beginning point
  8312. automatically when this device is opened or closed. Since @command{tar}
  8313. opens the archive file before using it and closes it afterwards, this
  8314. means that a simple:
  8315. @smallexample
  8316. $ @kbd{tar cf /dev/tape @var{directory}}
  8317. @end smallexample
  8318. @noindent
  8319. will reposition the tape to its beginning both prior and after saving
  8320. @var{directory} contents to it, thus erasing prior tape contents and
  8321. making it so that any subsequent write operation will destroy what has
  8322. just been saved.
  8323. @cindex tape positioning
  8324. So, a rewinding device is normally meant to hold one and only one file.
  8325. If you want to put more than one @command{tar} archive on a given tape, you
  8326. will need to avoid using the rewinding version of the tape device. You
  8327. will also have to pay special attention to tape positioning. Errors in
  8328. positioning may overwrite the valuable data already on your tape. Many
  8329. people, burnt by past experiences, will only use rewinding devices and
  8330. limit themselves to one file per tape, precisely to avoid the risk of
  8331. such errors. Be fully aware that writing at the wrong position on a
  8332. tape loses all information past this point and most probably until the
  8333. end of the tape, and this destroyed information @emph{cannot} be
  8334. recovered.
  8335. To save @var{directory-1} as a first archive at the beginning of a
  8336. tape, and leave that tape ready for a second archive, you should use:
  8337. @smallexample
  8338. $ @kbd{mt -f /dev/nrtape rewind}
  8339. $ @kbd{tar cf /dev/nrtape @var{directory-1}}
  8340. @end smallexample
  8341. @cindex tape marks
  8342. @dfn{Tape marks} are special magnetic patterns written on the tape
  8343. media, which are later recognizable by the reading hardware. These
  8344. marks are used after each file, when there are many on a single tape.
  8345. An empty file (that is to say, two tape marks in a row) signal the
  8346. logical end of the tape, after which no file exist. Usually,
  8347. non-rewinding tape device drivers will react to the close request issued
  8348. by @command{tar} by first writing two tape marks after your archive, and by
  8349. backspacing over one of these. So, if you remove the tape at that time
  8350. from the tape drive, it is properly terminated. But if you write
  8351. another file at the current position, the second tape mark will be
  8352. erased by the new information, leaving only one tape mark between files.
  8353. So, you may now save @var{directory-2} as a second archive after the
  8354. first on the same tape by issuing the command:
  8355. @smallexample
  8356. $ @kbd{tar cf /dev/nrtape @var{directory-2}}
  8357. @end smallexample
  8358. @noindent
  8359. and so on for all the archives you want to put on the same tape.
  8360. Another usual case is that you do not write all the archives the same
  8361. day, and you need to remove and store the tape between two archive
  8362. sessions. In general, you must remember how many files are already
  8363. saved on your tape. Suppose your tape already has 16 files on it, and
  8364. that you are ready to write the 17th. You have to take care of skipping
  8365. the first 16 tape marks before saving @var{directory-17}, say, by using
  8366. these commands:
  8367. @smallexample
  8368. $ @kbd{mt -f /dev/nrtape rewind}
  8369. $ @kbd{mt -f /dev/nrtape fsf 16}
  8370. $ @kbd{tar cf /dev/nrtape @var{directory-17}}
  8371. @end smallexample
  8372. In all the previous examples, we put aside blocking considerations, but
  8373. you should do the proper things for that as well. @xref{Blocking}.
  8374. @menu
  8375. * Tape Positioning:: Tape Positions and Tape Marks
  8376. * mt:: The @command{mt} Utility
  8377. @end menu
  8378. @node Tape Positioning
  8379. @subsection Tape Positions and Tape Marks
  8380. @UNREVISED
  8381. Just as archives can store more than one file from the file system,
  8382. tapes can store more than one archive file. To keep track of where
  8383. archive files (or any other type of file stored on tape) begin and
  8384. end, tape archive devices write magnetic @dfn{tape marks} on the
  8385. archive media. Tape drives write one tape mark between files,
  8386. two at the end of all the file entries.
  8387. If you think of data as a series of records "rrrr"'s, and tape marks as
  8388. "*"'s, a tape might look like the following:
  8389. @smallexample
  8390. rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
  8391. @end smallexample
  8392. Tape devices read and write tapes using a read/write @dfn{tape
  8393. head}---a physical part of the device which can only access one
  8394. point on the tape at a time. When you use @command{tar} to read or
  8395. write archive data from a tape device, the device will begin reading
  8396. or writing from wherever on the tape the tape head happens to be,
  8397. regardless of which archive or what part of the archive the tape
  8398. head is on. Before writing an archive, you should make sure that no
  8399. data on the tape will be overwritten (unless it is no longer needed).
  8400. Before reading an archive, you should make sure the tape head is at
  8401. the beginning of the archive you want to read. You can do it manually
  8402. via @code{mt} utility (@pxref{mt}). The @code{restore} script does
  8403. that automatically (@pxref{Scripted Restoration}).
  8404. If you want to add new archive file entries to a tape, you should
  8405. advance the tape to the end of the existing file entries, backspace
  8406. over the last tape mark, and write the new archive file. If you were
  8407. to add two archives to the example above, the tape might look like the
  8408. following:
  8409. @smallexample
  8410. rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
  8411. @end smallexample
  8412. @node mt
  8413. @subsection The @command{mt} Utility
  8414. @UNREVISED
  8415. @FIXME{Is it true that this only works on non-block devices?
  8416. should explain the difference, (fixed or variable).}
  8417. @xref{Blocking Factor}.
  8418. You can use the @command{mt} utility to advance or rewind a tape past a
  8419. specified number of archive files on the tape. This will allow you
  8420. to move to the beginning of an archive before extracting or reading
  8421. it, or to the end of all the archives before writing a new one.
  8422. @FIXME{Why isn't there an "advance 'til you find two tape marks
  8423. together"?}
  8424. The syntax of the @command{mt} command is:
  8425. @smallexample
  8426. @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
  8427. @end smallexample
  8428. where @var{tapename} is the name of the tape device, @var{number} is
  8429. the number of times an operation is performed (with a default of one),
  8430. and @var{operation} is one of the following:
  8431. @FIXME{is there any use for record operations?}
  8432. @table @option
  8433. @item eof
  8434. @itemx weof
  8435. Writes @var{number} tape marks at the current position on the tape.
  8436. @item fsf
  8437. Moves tape position forward @var{number} files.
  8438. @item bsf
  8439. Moves tape position back @var{number} files.
  8440. @item rewind
  8441. Rewinds the tape. (Ignores @var{number}).
  8442. @item offline
  8443. @itemx rewoff1
  8444. Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
  8445. @item status
  8446. Prints status information about the tape unit.
  8447. @end table
  8448. @FIXME{Is there a better way to frob the spacing on the list?}
  8449. If you don't specify a @var{tapename}, @command{mt} uses the environment
  8450. variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
  8451. the default device specified in your @file{sys/mtio.h} file
  8452. (@code{DEFTAPE} variable). If this is not defined, the program will
  8453. display a descriptive error message and exit with code 1.
  8454. @command{mt} returns a 0 exit status when the operation(s) were
  8455. successful, 1 if the command was unrecognized, and 2 if an operation
  8456. failed.
  8457. @node Using Multiple Tapes
  8458. @section Using Multiple Tapes
  8459. Often you might want to write a large archive, one larger than will fit
  8460. on the actual tape you are using. In such a case, you can run multiple
  8461. @command{tar} commands, but this can be inconvenient, particularly if you
  8462. are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
  8463. Therefore, @command{tar} provides a special mode for creating
  8464. multi-volume archives.
  8465. @dfn{Multi-volume} archive is a single @command{tar} archive, stored
  8466. on several media volumes of fixed size. Although in this section we will
  8467. often call @samp{volume} a @dfn{tape}, there is absolutely no
  8468. requirement for multi-volume archives to be stored on tapes. Instead,
  8469. they can use whatever media type the user finds convenient, they can
  8470. even be located on files.
  8471. When creating a multi-volume archive, @GNUTAR{} continues to fill
  8472. current volume until it runs out of space, then it switches to
  8473. next volume (usually the operator is queried to replace the tape on
  8474. this point), and continues working on the new volume. This operation
  8475. continues until all requested files are dumped. If @GNUTAR{} detects
  8476. end of media while dumping a file, such a file is archived in split
  8477. form. Some very big files can even be split across several volumes.
  8478. Each volume is itself a valid @GNUTAR{} archive, so it can be read
  8479. without any special options. Consequently any file member residing
  8480. entirely on one volume can be extracted or otherwise operated upon
  8481. without needing the other volume. Sure enough, to extract a split
  8482. member you would need all volumes its parts reside on.
  8483. Multi-volume archives suffer from several limitations. In particular,
  8484. they cannot be compressed.
  8485. @GNUTAR{} is able to create multi-volume archives of two formats
  8486. (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
  8487. @menu
  8488. * Multi-Volume Archives:: Archives Longer than One Tape or Disk
  8489. * Tape Files:: Tape Files
  8490. * Tarcat:: Concatenate Volumes into a Single Archive
  8491. @end menu
  8492. @node Multi-Volume Archives
  8493. @subsection Archives Longer than One Tape or Disk
  8494. @cindex Multi-volume archives
  8495. @opindex multi-volume
  8496. To create an archive that is larger than will fit on a single unit of
  8497. the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
  8498. the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
  8499. archive can be manipulated like any other archive (provided the
  8500. @option{--multi-volume} option is specified), but is stored on more
  8501. than one tape or disk.
  8502. When you specify @option{--multi-volume}, @command{tar} does not report an
  8503. error when it comes to the end of an archive volume (when reading), or
  8504. the end of the media (when writing). Instead, it prompts you to load
  8505. a new storage volume. If the archive is on a magnetic tape, you
  8506. should change tapes when you see the prompt; if the archive is on a
  8507. floppy disk, you should change disks; etc.
  8508. @table @option
  8509. @item --multi-volume
  8510. @itemx -M
  8511. Creates a multi-volume archive, when used in conjunction with
  8512. @option{--create} (@option{-c}). To perform any other operation on a multi-volume
  8513. archive, specify @option{--multi-volume} in conjunction with that
  8514. operation.
  8515. For example:
  8516. @smallexample
  8517. $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
  8518. @end smallexample
  8519. @end table
  8520. The method @command{tar} uses to detect end of tape is not perfect, and
  8521. fails on some operating systems or on some devices. If @command{tar}
  8522. cannot detect the end of the tape itself, you can use
  8523. @option{--tape-length} option to inform it about the capacity of the
  8524. tape:
  8525. @anchor{tape-length}
  8526. @table @option
  8527. @opindex tape-length
  8528. @item --tape-length=@var{size}
  8529. @itemx -L @var{size}
  8530. Set maximum length of a volume. The @var{size} argument should then
  8531. be the usable size of the tape in units of 1024 bytes. This option
  8532. selects @option{--multi-volume} automatically. For example:
  8533. @smallexample
  8534. $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
  8535. @end smallexample
  8536. @end table
  8537. @anchor{change volume prompt}
  8538. When @GNUTAR{} comes to the end of a storage media, it asks you to
  8539. change the volume. The built-in prompt for POSIX locale
  8540. is@footnote{If you run @GNUTAR{} under a different locale, the
  8541. translation to the locale's language will be used.}:
  8542. @smallexample
  8543. Prepare volume #@var{n} for `@var{archive}' and hit return:
  8544. @end smallexample
  8545. @noindent
  8546. where @var{n} is the ordinal number of the volume to be created and
  8547. @var{archive} is archive file or device name.
  8548. When prompting for a new tape, @command{tar} accepts any of the following
  8549. responses:
  8550. @table @kbd
  8551. @item ?
  8552. Request @command{tar} to explain possible responses
  8553. @item q
  8554. Request @command{tar} to exit immediately.
  8555. @item n @var{file-name}
  8556. Request @command{tar} to write the next volume on the file @var{file-name}.
  8557. @item !
  8558. Request @command{tar} to run a subshell. This option can be disabled
  8559. by giving @option{--restrict} command line option to
  8560. @command{tar}@footnote{@xref{--restrict}, for more information about
  8561. this option}.
  8562. @item y
  8563. Request @command{tar} to begin writing the next volume.
  8564. @end table
  8565. (You should only type @samp{y} after you have changed the tape;
  8566. otherwise @command{tar} will write over the volume it just finished.)
  8567. @cindex Volume number file
  8568. @cindex volno file
  8569. @anchor{volno-file}
  8570. @opindex volno-file
  8571. The volume number used by @command{tar} in its tape-changing prompt
  8572. can be changed; if you give the
  8573. @option{--volno-file=@var{file-of-number}} option, then
  8574. @var{file-of-number} should be an non-existing file to be created, or
  8575. else, a file already containing a decimal number. That number will be
  8576. used as the volume number of the first volume written. When
  8577. @command{tar} is finished, it will rewrite the file with the
  8578. now-current volume number. (This does not change the volume number
  8579. written on a tape label, as per @ref{label}, it @emph{only} affects
  8580. the number used in the prompt.)
  8581. @cindex End-of-archive info script
  8582. @cindex Info script
  8583. @anchor{info-script}
  8584. @opindex info-script
  8585. @opindex new-volume-script
  8586. If you want more elaborate behavior than this, you can write a special
  8587. @dfn{new volume script}, that will be responsible for changing the
  8588. volume, and instruct @command{tar} to use it instead of its normal
  8589. prompting procedure:
  8590. @table @option
  8591. @item --info-script=@var{script-name}
  8592. @itemx --new-volume-script=@var{script-name}
  8593. @itemx -F @var{script-name}
  8594. Specify the full name of the volume script to use. The script can be
  8595. used to eject cassettes, or to broadcast messages such as
  8596. @samp{Someone please come change my tape} when performing unattended
  8597. backups.
  8598. @end table
  8599. The @var{script-name} is executed without any command line
  8600. arguments. It inherits @command{tar}'s shell environment.
  8601. Additional data is passed to it via the following
  8602. environment variables:
  8603. @table @env
  8604. @vrindex TAR_VERSION, info script environment variable
  8605. @item TAR_VERSION
  8606. @GNUTAR{} version number.
  8607. @vrindex TAR_ARCHIVE, info script environment variable
  8608. @item TAR_ARCHIVE
  8609. The name of the archive @command{tar} is processing.
  8610. @vrindex TAR_VOLUME, info script environment variable
  8611. @item TAR_VOLUME
  8612. Ordinal number of the volume @command{tar} is about to start.
  8613. @vrindex TAR_SUBCOMMAND, info script environment variable
  8614. @item TAR_SUBCOMMAND
  8615. A short option describing the operation @command{tar} is executing
  8616. @xref{Operations}, for a complete list of subcommand options.
  8617. @vrindex TAR_FORMAT, info script environment variable
  8618. @item TAR_FORMAT
  8619. Format of the archive being processed. @xref{Formats}, for a complete
  8620. list of archive format names.
  8621. @vrindex TAR_FD, info script environment variable
  8622. @item TAR_FD
  8623. File descriptor which can be used to communicate the new volume
  8624. name to @command{tar}.
  8625. @end table
  8626. The volume script can instruct @command{tar} to use new archive name,
  8627. by writing in to file descriptor @env{$TAR_FD} (see below for an example).
  8628. If the info script fails, @command{tar} exits; otherwise, it begins
  8629. writing the next volume.
  8630. If you want @command{tar} to cycle through a series of files or tape
  8631. drives, there are three approaches to choose from. First of all, you
  8632. can give @command{tar} multiple @option{--file} options. In this case
  8633. the specified files will be used, in sequence, as the successive
  8634. volumes of the archive. Only when the first one in the sequence needs
  8635. to be used again will @command{tar} prompt for a tape change (or run
  8636. the info script). For example, suppose someone has two tape drives on
  8637. a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
  8638. @GNUTAR{} to switch to the second drive when it needs to write the
  8639. second tape, and then back to the first tape, etc., just do either of:
  8640. @smallexample
  8641. $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
  8642. $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
  8643. @end smallexample
  8644. The second method is to use the @samp{n} response to the tape-change
  8645. prompt.
  8646. Finally, the most flexible approach is to use a volume script, that
  8647. writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
  8648. following volume script will create a series of archive files, named
  8649. @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
  8650. archive being created (as given by @option{--file} option) and
  8651. @var{vol} is the ordinal number of the archive being created:
  8652. @smallexample
  8653. @group
  8654. #! /bin/sh
  8655. echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
  8656. name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
  8657. case $TAR_SUBCOMMAND in
  8658. -c) ;;
  8659. -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
  8660. ;;
  8661. *) exit 1
  8662. esac
  8663. echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
  8664. @end group
  8665. @end smallexample
  8666. The same script can be used while listing, comparing or extracting
  8667. from the created archive. For example:
  8668. @smallexample
  8669. @group
  8670. # @r{Create a multi-volume archive:}
  8671. $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
  8672. # @r{Extract from the created archive:}
  8673. $ @kbd{tar -x -f archive.tar -F new-volume .}
  8674. @end group
  8675. @end smallexample
  8676. @noindent
  8677. Notice, that the first command had to use @option{-L} option, since
  8678. otherwise @GNUTAR{} will end up writing everything to file
  8679. @file{archive.tar}.
  8680. You can read each individual volume of a multi-volume archive as if it
  8681. were an archive by itself. For example, to list the contents of one
  8682. volume, use @option{--list}, without @option{--multi-volume} specified.
  8683. To extract an archive member from one volume (assuming it is described
  8684. that volume), use @option{--extract}, again without
  8685. @option{--multi-volume}.
  8686. If an archive member is split across volumes (i.e., its entry begins on
  8687. one volume of the media and ends on another), you need to specify
  8688. @option{--multi-volume} to extract it successfully. In this case, you
  8689. should load the volume where the archive member starts, and use
  8690. @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
  8691. volumes as it needs them. @xref{extracting archives}, for more
  8692. information about extracting archives.
  8693. Multi-volume archives can be modified like any other archive. To add
  8694. files to a multi-volume archive, you need to only mount the last
  8695. volume of the archive media (and new volumes, if needed). For all
  8696. other operations, you need to use the entire archive.
  8697. If a multi-volume archive was labeled using
  8698. @option{--label=@var{archive-label}} (@pxref{label}) when it was
  8699. created, @command{tar} will not automatically label volumes which are
  8700. added later. To label subsequent volumes, specify
  8701. @option{--label=@var{archive-label}} again in conjunction with the
  8702. @option{--append}, @option{--update} or @option{--concatenate} operation.
  8703. Notice that multi-volume support is a GNU extension and the archives
  8704. created in this mode should be read only using @GNUTAR{}. If you
  8705. absolutely have to process such archives using a third-party @command{tar}
  8706. implementation, read @ref{Split Recovery}.
  8707. @node Tape Files
  8708. @subsection Tape Files
  8709. @UNREVISED
  8710. To give the archive a name which will be recorded in it, use the
  8711. @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
  8712. option. This will write a special block identifying
  8713. @var{volume-label} as the name of the archive to the front of the
  8714. archive which will be displayed when the archive is listed with
  8715. @option{--list}. If you are creating a multi-volume archive with
  8716. @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
  8717. volume label will have @samp{Volume @var{nnn}} appended to the name
  8718. you give, where @var{nnn} is the number of the volume of the archive.
  8719. (If you use the @option{--label=@var{volume-label}}) option when
  8720. reading an archive, it checks to make sure the label on the tape
  8721. matches the one you give. @xref{label}.
  8722. When @command{tar} writes an archive to tape, it creates a single
  8723. tape file. If multiple archives are written to the same tape, one
  8724. after the other, they each get written as separate tape files. When
  8725. extracting, it is necessary to position the tape at the right place
  8726. before running @command{tar}. To do this, use the @command{mt} command.
  8727. For more information on the @command{mt} command and on the organization
  8728. of tapes into a sequence of tape files, see @ref{mt}.
  8729. People seem to often do:
  8730. @smallexample
  8731. @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
  8732. @end smallexample
  8733. or such, for pushing a common date in all volumes or an archive set.
  8734. @node Tarcat
  8735. @subsection Concatenate Volumes into a Single Archive
  8736. @pindex tarcat
  8737. Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
  8738. archive to a single @command{tar} archive. Simply concatenating all
  8739. volumes into one will not work, since each volume carries an additional
  8740. information at the beginning. @GNUTAR{} is shipped with the shell
  8741. script @command{tarcat} designed for this purpose.
  8742. The script takes a list of files comprising a multi-volume archive
  8743. and creates the resulting archive at the standard output. For example:
  8744. @smallexample
  8745. @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
  8746. @end smallexample
  8747. The script implements a simple heuristics to determine the format of
  8748. the first volume file and to decide how to process the rest of the
  8749. files. However, it makes no attempt to verify whether the files are
  8750. given in order or even if they are valid @command{tar} archives.
  8751. It uses @command{dd} and does not filter its standard error, so you
  8752. will usually see lots of spurious messages.
  8753. @FIXME{The script is not installed. Should we install it?}
  8754. @node label
  8755. @section Including a Label in the Archive
  8756. @cindex Labeling an archive
  8757. @cindex Labels on the archive media
  8758. @cindex Labeling multi-volume archives
  8759. @UNREVISED
  8760. @opindex label
  8761. To avoid problems caused by misplaced paper labels on the archive
  8762. media, you can include a @dfn{label} entry---an archive member which
  8763. contains the name of the archive---in the archive itself. Use the
  8764. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  8765. option in conjunction with the @option{--create} operation to include
  8766. a label entry in the archive as it is being created.
  8767. @table @option
  8768. @item --label=@var{archive-label}
  8769. @itemx -V @var{archive-label}
  8770. Includes an @dfn{archive-label} at the beginning of the archive when
  8771. the archive is being created, when used in conjunction with the
  8772. @option{--create} operation. Checks to make sure the archive label
  8773. matches the one specified (when used in conjunction with any other
  8774. operation.
  8775. @end table
  8776. If you create an archive using both
  8777. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  8778. and @option{--multi-volume} (@option{-M}), each volume of the archive
  8779. will have an archive label of the form @samp{@var{archive-label}
  8780. Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
  8781. next, and so on. @xref{Using Multiple Tapes}, for information on
  8782. creating multiple volume archives.
  8783. @cindex Volume label, listing
  8784. @cindex Listing volume label
  8785. The volume label will be displayed by @option{--list} along with
  8786. the file contents. If verbose display is requested, it will also be
  8787. explicitly marked as in the example below:
  8788. @smallexample
  8789. @group
  8790. $ @kbd{tar --verbose --list --file=iamanarchive}
  8791. V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
  8792. -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
  8793. @end group
  8794. @end smallexample
  8795. @opindex test-label
  8796. @anchor{--test-label option}
  8797. However, @option{--list} option will cause listing entire
  8798. contents of the archive, which may be undesirable (for example, if the
  8799. archive is stored on a tape). You can request checking only the volume
  8800. by specifying @option{--test-label} option. This option reads only the
  8801. first block of an archive, so it can be used with slow storage
  8802. devices. For example:
  8803. @smallexample
  8804. @group
  8805. $ @kbd{tar --test-label --file=iamanarchive}
  8806. iamalabel
  8807. @end group
  8808. @end smallexample
  8809. If @option{--test-label} is used with a single command line
  8810. argument, @command{tar} compares the volume label with the
  8811. argument. It exits with code 0 if the two strings match, and with code
  8812. 2 otherwise. In this case no output is displayed. For example:
  8813. @smallexample
  8814. @group
  8815. $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
  8816. @result{} 0
  8817. $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
  8818. @result{} 1
  8819. @end group
  8820. @end smallexample
  8821. If you request any operation, other than @option{--create}, along
  8822. with using @option{--label} option, @command{tar} will first check if
  8823. the archive label matches the one specified and will refuse to proceed
  8824. if it does not. Use this as a safety precaution to avoid accidentally
  8825. overwriting existing archives. For example, if you wish to add files
  8826. to @file{archive}, presumably labeled with string @samp{My volume},
  8827. you will get:
  8828. @smallexample
  8829. @group
  8830. $ @kbd{tar -rf archive --label 'My volume' .}
  8831. tar: Archive not labeled to match `My volume'
  8832. @end group
  8833. @end smallexample
  8834. @noindent
  8835. in case its label does not match. This will work even if
  8836. @file{archive} is not labeled at all.
  8837. Similarly, @command{tar} will refuse to list or extract the
  8838. archive if its label doesn't match the @var{archive-label}
  8839. specified. In those cases, @var{archive-label} argument is interpreted
  8840. as a globbing-style pattern which must match the actual magnetic
  8841. volume label. @xref{exclude}, for a precise description of how match
  8842. is attempted@footnote{Previous versions of @command{tar} used full
  8843. regular expression matching, or before that, only exact string
  8844. matching, instead of wildcard matchers. We decided for the sake of
  8845. simplicity to use a uniform matching device through
  8846. @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
  8847. the volume label matcher will also suffix @var{archive-label} by
  8848. @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
  8849. up. Since the volume numbering is automatically added in labels at
  8850. creation time, it sounded logical to equally help the user taking care
  8851. of it when the archive is being read.
  8852. The @option{--label} was once called @option{--volume}, but is not
  8853. available under that name anymore.
  8854. You can also use @option{--label} to get a common information on
  8855. all tapes of a series. For having this information different in each
  8856. series created through a single script used on a regular basis, just
  8857. manage to get some date string as part of the label. For example:
  8858. @smallexample
  8859. @group
  8860. $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
  8861. $ @kbd{tar --create --file=/dev/tape --multi-volume \
  8862. --volume="Daily backup for `date +%Y-%m-%d`"}
  8863. @end group
  8864. @end smallexample
  8865. Also note that each label has its own date and time, which corresponds
  8866. to when @GNUTAR{} initially attempted to write it,
  8867. often soon after the operator launches @command{tar} or types the
  8868. carriage return telling that the next tape is ready. Comparing date
  8869. labels does give an idea of tape throughput only if the delays for
  8870. rewinding tapes and the operator switching them were negligible, which
  8871. is usually not the case.
  8872. @node verify
  8873. @section Verifying Data as It is Stored
  8874. @cindex Verifying a write operation
  8875. @cindex Double-checking a write operation
  8876. @table @option
  8877. @item -W
  8878. @itemx --verify
  8879. @opindex verify, short description
  8880. Attempt to verify the archive after writing.
  8881. @end table
  8882. This option causes @command{tar} to verify the archive after writing it.
  8883. Each volume is checked after it is written, and any discrepancies
  8884. are recorded on the standard error output.
  8885. Verification requires that the archive be on a back-space-able medium.
  8886. This means pipes, some cartridge tape drives, and some other devices
  8887. cannot be verified.
  8888. You can insure the accuracy of an archive by comparing files in the
  8889. system with archive members. @command{tar} can compare an archive to the
  8890. file system as the archive is being written, to verify a write
  8891. operation, or can compare a previously written archive, to insure that
  8892. it is up to date.
  8893. @xopindex{verify, using with @option{--create}}
  8894. @xopindex{create, using with @option{--verify}}
  8895. To check for discrepancies in an archive immediately after it is
  8896. written, use the @option{--verify} (@option{-W}) option in conjunction with
  8897. the @option{--create} operation. When this option is
  8898. specified, @command{tar} checks archive members against their counterparts
  8899. in the file system, and reports discrepancies on the standard error.
  8900. To verify an archive, you must be able to read it from before the end
  8901. of the last written entry. This option is useful for detecting data
  8902. errors on some tapes. Archives written to pipes, some cartridge tape
  8903. drives, and some other devices cannot be verified.
  8904. One can explicitly compare an already made archive with the file
  8905. system by using the @option{--compare} (@option{--diff}, @option{-d})
  8906. option, instead of using the more automatic @option{--verify} option.
  8907. @xref{compare}.
  8908. Note that these two options have a slightly different intent. The
  8909. @option{--compare} option checks how identical are the logical contents of some
  8910. archive with what is on your disks, while the @option{--verify} option is
  8911. really for checking if the physical contents agree and if the recording
  8912. media itself is of dependable quality. So, for the @option{--verify}
  8913. operation, @command{tar} tries to defeat all in-memory cache pertaining to
  8914. the archive, while it lets the speed optimization undisturbed for the
  8915. @option{--compare} option. If you nevertheless use @option{--compare} for
  8916. media verification, you may have to defeat the in-memory cache yourself,
  8917. maybe by opening and reclosing the door latch of your recording unit,
  8918. forcing some doubt in your operating system about the fact this is really
  8919. the same volume as the one just written or read.
  8920. The @option{--verify} option would not be necessary if drivers were indeed
  8921. able to detect dependably all write failures. This sometimes require many
  8922. magnetic heads, some able to read after the writes occurred. One would
  8923. not say that drivers unable to detect all cases are necessarily flawed,
  8924. as long as programming is concerned.
  8925. The @option{--verify} (@option{-W}) option will not work in
  8926. conjunction with the @option{--multi-volume} (@option{-M}) option or
  8927. the @option{--append} (@option{-r}), @option{--update} (@option{-u})
  8928. and @option{--delete} operations. @xref{Operations}, for more
  8929. information on these operations.
  8930. Also, since @command{tar} normally strips leading @samp{/} from file
  8931. names (@pxref{absolute}), a command like @samp{tar --verify -cf
  8932. /tmp/foo.tar /etc} will work as desired only if the working directory is
  8933. @file{/}, as @command{tar} uses the archive's relative member names
  8934. (e.g., @file{etc/motd}) when verifying the archive.
  8935. @node Write Protection
  8936. @section Write Protection
  8937. Almost all tapes and diskettes, and in a few rare cases, even disks can
  8938. be @dfn{write protected}, to protect data on them from being changed.
  8939. Once an archive is written, you should write protect the media to prevent
  8940. the archive from being accidentally overwritten or deleted. (This will
  8941. protect the archive from being changed with a tape or floppy drive---it
  8942. will not protect it from magnet fields or other physical hazards).
  8943. The write protection device itself is usually an integral part of the
  8944. physical media, and can be a two position (write enabled/write
  8945. disabled) switch, a notch which can be popped out or covered, a ring
  8946. which can be removed from the center of a tape reel, or some other
  8947. changeable feature.
  8948. @node Changes
  8949. @appendix Changes
  8950. This appendix lists some important user-visible changes between
  8951. version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
  8952. version of this document is available at
  8953. @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
  8954. @GNUTAR{} documentation page}.
  8955. @table @asis
  8956. @item Use of globbing patterns when listing and extracting.
  8957. Previous versions of GNU tar assumed shell-style globbing when
  8958. extracting from or listing an archive. For example:
  8959. @smallexample
  8960. $ @kbd{tar xf foo.tar '*.c'}
  8961. @end smallexample
  8962. would extract all files whose names end in @samp{.c}. This behavior
  8963. was not documented and was incompatible with traditional tar
  8964. implementations. Therefore, starting from version 1.15.91, GNU tar
  8965. no longer uses globbing by default. For example, the above invocation
  8966. is now interpreted as a request to extract from the archive the file
  8967. named @file{*.c}.
  8968. To facilitate transition to the new behavior for those users who got
  8969. used to the previous incorrect one, @command{tar} will print a warning
  8970. if it finds out that a requested member was not found in the archive
  8971. and its name looks like a globbing pattern. For example:
  8972. @smallexample
  8973. $ @kbd{tar xf foo.tar '*.c'}
  8974. tar: Pattern matching characters used in file names. Please,
  8975. tar: use --wildcards to enable pattern matching, or --no-wildcards to
  8976. tar: suppress this warning.
  8977. tar: *.c: Not found in archive
  8978. tar: Error exit delayed from previous errors
  8979. @end smallexample
  8980. To treat member names as globbing patterns, use --wildcards option.
  8981. If you want to tar to mimic the behavior of versions prior to 1.15.91,
  8982. add this option to your @env{TAR_OPTIONS} variable.
  8983. @xref{wildcards}, for the detailed discussion of the use of globbing
  8984. patterns by @GNUTAR{}.
  8985. @item Use of short option @option{-o}.
  8986. Earlier versions of @GNUTAR{} understood @option{-o} command line
  8987. option as a synonym for @option{--old-archive}.
  8988. @GNUTAR{} starting from version 1.13.90 understands this option as
  8989. a synonym for @option{--no-same-owner}. This is compatible with
  8990. UNIX98 @command{tar} implementations.
  8991. However, to facilitate transition, @option{-o} option retains its
  8992. old semantics when it is used with one of archive-creation commands.
  8993. Users are encouraged to use @option{--format=oldgnu} instead.
  8994. It is especially important, since versions of @acronym{GNU} Automake
  8995. up to and including 1.8.4 invoke tar with this option to produce
  8996. distribution tarballs. @xref{Formats,v7}, for the detailed discussion
  8997. of this issue and its implications.
  8998. @FIXME{Change the first argument to tar-formats when the new Automake is
  8999. out. The proposition to add @anchor{} to the appropriate place of its
  9000. docs was accepted by Automake people --Sergey 2006-05-25}.
  9001. @xref{Options, tar-v7, Changing Automake's Behavior,
  9002. automake, GNU Automake}, for a description on how to use various
  9003. archive formats with @command{automake}.
  9004. Future versions of @GNUTAR{} will understand @option{-o} only as a
  9005. synonym for @option{--no-same-owner}.
  9006. @item Use of short option @option{-l}
  9007. Earlier versions of @GNUTAR{} understood @option{-l} option as a
  9008. synonym for @option{--one-file-system}. Since such usage contradicted
  9009. to UNIX98 specification and harmed compatibility with other
  9010. implementation, it was declared deprecated in version 1.14. However,
  9011. to facilitate transition to its new semantics, it was supported by
  9012. versions 1.15 and 1.15.90. The present use of @option{-l} as a short
  9013. variant of @option{--check-links} was introduced in version 1.15.91.
  9014. @item Use of options @option{--portability} and @option{--old-archive}
  9015. These options are deprecated. Please use @option{--format=v7} instead.
  9016. @item Use of option @option{--posix}
  9017. This option is deprecated. Please use @option{--format=posix} instead.
  9018. @end table
  9019. @node Configuring Help Summary
  9020. @appendix Configuring Help Summary
  9021. Running @kbd{tar --help} displays the short @command{tar} option
  9022. summary (@pxref{help}). This summary is organized by @dfn{groups} of
  9023. semantically close options. The options within each group are printed
  9024. in the following order: a short option, eventually followed by a list
  9025. of corresponding long option names, followed by a short description of
  9026. the option. For example, here is an excerpt from the actual @kbd{tar
  9027. --help} output:
  9028. @verbatim
  9029. Main operation mode:
  9030. -A, --catenate, --concatenate append tar files to an archive
  9031. -c, --create create a new archive
  9032. -d, --diff, --compare find differences between archive and
  9033. file system
  9034. --delete delete from the archive
  9035. @end verbatim
  9036. @vrindex ARGP_HELP_FMT, environment variable
  9037. The exact visual representation of the help output is configurable via
  9038. @env{ARGP_HELP_FMT} environment variable. The value of this variable
  9039. is a comma-separated list of @dfn{format variable} assignments. There
  9040. are two kinds of format variables. An @dfn{offset variable} keeps the
  9041. offset of some part of help output text from the leftmost column on
  9042. the screen. A @dfn{boolean} variable is a flag that toggles some
  9043. output feature on or off. Depending on the type of the corresponding
  9044. variable, there are two kinds of assignments:
  9045. @table @asis
  9046. @item Offset assignment
  9047. The assignment to an offset variable has the following syntax:
  9048. @smallexample
  9049. @var{variable}=@var{value}
  9050. @end smallexample
  9051. @noindent
  9052. where @var{variable} is the variable name, and @var{value} is a
  9053. numeric value to be assigned to the variable.
  9054. @item Boolean assignment
  9055. To assign @code{true} value to a variable, simply put this variable name. To
  9056. assign @code{false} value, prefix the variable name with @samp{no-}. For
  9057. example:
  9058. @smallexample
  9059. @group
  9060. # Assign @code{true} value:
  9061. dup-args
  9062. # Assign @code{false} value:
  9063. no-dup-args
  9064. @end group
  9065. @end smallexample
  9066. @end table
  9067. Following variables are declared:
  9068. @deftypevr {Help Output} boolean dup-args
  9069. If true, arguments for an option are shown with both short and long
  9070. options, even when a given option has both forms, for example:
  9071. @smallexample
  9072. -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
  9073. @end smallexample
  9074. If false, then if an option has both short and long forms, the
  9075. argument is only shown with the long one, for example:
  9076. @smallexample
  9077. -f, --file=ARCHIVE use archive file or device ARCHIVE
  9078. @end smallexample
  9079. @noindent
  9080. and a message indicating that the argument is applicable to both
  9081. forms is printed below the options. This message can be disabled
  9082. using @code{dup-args-note} (see below).
  9083. The default is false.
  9084. @end deftypevr
  9085. @deftypevr {Help Output} boolean dup-args-note
  9086. If this variable is true, which is the default, the following notice
  9087. is displayed at the end of the help output:
  9088. @quotation
  9089. Mandatory or optional arguments to long options are also mandatory or
  9090. optional for any corresponding short options.
  9091. @end quotation
  9092. Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
  9093. variables @code{dup-args} or @code{dup-args-note} should be set.
  9094. @end deftypevr
  9095. @deftypevr {Help Output} offset short-opt-col
  9096. Column in which short options start. Default is 2.
  9097. @smallexample
  9098. @group
  9099. $ @kbd{tar --help|grep ARCHIVE}
  9100. -f, --file=ARCHIVE use archive file or device ARCHIVE
  9101. $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
  9102. -f, --file=ARCHIVE use archive file or device ARCHIVE
  9103. @end group
  9104. @end smallexample
  9105. @end deftypevr
  9106. @deftypevr {Help Output} offset long-opt-col
  9107. Column in which long options start. Default is 6. For example:
  9108. @smallexample
  9109. @group
  9110. $ @kbd{tar --help|grep ARCHIVE}
  9111. -f, --file=ARCHIVE use archive file or device ARCHIVE
  9112. $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
  9113. -f, --file=ARCHIVE use archive file or device ARCHIVE
  9114. @end group
  9115. @end smallexample
  9116. @end deftypevr
  9117. @deftypevr {Help Output} offset doc-opt-col
  9118. Column in which @dfn{doc options} start. A doc option isn't actually
  9119. an option, but rather an arbitrary piece of documentation that is
  9120. displayed in much the same manner as the options. For example, in
  9121. the description of @option{--format} option:
  9122. @smallexample
  9123. @group
  9124. -H, --format=FORMAT create archive of the given format.
  9125. FORMAT is one of the following:
  9126. gnu GNU tar 1.13.x format
  9127. oldgnu GNU format as per tar <= 1.12
  9128. pax POSIX 1003.1-2001 (pax) format
  9129. posix same as pax
  9130. ustar POSIX 1003.1-1988 (ustar) format
  9131. v7 old V7 tar format
  9132. @end group
  9133. @end smallexample
  9134. @noindent
  9135. the format names are doc options. Thus, if you set
  9136. @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
  9137. will look as follows:
  9138. @smallexample
  9139. @group
  9140. -H, --format=FORMAT create archive of the given format.
  9141. FORMAT is one of the following:
  9142. gnu GNU tar 1.13.x format
  9143. oldgnu GNU format as per tar <= 1.12
  9144. pax POSIX 1003.1-2001 (pax) format
  9145. posix same as pax
  9146. ustar POSIX 1003.1-1988 (ustar) format
  9147. v7 old V7 tar format
  9148. @end group
  9149. @end smallexample
  9150. @end deftypevr
  9151. @deftypevr {Help Output} offset opt-doc-col
  9152. Column in which option description starts. Default is 29.
  9153. @smallexample
  9154. @group
  9155. $ @kbd{tar --help|grep ARCHIVE}
  9156. -f, --file=ARCHIVE use archive file or device ARCHIVE
  9157. $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
  9158. -f, --file=ARCHIVE use archive file or device ARCHIVE
  9159. $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
  9160. -f, --file=ARCHIVE
  9161. use archive file or device ARCHIVE
  9162. @end group
  9163. @end smallexample
  9164. @noindent
  9165. Notice, that the description starts on a separate line if
  9166. @code{opt-doc-col} value is too small.
  9167. @end deftypevr
  9168. @deftypevr {Help Output} offset header-col
  9169. Column in which @dfn{group headers} are printed. A group header is a
  9170. descriptive text preceding an option group. For example, in the
  9171. following text:
  9172. @verbatim
  9173. Main operation mode:
  9174. -A, --catenate, --concatenate append tar files to
  9175. an archive
  9176. -c, --create create a new archive
  9177. @end verbatim
  9178. @noindent
  9179. @samp{Main operation mode:} is the group header.
  9180. The default value is 1.
  9181. @end deftypevr
  9182. @deftypevr {Help Output} offset usage-indent
  9183. Indentation of wrapped usage lines. Affects @option{--usage}
  9184. output. Default is 12.
  9185. @end deftypevr
  9186. @deftypevr {Help Output} offset rmargin
  9187. Right margin of the text output. Used for wrapping.
  9188. @end deftypevr
  9189. @node Fixing Snapshot Files
  9190. @appendix Fixing Snapshot Files
  9191. @include tar-snapshot-edit.texi
  9192. @node Tar Internals
  9193. @appendix Tar Internals
  9194. @include intern.texi
  9195. @node Genfile
  9196. @appendix Genfile
  9197. @include genfile.texi
  9198. @node Free Software Needs Free Documentation
  9199. @appendix Free Software Needs Free Documentation
  9200. @include freemanuals.texi
  9201. @node Copying This Manual
  9202. @appendix Copying This Manual
  9203. @menu
  9204. * GNU Free Documentation License:: License for copying this manual
  9205. @end menu
  9206. @include fdl.texi
  9207. @node Index of Command Line Options
  9208. @appendix Index of Command Line Options
  9209. This appendix contains an index of all @GNUTAR{} long command line
  9210. options. The options are listed without the preceding double-dash.
  9211. For a cross-reference of short command line options, @ref{Short Option Summary}.
  9212. @printindex op
  9213. @node Index
  9214. @appendix Index
  9215. @printindex cp
  9216. @summarycontents
  9217. @contents
  9218. @bye
  9219. @c Local variables:
  9220. @c texinfo-column-for-description: 32
  9221. @c End: