tar.texi 494 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531
  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. @documentencoding UTF-8
  8. @c These two commands require Texinfo 5.0; for now use the older
  9. @c equivalent @set commands supported in Texinfo 4.11 and later.
  10. @ignore
  11. @codequotebacktick on
  12. @codequoteundirected on
  13. @end ignore
  14. @set txicodequoteundirected
  15. @set txicodequotebacktick
  16. @finalout
  17. @smallbook
  18. @c %**end of header
  19. @c Maintenance notes:
  20. @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
  21. @c 2. Before creating final variant:
  22. @c 2.1. Run 'make check-options' to make sure all options are properly
  23. @c documented;
  24. @c 2.2. Run 'make master-menu' (see comment before the master menu).
  25. @include rendition.texi
  26. @include value.texi
  27. @defcodeindex op
  28. @defcodeindex kw
  29. @c Put everything in one index (arbitrarily chosen to be the concept index).
  30. @syncodeindex fn cp
  31. @syncodeindex ky cp
  32. @syncodeindex pg cp
  33. @syncodeindex vr cp
  34. @syncodeindex kw cp
  35. @copying
  36. This manual is for @acronym{GNU} @command{tar} (version
  37. @value{VERSION}, @value{UPDATED}), which creates and extracts files
  38. from archives.
  39. Copyright @copyright{} 1992, 1994--1997, 1999--2001, 2003--2017,
  40. 2021--2023 Free Software Foundation, Inc.
  41. @quotation
  42. Permission is granted to copy, distribute and/or modify this document
  43. under the terms of the GNU Free Documentation License, Version 1.3 or
  44. any later version published by the Free Software Foundation; with the
  45. Invariant Sections being ``GNU General Public License'', with the
  46. Front-Cover Texts being ``A GNU Manual'', and with the Back-Cover Texts
  47. as in (a) below. A copy of the license is included in the section
  48. entitled ``GNU Free Documentation License''.
  49. (a) The FSF's Back-Cover Text is: ``You have the freedom to
  50. copy and modify this GNU manual.''
  51. @end quotation
  52. @end copying
  53. @dircategory Archiving
  54. @direntry
  55. * Tar: (tar). Making tape (or disk) archives.
  56. @end direntry
  57. @dircategory Individual utilities
  58. @direntry
  59. * tar: (tar)tar invocation. Invoking @GNUTAR{}.
  60. @end direntry
  61. @shorttitlepage @acronym{GNU} @command{tar}
  62. @titlepage
  63. @title @acronym{GNU} tar: an archiver tool
  64. @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
  65. @author John Gilmore, Jay Fenlason et al.
  66. @page
  67. @vskip 0pt plus 1filll
  68. @insertcopying
  69. @end titlepage
  70. @ifnottex
  71. @node Top
  72. @top @acronym{GNU} tar: an archiver tool
  73. @insertcopying
  74. @cindex file archival
  75. @cindex archiving files
  76. The first part of this master menu lists the major nodes in this Info
  77. document. The rest of the menu lists all the lower level nodes.
  78. @end ifnottex
  79. @c The master menu goes here.
  80. @c
  81. @c NOTE: To update it from within Emacs, make sure mastermenu.el is
  82. @c loaded and run texinfo-master-menu.
  83. @c To update it from the command line, run
  84. @c
  85. @c make master-menu
  86. @menu
  87. * Introduction::
  88. * Tutorial::
  89. * tar invocation::
  90. * operations::
  91. * Backups::
  92. * Choosing::
  93. * Date input formats::
  94. * Formats::
  95. * Media::
  96. * Reliability and security::
  97. Appendices
  98. * Changes::
  99. * Recipes:: Frequently used tar recipes
  100. * Configuring Help Summary::
  101. * Fixing Snapshot Files::
  102. * Tar Internals::
  103. * Genfile::
  104. * GNU Free Documentation License::
  105. * Index of Command Line Options::
  106. * Index::
  107. @detailmenu
  108. --- The Detailed Node Listing ---
  109. Introduction
  110. * Book Contents:: What this Book Contains
  111. * Definitions:: Some Definitions
  112. * What tar Does:: What @command{tar} Does
  113. * Naming tar Archives:: How @command{tar} Archives are Named
  114. * Authors:: @GNUTAR{} Authors
  115. * Reports:: Reporting bugs or suggestions
  116. Tutorial Introduction to @command{tar}
  117. * assumptions::
  118. * stylistic conventions::
  119. * basic tar options:: Basic @command{tar} Operations and Options
  120. * frequent operations::
  121. * Two Frequent Options::
  122. * create:: How to Create Archives
  123. * list:: How to List Archives
  124. * extract:: How to Extract Members from an Archive
  125. * going further::
  126. Two Frequently Used Options
  127. * file tutorial::
  128. * verbose tutorial::
  129. * help tutorial::
  130. How to Create Archives
  131. * prepare for examples::
  132. * Creating the archive::
  133. * create verbose::
  134. * short create::
  135. * create dir::
  136. How to List Archives
  137. * list dir::
  138. How to Extract Members from an Archive
  139. * extracting archives::
  140. * extracting files::
  141. * extract dir::
  142. * extracting untrusted archives::
  143. * failing commands::
  144. Invoking @GNUTAR{}
  145. * Synopsis::
  146. * using tar options::
  147. * Styles::
  148. * All Options:: All @command{tar} Options.
  149. * help:: Where to Get Help.
  150. * defaults:: What are the Default Values.
  151. * verbose:: Checking @command{tar} progress.
  152. * checkpoints:: Checkpoints.
  153. * warnings:: Controlling Warning Messages.
  154. * interactive:: Asking for Confirmation During Operations.
  155. * external:: Running External Commands.
  156. The Three Option Styles
  157. * Long Options:: Long Option Style
  158. * Short Options:: Short Option Style
  159. * Old Options:: Old Option Style
  160. * Mixing:: Mixing Option Styles
  161. All @command{tar} Options
  162. * Operation Summary::
  163. * Option Summary::
  164. * Short Option Summary::
  165. * Position-Sensitive Options::
  166. Controlling Warning Messages
  167. * General Warnings:: Keywords applicable for @command{tar --create}.
  168. * Archive Creation Warnings:: Keywords applicable for @command{tar --create}.
  169. * Archive Extraction Warnings:: Keywords applicable for @command{tar --extract}.
  170. * Incremental Extraction Warnings:: Keywords controlling incremental extraction.
  171. * Warning Classes:: Convenience keywords control multiple warnings.
  172. * Warning Defaults:: Default settings for warnings.
  173. @GNUTAR{} Operations
  174. * Basic tar::
  175. * Advanced tar::
  176. * create options::
  177. * extract options::
  178. * backup::
  179. * looking ahead::
  180. Advanced @GNUTAR{} Operations
  181. * Operations::
  182. * append::
  183. * update::
  184. * concatenate::
  185. * delete::
  186. * compare::
  187. How to Add Files to Existing Archives: @option{--append}
  188. * appending files:: Appending Files to an Archive
  189. * multiple::
  190. Updating an Archive
  191. * how to update::
  192. Options Used by @option{--create}
  193. * override:: Overriding File Metadata.
  194. * Extended File Attributes::
  195. * Ignore Failed Read::
  196. Options Used by @option{--extract}
  197. * Reading:: Options to Help Read Archives
  198. * Writing:: Changing How @command{tar} Writes Files
  199. * Scarce:: Coping with Scarce Resources
  200. Options to Help Read Archives
  201. * read full records::
  202. * Ignore Zeros::
  203. Changing How @command{tar} Writes Files
  204. * Dealing with Old Files::
  205. * Overwrite Old Files::
  206. * Keep Old Files::
  207. * Keep Newer Files::
  208. * Unlink First::
  209. * Recursive Unlink::
  210. * Data Modification Times::
  211. * Setting Access Permissions::
  212. * Directory Modification Times and Permissions::
  213. * Writing to Standard Output::
  214. * Writing to an External Program::
  215. * remove files::
  216. Coping with Scarce Resources
  217. * Starting File::
  218. * Same Order::
  219. Performing Backups and Restoring Files
  220. * Full Dumps:: Using @command{tar} to Perform Full Dumps
  221. * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
  222. * Backup Levels:: Levels of Backups
  223. * Backup Parameters:: Setting Parameters for Backups and Restoration
  224. * Scripted Backups:: Using the Backup Scripts
  225. * Scripted Restoration:: Using the Restore Script
  226. Setting Parameters for Backups and Restoration
  227. * General-Purpose Variables::
  228. * Magnetic Tape Control::
  229. * User Hooks::
  230. * backup-specs example:: An Example Text of @file{Backup-specs}
  231. Choosing Files and Names for @command{tar}
  232. * file:: Choosing the Archive's Name
  233. * Selecting Archive Members::
  234. * files:: Reading Names from a File
  235. * exclude:: Excluding Some Files
  236. * wildcards:: Wildcards Patterns and Matching
  237. * quoting styles:: Ways of Quoting Special Characters in Names
  238. * transform:: Modifying File and Member Names
  239. * after:: Operating Only on New Files
  240. * recurse:: Descending into Directories
  241. * one:: Crossing File System Boundaries
  242. Reading Names from a File
  243. * nul::
  244. Excluding Some Files
  245. * problems with exclude::
  246. Wildcards Patterns and Matching
  247. * controlling pattern-matching::
  248. Crossing File System Boundaries
  249. * directory:: Changing Directory
  250. * absolute:: Absolute File Names
  251. Date input formats
  252. * General date syntax:: Common rules
  253. * Calendar date items:: 21 Jul 2020
  254. * Time of day items:: 9:20pm
  255. * Time zone items:: UTC, -0700, +0900, @dots{}
  256. * Combined date and time of day items:: 2020-07-21T20:02:00,000000-0400
  257. * Day of week items:: Monday and others
  258. * Relative items in date strings:: next tuesday, 2 years ago
  259. * Pure numbers in date strings:: 20200721, 1440
  260. * Seconds since the Epoch:: @@1595289600
  261. * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0"
  262. * Authors of parse_datetime:: Bellovin, Eggert, Salz, Berets, et al.
  263. Controlling the Archive Format
  264. * Compression:: Using Less Space through Compression
  265. * Attributes:: Handling File Attributes
  266. * Portability:: Making @command{tar} Archives More Portable
  267. * Reproducibility:: Making @command{tar} Archives More Reproducible
  268. * cpio:: Comparison of @command{tar} and @command{cpio}
  269. Using Less Space through Compression
  270. * gzip:: Creating and Reading Compressed Archives
  271. * sparse:: Archiving Sparse Files
  272. Creating and Reading Compressed Archives
  273. * lbzip2:: Using lbzip2 with @GNUTAR{}.
  274. Making @command{tar} Archives More Portable
  275. * Portable Names:: Portable Names
  276. * dereference:: Symbolic Links
  277. * hard links:: Hard Links
  278. * old:: Old V7 Archives
  279. * ustar:: Ustar Archives
  280. * gnu:: GNU and old GNU format archives.
  281. * posix:: @acronym{POSIX} archives
  282. * Checksumming:: Checksumming Problems
  283. * Large or Negative Values:: Large files, negative time stamps, etc.
  284. * Other Tars:: How to Extract GNU-Specific Data Using
  285. Other @command{tar} Implementations
  286. @GNUTAR{} and @acronym{POSIX} @command{tar}
  287. * PAX keywords:: Controlling Extended Header Keywords.
  288. How to Extract GNU-Specific Data Using Other @command{tar} Implementations
  289. * Split Recovery:: Members Split Between Volumes
  290. * Sparse Recovery:: Sparse Members
  291. Tapes and Other Archive Media
  292. * Device:: Device selection and switching
  293. * Remote Tape Server::
  294. * Common Problems and Solutions::
  295. * Blocking:: Blocking
  296. * Many:: Many archives on one tape
  297. * Using Multiple Tapes:: Using Multiple Tapes
  298. * label:: Including a Label in the Archive
  299. * verify::
  300. * Write Protection::
  301. Blocking
  302. * Format Variations:: Format Variations
  303. * Blocking Factor:: The Blocking Factor of an Archive
  304. Many Archives on One Tape
  305. * Tape Positioning:: Tape Positions and Tape Marks
  306. * mt:: The @command{mt} Utility
  307. Using Multiple Tapes
  308. * Multi-Volume Archives:: Archives Longer than One Tape or Disk
  309. * Tape Files:: Tape Files
  310. * Tarcat:: Concatenate Volumes into a Single Archive
  311. Reliability and Security
  312. * Reliability::
  313. * Security::
  314. Reliability
  315. * Permissions problems::
  316. * Data corruption and repair::
  317. * Race conditions::
  318. Security
  319. * Privacy::
  320. * Integrity::
  321. * Live untrusted data::
  322. * Security rules of thumb::
  323. Recipes
  324. * copy directory hierarchy::
  325. * intermediate directories::
  326. Tar Internals
  327. * Standard:: Basic Tar Format
  328. * Extensions:: @acronym{GNU} Extensions to the Archive Format
  329. * Sparse Formats:: Storing Sparse Files
  330. * Snapshot Files::
  331. * Dumpdir::
  332. Storing Sparse Files
  333. * Old GNU Format::
  334. * PAX 0:: PAX Format, Versions 0.0 and 0.1
  335. * PAX 1:: PAX Format, Version 1.0
  336. Genfile
  337. * Generate Mode:: File Generation Mode.
  338. * Status Mode:: File Status Mode.
  339. * Exec Mode:: Synchronous Execution mode.
  340. Copying This Manual
  341. * GNU Free Documentation License:: License for copying this manual.
  342. @end detailmenu
  343. @end menu
  344. @node Introduction
  345. @chapter Introduction
  346. @GNUTAR{} creates
  347. and manipulates @dfn{archives} which are actually collections of
  348. many other files; the program provides users with an organized and
  349. systematic method for controlling a large amount of data.
  350. The name ``tar'' originally came from the phrase ``Tape ARchive'', but
  351. archives need not (and these days, typically do not) reside on tapes.
  352. @menu
  353. * Book Contents:: What this Book Contains
  354. * Definitions:: Some Definitions
  355. * What tar Does:: What @command{tar} Does
  356. * Naming tar Archives:: How @command{tar} Archives are Named
  357. * Authors:: @GNUTAR{} Authors
  358. * Reports:: Reporting bugs or suggestions
  359. @end menu
  360. @node Book Contents
  361. @section What this Book Contains
  362. The first part of this chapter introduces you to various terms that will
  363. recur throughout the book. It also tells you who has worked on @GNUTAR{}
  364. and its documentation, and where you should send bug reports
  365. or comments.
  366. The second chapter is a tutorial (@pxref{Tutorial}) which provides a
  367. gentle introduction for people who are new to using @command{tar}. It is
  368. meant to be self-contained, not requiring any reading from subsequent
  369. chapters to make sense. It moves from topic to topic in a logical,
  370. progressive order, building on information already explained.
  371. Although the tutorial is paced and structured to allow beginners to
  372. learn how to use @command{tar}, it is not intended solely for beginners.
  373. The tutorial explains how to use the three most frequently used
  374. operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
  375. two frequently used options (@samp{file} and @samp{verbose}). The other
  376. chapters do not refer to the tutorial frequently; however, if a section
  377. discusses something which is a complex variant of a basic concept, there
  378. may be a cross-reference to that basic concept. (The entire book,
  379. including the tutorial, assumes that the reader understands some basic
  380. concepts of using a Unix-type operating system; @pxref{Tutorial}.)
  381. The third chapter presents the remaining five operations, and
  382. information about using @command{tar} options and option syntax.
  383. The other chapters are meant to be used as a reference. Each chapter
  384. presents everything that needs to be said about a specific topic.
  385. One of the chapters (@pxref{Date input formats}) exists in its
  386. entirety in other @acronym{GNU} manuals, and is mostly self-contained.
  387. In addition, one section of this manual (@pxref{Standard}) contains a
  388. big quote which is taken directly from @command{tar} sources.
  389. In general, we give both long and short (abbreviated) option names
  390. at least once in each section where the relevant option is covered, so
  391. that novice readers will become familiar with both styles. (A few
  392. options have no short versions, and the relevant sections will
  393. indicate this.)
  394. @node Definitions
  395. @section Some Definitions
  396. @cindex archive
  397. @cindex tar archive
  398. The @command{tar} program is used to create and manipulate @command{tar}
  399. archives. An @dfn{archive} is a single file which contains the contents
  400. of many files, while still identifying the names of the files, their
  401. owner(s), and so forth. (In addition, archives record access
  402. permissions, user and group, size in bytes, and data modification time.
  403. Some archives also record the file names in each archived directory, as
  404. well as other file and directory information.) You can use @command{tar}
  405. to @dfn{create} a new archive in a specified directory.
  406. @cindex member
  407. @cindex archive member
  408. @cindex file name
  409. @cindex member name
  410. The files inside an archive are called @dfn{members}. Within this
  411. manual, we use the term @dfn{file} to refer only to files accessible in
  412. the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
  413. @dfn{member} to refer only to the members of an archive. Similarly, a
  414. @dfn{file name} is the name of a file, as it resides in the file system,
  415. and a @dfn{member name} is the name of an archive member within the
  416. archive.
  417. @cindex extraction
  418. @cindex unpacking
  419. The term @dfn{extraction} refers to the process of copying an archive
  420. member (or multiple members) into a file in the file system. Extracting
  421. all the members of an archive is often called @dfn{extracting the
  422. archive}. The term @dfn{unpack} can also be used to refer to the
  423. extraction of many or all the members of an archive. Extracting an
  424. archive does not destroy the archive's structure, just as creating an
  425. archive does not destroy the copies of the files that exist outside of
  426. the archive. You may also @dfn{list} the members in a given archive
  427. (this is often thought of as ``printing'' them to the standard output,
  428. or the command line), or @dfn{append} members to a pre-existing archive.
  429. All of these operations can be performed using @command{tar}.
  430. @node What tar Does
  431. @section What @command{tar} Does
  432. @cindex tar
  433. The @command{tar} program provides the ability to create @command{tar}
  434. archives, as well as various other kinds of manipulation. For example,
  435. you can use @command{tar} on previously created archives to extract files,
  436. to store additional files, or to update or list files which were already
  437. stored.
  438. Initially, @command{tar} archives were used to store files conveniently on
  439. magnetic tape. The name @command{tar} comes from this use; it stands for
  440. @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
  441. direct its output to available devices, files, or other programs (using
  442. pipes). @command{tar} may even access remote devices or files (as archives).
  443. You can use @command{tar} archives in many ways. We want to stress a few
  444. of them: storage, backup, and transportation.
  445. @FIXME{the following table entries need a bit of work.}
  446. @table @asis
  447. @item Storage
  448. Often, @command{tar} archives are used to store related files for
  449. convenient file transfer over a network. For example, the
  450. @acronym{GNU} Project distributes its software bundled into
  451. @command{tar} archives, so that all the files relating to a particular
  452. program (or set of related programs) can be transferred as a single
  453. unit.
  454. A magnetic tape can store several files in sequence. However, the tape
  455. has no names for these files; it only knows their relative position on
  456. the tape. One way to store several files on one tape and retain their
  457. names is by creating a @command{tar} archive. Even when the basic transfer
  458. mechanism can keep track of names, as FTP can, the nuisance of handling
  459. multiple files, directories, and multiple links makes @command{tar}
  460. archives useful.
  461. Archive files are also used for long-term storage. You can think of
  462. this as transportation from the present into the future. (It is a
  463. science-fiction idiom that you can move through time as well as in
  464. space; the idea here is that @command{tar} can be used to move archives in
  465. all dimensions, even time!)
  466. @item Backup
  467. Because the archive created by @command{tar} is capable of preserving
  468. file information and directory structure, @command{tar} is commonly
  469. used for performing full and incremental backups of disks. A backup
  470. puts a collection of files (possibly pertaining to many users and
  471. projects) together on a disk or a tape. This guards against
  472. accidental destruction of the information in those files.
  473. @GNUTAR{} has special features that allow it to be
  474. used to make incremental and full dumps of all the files in a
  475. file system.
  476. @item Transportation
  477. You can create an archive on one system, transfer it to another system,
  478. and extract the contents there. This allows you to transport a group of
  479. files from one system to another.
  480. @end table
  481. @node Naming tar Archives
  482. @section How @command{tar} Archives are Named
  483. Conventionally, @command{tar} archives are given names ending with
  484. @samp{.tar}. This is not necessary for @command{tar} to operate properly,
  485. but this manual follows that convention in order to accustom readers to
  486. it and to make examples more clear.
  487. @cindex tar file
  488. @cindex entry
  489. @cindex tar entry
  490. Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
  491. archive members as ``files'' or ``entries''. For people familiar with
  492. the operation of @command{tar}, this causes no difficulty. However, in
  493. this manual, we consistently refer to ``archives'' and ``archive
  494. members'' to make learning to use @command{tar} easier for novice users.
  495. @node Authors
  496. @section @GNUTAR{} Authors
  497. @GNUTAR{} was originally written by John Gilmore,
  498. and modified by many people. The @acronym{GNU} enhancements were
  499. written by Jay Fenlason, then Joy Kendall, and the whole package has
  500. been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
  501. Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
  502. numerous and kind users.
  503. We wish to stress that @command{tar} is a collective work, and owes much to
  504. all those people who reported problems, offered solutions and other
  505. insights, or shared their thoughts and suggestions. An impressive, yet
  506. partial list of those contributors can be found in the @file{THANKS}
  507. file from the @GNUTAR{} distribution.
  508. @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
  509. sure i want to spell out the history in this detail, at least not for
  510. the printed book. i'm just not sure it needs to be said this way.
  511. i'll think about it.}
  512. @FIXME{History is more important, and surely more interesting, than
  513. actual names. Quoting names without history would be meaningless. FP}
  514. Jay Fenlason put together a draft of a @GNUTAR{}
  515. manual, borrowing notes from the original man page from John Gilmore.
  516. This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
  517. Gorin worked on a tutorial and manual for @GNUTAR{}.
  518. Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
  519. taking information from all these sources and merging them. Melissa
  520. Weisshaus finally edited and redesigned the book to create version
  521. 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
  522. by the current maintainer, Sergey Poznyakoff.
  523. For version 1.12, Daniel Hagerty contributed a great deal of technical
  524. consulting. In particular, he is the primary author of @ref{Backups}.
  525. In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
  526. (see @url{https://savannah.gnu.org/projects/tar}), and
  527. active development and maintenance work has started
  528. again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
  529. Poznyakoff and Jeff Bailey.
  530. Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
  531. @node Reports
  532. @section Reporting bugs or suggestions
  533. @cindex bug reports
  534. @cindex reporting bugs
  535. If you find problems or have suggestions about this program or manual,
  536. please report them to @file{bug-tar@@gnu.org}.
  537. When reporting a bug, please be sure to include as much detail as
  538. possible, in order to reproduce it.
  539. @FIXME{Be more specific, I'd like to make this node as detailed as
  540. 'Bug reporting' node in Emacs manual.}
  541. @node Tutorial
  542. @chapter Tutorial Introduction to @command{tar}
  543. This chapter guides you through some basic examples of three @command{tar}
  544. operations: @option{--create}, @option{--list}, and @option{--extract}. If
  545. you already know how to use some other version of @command{tar}, then you
  546. may not need to read this chapter. This chapter omits most complicated
  547. details about how @command{tar} works.
  548. @menu
  549. * assumptions::
  550. * stylistic conventions::
  551. * basic tar options:: Basic @command{tar} Operations and Options
  552. * frequent operations::
  553. * Two Frequent Options::
  554. * create:: How to Create Archives
  555. * list:: How to List Archives
  556. * extract:: How to Extract Members from an Archive
  557. * going further::
  558. @end menu
  559. @node assumptions
  560. @section Assumptions this Tutorial Makes
  561. This chapter is paced to allow beginners to learn about @command{tar}
  562. slowly. At the same time, we will try to cover all the basic aspects of
  563. these three operations. In order to accomplish both of these tasks, we
  564. have made certain assumptions about your knowledge before reading this
  565. manual, and the hardware you will be using:
  566. @itemize @bullet
  567. @item
  568. Before you start to work through this tutorial, you should understand
  569. what the terms ``archive'' and ``archive member'' mean
  570. (@pxref{Definitions}). In addition, you should understand something
  571. about how Unix-type operating systems work, and you should know how to
  572. use some basic utilities. For example, you should know how to create,
  573. list, copy, rename, edit, and delete files and directories; how to
  574. change between directories; and how to figure out where you are in the
  575. file system. You should have some basic understanding of directory
  576. structure and how files are named according to which directory they are
  577. in. You should understand concepts such as standard output and standard
  578. input, what various definitions of the term @samp{argument} mean, and the
  579. differences between relative and absolute file names.
  580. @FIXME{and what else?}
  581. @item
  582. This manual assumes that you are working from your own home directory
  583. (unless we state otherwise). In this tutorial, you will create a
  584. directory to practice @command{tar} commands in. When we show file names,
  585. we will assume that those names are relative to your home directory.
  586. For example, my home directory is @file{/home/fsf/melissa}. All of
  587. my examples are in a subdirectory of the directory named by that file
  588. name; the subdirectory is called @file{practice}.
  589. @item
  590. In general, we show examples of archives which exist on (or can be
  591. written to, or worked with from) a directory on a hard disk. In most
  592. cases, you could write those archives to, or work with them on any other
  593. device, such as a tape drive. However, some of the later examples in
  594. the tutorial and next chapter will not work on tape drives.
  595. Additionally, working with tapes is much more complicated than working
  596. with hard disks. For these reasons, the tutorial does not cover working
  597. with tape drives. @xref{Media}, for complete information on using
  598. @command{tar} archives with tape drives.
  599. @FIXME{this is a cop out. need to add some simple tape drive info.}
  600. @end itemize
  601. @node stylistic conventions
  602. @section Stylistic Conventions
  603. In the examples, @samp{$} represents a typical shell prompt. It
  604. precedes lines you should type; to make this more clear, those lines are
  605. shown in @kbd{this font}, as opposed to lines which represent the
  606. computer's response; those lines are shown in @code{this font}, or
  607. sometimes @samp{like this}.
  608. @c When we have lines which are too long to be
  609. @c displayed in any other way, we will show them like this:
  610. @node basic tar options
  611. @section Basic @command{tar} Operations and Options
  612. @command{tar} can take a wide variety of arguments which specify and define
  613. the actions it will have on the particular set of files or the archive.
  614. The main types of arguments to @command{tar} fall into one of two classes:
  615. operations, and options.
  616. Some arguments fall into a class called @dfn{operations}; exactly one of
  617. these is both allowed and required for any instance of using @command{tar};
  618. you may @emph{not} specify more than one. People sometimes speak of
  619. @dfn{operating modes}. You are in a particular operating mode when you
  620. have specified the operation which specifies it; there are eight
  621. operations in total, and thus there are eight operating modes.
  622. The other arguments fall into the class known as @dfn{options}. You are
  623. not required to specify any options, and you are allowed to specify more
  624. than one at a time (depending on the way you are using @command{tar} at
  625. that time). Some options are used so frequently, and are so useful for
  626. helping you type commands more carefully that they are effectively
  627. ``required''. We will discuss them in this chapter.
  628. You can write most of the @command{tar} operations and options in any
  629. of three forms: long (mnemonic) form, short form, and old style. Some
  630. of the operations and options have no short or ``old'' forms; however,
  631. the operations and options which we will cover in this tutorial have
  632. corresponding abbreviations. We will indicate those abbreviations
  633. appropriately to get you used to seeing them. Note, that the ``old
  634. style'' option forms exist in @GNUTAR{} for compatibility with Unix
  635. @command{tar}. In this book we present a full discussion of this way
  636. of writing options and operations (@pxref{Old Options}), and we discuss
  637. the other two styles of writing options (@xref{Long Options}, and
  638. @pxref{Short Options}).
  639. In the examples and in the text of this tutorial, we usually use the
  640. long forms of operations and options; but the ``short'' forms produce
  641. the same result and can make typing long @command{tar} commands easier.
  642. For example, instead of typing
  643. @smallexample
  644. @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
  645. @end smallexample
  646. @noindent
  647. you can type
  648. @smallexample
  649. @kbd{tar -c -v -f afiles.tar apple angst aspic}
  650. @end smallexample
  651. @noindent
  652. or even
  653. @smallexample
  654. @kbd{tar -cvf afiles.tar apple angst aspic}
  655. @end smallexample
  656. @noindent
  657. For more information on option syntax, see @ref{Advanced tar}. In
  658. discussions in the text, when we name an option by its long form, we
  659. also give the corresponding short option in parentheses.
  660. The term, ``option'', can be confusing at times, since ``operations''
  661. are often lumped in with the actual, @emph{optional} ``options'' in certain
  662. general class statements. For example, we just talked about ``short and
  663. long forms of options and operations''. However, experienced @command{tar}
  664. users often refer to these by shorthand terms such as, ``short and long
  665. options''. This term assumes that the ``operations'' are included, also.
  666. Context will help you determine which definition of ``options'' to use.
  667. Similarly, the term ``command'' can be confusing, as it is often used in
  668. two different ways. People sometimes refer to @command{tar} ``commands''.
  669. A @command{tar} @dfn{command} is the entire command line of user input
  670. which tells @command{tar} what to do --- including the operation, options,
  671. and any arguments (file names, pipes, other commands, etc.). However,
  672. you will also sometimes hear the term ``the @command{tar} command''. When
  673. the word ``command'' is used specifically like this, a person is usually
  674. referring to the @command{tar} @emph{operation}, not the whole line.
  675. Again, use context to figure out which of the meanings the speaker
  676. intends.
  677. @node frequent operations
  678. @section The Three Most Frequently Used Operations
  679. Here are the three most frequently used operations (both short and long
  680. forms), as well as a brief description of their meanings. The rest of
  681. this chapter will cover how to use these operations in detail. We will
  682. present the rest of the operations in the next chapter.
  683. @table @option
  684. @item --create
  685. @itemx -c
  686. Create a new @command{tar} archive.
  687. @item --list
  688. @itemx -t
  689. List the contents of an archive.
  690. @item --extract
  691. @itemx -x
  692. Extract one or more members from an archive.
  693. @end table
  694. @node Two Frequent Options
  695. @section Two Frequently Used Options
  696. To understand how to run @command{tar} in the three operating modes listed
  697. previously, you also need to understand how to use two of the options to
  698. @command{tar}: @option{--file} (which takes an archive file as an argument)
  699. and @option{--verbose}. (You are usually not @emph{required} to specify
  700. either of these options when you run @command{tar}, but they can be very
  701. useful in making things more clear and helping you avoid errors.)
  702. @menu
  703. * file tutorial::
  704. * verbose tutorial::
  705. * help tutorial::
  706. @end menu
  707. @node file tutorial
  708. @unnumberedsubsec The @option{--file} Option
  709. @table @option
  710. @xopindex{file, tutorial}
  711. @item --file=@var{archive-name}
  712. @itemx -f @var{archive-name}
  713. Specify the name of an archive file.
  714. @end table
  715. You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
  716. use @command{tar}; this option determines the name of the archive file
  717. that @command{tar} will work on.
  718. @vrindex TAPE
  719. If you don't specify this argument, then @command{tar} will examine
  720. the environment variable @env{TAPE}. If it is set, its value will be
  721. used as the archive name. Otherwise, @command{tar} will use the
  722. default archive, determined at compile time. Usually it is
  723. standard output or some physical tape drive attached to your machine
  724. (you can verify what the default is by running @kbd{tar
  725. --show-defaults}, @pxref{defaults}). If there is no tape drive
  726. attached, or the default is not meaningful, then @command{tar} will
  727. print an error message. The error message might look roughly like one
  728. of the following:
  729. @smallexample
  730. tar: can't open /dev/rmt8 : No such device or address
  731. tar: can't open /dev/rsmt0 : I/O error
  732. @end smallexample
  733. @noindent
  734. To avoid confusion, we recommend that you always specify an archive file
  735. name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
  736. For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
  737. @ref{file}.
  738. @node verbose tutorial
  739. @unnumberedsubsec The @option{--verbose} Option
  740. @table @option
  741. @xopindex{verbose, introduced}
  742. @item --verbose
  743. @itemx -v
  744. Show the files being worked on as @command{tar} is running.
  745. @end table
  746. @option{--verbose} (@option{-v}) shows details about the results of running
  747. @command{tar}. This can be especially useful when the results might not be
  748. obvious. For example, if you want to see the progress of @command{tar} as
  749. it writes files into the archive, you can use the @option{--verbose}
  750. option. In the beginning, you may find it useful to use
  751. @option{--verbose} at all times; when you are more accustomed to
  752. @command{tar}, you will likely want to use it at certain times but not at
  753. others. We will use @option{--verbose} at times to help make something
  754. clear, and we will give many examples both using and not using
  755. @option{--verbose} to show the differences.
  756. Each instance of @option{--verbose} on the command line increases the
  757. verbosity level by one, so if you need more details on the output,
  758. specify it twice.
  759. When reading archives (@option{--list}, @option{--extract},
  760. @option{--diff}), @command{tar} by default prints only the names of
  761. the members being extracted. Using @option{--verbose} will show a full,
  762. @command{ls} style member listing.
  763. In contrast, when writing archives (@option{--create}, @option{--append},
  764. @option{--update}), @command{tar} does not print file names by
  765. default. So, a single @option{--verbose} option shows the file names
  766. being added to the archive, while two @option{--verbose} options
  767. enable the full listing.
  768. For example, to create an archive in verbose mode:
  769. @smallexample
  770. $ @kbd{tar -cvf afiles.tar apple angst aspic}
  771. apple
  772. angst
  773. aspic
  774. @end smallexample
  775. @noindent
  776. Creating the same archive with the verbosity level 2 could give:
  777. @smallexample
  778. $ @kbd{tar -cvvf afiles.tar apple angst aspic}
  779. -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
  780. -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
  781. -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
  782. @end smallexample
  783. @noindent
  784. This works equally well using short or long forms of options. Using
  785. long forms, you would simply write out the mnemonic form of the option
  786. twice, like this:
  787. @smallexample
  788. $ @kbd{tar --create --verbose --verbose @dots{}}
  789. @end smallexample
  790. @noindent
  791. Note that you must double the hyphens properly each time.
  792. Later in the tutorial, we will give examples using @w{@option{--verbose
  793. --verbose}}.
  794. The @option{--verbose} option also enables several @dfn{warning
  795. messages}, that tar does not issue otherwise, such as the
  796. warning about record size being used (@pxref{Blocking Factor}), selecting
  797. the decompress program and the like. If these are of no interest to
  798. you, you can suppress them using the @option{--warning} option
  799. @emph{after} @option{--verbose}, e.g.:
  800. @example
  801. $ @kbd{tar -c -v --warning=no-verbose -f afiles.tar apple angst aspic}
  802. @end example
  803. @xref{Warning Classes, verbose}, for details.
  804. @anchor{verbose member listing}
  805. The full output consists of six fields:
  806. @itemize @bullet
  807. @item File type and permissions in symbolic form.
  808. These are displayed in the same format as the first column of
  809. @command{ls -l} output (@pxref{What information is listed,
  810. format=verbose, Verbose listing, fileutils, GNU file utilities}).
  811. @item Owner name and group separated by a slash character.
  812. If these data are not available (for example, when listing a @samp{v7} format
  813. archive), numeric @acronym{ID} values are printed instead.
  814. @item Size of the file, in bytes.
  815. @item File modification date in ISO 8601 format.
  816. @item File modification time.
  817. @item File name.
  818. If the name contains any special characters (white space, newlines,
  819. etc.)@: these are displayed in an unambiguous form using so called
  820. @dfn{quoting style}. For the detailed discussion of available styles
  821. and on how to use them, see @ref{quoting styles}.
  822. Depending on the file type, the name can be followed by some
  823. additional information, described in the following table:
  824. @table @samp
  825. @item -> @var{link-name}
  826. The file or archive member is a @dfn{symbolic link} and
  827. @var{link-name} is the name of file it links to.
  828. @item link to @var{link-name}
  829. The file or archive member is a @dfn{hard link} and @var{link-name} is
  830. the name of file it links to.
  831. @item --Long Link--
  832. The archive member is an old GNU format long link. You will normally
  833. not encounter this.
  834. @item --Long Name--
  835. The archive member is an old GNU format long name. You will normally
  836. not encounter this.
  837. @item --Volume Header--
  838. The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
  839. @item --Continued at byte @var{n}--
  840. Encountered only at the beginning of a multi-volume archive
  841. (@pxref{Using Multiple Tapes}). This archive member is a continuation
  842. from the previous volume. The number @var{n} gives the offset where
  843. the original file was split.
  844. @item unknown file type @var{c}
  845. An archive member of unknown type. @var{c} is the type character from
  846. the archive header. If you encounter such a message, it means that
  847. either your archive contains proprietary member types @GNUTAR{} is not
  848. able to handle, or the archive is corrupted.
  849. @end table
  850. @end itemize
  851. For example, here is an archive listing containing most of the special
  852. suffixes explained above:
  853. @smallexample
  854. @group
  855. V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
  856. -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at byte 32456--
  857. -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
  858. lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
  859. -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
  860. hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
  861. @end group
  862. @end smallexample
  863. @node help tutorial
  864. @unnumberedsubsec Getting Help: Using the @option{--help} Option
  865. @table @option
  866. @opindex help
  867. @item --help
  868. The @option{--help} option to @command{tar} prints out a very brief list of
  869. all operations and option available for the current version of
  870. @command{tar} available on your system.
  871. @end table
  872. @node create
  873. @section How to Create Archives
  874. @cindex Creation of the archive
  875. @cindex Archive, creation of
  876. One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
  877. you use to create a @command{tar} archive. We will explain
  878. @option{--create} first because, in order to learn about the other
  879. operations, you will find it useful to have an archive available to
  880. practice on.
  881. To make this easier, in this section you will first create a directory
  882. containing three files. Then, we will show you how to create an
  883. @emph{archive} (inside the new directory). Both the directory, and
  884. the archive are specifically for you to practice on. The rest of this
  885. chapter and the next chapter will show many examples using this
  886. directory and the files you will create: some of those files may be
  887. other directories and other archives.
  888. The three files you will archive in this example are called
  889. @file{blues}, @file{folk}, and @file{jazz}. The archive is called
  890. @file{collection.tar}.
  891. This section will proceed slowly, detailing how to use @option{--create}
  892. in @code{verbose} mode, and showing examples using both short and long
  893. forms. In the rest of the tutorial, and in the examples in the next
  894. chapter, we will proceed at a slightly quicker pace. This section
  895. moves more slowly to allow beginning users to understand how
  896. @command{tar} works.
  897. @menu
  898. * prepare for examples::
  899. * Creating the archive::
  900. * create verbose::
  901. * short create::
  902. * create dir::
  903. @end menu
  904. @node prepare for examples
  905. @subsection Preparing a Practice Directory for Examples
  906. To follow along with this and future examples, create a new directory
  907. called @file{practice} containing files called @file{blues}, @file{folk}
  908. and @file{jazz}. The files can contain any information you like:
  909. ideally, they should contain information which relates to their names,
  910. and be of different lengths. Our examples assume that @file{practice}
  911. is a subdirectory of your home directory.
  912. Now @command{cd} to the directory named @file{practice}; @file{practice}
  913. is now your @dfn{working directory}. (@emph{Please note}: Although
  914. the full file name of this directory is
  915. @file{/@var{homedir}/practice}, in our examples we will refer to
  916. this directory as @file{practice}; the @var{homedir} is presumed.)
  917. In general, you should check that the files to be archived exist where
  918. you think they do (in the working directory) by running @command{ls}.
  919. Because you just created the directory and the files and have changed to
  920. that directory, you probably don't need to do that this time.
  921. It is very important to make sure there isn't already a file in the
  922. working directory with the archive name you intend to use (in this case,
  923. @samp{collection.tar}), or that you don't care about its contents.
  924. Whenever you use @samp{create}, @command{tar} will erase the current
  925. contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
  926. will not tell you if you are about to overwrite an archive unless you
  927. specify an option which does this (@pxref{backup}, for the
  928. information on how to do so). To add files to an existing archive,
  929. you need to use a different option, such as @option{--append} (@option{-r}); see
  930. @ref{append} for information on how to do this.
  931. @node Creating the archive
  932. @subsection Creating the Archive
  933. @xopindex{create, introduced}
  934. To place the files @file{blues}, @file{folk}, and @file{jazz} into an
  935. archive named @file{collection.tar}, use the following command:
  936. @smallexample
  937. $ @kbd{tar --create --file=collection.tar blues folk jazz}
  938. @end smallexample
  939. The order of the arguments is not very important, @emph{when using long
  940. option forms}, however you should always remember to use option as the
  941. first argument to tar. For example, the following is wrong:
  942. @smallexample
  943. $ @kbd{tar blues -c folk -f collection.tar jazz}
  944. tar: -c: Invalid blocking factor
  945. Try 'tar --help' or 'tar --usage' for more information.
  946. @end smallexample
  947. The error message is produced because @command{tar} always treats its
  948. first argument as an option (or cluster of options), even if it does
  949. not start with dash. This is @dfn{traditional} or @dfn{old option}
  950. style, called so because all implementations of @command{tar} have
  951. used it since the very inception of the tar archiver in 1970s. This
  952. option style will be explained later (@pxref{Old Options}), for now
  953. just remember to always place option as the first argument.
  954. That being said, you could issue the following command:
  955. @smallexample
  956. $ @kbd{tar --create folk blues --file=collection.tar jazz}
  957. @end smallexample
  958. @noindent
  959. However, you can see that this order is harder to understand; this is
  960. why we will list the arguments in the order that makes the commands
  961. easiest to understand (and we encourage you to do the same when you use
  962. @command{tar}, to avoid errors).
  963. Note that the sequence
  964. @option{--file=@-collection.tar} is considered to be @emph{one} argument.
  965. If you substituted any other string of characters for
  966. @kbd{collection.tar}, then that string would become the name of the
  967. archive file you create.
  968. The order of the options becomes more important when you begin to use
  969. short forms. With short forms, if you type commands in the wrong order
  970. (even if you type them correctly in all other ways), you may end up with
  971. results you don't expect. For this reason, it is a good idea to get
  972. into the habit of typing options in the order that makes inherent sense.
  973. @xref{short create}, for more information on this.
  974. In this example, you type the command as shown above: @option{--create}
  975. is the operation which creates the new archive
  976. (@file{collection.tar}), and @option{--file} is the option which lets
  977. you give it the name you chose. The files, @file{blues}, @file{folk},
  978. and @file{jazz}, are now members of the archive, @file{collection.tar}
  979. (they are @dfn{file name arguments} to the @option{--create} operation.
  980. @xref{Choosing}, for the detailed discussion on these.) Now that they are
  981. in the archive, they are called @emph{archive members}, not files.
  982. (@pxref{Definitions,members}).
  983. When you create an archive, you @emph{must} specify which files you
  984. want placed in the archive. If you do not specify any archive
  985. members, @GNUTAR{} will complain.
  986. If you now list the contents of the working directory (@command{ls}), you will
  987. find the archive file listed as well as the files you saw previously:
  988. @smallexample
  989. blues folk jazz collection.tar
  990. @end smallexample
  991. @noindent
  992. Creating the archive @samp{collection.tar} did not destroy the copies of
  993. the files in the directory.
  994. Keep in mind that if you don't indicate an operation, @command{tar} will not
  995. run and will prompt you for one. If you don't name any files, @command{tar}
  996. will complain. You must have write access to the working directory,
  997. or else you will not be able to create an archive in that directory.
  998. @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
  999. an existing archive; it will delete the archive and write a new one.
  1000. Use @option{--append} (@option{-r}) instead. @xref{append}.
  1001. @node create verbose
  1002. @subsection Running @option{--create} with @option{--verbose}
  1003. @xopindex{create, using with @option{--verbose}}
  1004. @xopindex{verbose, using with @option{--create}}
  1005. If you include the @option{--verbose} (@option{-v}) option on the command line,
  1006. @command{tar} will list the files it is acting on as it is working. In
  1007. verbose mode, the @code{create} example above would appear as:
  1008. @smallexample
  1009. $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
  1010. blues
  1011. folk
  1012. jazz
  1013. @end smallexample
  1014. This example is just like the example we showed which did not use
  1015. @option{--verbose}, except that @command{tar} generated three output
  1016. lines.
  1017. In the rest of the examples in this chapter, we will frequently use
  1018. @code{verbose} mode so we can show actions or @command{tar} responses that
  1019. you would otherwise not see, and which are important for you to
  1020. understand.
  1021. @node short create
  1022. @subsection Short Forms with @samp{create}
  1023. As we said before, the @option{--create} (@option{-c}) operation is one of the most
  1024. basic uses of @command{tar}, and you will use it countless times.
  1025. Eventually, you will probably want to use abbreviated (or ``short'')
  1026. forms of options. A full discussion of the three different forms that
  1027. options can take appears in @ref{Styles}; for now, here is what the
  1028. previous example (including the @option{--verbose} (@option{-v}) option) looks like
  1029. using short option forms:
  1030. @smallexample
  1031. $ @kbd{tar -cvf collection.tar blues folk jazz}
  1032. blues
  1033. folk
  1034. jazz
  1035. @end smallexample
  1036. @noindent
  1037. As you can see, the system responds the same no matter whether you use
  1038. long or short option forms.
  1039. @FIXME{i don't like how this is worded:} One difference between using
  1040. short and long option forms is that, although the exact placement of
  1041. arguments following options is no more specific when using short forms,
  1042. it is easier to become confused and make a mistake when using short
  1043. forms. For example, suppose you attempted the above example in the
  1044. following way:
  1045. @smallexample
  1046. $ @kbd{tar -cfv collection.tar blues folk jazz}
  1047. @end smallexample
  1048. @noindent
  1049. In this case, @command{tar} will make an archive file called @file{v},
  1050. containing the files @file{blues}, @file{folk}, and @file{jazz}, because
  1051. the @samp{v} is the closest ``file name'' to the @option{-f} option, and
  1052. is thus taken to be the chosen archive file name. @command{tar} will try
  1053. to add a file called @file{collection.tar} to the @file{v} archive file;
  1054. if the file @file{collection.tar} did not already exist, @command{tar} will
  1055. report an error indicating that this file does not exist. If the file
  1056. @file{collection.tar} does already exist (e.g., from a previous command
  1057. you may have run), then @command{tar} will add this file to the archive.
  1058. Because the @option{-v} option did not get registered, @command{tar} will not
  1059. run under @samp{verbose} mode, and will not report its progress.
  1060. The end result is that you may be quite confused about what happened,
  1061. and possibly overwrite a file. To illustrate this further, we will show
  1062. you how an example we showed previously would look using short forms.
  1063. This example,
  1064. @smallexample
  1065. $ @kbd{tar --create folk blues --file=collection.tar jazz}
  1066. @end smallexample
  1067. @noindent
  1068. is confusing as it is. It becomes even more so when using short forms:
  1069. @smallexample
  1070. $ @kbd{tar -c folk blues -f collection.tar jazz}
  1071. @end smallexample
  1072. @noindent
  1073. It would be very easy to put the wrong string of characters
  1074. immediately following the @option{-f}, but doing that could sacrifice
  1075. valuable data.
  1076. For this reason, we recommend that you pay very careful attention to
  1077. the order of options and placement of file and archive names,
  1078. especially when using short option forms. Not having the option name
  1079. written out mnemonically can affect how well you remember which option
  1080. does what, and therefore where different names have to be placed.
  1081. @node create dir
  1082. @subsection Archiving Directories
  1083. @cindex Archiving Directories
  1084. @cindex Directories, Archiving
  1085. You can archive a directory by specifying its directory name as a
  1086. file name argument to @command{tar}. The files in the directory will be
  1087. archived relative to the working directory, and the directory will be
  1088. re-created along with its contents when the archive is extracted.
  1089. To archive a directory, first move to its superior directory. If you
  1090. have followed the previous instructions in this tutorial, you should
  1091. type:
  1092. @smallexample
  1093. $ @kbd{cd ..}
  1094. $
  1095. @end smallexample
  1096. @noindent
  1097. This will put you into the directory which contains @file{practice},
  1098. i.e., your home directory. Once in the superior directory, you can
  1099. specify the subdirectory, @file{practice}, as a file name argument. To
  1100. store @file{practice} in the new archive file @file{music.tar}, type:
  1101. @smallexample
  1102. $ @kbd{tar --create --verbose --file=music.tar practice}
  1103. @end smallexample
  1104. @noindent
  1105. @command{tar} should output:
  1106. @smallexample
  1107. practice/
  1108. practice/blues
  1109. practice/folk
  1110. practice/jazz
  1111. practice/collection.tar
  1112. @end smallexample
  1113. Note that the archive thus created is not in the subdirectory
  1114. @file{practice}, but rather in the current working directory---the
  1115. directory from which @command{tar} was invoked. Before trying to archive a
  1116. directory from its superior directory, you should make sure you have
  1117. write access to the superior directory itself, not only the directory
  1118. you are trying archive with @command{tar}. For example, you will probably
  1119. not be able to store your home directory in an archive by invoking
  1120. @command{tar} from the root directory; @xref{absolute}. (Note
  1121. also that @file{collection.tar}, the original archive file, has itself
  1122. been archived. @command{tar} will accept any file as a file to be
  1123. archived, regardless of its content. When @file{music.tar} is
  1124. extracted, the archive file @file{collection.tar} will be re-written
  1125. into the file system).
  1126. If you give @command{tar} a command such as
  1127. @smallexample
  1128. $ @kbd{tar --create --file=foo.tar .}
  1129. @end smallexample
  1130. @noindent
  1131. @command{tar} will report @samp{tar: ./foo.tar is the archive; not
  1132. dumped}. This happens because @command{tar} creates the archive
  1133. @file{foo.tar} in the current directory before putting any files into
  1134. it. Then, when @command{tar} attempts to add all the files in the
  1135. directory @file{.} to the archive, it notices that the file
  1136. @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
  1137. it. (It makes no sense to put an archive into itself.) @GNUTAR{}
  1138. will continue in this case, and create the archive
  1139. normally, except for the exclusion of that one file. (@emph{Please
  1140. note:} Other implementations of @command{tar} may not be so clever;
  1141. they will enter an infinite loop when this happens, so you should not
  1142. depend on this behavior unless you are certain you are running
  1143. @GNUTAR{}. In general, it is wise to always place the archive outside
  1144. of the directory being dumped.)
  1145. @node list
  1146. @section How to List Archives
  1147. @opindex list
  1148. Frequently, you will find yourself wanting to determine exactly what a
  1149. particular archive contains. You can use the @option{--list}
  1150. (@option{-t}) operation to get the member names as they currently
  1151. appear in the archive, as well as various attributes of the files at
  1152. the time they were archived. For example, assuming @file{practice} is
  1153. your working directory, you can examine the archive
  1154. @file{collection.tar} that you created in the last section with the
  1155. command,
  1156. @smallexample
  1157. $ @kbd{tar --list --file=collection.tar}
  1158. @end smallexample
  1159. @noindent
  1160. The output of @command{tar} would then be:
  1161. @smallexample
  1162. blues
  1163. folk
  1164. jazz
  1165. @end smallexample
  1166. @noindent
  1167. Be sure to use a @option{--file=@var{archive-name}} (@option{-f
  1168. @var{archive-name}}) option just as with @option{--create}
  1169. (@option{-c}) to specify the name of the archive.
  1170. @cindex File name arguments, using @option{--list} with
  1171. @xopindex{list, using with file name arguments}
  1172. You can specify one or more individual member names as arguments when
  1173. using @samp{list}. In this case, @command{tar} will only list the
  1174. names of members you identify. For example, @w{@kbd{tar --list
  1175. --file=collection.tar folk}} would only print @file{folk}:
  1176. @smallexample
  1177. $ @kbd{tar --list --file=collection.tar folk}
  1178. folk
  1179. @end smallexample
  1180. @xopindex{list, using with @option{--verbose}}
  1181. @xopindex{verbose, using with @option{--list}}
  1182. If you use the @option{--verbose} (@option{-v}) option with
  1183. @option{--list}, then @command{tar} will print out a listing
  1184. reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
  1185. forth. This output is described in detail in @ref{verbose member listing}.
  1186. If you had used @option{--verbose} (@option{-v}) mode, the example
  1187. above would look like:
  1188. @smallexample
  1189. $ @kbd{tar --list --verbose --file=collection.tar folk}
  1190. -rw-r--r-- myself/user 62 1990-05-23 10:55 folk
  1191. @end smallexample
  1192. @cindex listing member and file names
  1193. @anchor{listing member and file names}
  1194. It is important to notice that the output of @kbd{tar --list
  1195. --verbose} does not necessarily match that produced by @kbd{tar
  1196. --create --verbose} while creating the archive. It is because
  1197. @GNUTAR{}, unless told explicitly not to do so, removes some directory
  1198. prefixes from file names before storing them in the archive
  1199. (@xref{absolute}, for more information). In other
  1200. words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
  1201. an archive and @dfn{member names} when listing it. Consider this
  1202. example, run from your home directory:
  1203. @smallexample
  1204. @group
  1205. $ @kbd{tar --create --verbose --file practice.tar ~/practice}
  1206. tar: Removing leading '/' from member names
  1207. /home/myself/practice/
  1208. /home/myself/practice/blues
  1209. /home/myself/practice/folk
  1210. /home/myself/practice/jazz
  1211. /home/myself/practice/collection.tar
  1212. $ @kbd{tar --list --file practice.tar}
  1213. home/myself/practice/
  1214. home/myself/practice/blues
  1215. home/myself/practice/folk
  1216. home/myself/practice/jazz
  1217. home/myself/practice/collection.tar
  1218. @end group
  1219. @end smallexample
  1220. @opindex show-stored-names
  1221. This default behavior can sometimes be inconvenient. You can force
  1222. @GNUTAR{} show member names when creating archive by supplying
  1223. @option{--show-stored-names} option.
  1224. @table @option
  1225. @item --show-stored-names
  1226. Print member (as opposed to @emph{file}) names when creating the archive.
  1227. @end table
  1228. With this option, both commands produce the same output:
  1229. @smallexample
  1230. @group
  1231. $ @kbd{tar --create --verbose --show-stored-names \
  1232. --file practice.tar ~/practice}
  1233. tar: Removing leading '/' from member names
  1234. home/myself/practice/
  1235. home/myself/practice/blues
  1236. home/myself/practice/folk
  1237. home/myself/practice/jazz
  1238. home/myself/practice/collection.tar
  1239. $ @kbd{tar --list --file practice.tar}
  1240. home/myself/practice/
  1241. home/myself/practice/blues
  1242. home/myself/practice/folk
  1243. home/myself/practice/jazz
  1244. home/myself/practice/collection.tar
  1245. @end group
  1246. @end smallexample
  1247. Since @command{tar} preserves file names, those you wish to list must be
  1248. specified as they appear in the archive (i.e., relative to the
  1249. directory from which the archive was created). Continuing the example
  1250. above:
  1251. @smallexample
  1252. @group
  1253. $ @kbd{tar --list --file=practice.tar folk}
  1254. tar: folk: Not found in archive
  1255. tar: Exiting with failure status due to previous errors
  1256. @end group
  1257. @end smallexample
  1258. the error message is produced because there is no member named
  1259. @file{folk}, only one named @file{home/myself/folk}.
  1260. If you are not sure of the exact file name, use @dfn{globbing
  1261. patterns}, for example:
  1262. @smallexample
  1263. $ @kbd{tar --list --file=practice.tar --wildcards '*/folk'}
  1264. home/myself/practice/folk
  1265. @end smallexample
  1266. @noindent
  1267. @xref{wildcards}, for a detailed discussion of globbing patterns and related
  1268. @command{tar} command line options.
  1269. @menu
  1270. * list dir::
  1271. @end menu
  1272. @node list dir
  1273. @unnumberedsubsec Listing the Contents of a Stored Directory
  1274. To get information about the contents of an archived directory,
  1275. use the directory name as a file name argument in conjunction with
  1276. @option{--list} (@option{-t}). To find out file attributes, include the
  1277. @option{--verbose} (@option{-v}) option.
  1278. For example, to find out about files in the directory @file{practice}, in
  1279. the archive file @file{music.tar}, type:
  1280. @smallexample
  1281. $ @kbd{tar --list --verbose --file=music.tar practice}
  1282. @end smallexample
  1283. @command{tar} responds:
  1284. @smallexample
  1285. drwxrwxrwx myself/user 0 1990-05-31 21:49 practice/
  1286. -rw-r--r-- myself/user 42 1990-05-21 13:29 practice/blues
  1287. -rw-r--r-- myself/user 62 1990-05-23 10:55 practice/folk
  1288. -rw-r--r-- myself/user 40 1990-05-21 13:30 practice/jazz
  1289. -rw-r--r-- myself/user 10240 1990-05-31 21:49 practice/collection.tar
  1290. @end smallexample
  1291. When you use a directory name as a file name argument, @command{tar} acts on
  1292. all the files (including sub-directories) in that directory.
  1293. @node extract
  1294. @section How to Extract Members from an Archive
  1295. @cindex Extraction
  1296. @cindex Retrieving files from an archive
  1297. @cindex Resurrecting files from an archive
  1298. @opindex extract
  1299. Creating an archive is only half the job---there is no point in storing
  1300. files in an archive if you can't retrieve them. The act of retrieving
  1301. members from an archive so they can be used and manipulated as
  1302. unarchived files again is called @dfn{extraction}. To extract files
  1303. from an archive, use the @option{--extract} (@option{--get} or
  1304. @option{-x}) operation. As with @option{--create}, specify the name
  1305. of the archive with @option{--file} (@option{-f}) option. Extracting
  1306. an archive does not modify the archive in any way; you can extract it
  1307. multiple times if you want or need to.
  1308. Using @option{--extract}, you can extract an entire archive, or specific
  1309. files. The files can be directories containing other files, or not. As
  1310. with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
  1311. long form of the operation without affecting the performance.
  1312. @menu
  1313. * extracting archives::
  1314. * extracting files::
  1315. * extract dir::
  1316. * extracting untrusted archives::
  1317. * failing commands::
  1318. @end menu
  1319. @node extracting archives
  1320. @subsection Extracting an Entire Archive
  1321. To extract an entire archive, specify the archive file name only, with
  1322. no individual file names as arguments. For example,
  1323. @smallexample
  1324. $ @kbd{tar -xvf collection.tar}
  1325. @end smallexample
  1326. @noindent
  1327. produces this:
  1328. @smallexample
  1329. -rw-r--r-- myself/user 28 1996-10-18 16:31 jazz
  1330. -rw-r--r-- myself/user 21 1996-09-23 16:44 blues
  1331. -rw-r--r-- myself/user 20 1996-09-23 16:44 folk
  1332. @end smallexample
  1333. @node extracting files
  1334. @subsection Extracting Specific Files
  1335. To extract specific archive members, give their exact member names as
  1336. arguments, as printed by @option{--list} (@option{-t}). If you had
  1337. mistakenly deleted one of the files you had placed in the archive
  1338. @file{collection.tar} earlier (say, @file{blues}), you can extract it
  1339. from the archive without changing the archive's structure. Its
  1340. contents will be identical to the original file @file{blues} that you
  1341. deleted.
  1342. First, make sure you are in the @file{practice} directory, and list the
  1343. files in the directory. Now, delete the file, @samp{blues}, and list
  1344. the files in the directory again.
  1345. You can now extract the member @file{blues} from the archive file
  1346. @file{collection.tar} like this:
  1347. @smallexample
  1348. $ @kbd{tar --extract --file=collection.tar blues}
  1349. @end smallexample
  1350. @noindent
  1351. If you list the files in the directory again, you will see that the file
  1352. @file{blues} has been restored, with its original permissions, data
  1353. modification times, and owner.@footnote{This is only accidentally
  1354. true, but not in general. Whereas modification times are always
  1355. restored, in most cases, one has to be root for restoring the owner,
  1356. and use a special option for restoring permissions. Here, it just
  1357. happens that the restoring user is also the owner of the archived
  1358. members, and that the current @code{umask} is compatible with original
  1359. permissions.} (These parameters will be identical to those which
  1360. the file had when you originally placed it in the archive; any changes
  1361. you may have made before deleting the file from the file system,
  1362. however, will @emph{not} have been made to the archive member.) The
  1363. archive file, @samp{collection.tar}, is the same as it was before you
  1364. extracted @samp{blues}. You can confirm this by running @command{tar} with
  1365. @option{--list} (@option{-t}).
  1366. Remember that as with other operations, specifying the exact member
  1367. name is important (@xref{failing commands}, for more examples).
  1368. You can extract a file to standard output by combining the above options
  1369. with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
  1370. Output}).
  1371. If you give the @option{--verbose} option, then @option{--extract}
  1372. will print the names of the archive members as it extracts them.
  1373. @node extract dir
  1374. @subsection Extracting Files that are Directories
  1375. Extracting directories which are members of an archive is similar to
  1376. extracting other files. The main difference to be aware of is that if
  1377. the extracted directory has the same name as any directory already in
  1378. the working directory, then files in the extracted directory will be
  1379. placed into the directory of the same name. Likewise, if there are
  1380. files in the pre-existing directory with the same names as the members
  1381. which you extract, the files from the extracted archive will replace
  1382. the files already in the working directory (and possible
  1383. subdirectories). This will happen regardless of whether or not the
  1384. files in the working directory were more recent than those extracted
  1385. (there exist, however, special options that alter this behavior
  1386. @pxref{Writing}).
  1387. However, if a file was stored with a directory name as part of its file
  1388. name, and that directory does not exist under the working directory when
  1389. the file is extracted, @command{tar} will create the directory.
  1390. We can demonstrate how to use @option{--extract} to extract a directory
  1391. file with an example. Change to the @file{practice} directory if you
  1392. weren't there, and remove the files @file{folk} and @file{jazz}. Then,
  1393. go back to the parent directory and extract the archive
  1394. @file{music.tar}. You may either extract the entire archive, or you may
  1395. extract only the files you just deleted. To extract the entire archive,
  1396. don't give any file names as arguments after the archive name
  1397. @file{music.tar}. To extract only the files you deleted, use the
  1398. following command:
  1399. @smallexample
  1400. $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
  1401. practice/folk
  1402. practice/jazz
  1403. @end smallexample
  1404. @noindent
  1405. If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
  1406. would have displayed more detail about the extracted files, as shown
  1407. in the example below:
  1408. @smallexample
  1409. $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
  1410. -rw-r--r-- me/user 28 1996-10-18 16:31 practice/jazz
  1411. -rw-r--r-- me/user 20 1996-09-23 16:44 practice/folk
  1412. @end smallexample
  1413. @noindent
  1414. Because you created the directory with @file{practice} as part of the
  1415. file names of each of the files by archiving the @file{practice}
  1416. directory as @file{practice}, you must give @file{practice} as part
  1417. of the file names when you extract those files from the archive.
  1418. @node extracting untrusted archives
  1419. @subsection Extracting Archives from Untrusted Sources
  1420. Extracting files from archives can overwrite files that already exist.
  1421. If you receive an archive from an untrusted source, you should make a
  1422. new directory and extract into that directory, so that you don't have
  1423. to worry about the extraction overwriting one of your existing files.
  1424. For example, if @file{untrusted.tar} came from somewhere else on the
  1425. Internet, and you don't necessarily trust its contents, you can
  1426. extract it as follows:
  1427. @smallexample
  1428. $ @kbd{mkdir newdir}
  1429. $ @kbd{cd newdir}
  1430. $ @kbd{tar -xvf ../untrusted.tar}
  1431. @end smallexample
  1432. It is also a good practice to examine contents of the archive
  1433. before extracting it, using @option{--list} (@option{-t}) option, possibly combined
  1434. with @option{--verbose} (@option{-v}).
  1435. @node failing commands
  1436. @subsection Commands That Will Fail
  1437. Here are some sample commands you might try which will not work, and why
  1438. they won't work.
  1439. If you try to use this command,
  1440. @smallexample
  1441. $ @kbd{tar -xvf music.tar folk jazz}
  1442. @end smallexample
  1443. @noindent
  1444. you will get the following response:
  1445. @smallexample
  1446. tar: folk: Not found in archive
  1447. tar: jazz: Not found in archive
  1448. @end smallexample
  1449. @noindent
  1450. This is because these files were not originally @emph{in} the parent
  1451. directory @file{..}, where the archive is located; they were in the
  1452. @file{practice} directory, and their file names reflect this:
  1453. @smallexample
  1454. $ @kbd{tar -tvf music.tar}
  1455. practice/blues
  1456. practice/folk
  1457. practice/jazz
  1458. @end smallexample
  1459. @noindent
  1460. Likewise, if you try to use this command,
  1461. @smallexample
  1462. $ @kbd{tar -tvf music.tar folk jazz}
  1463. @end smallexample
  1464. @noindent
  1465. you would get a similar response. Members with those names are not in the
  1466. archive. You must use the correct member names, or wildcards, in order
  1467. to extract the files from the archive.
  1468. If you have forgotten the correct names of the files in the archive,
  1469. use @w{@kbd{tar --list --verbose}} to list them correctly.
  1470. To extract the member named @file{practice/folk}, you must specify
  1471. @smallexample
  1472. $ @kbd{tar --extract --file=music.tar practice/folk}
  1473. @end smallexample
  1474. @noindent
  1475. Notice also, that as explained above, the @file{practice} directory
  1476. will be created, if it didn't already exist. There are options that
  1477. allow you to strip away a certain number of leading directory
  1478. components (@pxref{transform}). For example,
  1479. @smallexample
  1480. $ @kbd{tar --extract --file=music.tar --strip-components=1 folk}
  1481. @end smallexample
  1482. @noindent
  1483. will extract the file @file{folk} into the current working directory.
  1484. @node going further
  1485. @section Going Further Ahead in this Manual
  1486. @UNREVISED{}
  1487. @FIXME{need to write up a node here about the things that are going to
  1488. be in the rest of the manual.}
  1489. @node tar invocation
  1490. @chapter Invoking @GNUTAR{}
  1491. This chapter is about how one invokes the @GNUTAR{}
  1492. command, from the command synopsis (@pxref{Synopsis}). There are
  1493. numerous options, and many styles for writing them. One mandatory
  1494. option specifies the operation @command{tar} should perform
  1495. (@pxref{Operation Summary}), other options are meant to detail how
  1496. this operation should be performed (@pxref{Option Summary}).
  1497. Non-option arguments are not always interpreted the same way,
  1498. depending on what the operation is.
  1499. You will find in this chapter everything about option styles and rules for
  1500. writing them (@pxref{Styles}). On the other hand, operations and options
  1501. are fully described elsewhere, in other chapters. Here, you will find
  1502. only synthetic descriptions for operations and options, together with
  1503. pointers to other parts of the @command{tar} manual.
  1504. Some options are so special they are fully described right in this
  1505. chapter. They have the effect of inhibiting the normal operation of
  1506. @command{tar} or else, they globally alter the amount of feedback the user
  1507. receives about what is going on. These are the @option{--help} and
  1508. @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
  1509. and @option{--interactive} options (@pxref{interactive}).
  1510. @menu
  1511. * Synopsis::
  1512. * using tar options::
  1513. * Styles::
  1514. * All Options:: All @command{tar} Options.
  1515. * help:: Where to Get Help.
  1516. * defaults:: What are the Default Values.
  1517. * verbose:: Checking @command{tar} progress.
  1518. * checkpoints:: Checkpoints.
  1519. * warnings:: Controlling Warning Messages.
  1520. * interactive:: Asking for Confirmation During Operations.
  1521. * external:: Running External Commands.
  1522. @end menu
  1523. @node Synopsis
  1524. @section General Synopsis of @command{tar}
  1525. The @GNUTAR{} program is invoked as either one of:
  1526. @smallexample
  1527. @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
  1528. @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
  1529. @end smallexample
  1530. The second form is for when old options are being used.
  1531. You can use @command{tar} to store files in an archive, to extract them from
  1532. an archive, and to do other types of archive manipulation. The primary
  1533. argument to @command{tar}, which is called the @dfn{operation}, specifies
  1534. which action to take. The other arguments to @command{tar} are either
  1535. @dfn{options}, which change the way @command{tar} performs an operation,
  1536. or file names or archive members, which specify the files or members
  1537. @command{tar} is to act on.
  1538. You can actually type in arguments in any order, even if in this manual
  1539. the options always precede the other arguments, to make examples easier
  1540. to understand. Further, the option stating the main operation mode
  1541. (the @command{tar} main command) is usually given first.
  1542. Each @var{name} in the synopsis above is interpreted as an archive member
  1543. name when the main command is one of @option{--compare}
  1544. (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
  1545. (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
  1546. @option{--update} (@option{-u}). When naming archive members, you
  1547. must give the exact name of the member in the archive, as it is
  1548. printed by @option{--list}. For @option{--append} (@option{-r}) and
  1549. @option{--create} (@option{-c}), these @var{name} arguments specify
  1550. the names of either files or directory hierarchies to place in the archive.
  1551. These files or hierarchies should already exist in the file system,
  1552. prior to the execution of the @command{tar} command.
  1553. @command{tar} interprets relative file names as being relative to the
  1554. working directory. @command{tar} will make all file names relative
  1555. (by removing leading slashes when archiving or restoring files),
  1556. unless you specify otherwise (using the @option{--absolute-names}
  1557. option). @xref{absolute}, for more information about
  1558. @option{--absolute-names}.
  1559. If you give the name of a directory as either a file name or a member
  1560. name, then @command{tar} acts recursively on all the files and directories
  1561. beneath that directory. For example, the name @file{/} identifies all
  1562. the files in the file system to @command{tar}.
  1563. The distinction between file names and archive member names is especially
  1564. important when shell globbing is used, and sometimes a source of confusion
  1565. for newcomers. @xref{wildcards}, for more information about globbing.
  1566. The problem is that shells may only glob using existing files in the
  1567. file system. Only @command{tar} itself may glob on archive members, so when
  1568. needed, you must ensure that wildcard characters reach @command{tar} without
  1569. being interpreted by the shell first. Using a backslash before @samp{*}
  1570. or @samp{?}, or putting the whole argument between quotes, is usually
  1571. sufficient for this.
  1572. Even if @var{name}s are often specified on the command line, they
  1573. can also be read from a text file in the file system, using the
  1574. @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
  1575. If you don't use any file name arguments, @option{--append} (@option{-r}),
  1576. @option{--delete} and @option{--concatenate} (@option{--catenate},
  1577. @option{-A}) will do nothing, while @option{--create} (@option{-c})
  1578. will usually yield a diagnostic and inhibit @command{tar} execution.
  1579. The other operations of @command{tar} (@option{--list},
  1580. @option{--extract}, @option{--compare}, and @option{--update})
  1581. will act on the entire contents of the archive.
  1582. @anchor{exit status}
  1583. @cindex exit status
  1584. @cindex return status
  1585. Besides successful exits, @GNUTAR{} may fail for
  1586. many reasons. Some reasons correspond to bad usage, that is, when the
  1587. @command{tar} command line is improperly written. Errors may be
  1588. encountered later, while processing the archive or the files. Some
  1589. errors are recoverable, in which case the failure is delayed until
  1590. @command{tar} has completed all its work. Some errors are such that
  1591. it would be not meaningful, or at least risky, to continue processing:
  1592. @command{tar} then aborts processing immediately. All abnormal exits,
  1593. whether immediate or delayed, should always be clearly diagnosed on
  1594. @code{stderr}, after a line stating the nature of the error.
  1595. Possible exit codes of @GNUTAR{} are summarized in the following
  1596. table:
  1597. @table @asis
  1598. @item 0
  1599. @samp{Successful termination}.
  1600. @item 1
  1601. @samp{Some files differ}. If tar was invoked with @option{--compare}
  1602. (@option{--diff}, @option{-d}) command line option, this means that
  1603. some files in the archive differ from their disk counterparts
  1604. (@pxref{compare}). If tar was given @option{--create},
  1605. @option{--append} or @option{--update} option, this exit code means
  1606. that some files were changed while being archived and so the resulting
  1607. archive does not contain the exact copy of the file set.
  1608. @item 2
  1609. @samp{Fatal error}. This means that some fatal, unrecoverable error
  1610. occurred.
  1611. @end table
  1612. If @command{tar} has invoked a subprocess and that subprocess exited with a
  1613. nonzero exit code, @command{tar} exits with that code as well.
  1614. This can happen, for example, if @command{tar} was given some
  1615. compression option (@pxref{gzip}) and the external compressor program
  1616. failed. Another example is @command{rmt} failure during backup to the
  1617. remote device (@pxref{Remote Tape Server}).
  1618. @node using tar options
  1619. @section Using @command{tar} Options
  1620. @GNUTAR{} has a total of eight operating modes which
  1621. allow you to perform a variety of tasks. You are required to choose
  1622. one operating mode each time you employ the @command{tar} program by
  1623. specifying one, and only one operation as an argument to the
  1624. @command{tar} command (the corresponding options may be found
  1625. at @ref{frequent operations} and @ref{Operations}). Depending on
  1626. circumstances, you may also wish to customize how the chosen operating
  1627. mode behaves. For example, you may wish to change the way the output
  1628. looks, or the format of the files that you wish to archive may require
  1629. you to do something special in order to make the archive look right.
  1630. You can customize and control @command{tar}'s performance by running
  1631. @command{tar} with one or more options (such as @option{--verbose}
  1632. (@option{-v}), which we used in the tutorial). As we said in the
  1633. tutorial, @dfn{options} are arguments to @command{tar} which are (as
  1634. their name suggests) optional. Depending on the operating mode, you
  1635. may specify one or more options. Different options will have different
  1636. effects, but in general they all change details of the operation, such
  1637. as archive format, archive name, or level of user interaction. Some
  1638. options make sense with all operating modes, while others are
  1639. meaningful only with particular modes. You will likely use some
  1640. options frequently, while you will only use others infrequently, or
  1641. not at all. (A full list of options is available in @pxref{All Options}.)
  1642. @vrindex TAR_OPTIONS, environment variable
  1643. @anchor{TAR_OPTIONS}
  1644. The @env{TAR_OPTIONS} environment variable specifies default options to
  1645. be placed in front of any explicit options. For example, if
  1646. @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
  1647. if the two options @option{-v} and @option{--unlink-first} had been
  1648. specified before any explicit options. Option specifications are
  1649. separated by whitespace. A backslash escapes the next character, so it
  1650. can be used to specify an option containing whitespace or a backslash.
  1651. Note that @command{tar} options are case sensitive. For example, the
  1652. options @option{-T} and @option{-t} are different; the first requires an
  1653. argument for stating the name of a file providing a list of @var{name}s,
  1654. while the second does not require an argument and is another way to
  1655. write @option{--list} (@option{-t}).
  1656. In addition to the eight operations, there are many options to
  1657. @command{tar}, and three different styles for writing both: long (mnemonic)
  1658. form, short form, and old style. These styles are discussed below.
  1659. Both the options and the operations can be written in any of these three
  1660. styles.
  1661. @FIXME{menu at end of this node. need to think of an actual outline
  1662. for this chapter; probably do that after stuff from chapter 4 is
  1663. incorporated.}
  1664. @node Styles
  1665. @section The Three Option Styles
  1666. There are three styles for writing operations and options to the command
  1667. line invoking @command{tar}. The different styles were developed at
  1668. different times during the history of @command{tar}. These styles will be
  1669. presented below, from the most recent to the oldest.
  1670. Some options must take an argument@footnote{For example, @option{--file}
  1671. (@option{-f}) takes the name of an archive file as an argument. If
  1672. you do not supply an archive file name, @command{tar} will use a
  1673. default, but this can be confusing; thus, we recommend that you always
  1674. supply a specific archive file name.}. Where you @emph{place} the
  1675. arguments generally depends on which style of options you choose. We
  1676. will detail specific information relevant to each option style in the
  1677. sections on the different option styles, below. The differences are
  1678. subtle, yet can often be very important; incorrect option placement
  1679. can cause you to overwrite a number of important files. We urge you
  1680. to note these differences, and only use the option style(s) which
  1681. makes the most sense to you until you feel comfortable with the others.
  1682. Some options @emph{may} take an argument. Such options may have at
  1683. most long and short forms, they do not have old style equivalent. The
  1684. rules for specifying an argument for such options are stricter than
  1685. those for specifying mandatory arguments. Please, pay special
  1686. attention to them.
  1687. @menu
  1688. * Long Options:: Long Option Style
  1689. * Short Options:: Short Option Style
  1690. * Old Options:: Old Option Style
  1691. * Mixing:: Mixing Option Styles
  1692. @end menu
  1693. @node Long Options
  1694. @subsection Long Option Style
  1695. @cindex long options
  1696. @cindex options, long style
  1697. @cindex options, GNU style
  1698. @cindex options, mnemonic names
  1699. Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
  1700. dashes in a row, e.g., @option{--list}. The long names are more clear than
  1701. their corresponding short or old names. It sometimes happens that a
  1702. single long option has many different names which are
  1703. synonymous, such as @option{--compare} and @option{--diff}. In addition,
  1704. long option names can be given unique abbreviations. For example,
  1705. @option{--cre} can be used in place of @option{--create} because there is no
  1706. other long option which begins with @samp{cre}. (One way to find
  1707. this out is by trying it and seeing what happens; if a particular
  1708. abbreviation could represent more than one option, @command{tar} will tell
  1709. you that that abbreviation is ambiguous and you'll know that that
  1710. abbreviation won't work. You may also choose to run @samp{tar --help}
  1711. to see a list of options. Be aware that if you run @command{tar} with a
  1712. unique abbreviation for the long name of an option you didn't want to
  1713. use, you are stuck; @command{tar} will perform the command as ordered.)
  1714. Long options are meant to be obvious and easy to remember, and their
  1715. meanings are generally easier to discern than those of their
  1716. corresponding short options (see below). For example:
  1717. @smallexample
  1718. $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
  1719. @end smallexample
  1720. @noindent
  1721. gives a fairly good set of hints about what the command does, even
  1722. for those not fully acquainted with @command{tar}.
  1723. @cindex arguments to long options
  1724. @cindex long options with mandatory arguments
  1725. Long options which require arguments take those arguments
  1726. immediately following the option name. There are two ways of
  1727. specifying a mandatory argument. It can be separated from the
  1728. option name either by an equal sign, or by any amount of
  1729. white space characters. For example, the @option{--file} option (which
  1730. tells the name of the @command{tar} archive) is given a file such as
  1731. @file{archive.tar} as argument by using any of the following notations:
  1732. @option{--file=archive.tar} or @option{--file archive.tar}.
  1733. @cindex optional arguments to long options
  1734. @cindex long options with optional arguments
  1735. In contrast, optional arguments must always be introduced using
  1736. an equal sign. For example, the @option{--backup} option takes
  1737. an optional argument specifying backup type. It must be used
  1738. as @option{--backup=@var{backup-type}}.
  1739. @node Short Options
  1740. @subsection Short Option Style
  1741. @cindex short options
  1742. @cindex options, short style
  1743. @cindex options, traditional
  1744. Most options also have a @dfn{short option} name. Short options start with
  1745. a single dash, and are followed by a single character, e.g., @option{-t}
  1746. (which is equivalent to @option{--list}). The forms are absolutely
  1747. identical in function; they are interchangeable.
  1748. The short option names are faster to type than long option names.
  1749. @cindex arguments to short options
  1750. @cindex short options with mandatory arguments
  1751. Short options which require arguments take their arguments immediately
  1752. following the option, usually separated by white space. It is also
  1753. possible to stick the argument right after the short option name, using
  1754. no intervening space. For example, you might write @w{@option{-f
  1755. archive.tar}} or @option{-farchive.tar} instead of using
  1756. @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
  1757. @w{@option{-f @var{archive-name}}} denote the option which indicates a
  1758. specific archive, here named @file{archive.tar}.
  1759. @cindex optional arguments to short options
  1760. @cindex short options with optional arguments
  1761. Short options which take optional arguments take their arguments
  1762. immediately following the option letter, @emph{without any intervening
  1763. white space characters}.
  1764. Short options' letters may be clumped together, but you are not
  1765. required to do this (as compared to old options; see below). When
  1766. short options are clumped as a set, use one (single) dash for them
  1767. all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
  1768. such a set is allowed to have an argument@footnote{Clustering many
  1769. options, the last of which has an argument, is a rather opaque way to
  1770. write options. Some wonder if @acronym{GNU} @code{getopt} should not
  1771. even be made helpful enough for considering such usages as invalid.}.
  1772. When the options are separated, the argument for each option which requires
  1773. an argument directly follows that option, as is usual for Unix programs.
  1774. For example:
  1775. @smallexample
  1776. $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
  1777. @end smallexample
  1778. If you reorder short options' locations, be sure to move any arguments
  1779. that belong to them. If you do not move the arguments properly, you may
  1780. end up overwriting files.
  1781. @node Old Options
  1782. @subsection Old Option Style
  1783. @cindex options, old style
  1784. @cindex old option style
  1785. @cindex option syntax, traditional
  1786. As far as we know, all @command{tar} programs, @acronym{GNU} and
  1787. non-@acronym{GNU}, support @dfn{old options}: that is, if the first
  1788. argument does not start with @samp{-}, it is assumed to specify option
  1789. letters. @GNUTAR{} supports old options not only for historical
  1790. reasons, but also because many people are used to them. If the first
  1791. argument does not start with a dash, you are announcing the old option
  1792. style instead of the short option style; old options are decoded
  1793. differently.
  1794. Like short options, old options are single letters. However, old options
  1795. must be written together as a single clumped set, without spaces separating
  1796. them or dashes preceding them. This set
  1797. of letters must be the first to appear on the command line, after the
  1798. @command{tar} program name and some white space; old options cannot appear
  1799. anywhere else. The letter of an old option is exactly the same letter as
  1800. the corresponding short option. For example, the old option @samp{t} is
  1801. the same as the short option @option{-t}, and consequently, the same as the
  1802. long option @option{--list}. So for example, the command @w{@samp{tar
  1803. cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
  1804. @cindex arguments to old options
  1805. @cindex old options with mandatory arguments
  1806. When options that need arguments are given together with the command,
  1807. all the associated arguments follow, in the same order as the options.
  1808. Thus, the example given previously could also be written in the old
  1809. style as follows:
  1810. @smallexample
  1811. $ @kbd{tar cvbf 20 /dev/rmt0}
  1812. @end smallexample
  1813. @noindent
  1814. Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
  1815. the argument of @option{-f}.
  1816. The old style syntax can make it difficult to match
  1817. option letters with their corresponding arguments, and is often
  1818. confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
  1819. @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
  1820. argument for @option{-f}, and @option{-v} does not have a corresponding
  1821. argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
  1822. /dev/rmt0}} is clearer, putting all arguments next to the option they
  1823. pertain to.
  1824. If you want to reorder the letters in the old option argument, be
  1825. sure to reorder any corresponding argument appropriately.
  1826. This old way of writing @command{tar} options can surprise even experienced
  1827. users. For example, the two commands:
  1828. @smallexample
  1829. @kbd{tar cfz archive.tar.gz file}
  1830. @kbd{tar -cfz archive.tar.gz file}
  1831. @end smallexample
  1832. @noindent
  1833. are quite different. The first example uses @file{archive.tar.gz} as
  1834. the value for option @samp{f} and recognizes the option @samp{z}. The
  1835. second example, however, uses @file{z} as the value for option
  1836. @samp{f} --- probably not what was intended.
  1837. This second example could be corrected in many ways, among which the
  1838. following are equivalent:
  1839. @smallexample
  1840. @kbd{tar -czf archive.tar.gz file}
  1841. @kbd{tar -cf archive.tar.gz -z file}
  1842. @kbd{tar cf archive.tar.gz -z file}
  1843. @end smallexample
  1844. @node Mixing
  1845. @subsection Mixing Option Styles
  1846. @cindex options, mixing different styles
  1847. All three styles may be intermixed in a single @command{tar} command,
  1848. so long as the rules for each style are fully
  1849. respected@footnote{Before @GNUTAR{} version 1.11.6,
  1850. a bug prevented intermixing old style options with long options in
  1851. some cases.}. Old style options and either of the modern styles of
  1852. options may be mixed within a single @command{tar} command. However,
  1853. old style options must be introduced as the first arguments only,
  1854. following the rule for old options (old options must appear directly
  1855. after the @command{tar} command and some white space). Modern options
  1856. may be given only after all arguments to the old options have been
  1857. collected. If this rule is not respected, a modern option might be
  1858. falsely interpreted as the value of the argument to one of the old
  1859. style options.
  1860. For example, all the following commands are wholly equivalent, and
  1861. illustrate the many combinations and orderings of option styles.
  1862. @smallexample
  1863. @kbd{tar --create --file=archive.tar}
  1864. @kbd{tar --create -f archive.tar}
  1865. @kbd{tar --create -farchive.tar}
  1866. @kbd{tar --file=archive.tar --create}
  1867. @kbd{tar --file=archive.tar -c}
  1868. @kbd{tar -c --file=archive.tar}
  1869. @kbd{tar -c -f archive.tar}
  1870. @kbd{tar -c -farchive.tar}
  1871. @kbd{tar -cf archive.tar}
  1872. @kbd{tar -cfarchive.tar}
  1873. @kbd{tar -f archive.tar --create}
  1874. @kbd{tar -f archive.tar -c}
  1875. @kbd{tar -farchive.tar --create}
  1876. @kbd{tar -farchive.tar -c}
  1877. @kbd{tar c --file=archive.tar}
  1878. @kbd{tar c -f archive.tar}
  1879. @kbd{tar c -farchive.tar}
  1880. @kbd{tar cf archive.tar}
  1881. @kbd{tar f archive.tar --create}
  1882. @kbd{tar f archive.tar -c}
  1883. @kbd{tar fc archive.tar}
  1884. @end smallexample
  1885. On the other hand, the following commands are @emph{not} equivalent to
  1886. the previous set:
  1887. @smallexample
  1888. @kbd{tar -f -c archive.tar}
  1889. @kbd{tar -fc archive.tar}
  1890. @kbd{tar -fcarchive.tar}
  1891. @kbd{tar -farchive.tarc}
  1892. @kbd{tar cfarchive.tar}
  1893. @end smallexample
  1894. @noindent
  1895. These last examples mean something completely different from what the
  1896. user intended (judging based on the example in the previous set which
  1897. uses long options, whose intent is therefore very clear). The first
  1898. four specify that the @command{tar} archive would be a file named
  1899. @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
  1900. respectively. The first two examples also specify a single non-option,
  1901. @var{name} argument having the value @samp{archive.tar}. The last
  1902. example contains only old style option letters (repeating option
  1903. @samp{c} twice), not all of which are meaningful (eg., @samp{.},
  1904. @samp{h}, or @samp{i}), with no argument value.
  1905. @FIXME{not sure i liked
  1906. the first sentence of this paragraph..}
  1907. @node All Options
  1908. @section All @command{tar} Options
  1909. The coming manual sections contain an alphabetical listing of all
  1910. @command{tar} operations and options, with brief descriptions and
  1911. cross-references to more in-depth explanations in the body of the manual.
  1912. They also contain an alphabetically arranged table of the short option
  1913. forms with their corresponding long option. You can use this table as
  1914. a reference for deciphering @command{tar} commands in scripts.
  1915. @menu
  1916. * Operation Summary::
  1917. * Option Summary::
  1918. * Short Option Summary::
  1919. * Position-Sensitive Options::
  1920. @end menu
  1921. @node Operation Summary
  1922. @subsection Operations
  1923. @table @option
  1924. @opsummary{append}
  1925. @item --append
  1926. @itemx -r
  1927. Appends files to the end of the archive. @xref{append}.
  1928. @opsummary{catenate}
  1929. @item --catenate
  1930. @itemx -A
  1931. Same as @option{--concatenate}. @xref{concatenate}.
  1932. @opsummary{compare}
  1933. @item --compare
  1934. @itemx -d
  1935. Compares archive members with their counterparts in the file
  1936. system, and reports differences in file size, mode, owner,
  1937. modification date and contents. @xref{compare}.
  1938. @opsummary{concatenate}
  1939. @item --concatenate
  1940. @itemx -A
  1941. Appends other @command{tar} archives to the end of the archive.
  1942. @xref{concatenate}.
  1943. @opsummary{create}
  1944. @item --create
  1945. @itemx -c
  1946. Creates a new @command{tar} archive. @xref{create}.
  1947. @opsummary{delete}
  1948. @item --delete
  1949. Deletes members from the archive. Don't try this on an archive on a
  1950. tape! @xref{delete}.
  1951. @opsummary{diff}
  1952. @item --diff
  1953. @itemx -d
  1954. Same as @option{--compare}. @xref{compare}.
  1955. @opsummary{extract}
  1956. @item --extract
  1957. @itemx -x
  1958. Extracts members from the archive into the file system. @xref{extract}.
  1959. @opsummary{get}
  1960. @item --get
  1961. @itemx -x
  1962. Same as @option{--extract}. @xref{extract}.
  1963. @opsummary{list}
  1964. @item --list
  1965. @itemx -t
  1966. Lists the members in an archive. @xref{list}.
  1967. @opsummary{update}
  1968. @item --update
  1969. @itemx -u
  1970. Adds files to the end of the archive, but only if they are newer than
  1971. their counterparts already in the archive, or if they do not already
  1972. exist in the archive. @xref{update}.
  1973. @end table
  1974. @node Option Summary
  1975. @subsection @command{tar} Options
  1976. @table @option
  1977. @opsummary{absolute-names}
  1978. @item --absolute-names
  1979. @itemx -P
  1980. Normally when creating an archive, @command{tar} strips an initial
  1981. @samp{/} from member names, and when extracting from an archive @command{tar}
  1982. treats names specially if they have initial @samp{/} or internal
  1983. @samp{..}. This option disables that behavior. @xref{absolute}.
  1984. @opsummary{acls}
  1985. @item --acls
  1986. Enable POSIX ACLs support. @xref{Extended File Attributes, acls}.
  1987. @opsummary{after-date}
  1988. @item --after-date
  1989. (See @option{--newer}, @pxref{after})
  1990. @opsummary{anchored}
  1991. @item --anchored
  1992. A pattern must match an initial subsequence of the name's components.
  1993. @xref{controlling pattern-matching}.
  1994. @opsummary{atime-preserve}
  1995. @item --atime-preserve
  1996. @itemx --atime-preserve=replace
  1997. @itemx --atime-preserve=system
  1998. Attempt to preserve the access time of files when reading them. This
  1999. option currently is effective only on files that you own, unless you
  2000. have superuser privileges.
  2001. @option{--atime-preserve=replace} remembers the access time of a file
  2002. before reading it, and then restores the access time afterwards. This
  2003. may cause problems if other programs are reading the file at the same
  2004. time, as the times of their accesses will be lost. On most platforms
  2005. restoring the access time also requires @command{tar} to restore the
  2006. data modification time too, so this option may also cause problems if
  2007. other programs are writing the file at the same time (@command{tar} attempts
  2008. to detect this situation, but cannot do so reliably due to race
  2009. conditions). Worse, on most platforms restoring the access time also
  2010. updates the status change time, which means that this option is
  2011. incompatible with incremental backups.
  2012. @option{--atime-preserve=system} avoids changing time stamps on files,
  2013. without interfering with time stamp updates
  2014. caused by other programs, so it works better with incremental backups.
  2015. However, it requires a special @code{O_NOATIME} option from the
  2016. underlying operating and file system implementation, and it also requires
  2017. that searching directories does not update their access times. As of
  2018. this writing (November 2005) this works only with Linux, and only with
  2019. Linux kernels 2.6.8 and later. Worse, there is currently no reliable
  2020. way to know whether this feature actually works. Sometimes
  2021. @command{tar} knows that it does not work, and if you use
  2022. @option{--atime-preserve=system} then @command{tar} complains and
  2023. exits right away. But other times @command{tar} might think that the
  2024. option works when it actually does not.
  2025. Currently @option{--atime-preserve} with no operand defaults to
  2026. @option{--atime-preserve=replace}, but this may change in the future
  2027. as support for @option{--atime-preserve=system} improves.
  2028. If your operating or file system does not support
  2029. @option{--atime-preserve=@-system}, you might be able to preserve access
  2030. times reliably by using the @command{mount} command. For example,
  2031. you can mount the file system read-only, or access the file system via
  2032. a read-only loopback mount, or use the @samp{noatime} mount option
  2033. available on some systems. However, mounting typically requires
  2034. superuser privileges and can be a pain to manage.
  2035. @opsummary{auto-compress}
  2036. @item --auto-compress
  2037. @itemx -a
  2038. During a @option{--create} operation, enables automatic compressed
  2039. format recognition based on the archive suffix. The effect of this
  2040. option is cancelled by @option{--no-auto-compress}. @xref{gzip}.
  2041. @opsummary{backup}
  2042. @item --backup=@var{backup-type}
  2043. Rather than deleting files from the file system, @command{tar} will
  2044. back them up using simple or numbered backups, depending upon
  2045. @var{backup-type}. @xref{backup}.
  2046. @opsummary{block-number}
  2047. @item --block-number
  2048. @itemx -R
  2049. With this option present, @command{tar} prints error messages for read errors
  2050. with the block number in the archive file. @xref{block-number}.
  2051. @opsummary{blocking-factor}
  2052. @item --blocking-factor=@var{blocking}
  2053. @itemx -b @var{blocking}
  2054. Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
  2055. record. @xref{Blocking Factor}.
  2056. @opsummary{bzip2}
  2057. @item --bzip2
  2058. @itemx -j
  2059. This option tells @command{tar} to read or write archives through
  2060. @code{bzip2}. @xref{gzip}.
  2061. @opsummary{check-device}
  2062. @item --check-device
  2063. Check device numbers when creating a list of modified files for
  2064. incremental archiving. This is the default. @xref{device numbers},
  2065. for a detailed description.
  2066. @opsummary{checkpoint}
  2067. @item --checkpoint[=@var{number}]
  2068. This option directs @command{tar} to print periodic checkpoint
  2069. messages as it reads through the archive. It is intended for when you
  2070. want a visual indication that @command{tar} is still running, but
  2071. don't want to see @option{--verbose} output. You can also instruct
  2072. @command{tar} to execute a list of actions on each checkpoint, see
  2073. @option{--checkpoint-action} below. For a detailed description, see
  2074. @ref{checkpoints}.
  2075. @opsummary{checkpoint-action}
  2076. @item --checkpoint-action=@var{action}
  2077. Instruct @command{tar} to execute an action upon hitting a
  2078. breakpoint. Here we give only a brief outline. @xref{checkpoints},
  2079. for a complete description.
  2080. The @var{action} argument can be one of the following:
  2081. @table @asis
  2082. @item bell
  2083. Produce an audible bell on the console.
  2084. @item dot
  2085. @itemx .
  2086. Print a single dot on the standard listing stream.
  2087. @item echo
  2088. Display a textual message on the standard error, with the status and
  2089. number of the checkpoint. This is the default.
  2090. @item echo=@var{string}
  2091. Display @var{string} on the standard error. Before output, the string
  2092. is subject to meta-character expansion.
  2093. @item exec=@var{command}
  2094. Execute the given @var{command}.
  2095. @item sleep=@var{time}
  2096. Wait for @var{time} seconds.
  2097. @item ttyout=@var{string}
  2098. Output @var{string} on the current console (@file{/dev/tty}).
  2099. @item totals
  2100. Print statistics (see @pxref{totals}).
  2101. @item wait=@var{signo}
  2102. Wait for signal @var{signo}.
  2103. @end table
  2104. Several @option{--checkpoint-action} options can be specified. The
  2105. supplied actions will be executed in order of their appearance in the
  2106. command line.
  2107. Using @option{--checkpoint-action} without @option{--checkpoint}
  2108. assumes default checkpoint frequency of one checkpoint per 10 records.
  2109. @opsummary{check-links}
  2110. @item --check-links
  2111. @itemx -l
  2112. If this option was given, @command{tar} will check the number of links
  2113. dumped for each processed file. If this number does not match the
  2114. total number of hard links for the file, a warning message will be
  2115. output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
  2116. synonym for @option{--one-file-system}. The current semantics, which
  2117. complies to UNIX98, was introduced with version
  2118. 1.15.91. @xref{Changes}, for more information.}.
  2119. @xref{hard links}.
  2120. @opsummary{compress}
  2121. @opsummary{uncompress}
  2122. @item --compress
  2123. @itemx --uncompress
  2124. @itemx -Z
  2125. @command{tar} will use the @command{compress} program when reading or
  2126. writing the archive. This allows you to directly act on archives
  2127. while saving space. @xref{gzip}.
  2128. @opsummary{clamp-mtime}
  2129. @item --clamp-mtime
  2130. (See @option{--mtime}.)
  2131. @opsummary{confirmation}
  2132. @item --confirmation
  2133. (See @option{--interactive}.) @xref{interactive}.
  2134. @opsummary{delay-directory-restore}
  2135. @item --delay-directory-restore
  2136. Delay setting modification times and permissions of extracted
  2137. directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
  2138. @opsummary{dereference}
  2139. @item --dereference
  2140. @itemx -h
  2141. When reading or writing a file to be archived, @command{tar} accesses
  2142. the file that a symbolic link points to, rather than the symlink
  2143. itself. @xref{dereference}.
  2144. @opsummary{directory}
  2145. @item --directory=@var{dir}
  2146. @itemx -C @var{dir}
  2147. When this option is specified, @command{tar} will change its current directory
  2148. to @var{dir} before performing any operations. When this option is used
  2149. during archive creation, it is order sensitive. @xref{directory}.
  2150. @opsummary{exclude}
  2151. @item --exclude=@var{pattern}
  2152. When performing operations, @command{tar} will skip files that match
  2153. @var{pattern}. @xref{exclude}.
  2154. @opsummary{exclude-backups}
  2155. @item --exclude-backups
  2156. Exclude backup and lock files. @xref{exclude,, exclude-backups}.
  2157. @opsummary{exclude-from}
  2158. @item --exclude-from=@var{file}
  2159. @itemx -X @var{file}
  2160. Similar to @option{--exclude}, except @command{tar} will use the list of
  2161. patterns in the file @var{file}. @xref{exclude}.
  2162. @opsummary{exclude-caches}
  2163. @item --exclude-caches
  2164. Exclude from dump any directory containing a valid cache directory
  2165. tag file, but still dump the directory node and the tag file itself.
  2166. @xref{exclude,, exclude-caches}.
  2167. @opsummary{exclude-caches-under}
  2168. @item --exclude-caches-under
  2169. Exclude from dump any directory containing a valid cache directory
  2170. tag file, but still dump the directory node itself.
  2171. @xref{exclude}.
  2172. @opsummary{exclude-caches-all}
  2173. @item --exclude-caches-all
  2174. Exclude from dump any directory containing a valid cache directory
  2175. tag file. @xref{exclude}.
  2176. @opsummary{exclude-ignore}
  2177. @item --exclude-ignore=@var{file}
  2178. Before dumping a directory, @command{tar} checks if it contains
  2179. @var{file}. If so, exclusion patterns are read from this file.
  2180. The patterns affect only the directory itself. @xref{exclude}.
  2181. @opsummary{exclude-ignore-recursive}
  2182. @item --exclude-ignore-recursive=@var{file}
  2183. Before dumping a directory, @command{tar} checks if it contains
  2184. @var{file}. If so, exclusion patterns are read from this file.
  2185. The patterns affect the directory and all itssubdirectories.
  2186. @xref{exclude}.
  2187. @opsummary{exclude-tag}
  2188. @item --exclude-tag=@var{file}
  2189. Exclude from dump any directory containing file named @var{file}, but
  2190. dump the directory node and @var{file} itself. @xref{exclude,, exclude-tag}.
  2191. @opsummary{exclude-tag-under}
  2192. @item --exclude-tag-under=@var{file}
  2193. Exclude from dump the contents of any directory containing file
  2194. named @var{file}, but dump the directory node itself. @xref{exclude,,
  2195. exclude-tag-under}.
  2196. @opsummary{exclude-tag-all}
  2197. @item --exclude-tag-all=@var{file}
  2198. Exclude from dump any directory containing file named @var{file}.
  2199. @xref{exclude,,exclude-tag-all}.
  2200. @opsummary{exclude-vcs}
  2201. @item --exclude-vcs
  2202. Exclude from dump directories and files, that are internal for some
  2203. widely used version control systems.
  2204. @xref{exclude-vcs}.
  2205. @opsummary{exclude-vcs-ignores}
  2206. @item --exclude-vcs-ignores
  2207. Exclude files that match patterns read from VCS-specific ignore
  2208. files. Supported files are: @file{.cvsignore}, @file{.gitignore},
  2209. @file{.bzrignore}, and @file{.hgignore}. The semantics of each file
  2210. is the same as for the corresponding VCS, e.g. patterns read from
  2211. @file{.gitignore} affect the directory and all its subdirectories.
  2212. @xref{exclude-vcs-ignores}.
  2213. @opsummary{file}
  2214. @item --file=@var{archive}
  2215. @itemx -f @var{archive}
  2216. @command{tar} will use the file @var{archive} as the @command{tar} archive it
  2217. performs operations on, rather than @command{tar}'s compilation dependent
  2218. default. @xref{file tutorial}.
  2219. @opsummary{files-from}
  2220. @item --files-from=@var{file}
  2221. @itemx -T @var{file}
  2222. @command{tar} will use the contents of @var{file} as a list of archive members
  2223. or files to operate on, in addition to those specified on the
  2224. command-line. @xref{files}.
  2225. @opsummary{force-local}
  2226. @item --force-local
  2227. Forces @command{tar} to interpret the file name given to @option{--file}
  2228. as a local file, even if it looks like a remote tape drive name.
  2229. @xref{local and remote archives}.
  2230. @opsummary{format}
  2231. @item --format=@var{format}
  2232. @itemx -H @var{format}
  2233. Selects output archive format. @var{Format} may be one of the
  2234. following:
  2235. @table @samp
  2236. @item v7
  2237. Creates an archive that is compatible with Unix V7 @command{tar}.
  2238. @item oldgnu
  2239. Creates an archive that is compatible with GNU @command{tar} version
  2240. 1.12 or earlier.
  2241. @item gnu
  2242. Creates archive in GNU tar 1.13 format. Basically it is the same as
  2243. @samp{oldgnu} with the only difference in the way it handles long
  2244. numeric fields.
  2245. @item ustar
  2246. Creates a @acronym{POSIX.1-1988} compatible archive.
  2247. @item posix
  2248. Creates a @acronym{POSIX.1-2001} archive.
  2249. @end table
  2250. @xref{Formats}, for a detailed discussion of these formats.
  2251. @opsummary{full-time}
  2252. @item --full-time
  2253. This option instructs @command{tar} to print file times to their full
  2254. resolution. Usually this means 1-second resolution, but that depends
  2255. on the underlying file system. The @option{--full-time} option takes
  2256. effect only when detailed output (verbosity level 2 or higher) has
  2257. been requested using the @option{--verbose} option, e.g., when listing
  2258. or extracting archives:
  2259. @smallexample
  2260. $ @kbd{tar -t -v --full-time -f archive.tar}
  2261. @end smallexample
  2262. @noindent
  2263. or, when creating an archive:
  2264. @smallexample
  2265. $ @kbd{tar -c -vv --full-time -f archive.tar .}
  2266. @end smallexample
  2267. Notice, thar when creating the archive you need to specify
  2268. @option{--verbose} twice to get a detailed output (@pxref{verbose
  2269. tutorial}).
  2270. @opsummary{group}
  2271. @item --group=@var{group}
  2272. Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
  2273. rather than the group from the source file. @var{group} can specify a
  2274. symbolic name, or a numeric @acronym{ID}, or both as
  2275. @var{name}:@var{id}. @xref{override}.
  2276. Also see the @option{--group-map} option and comments for the
  2277. @option{--owner=@var{user}} option.
  2278. @opsummary{group-map}
  2279. @item --group-map=@var{file}
  2280. Read owner group translation map from @var{file}. This option allows to
  2281. translate only certain group names and/or UIDs. @xref{override}, for a
  2282. detailed description. When used together with @option{--group}
  2283. option, the latter affects only those files whose owner group is not listed
  2284. in the @var{file}.
  2285. This option does not affect extraction from archives.
  2286. @opsummary{gzip}
  2287. @opsummary{gunzip}
  2288. @opsummary{ungzip}
  2289. @item --gzip
  2290. @itemx --gunzip
  2291. @itemx --ungzip
  2292. @itemx -z
  2293. This option tells @command{tar} to read or write archives through
  2294. @command{gzip}, allowing @command{tar} to directly operate on several
  2295. kinds of compressed archives transparently. @xref{gzip}.
  2296. @opsummary{hard-dereference}
  2297. @item --hard-dereference
  2298. When creating an archive, dereference hard links and store the files
  2299. they refer to, instead of creating usual hard link members.
  2300. @xref{hard links}.
  2301. @opsummary{help}
  2302. @item --help
  2303. @itemx -?
  2304. @command{tar} will print out a short message summarizing the operations and
  2305. options to @command{tar} and exit. @xref{help}.
  2306. @opsummary{hole-detection}
  2307. @item --hole-detection=@var{method}
  2308. Use @var{method} to detect holes in sparse files. This option implies
  2309. @option{--sparse}. Valid methods are @samp{seek} and @samp{raw}.
  2310. Default is @samp{seek} with fallback to @samp{raw} when not
  2311. applicable. @xref{sparse}.
  2312. @opsummary{ignore-case}
  2313. @item --ignore-case
  2314. Ignore case when matching member or file names with
  2315. patterns. @xref{controlling pattern-matching}.
  2316. @opsummary{ignore-command-error}
  2317. @item --ignore-command-error
  2318. Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
  2319. @opsummary{ignore-failed-read}
  2320. @item --ignore-failed-read
  2321. Do not exit unsuccessfully merely because reading failed.
  2322. @xref{Ignore Failed Read}.
  2323. @opsummary{ignore-zeros}
  2324. @item --ignore-zeros
  2325. @itemx -i
  2326. With this option, @command{tar} will ignore zeroed blocks in the
  2327. archive, which normally signals EOF. This option also suppresses
  2328. warnings about missing or incomplete zero blocks at the end of the
  2329. archive. @xref{Ignore Zeros}.
  2330. @opsummary{incremental}
  2331. @item --incremental
  2332. @itemx -G
  2333. Informs @command{tar} that it is working with an old
  2334. @acronym{GNU}-format incremental backup archive. It is intended
  2335. primarily for backwards compatibility only. @xref{Incremental Dumps},
  2336. for a detailed discussion of incremental archives.
  2337. @opsummary{index-file}
  2338. @item --index-file=@var{file}
  2339. Send verbose output to @var{file} instead of to standard output.
  2340. @opsummary{info-script}
  2341. @opsummary{new-volume-script}
  2342. @item --info-script=@var{command}
  2343. @itemx --new-volume-script=@var{command}
  2344. @itemx -F @var{command}
  2345. When @command{tar} is performing multi-tape backups, @var{command} is run
  2346. at the end of each tape. If it exits with nonzero status,
  2347. @command{tar} fails immediately. @xref{info-script}, for a detailed
  2348. discussion of this feature.
  2349. @opsummary{interactive}
  2350. @item --interactive
  2351. @itemx --confirmation
  2352. @itemx -w
  2353. Specifies that @command{tar} should ask the user for confirmation before
  2354. performing potentially destructive options, such as overwriting files.
  2355. @xref{interactive}.
  2356. @opsummary{keep-directory-symlink}
  2357. @item --keep-directory-symlink
  2358. This option changes the behavior of tar when it encounters a symlink
  2359. with the same name as the directory that it is about to extract. By
  2360. default, in this case tar would first remove the symlink and then
  2361. proceed extracting the directory.
  2362. The @option{--keep-directory-symlink} option disables this behavior
  2363. and instructs tar to follow symlinks to directories when extracting
  2364. from the archive.
  2365. It is mainly intended to provide compatibility with the Slackware
  2366. installation scripts.
  2367. @opsummary{keep-newer-files}
  2368. @item --keep-newer-files
  2369. Do not replace existing files that are newer than their archive copies
  2370. when extracting files from an archive.
  2371. @opsummary{keep-old-files}
  2372. @item --keep-old-files
  2373. @itemx -k
  2374. Do not overwrite existing files when extracting files from an
  2375. archive. Return error if such files exist. See also
  2376. @ref{--skip-old-files}.
  2377. @xref{Keep Old Files}.
  2378. @opsummary{label}
  2379. @item --label=@var{name}
  2380. @itemx -V @var{name}
  2381. When creating an archive, instructs @command{tar} to write @var{name}
  2382. as a name record in the archive. When extracting or listing archives,
  2383. @command{tar} will only operate on archives that have a label matching
  2384. the pattern specified in @var{name}. @xref{Tape Files}.
  2385. @opsummary{level}
  2386. @item --level=@var{n}
  2387. Force incremental backup of level @var{n}. As of @GNUTAR{} version
  2388. @value{VERSION}, the option @option{--level=0} truncates the snapshot
  2389. file, thereby forcing the level 0 dump. Other values of @var{n} are
  2390. effectively ignored. @xref{--level=0}, for details and examples.
  2391. The use of this option is valid only in conjunction with the
  2392. @option{--listed-incremental} option. @xref{Incremental Dumps},
  2393. for a detailed description.
  2394. @opsummary{listed-incremental}
  2395. @item --listed-incremental=@var{snapshot-file}
  2396. @itemx -g @var{snapshot-file}
  2397. During a @option{--create} operation, specifies that the archive that
  2398. @command{tar} creates is a new @acronym{GNU}-format incremental
  2399. backup, using @var{snapshot-file} to determine which files to backup.
  2400. With other operations, informs @command{tar} that the archive is in
  2401. incremental format. @xref{Incremental Dumps}.
  2402. @opsummary{lzip}
  2403. @item --lzip
  2404. This option tells @command{tar} to read or write archives through
  2405. @command{lzip}. @xref{gzip}.
  2406. @opsummary{lzma}
  2407. @item --lzma
  2408. This option tells @command{tar} to read or write archives through
  2409. @command{lzma}. @xref{gzip}.
  2410. @item --lzop
  2411. This option tells @command{tar} to read or write archives through
  2412. @command{lzop}. @xref{gzip}.
  2413. @opsummary{mode}
  2414. @item --mode=@var{permissions}
  2415. When adding files to an archive, @command{tar} will use
  2416. @var{permissions} for the archive members, rather than the permissions
  2417. from the files. @var{permissions} can be specified either as an octal
  2418. number or as symbolic permissions, like with
  2419. @command{chmod}. @xref{override}.
  2420. @opsummary{mtime}
  2421. @item --mtime=@var{date}
  2422. When adding files to an archive, @command{tar} will use @var{date} as
  2423. the modification time of members when creating archives, instead of
  2424. their actual modification times. The value of @var{date} can be
  2425. either a textual date representation (@pxref{Date input formats}) or a
  2426. name of the existing file, starting with @samp{/} or @samp{.}. In the
  2427. latter case, the modification time of that file is used. @xref{override}.
  2428. When @command{--clamp-mtime} is also specified, files with
  2429. modification times earlier than @var{date} will retain their actual
  2430. modification times, and @var{date} will be used only for files with
  2431. modification times later than @var{date}.
  2432. @opsummary{multi-volume}
  2433. @item --multi-volume
  2434. @itemx -M
  2435. Informs @command{tar} that it should create or otherwise operate on a
  2436. multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
  2437. @opsummary{new-volume-script}
  2438. @item --new-volume-script
  2439. (see @option{--info-script})
  2440. @opsummary{newer}
  2441. @item --newer=@var{date}
  2442. @itemx --after-date=@var{date}
  2443. @itemx -N
  2444. When creating an archive, @command{tar} will only add files that have changed
  2445. since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
  2446. is taken to be the name of a file whose data modification time specifies
  2447. the date. @xref{after}.
  2448. @opsummary{newer-mtime}
  2449. @item --newer-mtime=@var{date}
  2450. Like @option{--newer}, but add only files whose
  2451. contents have changed (as opposed to just @option{--newer}, which will
  2452. also back up files for which any status information has
  2453. changed). @xref{after}.
  2454. @opsummary{no-acls}
  2455. @item --no-acls
  2456. Disable the POSIX ACLs support. @xref{Extended File Attributes, acls}.
  2457. @opsummary{no-anchored}
  2458. @item --no-anchored
  2459. An exclude pattern can match any subsequence of the name's components.
  2460. @xref{controlling pattern-matching}.
  2461. @opsummary{no-auto-compress}
  2462. @item --no-auto-compress
  2463. Disables automatic compressed format recognition based on the archive
  2464. suffix. @xref{--auto-compress}. @xref{gzip}.
  2465. @opsummary{no-check-device}
  2466. @item --no-check-device
  2467. Do not check device numbers when creating a list of modified files
  2468. for incremental archiving. @xref{device numbers}, for
  2469. a detailed description.
  2470. @opsummary{no-delay-directory-restore}
  2471. @item --no-delay-directory-restore
  2472. Modification times and permissions of extracted
  2473. directories are set when all files from this directory have been
  2474. extracted. This is the default.
  2475. @xref{Directory Modification Times and Permissions}.
  2476. @opsummary{no-ignore-case}
  2477. @item --no-ignore-case
  2478. Use case-sensitive matching.
  2479. @xref{controlling pattern-matching}.
  2480. @opsummary{no-ignore-command-error}
  2481. @item --no-ignore-command-error
  2482. Print warnings about subprocesses that terminated with a nonzero exit
  2483. code. @xref{Writing to an External Program}.
  2484. @opsummary{no-null}
  2485. @item --no-null
  2486. If the @option{--null} option was given previously, this option
  2487. cancels its effect, so that any following @option{--files-from}
  2488. options will expect their file lists to be newline-terminated.
  2489. @opsummary{no-overwrite-dir}
  2490. @item --no-overwrite-dir
  2491. Preserve metadata of existing directories when extracting files
  2492. from an archive. @xref{Overwrite Old Files}.
  2493. @opsummary{no-quote-chars}
  2494. @item --no-quote-chars=@var{string}
  2495. Remove characters listed in @var{string} from the list of quoted
  2496. characters set by the previous @option{--quote-chars} option
  2497. (@pxref{quoting styles}).
  2498. @opsummary{no-recursion}
  2499. @item --no-recursion
  2500. With this option, @command{tar} will not recurse into directories.
  2501. @xref{recurse}.
  2502. @opsummary{no-same-owner}
  2503. @item --no-same-owner
  2504. @itemx -o
  2505. When extracting an archive, do not attempt to preserve the owner
  2506. specified in the @command{tar} archive. This the default behavior
  2507. for ordinary users.
  2508. @opsummary{no-same-permissions}
  2509. @item --no-same-permissions
  2510. When extracting an archive, subtract the user's umask from files from
  2511. the permissions specified in the archive. This is the default behavior
  2512. for ordinary users.
  2513. @opsummary{no-seek}
  2514. @item --no-seek
  2515. The archive media does not support seeks to arbitrary
  2516. locations. Usually @command{tar} determines automatically whether
  2517. the archive can be seeked or not. Use this option to disable this
  2518. mechanism.
  2519. @opsummary{no-selinux}
  2520. @item --no-selinux
  2521. Disable SELinux context support. @xref{Extended File Attributes, SELinux}.
  2522. @opsummary{no-unquote}
  2523. @item --no-unquote
  2524. Treat all input file or member names literally, do not interpret
  2525. escape sequences. @xref{input name quoting}.
  2526. @opsummary{no-verbatim-files-from}
  2527. @item --no-verbatim-files-from
  2528. Instructs @GNUTAR{} to treat each line read from a file list as if it
  2529. were supplied in the command line. I.e., leading and trailing
  2530. whitespace is removed and, if the result begins with a dash, it is
  2531. treated as a @GNUTAR{} command line option.
  2532. This is default behavior. This option is provided as a way to restore
  2533. it after @option{--verbatim-files-from} option.
  2534. It is implied by the @option{--no-null} option.
  2535. @xref{no-verbatim-files-from}.
  2536. @opsummary{no-wildcards}
  2537. @item --no-wildcards
  2538. Do not use wildcards.
  2539. @xref{controlling pattern-matching}.
  2540. @opsummary{no-wildcards-match-slash}
  2541. @item --no-wildcards-match-slash
  2542. Wildcards do not match @samp{/}.
  2543. @xref{controlling pattern-matching}.
  2544. @opsummary{no-xattrs}
  2545. @item --no-xattrs
  2546. Disable extended attributes support. @xref{Extended File Attributes, xattrs}.
  2547. @opsummary{null}
  2548. @item --null
  2549. When @command{tar} is using the @option{--files-from} option, this option
  2550. instructs @command{tar} to expect file names terminated with
  2551. @acronym{NUL}, and to process file names verbatim.
  2552. This means that @command{tar} correctly works with file names that
  2553. contain newlines or begin with a dash.
  2554. @xref{nul}.
  2555. See also @ref{verbatim-files-from}.
  2556. @opsummary{numeric-owner}
  2557. @item --numeric-owner
  2558. This option will notify @command{tar} that it should use numeric user
  2559. and group IDs when creating a @command{tar} file, rather than names.
  2560. @xref{Attributes}.
  2561. @item -o
  2562. The function of this option depends on the action @command{tar} is
  2563. performing. When extracting files, @option{-o} is a synonym for
  2564. @option{--no-same-owner}, i.e., it prevents @command{tar} from
  2565. restoring ownership of files being extracted.
  2566. When creating an archive, it is a synonym for
  2567. @option{--old-archive}. This behavior is for compatibility
  2568. with previous versions of @GNUTAR{}, and will be
  2569. removed in future releases.
  2570. @xref{Changes}, for more information.
  2571. @opsummary{occurrence}
  2572. @item --occurrence[=@var{number}]
  2573. This option can be used in conjunction with one of the subcommands
  2574. @option{--delete}, @option{--diff}, @option{--extract} or
  2575. @option{--list} when a list of files is given either on the command
  2576. line or via @option{-T} option.
  2577. This option instructs @command{tar} to process only the @var{number}th
  2578. occurrence of each named file. @var{Number} defaults to 1, so
  2579. @smallexample
  2580. tar -x -f archive.tar --occurrence filename
  2581. @end smallexample
  2582. @noindent
  2583. will extract the first occurrence of the member @file{filename} from @file{archive.tar}
  2584. and will terminate without scanning to the end of the archive.
  2585. @opsummary{old-archive}
  2586. @item --old-archive
  2587. Synonym for @option{--format=v7}.
  2588. @opsummary{one-file-system}
  2589. @item --one-file-system
  2590. Used when creating an archive. Prevents @command{tar} from recursing into
  2591. directories that are on different file systems from the current
  2592. directory.
  2593. @opsummary{one-top-level}
  2594. @item --one-top-level[=@var{dir}]
  2595. Tells @command{tar} to create a new directory beneath the extraction directory
  2596. (or the one passed to @option{-C}) and use it to guard against
  2597. tarbombs. In the absence of @var{dir} argument, the name of the new directory
  2598. will be equal to the base name of the archive (file name minus the
  2599. archive suffix, if recognized). Any member names that do not begin
  2600. with that directory name (after
  2601. transformations from @option{--transform} and
  2602. @option{--strip-components}) will be prefixed with it. Recognized
  2603. file name suffixes are @samp{.tar}, and any compression suffixes
  2604. recognizable by @xref{--auto-compress}.
  2605. @opsummary{overwrite}
  2606. @item --overwrite
  2607. Overwrite existing files and directory metadata when extracting files
  2608. from an archive. @xref{Overwrite Old Files}.
  2609. @opsummary{overwrite-dir}
  2610. @item --overwrite-dir
  2611. Overwrite the metadata of existing directories when extracting files
  2612. from an archive. @xref{Overwrite Old Files}.
  2613. @opsummary{owner}
  2614. @item --owner=@var{user}
  2615. Specifies that @command{tar} should use @var{user} as the owner of members
  2616. when creating archives, instead of the user associated with the source
  2617. file. @var{user} can specify a symbolic name, or a numeric
  2618. @acronym{ID}, or both as @var{name}:@var{id}.
  2619. @xref{override}.
  2620. This option does not affect extraction from archives. See also
  2621. @option{--owner-map}, below.
  2622. @opsummary{owner-map}
  2623. @item --owner-map=@var{file}
  2624. Read owner translation map from @var{file}. This option allows to
  2625. translate only certain owner names or UIDs. @xref{override}, for a
  2626. detailed description. When used together with @option{--owner}
  2627. option, the latter affects only those files whose owner is not listed
  2628. in the @var{file}.
  2629. This option does not affect extraction from archives.
  2630. @opsummary{pax-option}
  2631. @item --pax-option=@var{keyword-list}
  2632. This option enables creation of the archive in @acronym{POSIX.1-2001}
  2633. format (@pxref{posix}) and modifies the way @command{tar} handles the
  2634. extended header keywords. @var{Keyword-list} is a comma-separated
  2635. list of keyword options. @xref{PAX keywords}, for a detailed
  2636. discussion.
  2637. @opsummary{portability}
  2638. @item --portability
  2639. @itemx --old-archive
  2640. Synonym for @option{--format=v7}.
  2641. @opsummary{posix}
  2642. @item --posix
  2643. Same as @option{--format=posix}.
  2644. @opsummary{preserve-order}
  2645. @item --preserve-order
  2646. (See @option{--same-order}; @pxref{Same Order}.)
  2647. @opsummary{preserve-permissions}
  2648. @opsummary{same-permissions}
  2649. @item --preserve-permissions
  2650. @itemx --same-permissions
  2651. @itemx -p
  2652. When @command{tar} is extracting an archive, it normally subtracts the
  2653. users' umask from the permissions specified in the archive and uses
  2654. that number as the permissions to create the destination file.
  2655. Specifying this option instructs @command{tar} that it should use the
  2656. permissions directly from the archive. @xref{Setting Access Permissions}.
  2657. @opsummary{quote-chars}
  2658. @item --quote-chars=@var{string}
  2659. Always quote characters from @var{string}, even if the selected
  2660. quoting style would not quote them (@pxref{quoting styles}).
  2661. @opsummary{quoting-style}
  2662. @item --quoting-style=@var{style}
  2663. Set quoting style to use when printing member and file names
  2664. (@pxref{quoting styles}). Valid @var{style} values are:
  2665. @code{literal}, @code{shell}, @code{shell-always}, @code{c},
  2666. @code{escape}, @code{locale}, and @code{clocale}. Default quoting
  2667. style is @code{escape}, unless overridden while configuring the
  2668. package.
  2669. @opsummary{read-full-records}
  2670. @item --read-full-records
  2671. @itemx -B
  2672. Specifies that @command{tar} should reblock its input, for reading
  2673. from pipes on systems with buggy implementations. @xref{Reading}.
  2674. @opsummary{record-size}
  2675. @item --record-size=@var{size}[@var{suf}]
  2676. Instructs @command{tar} to use @var{size} bytes per record when accessing the
  2677. archive. The argument can be suffixed with a @dfn{size suffix}, e.g.
  2678. @option{--record-size=10K} for 10 Kilobytes. @xref{size-suffixes},
  2679. for a list of valid suffixes. @xref{Blocking Factor}, for a detailed
  2680. description of this option.
  2681. @opsummary{recursion}
  2682. @item --recursion
  2683. With this option, @command{tar} recurses into directories (default).
  2684. @xref{recurse}.
  2685. @opsummary{recursive-unlink}
  2686. @item --recursive-unlink
  2687. Remove existing
  2688. directory hierarchies before extracting directories of the same name
  2689. from the archive. @xref{Recursive Unlink}.
  2690. @opsummary{remove-files}
  2691. @item --remove-files
  2692. Directs @command{tar} to remove the source file from the file system after
  2693. appending it to an archive. @xref{remove files}.
  2694. @opsummary{restrict}
  2695. @item --restrict
  2696. Disable use of some potentially harmful @command{tar} options.
  2697. Currently this option disables shell invocation from multi-volume menu
  2698. (@pxref{Using Multiple Tapes}).
  2699. @opsummary{rmt-command}
  2700. @item --rmt-command=@var{cmd}
  2701. Notifies @command{tar} that it should use @var{cmd} instead of
  2702. the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
  2703. @opsummary{rsh-command}
  2704. @item --rsh-command=@var{cmd}
  2705. Notifies @command{tar} that is should use @var{cmd} to communicate with remote
  2706. devices. @xref{Device}.
  2707. @opsummary{same-order}
  2708. @item --same-order
  2709. @itemx --preserve-order
  2710. @itemx -s
  2711. This option is an optimization for @command{tar} when running on machines with
  2712. small amounts of memory. It informs @command{tar} that the list of file
  2713. arguments has already been sorted to match the order of files in the
  2714. archive. @xref{Same Order}.
  2715. @opsummary{same-owner}
  2716. @item --same-owner
  2717. When extracting an archive, @command{tar} will attempt to preserve the owner
  2718. specified in the @command{tar} archive with this option present.
  2719. This is the default behavior for the superuser; this option has an
  2720. effect only for ordinary users. @xref{Attributes}.
  2721. @opsummary{same-permissions}
  2722. @item --same-permissions
  2723. (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
  2724. @opsummary{seek}
  2725. @item --seek
  2726. @itemx -n
  2727. Assume that the archive media supports seeks to arbitrary
  2728. locations. Usually @command{tar} determines automatically whether
  2729. the archive can be seeked or not. This option is intended for use
  2730. in cases when such recognition fails. It takes effect only if the
  2731. archive is open for reading (e.g. with @option{--list} or
  2732. @option{--extract} options).
  2733. @opsummary{selinux}
  2734. @item --selinux
  2735. Enable the SELinux context support.
  2736. @xref{Extended File Attributes, selinux}.
  2737. @opsummary{show-defaults}
  2738. @item --show-defaults
  2739. Displays the default options used by @command{tar} and exits
  2740. successfully. This option is intended for use in shell scripts.
  2741. Here is an example of what you can see using this option:
  2742. @smallexample
  2743. $ @kbd{tar --show-defaults}
  2744. --format=gnu -f- -b20 --quoting-style=escape
  2745. --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
  2746. @end smallexample
  2747. @noindent
  2748. Notice, that this option outputs only one line. The example output
  2749. above has been split to fit page boundaries. @xref{defaults}.
  2750. @opsummary{show-omitted-dirs}
  2751. @item --show-omitted-dirs
  2752. Instructs @command{tar} to mention the directories it is skipping when
  2753. operating on a @command{tar} archive. @xref{show-omitted-dirs}.
  2754. @opsummary{show-snapshot-field-ranges}
  2755. @item --show-snapshot-field-ranges
  2756. Displays the range of values allowed by this version of @command{tar}
  2757. for each field in the snapshot file, then exits successfully.
  2758. @xref{Snapshot Files}.
  2759. @opsummary{show-transformed-names}
  2760. @opsummary{show-stored-names}
  2761. @item --show-transformed-names
  2762. @itemx --show-stored-names
  2763. Display file or member names after applying any transformations
  2764. (@pxref{transform}). In particular, when used in conjunction with one of
  2765. the archive creation operations it instructs @command{tar} to list the
  2766. member names stored in the archive, as opposed to the actual file
  2767. names. @xref{listing member and file names}.
  2768. @opsummary{skip-old-files}
  2769. @item --skip-old-files
  2770. Do not overwrite existing files when extracting files from an
  2771. archive. @xref{Keep Old Files}.
  2772. This option differs from @option{--keep-old-files} in that it does not
  2773. treat such files as an error, instead it just silently avoids
  2774. overwriting them.
  2775. The @option{--warning=existing-file} option can be used together with
  2776. this option to produce warning messages about existing old files
  2777. (@pxref{warnings}).
  2778. @opsummary{sort}
  2779. @item --sort=@var{order}
  2780. Specify the directory sorting order when reading directories.
  2781. @var{Order} may be one of the following:
  2782. @table @samp
  2783. @item none
  2784. No directory sorting is performed. This is the default.
  2785. @item name
  2786. Sort the directory entries on name. The operating system may deliver
  2787. directory entries in a more or less random order, and sorting them
  2788. makes archive creation more reproducible. @xref{Reproducibility}.
  2789. @item inode
  2790. Sort the directory entries on inode number. Sorting directories on
  2791. inode number may reduce the amount of disk seek operations when
  2792. creating an archive for some file systems.
  2793. @end table
  2794. @opsummary{sparse}
  2795. @item --sparse
  2796. @itemx -S
  2797. Invokes a @acronym{GNU} extension when adding files to an archive that handles
  2798. sparse files efficiently. @xref{sparse}.
  2799. @opsummary{sparse-version}
  2800. @item --sparse-version=@var{version}
  2801. Specifies the @dfn{format version} to use when archiving sparse
  2802. files. Implies @option{--sparse}. @xref{sparse}. For the description
  2803. of the supported sparse formats, @xref{Sparse Formats}.
  2804. @opsummary{starting-file}
  2805. @item --starting-file=@var{name}
  2806. @itemx -K @var{name}
  2807. This option affects extraction only; @command{tar} will skip extracting
  2808. files in the archive until it finds one that matches @var{name}.
  2809. @xref{Scarce}.
  2810. @opsummary{strip-components}
  2811. @item --strip-components=@var{number}
  2812. Strip given @var{number} of leading components from file names before
  2813. extraction. For example, if archive @file{archive.tar} contained
  2814. @file{/some/file/name}, then running
  2815. @smallexample
  2816. tar --extract --file archive.tar --strip-components=2
  2817. @end smallexample
  2818. @noindent
  2819. would extract this file to file @file{name}.
  2820. @xref{transform}.
  2821. @opsummary{suffix}
  2822. @item --suffix=@var{suffix}
  2823. Alters the suffix @command{tar} uses when backing up files from the default
  2824. @samp{~}. @xref{backup}.
  2825. @opsummary{tape-length}
  2826. @item --tape-length=@var{num}[@var{suf}]
  2827. @itemx -L @var{num}[@var{suf}]
  2828. Specifies the length of tapes that @command{tar} is writing as being
  2829. @w{@var{num} x 1024} bytes long. If optional @var{suf} is given, it
  2830. specifies a multiplicative factor to be used instead of 1024. For
  2831. example, @samp{-L2M} means 2 megabytes. @xref{size-suffixes}, for a
  2832. list of allowed suffixes. @xref{Using Multiple Tapes}, for a detailed
  2833. discussion of this option.
  2834. @opsummary{test-label}
  2835. @item --test-label
  2836. Reads the volume label. If an argument is specified, test whether it
  2837. matches the volume label. @xref{--test-label option}.
  2838. @opsummary{to-command}
  2839. @item --to-command=@var{command}
  2840. During extraction @command{tar} will pipe extracted files to the
  2841. standard input of @var{command}. @xref{Writing to an External Program}.
  2842. @opsummary{to-stdout}
  2843. @item --to-stdout
  2844. @itemx -O
  2845. During extraction, @command{tar} will extract files to stdout rather
  2846. than to the file system. @xref{Writing to Standard Output}.
  2847. @opsummary{totals}
  2848. @item --totals[=@var{signo}]
  2849. Displays the total number of bytes transferred when processing an
  2850. archive. If an argument is given, these data are displayed on
  2851. request, when signal @var{signo} is delivered to @command{tar}.
  2852. @xref{totals}.
  2853. @opsummary{touch}
  2854. @item --touch
  2855. @itemx -m
  2856. Sets the data modification time of extracted files to the extraction time,
  2857. rather than the data modification time stored in the archive.
  2858. @xref{Data Modification Times}.
  2859. @opsummary{transform}
  2860. @opsummary{xform}
  2861. @item --transform=@var{sed-expr}
  2862. @itemx --xform=@var{sed-expr}
  2863. Transform file or member names using @command{sed} replacement expression
  2864. @var{sed-expr}. For example,
  2865. @smallexample
  2866. $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
  2867. @end smallexample
  2868. @noindent
  2869. will add to @file{archive} files from the current working directory,
  2870. replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
  2871. discussion, @xref{transform}.
  2872. To see transformed member names in verbose listings, use
  2873. @option{--show-transformed-names} option
  2874. (@pxref{show-transformed-names}).
  2875. @opsummary{uncompress}
  2876. @item --uncompress
  2877. (See @option{--compress}, @pxref{gzip})
  2878. @opsummary{ungzip}
  2879. @item --ungzip
  2880. (See @option{--gzip}, @pxref{gzip})
  2881. @opsummary{unlink-first}
  2882. @item --unlink-first
  2883. @itemx -U
  2884. Directs @command{tar} to remove the corresponding file from the file
  2885. system before extracting it from the archive. @xref{Unlink First}.
  2886. @opsummary{unquote}
  2887. @item --unquote
  2888. Enable unquoting input file or member names (default). @xref{input
  2889. name quoting}.
  2890. @opsummary{use-compress-program}
  2891. @item --use-compress-program=@var{prog}
  2892. @itemx -I=@var{prog}
  2893. Instructs @command{tar} to access the archive through @var{prog}, which is
  2894. presumed to be a compression program of some sort. @xref{gzip}.
  2895. @opsummary{utc}
  2896. @item --utc
  2897. Display file modification dates in @acronym{UTC}. This option implies
  2898. @option{--verbose}.
  2899. @opsummary{verbatim-files-from}
  2900. @item --verbatim-files-from
  2901. Instructs @GNUTAR{} to treat each line read from a file list as a file
  2902. name, even if it starts with a dash.
  2903. File lists are supplied with the @option{--files-from} (@option{-T})
  2904. option. By default, each line read from a file list is first trimmed
  2905. off the leading and trailing whitespace and, if the result begins with
  2906. a dash, it is treated as a @GNUTAR{} command line option.
  2907. Use the @option{--verbatim-files-from} option to disable this special
  2908. handling. This facilitates the use of @command{tar} with file lists
  2909. created by @command{file} command.
  2910. This option affects all @option{--files-from} options that occur after
  2911. it in the command line. Its effect is reverted by the
  2912. @option{--no-verbatim-files-from} option.
  2913. This option is implied by the @option{--null} option.
  2914. @xref{verbatim-files-from}.
  2915. @opsummary{verbose}
  2916. @item --verbose
  2917. @itemx -v
  2918. Specifies that @command{tar} should be more verbose about the
  2919. operations it is performing. This option can be specified multiple
  2920. times for some operations to increase the amount of information displayed.
  2921. @xref{verbose}.
  2922. @opsummary{verify}
  2923. @item --verify
  2924. @itemx -W
  2925. Verifies that the archive was correctly written when creating an
  2926. archive. @xref{verify}.
  2927. @opsummary{version}
  2928. @item --version
  2929. Print information about the program's name, version, origin and legal
  2930. status, all on standard output, and then exit successfully.
  2931. @xref{help}.
  2932. @opsummary{volno-file}
  2933. @item --volno-file=@var{file}
  2934. Used in conjunction with @option{--multi-volume}. @command{tar} will
  2935. keep track of which volume of a multi-volume archive it is working in
  2936. @var{file}. @xref{volno-file}.
  2937. @opsummary{warning}
  2938. @item --warning=@var{keyword}
  2939. Enable or disable warning messages identified by @var{keyword}. The
  2940. messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
  2941. @xref{warnings}.
  2942. @opsummary{wildcards}
  2943. @item --wildcards
  2944. Use wildcards when matching member names with patterns.
  2945. @xref{controlling pattern-matching}.
  2946. @opsummary{wildcards-match-slash}
  2947. @item --wildcards-match-slash
  2948. Wildcards match @samp{/}.
  2949. @xref{controlling pattern-matching}.
  2950. @opsummary{xattrs}
  2951. @item --xattrs
  2952. Enable extended attributes support. @xref{Extended File Attributes, xattrs}.
  2953. @opsummary{xattrs-exclude}
  2954. @item --xattrs-exclude=@var{pattern}
  2955. Specify exclude pattern for xattr keys.
  2956. @xref{Extended File Attributes, xattrs-exclude}.
  2957. @opsummary{xattrs-include}
  2958. @item --xattrs-include=@var{pattern}.
  2959. Specify include pattern for xattr keys. @var{pattern} is a globbing
  2960. pattern, e.g. @samp{--xattrs-include='user.*'} to include
  2961. only attributes from the user namespace.
  2962. @xref{Extended File Attributes, xattrs-include}.
  2963. @opsummary{xz}
  2964. @item --xz
  2965. @itemx -J
  2966. Use @command{xz} for compressing or decompressing the archives. @xref{gzip}.
  2967. @item --zstd
  2968. Use @command{zstd} for compressing or decompressing the archives. @xref{gzip}.
  2969. @end table
  2970. @node Short Option Summary
  2971. @subsection Short Options Cross Reference
  2972. Here is an alphabetized list of all of the short option forms, matching
  2973. them with the equivalent long option.
  2974. @multitable @columnfractions 0.20 0.80
  2975. @headitem Short Option @tab Reference
  2976. @item -A @tab @ref{--concatenate}.
  2977. @item -B @tab @ref{--read-full-records}.
  2978. @item -C @tab @ref{--directory}.
  2979. @item -F @tab @ref{--info-script}.
  2980. @item -G @tab @ref{--incremental}.
  2981. @item -J @tab @ref{--xz}.
  2982. @item -K @tab @ref{--starting-file}.
  2983. @item -L @tab @ref{--tape-length}.
  2984. @item -M @tab @ref{--multi-volume}.
  2985. @item -N @tab @ref{--newer}.
  2986. @item -O @tab @ref{--to-stdout}.
  2987. @item -P @tab @ref{--absolute-names}.
  2988. @item -R @tab @ref{--block-number}.
  2989. @item -S @tab @ref{--sparse}.
  2990. @item -T @tab @ref{--files-from}.
  2991. @item -U @tab @ref{--unlink-first}.
  2992. @item -V @tab @ref{--label}.
  2993. @item -W @tab @ref{--verify}.
  2994. @item -X @tab @ref{--exclude-from}.
  2995. @item -Z @tab @ref{--compress}.
  2996. @item -b @tab @ref{--blocking-factor}.
  2997. @item -c @tab @ref{--create}.
  2998. @item -d @tab @ref{--compare}.
  2999. @item -f @tab @ref{--file}.
  3000. @item -g @tab @ref{--listed-incremental}.
  3001. @item -h @tab @ref{--dereference}.
  3002. @item -i @tab @ref{--ignore-zeros}.
  3003. @item -j @tab @ref{--bzip2}.
  3004. @item -k @tab @ref{--keep-old-files}.
  3005. @item -l @tab @ref{--check-links}.
  3006. @item -m @tab @ref{--touch}.
  3007. @item -o @tab When extracting, same as @ref{--no-same-owner}. When creating,
  3008. -- @ref{--old-archive}.
  3009. The latter usage is deprecated. It is retained for compatibility with
  3010. the earlier versions of @GNUTAR{}. In future releases
  3011. @option{-o} will be equivalent to @option{--no-same-owner} only.
  3012. @item -p @tab @ref{--preserve-permissions}.
  3013. @item -r @tab @ref{--append}.
  3014. @item -s @tab @ref{--same-order}.
  3015. @item -t @tab @ref{--list}.
  3016. @item -u @tab @ref{--update}.
  3017. @item -v @tab @ref{--verbose}.
  3018. @item -w @tab @ref{--interactive}.
  3019. @item -x @tab @ref{--extract}.
  3020. @item -z @tab @ref{--gzip}.
  3021. @end multitable
  3022. @node Position-Sensitive Options
  3023. @subsection Position-Sensitive Options
  3024. Some @GNUTAR{} options can be used multiple times in the same
  3025. invocation and affect all arguments that appear after them. These are
  3026. options that control how file names are selected and what kind of
  3027. pattern matching is used.
  3028. The most obvious example is the @option{-C} option. It instructs @command{tar}
  3029. to change to the directory given as its argument prior to processing
  3030. the rest of command line (@pxref{directory}). Thus, in the following
  3031. command:
  3032. @example
  3033. @kbd{tar -c -f a.tar -C /etc passwd -C /var log spool}
  3034. @end example
  3035. @noindent
  3036. the file @file{passwd} will be searched in the directory @file{/etc},
  3037. and files @file{log} and @file{spool} -- in @file{/var}.
  3038. These options can also be used in a file list supplied with the
  3039. @option{--files-from} (@option{-T}) option (@pxref{files}). In that
  3040. case they affect all files (patterns) appearing in that file after
  3041. them and remain in effect for any arguments processed after that file.
  3042. For example, if the file @file{list.txt} contained:
  3043. @example
  3044. README
  3045. -C src
  3046. main.c
  3047. @end example
  3048. @noindent
  3049. and @command{tar} were invoked as follows:
  3050. @example
  3051. @kbd{tar -c -f a.tar -T list.txt Makefile}
  3052. @end example
  3053. @noindent
  3054. then the file @file{README} would be looked up in the current working
  3055. directory, and files @file{main.c} and @file{Makefile} would be looked
  3056. up in the directory @file{src}.
  3057. Many options can be prefixed with @option{--no-} to cancel the effect
  3058. of the original option.
  3059. For example, the @option{--recursion} option controls whether to
  3060. recurse in the subdirectories. It's counterpart
  3061. @option{--no-recursion} disables this. Consider the command below. It will
  3062. store in the archive the directory @file{/usr} with all files and
  3063. directories that are located in it as well as any files and
  3064. directories in @file{/var}, without recursing into them@footnote{The @option{--recursion}
  3065. option is the default and is used here for clarity. The same example
  3066. can be written as:
  3067. @example
  3068. tar -cf a.tar /usr --no-recursion /var/*
  3069. @end example
  3070. }:
  3071. @example
  3072. tar -cf a.tar --recursion /usr --no-recursion /var/*
  3073. @end example
  3074. During archive creation, @GNUTAR{} keeps track of positional options
  3075. used and arguments affected by them. If it finds out that any such
  3076. options are used in an obviously erroneous way, the fact is reported
  3077. and exit code is set to 2. E.g.:
  3078. @example
  3079. @group
  3080. $ @kbd{tar -cf a.tar . --exclude '*.o'}
  3081. tar: The following options were used after any non-optional
  3082. arguments in archive create or update mode. These options are
  3083. positional and affect only arguments that follow them. Please,
  3084. rearrange them properly.
  3085. tar: --exclude '*.o' has no effect
  3086. tar: Exiting with failure status due to previous errors
  3087. @end group
  3088. @end example
  3089. The following table summarizes all position-sensitive options.
  3090. @table @option
  3091. @item --directory=@var{dir}
  3092. @itemx -C @var{dir}
  3093. @xref{directory}.
  3094. @item --null
  3095. @itemx --no-null
  3096. @xref{nul}.
  3097. @item --unquote
  3098. @itemx --no-unquote
  3099. @xref{input name quoting}.
  3100. @item --verbatim-files-from
  3101. @itemx --no-verbatim-files-from
  3102. @xref{verbatim-files-from}.
  3103. @item --recursion
  3104. @itemx --no-recursion
  3105. @xref{recurse}.
  3106. @item --anchored
  3107. @itemx --no-anchored
  3108. @xref{anchored patterns}.
  3109. @item --ignore-case
  3110. @itemx --no-ignore-case
  3111. @xref{case-insensitive matches}.
  3112. @item --wildcards
  3113. @itemx --no-wildcards
  3114. @xref{controlling pattern-matching}.
  3115. @item --wildcards-match-slash
  3116. @itemx --no-wildcards-match-slash
  3117. @xref{controlling pattern-matching}.
  3118. @item --exclude
  3119. @xref{exclude}.
  3120. @item --exclude-from
  3121. @itemx -X
  3122. @itemx --exclude-caches
  3123. @itemx --exclude-caches-under
  3124. @itemx --exclude-caches-all
  3125. @itemx --exclude-tag
  3126. @itemx --exclude-ignore
  3127. @itemx --exclude-ignore-recursive
  3128. @itemx --exclude-tag-under
  3129. @itemx --exclude-tag-all
  3130. @itemx --exclude-vcs
  3131. @itemx --exclude-vcs-ignores
  3132. @itemx --exclude-backups
  3133. @xref{exclude}.
  3134. @end table
  3135. @node help
  3136. @section @GNUTAR{} documentation
  3137. @cindex Getting program version number
  3138. @opindex version
  3139. @cindex Version of the @command{tar} program
  3140. Being careful, the first thing is really checking that you are using
  3141. @GNUTAR{}, indeed. The @option{--version} option
  3142. causes @command{tar} to print information about its name, version,
  3143. origin and legal status, all on standard output, and then exit
  3144. successfully. For example, @w{@samp{tar --version}} might print:
  3145. @smallexample
  3146. tar (GNU tar) @value{VERSION}
  3147. Copyright (C) 2013-2020 Free Software Foundation, Inc.
  3148. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
  3149. This is free software: you are free to change and redistribute it.
  3150. There is NO WARRANTY, to the extent permitted by law.
  3151. Written by John Gilmore and Jay Fenlason.
  3152. @end smallexample
  3153. @noindent
  3154. The first occurrence of @samp{tar} in the result above is the program
  3155. name in the package (for example, @command{rmt} is another program),
  3156. while the second occurrence of @samp{tar} is the name of the package
  3157. itself, containing possibly many programs. The package is currently
  3158. named @samp{tar}, after the name of the main program it
  3159. contains@footnote{There are plans to merge the @command{cpio} and
  3160. @command{tar} packages into a single one which would be called
  3161. @code{paxutils}. So, who knows, one of these days
  3162. @option{--version} might output @w{@samp{tar (@acronym{GNU}
  3163. paxutils) 3.2}}.}.
  3164. @cindex Obtaining help
  3165. @cindex Listing all @command{tar} options
  3166. @xopindex{help, introduction}
  3167. Another thing you might want to do is check the spelling or meaning
  3168. of some particular @command{tar} option, without resorting to this
  3169. manual, once you have carefully read it. @GNUTAR{}
  3170. has a short help feature, triggerable through the
  3171. @option{--help} option. By using this option, @command{tar} will
  3172. print a usage message listing all available options on standard
  3173. output, then exit successfully, without doing anything else and
  3174. ignoring all other options. Even if this is only a brief summary, it
  3175. may be several screens long. So, if you are not using some kind of
  3176. scrollable window, you might prefer to use something like:
  3177. @smallexample
  3178. $ @kbd{tar --help | less}
  3179. @end smallexample
  3180. @noindent
  3181. presuming, here, that you like using @command{less} for a pager. Other
  3182. popular pagers are @command{more} and @command{pg}. If you know about some
  3183. @var{keyword} which interests you and do not want to read all the
  3184. @option{--help} output, another common idiom is doing:
  3185. @smallexample
  3186. tar --help | grep @var{keyword}
  3187. @end smallexample
  3188. @noindent
  3189. for getting only the pertinent lines. Notice, however, that some
  3190. @command{tar} options have long description lines and the above
  3191. command will list only the first of them.
  3192. The exact look of the option summary displayed by @kbd{tar --help} is
  3193. configurable. @xref{Configuring Help Summary}, for a detailed description.
  3194. @opindex usage
  3195. If you only wish to check the spelling of an option, running @kbd{tar
  3196. --usage} may be a better choice. This will display a terse list of
  3197. @command{tar} options without accompanying explanations.
  3198. The short help output is quite succinct, and you might have to get
  3199. back to the full documentation for precise points. If you are reading
  3200. this paragraph, you already have the @command{tar} manual in some
  3201. form. This manual is available in a variety of forms from
  3202. @url{https://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
  3203. distribution, provided you have @TeX{} already installed somewhere,
  3204. and a laser printer around. Just configure the distribution, execute
  3205. the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
  3206. usual way (contact your local guru to know how). If @GNUTAR{}
  3207. has been conveniently installed at your place, this
  3208. manual is also available in interactive, hypertextual form as an Info
  3209. file. Just call @w{@samp{info tar}} or, if you do not have the
  3210. @command{info} program handy, use the Info reader provided within
  3211. @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
  3212. Since 2014, @GNUTAR{} also has a @code{man} page.
  3213. It briefly explains all the options and operations.
  3214. This might be preferable when you don't need any background.
  3215. But bear in mind that the authoritative source of
  3216. information about @GNUTAR{} is this Texinfo documentation.
  3217. @node defaults
  3218. @section Obtaining @GNUTAR{} default values
  3219. @opindex show-defaults
  3220. @GNUTAR{} has some predefined defaults that are used when you do not
  3221. explicitly specify another values. To obtain a list of such
  3222. defaults, use @option{--show-defaults} option. This will output the
  3223. values in the form of @command{tar} command line options:
  3224. @smallexample
  3225. @group
  3226. $ @kbd{tar --show-defaults}
  3227. --format=gnu -f- -b20 --quoting-style=escape
  3228. --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
  3229. @end group
  3230. @end smallexample
  3231. @noindent
  3232. Notice, that this option outputs only one line. The example output above
  3233. has been split to fit page boundaries.
  3234. @noindent
  3235. The above output shows that this version of @GNUTAR{} defaults to
  3236. using @samp{gnu} archive format (@pxref{Formats}), it uses standard
  3237. output as the archive, if no @option{--file} option has been given
  3238. (@pxref{file tutorial}), the default blocking factor is 20
  3239. (@pxref{Blocking Factor}). It also shows the default locations where
  3240. @command{tar} will look for @command{rmt} and @command{rsh} binaries.
  3241. @node verbose
  3242. @section Checking @command{tar} progress
  3243. Typically, @command{tar} performs most operations without reporting any
  3244. information to the user except error messages. When using @command{tar}
  3245. with many options, particularly ones with complicated or
  3246. difficult-to-predict behavior, it is possible to make serious mistakes.
  3247. @command{tar} provides several options that make observing @command{tar}
  3248. easier. These options cause @command{tar} to print information as it
  3249. progresses in its job, and you might want to use them just for being
  3250. more careful about what is going on, or merely for entertaining
  3251. yourself. If you have encountered a problem when operating on an
  3252. archive, however, you may need more information than just an error
  3253. message in order to solve the problem. The following options can be
  3254. helpful diagnostic tools.
  3255. @cindex Verbose operation
  3256. @opindex verbose
  3257. Normally, the @option{--list} (@option{-t}) command to list an archive
  3258. prints just the file names (one per line) and the other commands are
  3259. silent. When used with most operations, the @option{--verbose}
  3260. (@option{-v}) option causes @command{tar} to print the name of each
  3261. file or archive member as it is processed. This and the other options
  3262. which make @command{tar} print status information can be useful in
  3263. monitoring @command{tar}.
  3264. With @option{--create} or @option{--extract}, @option{--verbose} used
  3265. once just prints the names of the files or members as they are processed.
  3266. Using it twice causes @command{tar} to print a longer listing
  3267. (@xref{verbose member listing}, for the description) for each member.
  3268. Since @option{--list} already prints the names of the members,
  3269. @option{--verbose} used once with @option{--list} causes @command{tar}
  3270. to print an @samp{ls -l} type listing of the files in the archive.
  3271. The following examples both extract members with long list output:
  3272. @smallexample
  3273. $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
  3274. $ @kbd{tar xvvf archive.tar}
  3275. @end smallexample
  3276. Verbose output appears on the standard output except when an archive is
  3277. being written to the standard output, as with @samp{tar --create
  3278. --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
  3279. installer let standard output be the default archive). In that case
  3280. @command{tar} writes verbose output to the standard error stream.
  3281. If @option{--index-file=@var{file}} is specified, @command{tar} sends
  3282. verbose output to @var{file} rather than to standard output or standard
  3283. error.
  3284. @anchor{totals}
  3285. @cindex Obtaining total status information
  3286. @opindex totals
  3287. The @option{--totals} option causes @command{tar} to print on the
  3288. standard error the total amount of bytes transferred when processing
  3289. an archive. When creating or appending to an archive, this option
  3290. prints the number of bytes written to the archive and the average
  3291. speed at which they have been written, e.g.:
  3292. @smallexample
  3293. @group
  3294. $ @kbd{tar -c -f archive.tar --totals /home}
  3295. Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
  3296. @end group
  3297. @end smallexample
  3298. When reading an archive, this option displays the number of bytes
  3299. read:
  3300. @smallexample
  3301. @group
  3302. $ @kbd{tar -x -f archive.tar --totals}
  3303. Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
  3304. @end group
  3305. @end smallexample
  3306. Finally, when deleting from an archive, the @option{--totals} option
  3307. displays both numbers plus number of bytes removed from the archive:
  3308. @smallexample
  3309. @group
  3310. $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
  3311. Total bytes read: 9543680 (9.2MiB, 201MiB/s)
  3312. Total bytes written: 3829760 (3.7MiB, 81MiB/s)
  3313. Total bytes deleted: 1474048
  3314. @end group
  3315. @end smallexample
  3316. You can also obtain this information on request. When
  3317. @option{--totals} is used with an argument, this argument is
  3318. interpreted as a symbolic name of a signal, upon delivery of which the
  3319. statistics is to be printed:
  3320. @table @option
  3321. @item --totals=@var{signo}
  3322. Print statistics upon delivery of signal @var{signo}. Valid arguments
  3323. are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
  3324. @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
  3325. accepted.
  3326. @end table
  3327. Both forms of @option{--totals} option can be used simultaneously.
  3328. Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
  3329. extract all members from its default archive and print statistics
  3330. after finishing the extraction, as well as when receiving signal
  3331. @code{SIGUSR1}.
  3332. @anchor{Progress information}
  3333. @cindex Progress information
  3334. The @option{--checkpoint} option prints an occasional message
  3335. as @command{tar} reads or writes the archive. It is designed for
  3336. those who don't need the more detailed (and voluminous) output of
  3337. @option{--block-number} (@option{-R}), but do want visual confirmation
  3338. that @command{tar} is actually making forward progress. By default it
  3339. prints a message each 10 records read or written. This can be changed
  3340. by giving it a numeric argument after an equal sign:
  3341. @smallexample
  3342. $ @kbd{tar -c --checkpoint=1000} /var
  3343. tar: Write checkpoint 1000
  3344. tar: Write checkpoint 2000
  3345. tar: Write checkpoint 3000
  3346. @end smallexample
  3347. This example shows the default checkpoint message used by
  3348. @command{tar}. If you place a dot immediately after the equal
  3349. sign, it will print a @samp{.} at each checkpoint@footnote{This is
  3350. actually a shortcut for @option{--checkpoint=@var{n}
  3351. --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
  3352. @smallexample
  3353. $ @kbd{tar -c --checkpoint=.1000} /var
  3354. ...
  3355. @end smallexample
  3356. The @option{--checkpoint} option provides a flexible mechanism for
  3357. executing arbitrary actions upon hitting checkpoints, see the next
  3358. section (@pxref{checkpoints}), for more information on it.
  3359. @opindex show-omitted-dirs
  3360. @anchor{show-omitted-dirs}
  3361. The @option{--show-omitted-dirs} option, when reading an archive---with
  3362. @option{--list} or @option{--extract}, for example---causes a message
  3363. to be printed for each directory in the archive which is skipped.
  3364. This happens regardless of the reason for skipping: the directory might
  3365. not have been named on the command line (implicitly or explicitly),
  3366. it might be excluded by the use of the
  3367. @option{--exclude=@var{pattern}} option, or some other reason.
  3368. @opindex block-number
  3369. @cindex Block number where error occurred
  3370. @anchor{block-number}
  3371. If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
  3372. every message it would normally produce, the block number within the
  3373. archive where the message was triggered. Also, supplementary messages
  3374. are triggered when reading blocks full of NULs, or when hitting end of
  3375. file on the archive. As of now, if the archive is properly terminated
  3376. with a NUL block, the reading of the file may stop before end of file
  3377. is met, so the position of end of file will not usually show when
  3378. @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
  3379. drains the archive before exiting when reading the
  3380. archive from a pipe.
  3381. @cindex Error message, block number of
  3382. This option is especially useful when reading damaged archives, since
  3383. it helps pinpoint the damaged sections. It can also be used with
  3384. @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
  3385. choose among several backup tapes when retrieving a file later, in
  3386. favor of the tape where the file appears earliest (closest to the
  3387. front of the tape). @xref{backup}.
  3388. @node checkpoints
  3389. @section Checkpoints
  3390. @cindex checkpoints, defined
  3391. @opindex checkpoint
  3392. @opindex checkpoint-action
  3393. A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
  3394. the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
  3395. from the archive (a @dfn{read checkpoint}). Checkpoints allow to
  3396. periodically execute arbitrary actions.
  3397. The checkpoint facility is enabled using the following option:
  3398. @table @option
  3399. @xopindex{checkpoint, defined}
  3400. @item --checkpoint[=@var{n}]
  3401. Schedule checkpoints before writing or reading each @var{n}th record.
  3402. The default value for @var{n} is 10.
  3403. @end table
  3404. A list of arbitrary @dfn{actions} can be executed at each checkpoint.
  3405. These actions include: pausing, displaying textual messages, and
  3406. executing arbitrary external programs. Actions are defined using
  3407. the @option{--checkpoint-action} option.
  3408. @table @option
  3409. @xopindex{checkpoint-action, defined}
  3410. @item --checkpoint-action=@var{action}
  3411. Execute an @var{action} at each checkpoint.
  3412. @end table
  3413. @cindex @code{echo}, checkpoint action
  3414. The simplest value of @var{action} is @samp{echo}. It instructs
  3415. @command{tar} to display the default message on the standard error
  3416. stream upon arriving at each checkpoint. The default message is (in
  3417. @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
  3418. checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
  3419. Here, @var{n} represents ordinal number of the checkpoint.
  3420. In another locales, translated versions of this message are used.
  3421. This is the default action, so running:
  3422. @smallexample
  3423. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
  3424. @end smallexample
  3425. @noindent
  3426. is equivalent to:
  3427. @smallexample
  3428. $ @kbd{tar -c --checkpoint=1000} /var
  3429. @end smallexample
  3430. The @samp{echo} action also allows to supply a customized message.
  3431. You do so by placing an equals sign and the message right after it,
  3432. e.g.:
  3433. @smallexample
  3434. --checkpoint-action="echo=Hit %s checkpoint #%u"
  3435. @end smallexample
  3436. The @samp{%s} and @samp{%u} in the above example are
  3437. @dfn{format specifiers}. The @samp{%s} specifier is replaced with
  3438. the @dfn{type} of the checkpoint: @samp{write} or
  3439. @samp{read} (or a corresponding translated version in locales other
  3440. than @acronym{POSIX}). The @samp{%u} specifier is replaced with
  3441. the ordinal number of the checkpoint. Thus, the above example could
  3442. produce the following output when used with the @option{--create}
  3443. option:
  3444. @smallexample
  3445. tar: Hit write checkpoint #10
  3446. tar: Hit write checkpoint #20
  3447. tar: Hit write checkpoint #30
  3448. @end smallexample
  3449. The complete list of available format specifiers follows. Some of
  3450. them can take optional arguments. These arguments, if given, are
  3451. supplied in curly braces between the percent sign and the specifier
  3452. letter.
  3453. @table @samp
  3454. @item %s
  3455. Print type of the checkpoint (@samp{write} or @samp{read}).
  3456. @item %u
  3457. Print number of the checkpoint.
  3458. @item %@{r,w,d@}T
  3459. Print number of bytes transferred so far and approximate transfer
  3460. speed. Optional arguments supply prefixes to be used before number
  3461. of bytes read, written and deleted, correspondingly. If absent,
  3462. they default to @samp{R}. @samp{W}, @samp{D}. Any or all of them can
  3463. be omitted, so, that e.g. @samp{%@{@}T} means to print corresponding
  3464. statistics without any prefixes. Any surplus arguments, if present,
  3465. are silently ignored.
  3466. @example
  3467. $ @kbd{tar --delete -f f.tar --checkpoint-action=echo="#%u: %T" main.c}
  3468. tar: #1: R: 0 (0B, 0B/s),W: 0 (0B, 0B/s),D: 0
  3469. tar: #2: R: 10240 (10KiB, 19MiB/s),W: 0 (0B, 0B/s),D: 10240
  3470. @end example
  3471. @noindent
  3472. See also the @samp{totals} action, described below.
  3473. @item %@{@var{fmt}@}t
  3474. Output current local time using @var{fmt} as format for @command{strftime}
  3475. (@pxref{strftime, strftime,,strftime(3), strftime(3) man page}). The
  3476. @samp{@{@var{fmt}@}} part is optional. If not present, the default
  3477. format is @samp{%c}, i.e. the preferred date and time representation
  3478. for the current locale.
  3479. @item %@{@var{n}@}*
  3480. Pad output with spaces to the @var{n}th column. If the
  3481. @samp{@{@var{n}@}} part is omitted, the current screen width
  3482. is assumed.
  3483. @item %c
  3484. This is a shortcut for @samp{%@{%Y-%m-%d %H:%M:%S@}t: %ds, %@{read,wrote@}T%*\r},
  3485. intended mainly for use with @samp{ttyout} action (see below).
  3486. @end table
  3487. Aside from format expansion, the message string is subject to
  3488. @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
  3489. replaced with their corresponding @acronym{ASCII} characters
  3490. (@pxref{escape sequences}). E.g. the following action will produce an
  3491. audible bell and the message described above at each checkpoint:
  3492. @smallexample
  3493. --checkpoint-action='echo=\aHit %s checkpoint #%u'
  3494. @end smallexample
  3495. @cindex @code{bell}, checkpoint action
  3496. There is also a special action which produces an audible signal:
  3497. @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
  3498. @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
  3499. whereas @samp{echo='\a'} sends it to the standard error.
  3500. @cindex @code{ttyout}, checkpoint action
  3501. The @samp{ttyout=@var{string}} action outputs @var{string} to
  3502. @file{/dev/tty}, so it can be used even if the standard output is
  3503. redirected elsewhere. The @var{string} is subject to the same
  3504. modifications as with @samp{echo} action. In contrast to the latter,
  3505. @samp{ttyout} does not prepend @command{tar} executable name to the
  3506. string, nor does it output a newline after it. For example, the
  3507. following action will print the checkpoint message at the same screen
  3508. line, overwriting any previous message:
  3509. @smallexample
  3510. --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r"
  3511. @end smallexample
  3512. @noindent
  3513. Notice the use of @samp{%*} specifier to clear out any eventual
  3514. remains of the prior output line. As as more complex example,
  3515. consider this:
  3516. @smallexample
  3517. --checkpoint-action=ttyout='%@{%Y-%m-%d %H:%M:%S@}t (%d sec): #%u, %T%*\r'
  3518. @end smallexample
  3519. @noindent
  3520. This prints the current local time, number of seconds expired since
  3521. tar was started, the checkpoint ordinal number, transferred bytes and
  3522. average computed I/O speed.
  3523. @cindex @code{dot}, checkpoint action
  3524. Another available checkpoint action is @samp{dot} (or @samp{.}). It
  3525. instructs @command{tar} to print a single dot on the standard listing
  3526. stream, e.g.:
  3527. @smallexample
  3528. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
  3529. ...
  3530. @end smallexample
  3531. For compatibility with previous @GNUTAR{} versions, this action can
  3532. be abbreviated by placing a dot in front of the checkpoint frequency,
  3533. as shown in the previous section.
  3534. @cindex @code{totals}, checkpoint action
  3535. The @samp{totals} action prints the total number of bytes transferred
  3536. so far. The format of the data is the same as for the
  3537. @option{--totals} option (@pxref{totals}). See also @samp{%T} format
  3538. specifier of the @samp{echo} or @samp{ttyout} action.
  3539. @cindex @code{sleep}, checkpoint action
  3540. Yet another action, @samp{sleep}, pauses @command{tar} for a specified
  3541. amount of seconds. The following example will stop for 30 seconds at each
  3542. checkpoint:
  3543. @smallexample
  3544. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
  3545. @end smallexample
  3546. @anchor{checkpoint wait}
  3547. @cindex @code{wait}, checkpoint action
  3548. The @code{wait=@var{signo}} action stops further execution until the
  3549. signal @var{signo} is delivered. Valid values for @var{signo} are:
  3550. @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
  3551. @code{SIGUSR2}. The @samp{SIG} prefix is optional. For example:
  3552. @example
  3553. $ @kbd{tar -c -f arc --checkpoint=1000 --checkpoint-action wait=USR1 .}
  3554. @end example
  3555. In this example, @GNUTAR{} will stop archivation at each 1000th
  3556. checkpoint. wait until the @samp{SIGUSR1} signal is delivered,
  3557. and resume processing.
  3558. This action is used by the @command{genfile} utility to perform
  3559. modifications on the input files upon hitting certain checkpoints
  3560. (@pxref{Exec Mode, genfile}).
  3561. @anchor{checkpoint exec}
  3562. @cindex @code{exec}, checkpoint action
  3563. Finally, the @code{exec} action executes a given external command.
  3564. For example:
  3565. @smallexample
  3566. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
  3567. @end smallexample
  3568. The supplied command can be any valid command invocation, with or
  3569. without additional command line arguments. If it does contain
  3570. arguments, don't forget to quote it to prevent it from being split by
  3571. the shell. @xref{external, Running External Commands}, for more detail.
  3572. The command gets a copy of @command{tar}'s environment plus the
  3573. following variables:
  3574. @table @env
  3575. @vrindex TAR_VERSION, checkpoint script environment
  3576. @item TAR_VERSION
  3577. @GNUTAR{} version number.
  3578. @vrindex TAR_ARCHIVE, checkpoint script environment
  3579. @item TAR_ARCHIVE
  3580. The name of the archive @command{tar} is processing.
  3581. @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
  3582. @item TAR_BLOCKING_FACTOR
  3583. Current blocking factor (@pxref{Blocking}).
  3584. @vrindex TAR_CHECKPOINT, checkpoint script environment
  3585. @item TAR_CHECKPOINT
  3586. Number of the checkpoint.
  3587. @vrindex TAR_SUBCOMMAND, checkpoint script environment
  3588. @item TAR_SUBCOMMAND
  3589. A short option describing the operation @command{tar} is executing.
  3590. @xref{Operations}, for a complete list of subcommand options.
  3591. @vrindex TAR_FORMAT, checkpoint script environment
  3592. @item TAR_FORMAT
  3593. Format of the archive being processed. @xref{Formats}, for a complete
  3594. list of archive format names.
  3595. @end table
  3596. These environment variables can also be passed as arguments to the
  3597. command, provided that they are properly escaped, for example:
  3598. @smallexample
  3599. @kbd{tar -c -f arc.tar \
  3600. --checkpoint-action='exec=/sbin/cpoint $TAR_CHECKPOINT'}
  3601. @end smallexample
  3602. @noindent
  3603. Notice single quotes to prevent variable names from being expanded by
  3604. the shell when invoking @command{tar}.
  3605. Any number of actions can be defined, by supplying several
  3606. @option{--checkpoint-action} options in the command line. For
  3607. example, the command below displays two messages, pauses
  3608. execution for 30 seconds and executes the @file{/sbin/cpoint} script:
  3609. @example
  3610. @group
  3611. $ @kbd{tar -c -f arc.tar \
  3612. --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
  3613. --checkpoint-action='echo=Sleeping for 30 seconds' \
  3614. --checkpoint-action='sleep=30' \
  3615. --checkpoint-action='exec=/sbin/cpoint'}
  3616. @end group
  3617. @end example
  3618. This example also illustrates the fact that
  3619. @option{--checkpoint-action} can be used without
  3620. @option{--checkpoint}. In this case, the default checkpoint frequency
  3621. (at each 10th record) is assumed.
  3622. @node warnings
  3623. @section Controlling Warning Messages
  3624. Sometimes, while performing the requested task, @GNUTAR{} notices
  3625. some conditions that are not exactly errors, but which the user
  3626. should be aware of. When this happens, @command{tar} issues a
  3627. @dfn{warning message} describing the condition. Warning messages
  3628. are output to the standard error and they do not affect the exit
  3629. code of @command{tar} command.
  3630. @xopindex{warning, explained}
  3631. @GNUTAR{} allows the user to suppress some or all of its warning
  3632. messages:
  3633. @table @option
  3634. @item --warning=@var{keyword}
  3635. Control display of the warning messages identified by @var{keyword}.
  3636. If @var{keyword} starts with the prefix @samp{no-}, such messages are
  3637. suppressed. Otherwise, they are enabled.
  3638. Multiple @option{--warning} options accumulate.
  3639. @end table
  3640. By default, @GNUTAR enables all messages, except those that are
  3641. enabled in verbose mode (@pxref{verbose tutorial}). @xref{Warning
  3642. Defaults}, for details.
  3643. The subsections below discuss allowed values for @var{keyword} along with the
  3644. warning messages they control.
  3645. @menu
  3646. * General Warnings:: Keywords applicable for @command{tar --create}.
  3647. * Archive Creation Warnings:: Keywords applicable for @command{tar --create}.
  3648. * Archive Extraction Warnings:: Keywords applicable for @command{tar --extract}.
  3649. * Incremental Extraction Warnings:: Keywords controlling incremental extraction.
  3650. * Warning Classes:: Convenience keywords control multiple warnings.
  3651. * Warning Defaults:: Default settings for warnings.
  3652. @end menu
  3653. @node General Warnings
  3654. @subsection Keywords controlling @command{tar} operation
  3655. These keywords control warnings that may appear in any @GNUTAR{}
  3656. operation mode:
  3657. @defvr {warning} filename-with-nuls
  3658. @cindex @samp{file name read contains nul character}, warning message
  3659. @samp{file name read contains nul character}
  3660. @end defvr
  3661. @defvr {warning} filename-with-nuls
  3662. @cindex @samp{file name read contains nul character}, warning message
  3663. @samp{%s: file name read contains nul character}
  3664. @end defvr
  3665. @defvr {warning} alone-zero-block
  3666. @cindex @samp{A lone zero block at}, warning message
  3667. @samp{A lone zero block at %s}. Notice, that this warning is
  3668. suppressed if @option{--ignore-zeros} is in effect (@pxref{Ignore
  3669. Zeros}).
  3670. @end defvr
  3671. @defvr {warning} missing-zero-blocks
  3672. @cindex @samp{Terminating zero blocks missing}, warning message.
  3673. @samp{Terminating zero blocks missing at %s}. This warning is
  3674. suppressed if @option{--ignore-zeros} is in effect (@pxref{Ignore
  3675. Zeros}).
  3676. @end defvr
  3677. @node Archive Creation Warnings
  3678. @subsection Keywords applicable for @command{tar --create}
  3679. The following keywords control messages that can be issued while
  3680. creating archives.
  3681. @defvr {warning} cachedir
  3682. @cindex @samp{contains a cache directory tag}, warning message
  3683. @samp{%s: contains a cache directory tag %s; %s}
  3684. @end defvr
  3685. @defvr {warning} file-shrank
  3686. @cindex @samp{File shrank by %s bytes}, warning message
  3687. @samp{%s: File shrank by %s bytes; padding with zeros}
  3688. @end defvr
  3689. @defvr {warning} xdev
  3690. @cindex @samp{file is on a different filesystem}, warning message
  3691. @samp{%s: file is on a different filesystem; not dumped}
  3692. @end defvr
  3693. @defvr {warning} file-ignored
  3694. @cindex @samp{Unknown file type; file ignored}, warning message
  3695. @cindex @samp{socket ignored}, warning message
  3696. @cindex @samp{door ignored}, warning message
  3697. @samp{%s: Unknown file type; file ignored}
  3698. @*@samp{%s: socket ignored}
  3699. @*@samp{%s: door ignored}
  3700. @end defvr
  3701. @defvr {warning} file-unchanged
  3702. @cindex @samp{file is unchanged; not dumped}, warning message
  3703. @samp{%s: file is unchanged; not dumped}
  3704. @end defvr
  3705. @defvr {warning} ignore-archive
  3706. @cindex @samp{archive cannot contain itself; not dumped}, warning message
  3707. @samp{%s: archive cannot contain itself; not dumped}
  3708. @end defvr
  3709. @defvr {warning} file-removed
  3710. @cindex @samp{File removed before we read it}, warning message
  3711. @samp{%s: File removed before we read it}
  3712. @end defvr
  3713. @defvr {warning} file-changed
  3714. @cindex @samp{file changed as we read it}, warning message
  3715. @samp{%s: file changed as we read it}
  3716. Suppresses warnings about read failures, which can occur if files
  3717. or directories are unreadable, or if they change while being read. This
  3718. keyword applies only if used together with the @option{--ignore-failed-read}
  3719. option. @xref{Ignore Failed Read}.
  3720. @end defvr
  3721. @node Archive Extraction Warnings
  3722. @subsection Keywords applicable for @command{tar --extract}
  3723. The following keywords control warnings that can be issued during
  3724. archive extraction.
  3725. @defvr {warning} existing-file
  3726. @cindex @samp{%s: skipping existing file}, warning message
  3727. @samp{%s: skipping existing file}
  3728. @end defvr
  3729. @defvr {warning} timestamp
  3730. @cindex @samp{implausibly old time stamp %s}, warning message
  3731. @cindex @samp{time stamp %s is %s s in the future}, warning message
  3732. @samp{%s: implausibly old time stamp %s}
  3733. @*@samp{%s: time stamp %s is %s s in the future}
  3734. @end defvr
  3735. @defvr {warning} contiguous-cast
  3736. @cindex @samp{Extracting contiguous files as regular files}, warning message
  3737. @samp{Extracting contiguous files as regular files}
  3738. @end defvr
  3739. @defvr {warning} symlink-cast
  3740. @samp{Attempting extraction of symbolic links as hard links}, warning message
  3741. @samp{Attempting extraction of symbolic links as hard links}
  3742. @end defvr
  3743. @defvr {warning} unknown-cast
  3744. @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
  3745. @samp{%s: Unknown file type '%c', extracted as normal file}
  3746. @end defvr
  3747. @defvr {warning} ignore-newer
  3748. @cindex @samp{Current %s is newer or same age}, warning message
  3749. @samp{Current %s is newer or same age}
  3750. @end defvr
  3751. @defvr {warning} unknown-keyword
  3752. @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
  3753. @samp{Ignoring unknown extended header keyword '%s'}
  3754. @end defvr
  3755. @defvr {warning} decompress-program
  3756. Controls verbose description of failures occurring when trying to run
  3757. alternative decompressor programs (@pxref{alternative decompression
  3758. programs}). This warning is disabled by default (unless
  3759. @option{--verbose} is used). A common example of what you can get
  3760. when using this warning is:
  3761. @smallexample
  3762. $ @kbd{tar --warning=decompress-program -x -f archive.Z}
  3763. tar (child): cannot run compress: No such file or directory
  3764. tar (child): trying gzip
  3765. @end smallexample
  3766. This means that @command{tar} first tried to decompress
  3767. @file{archive.Z} using @command{compress}, and, when that
  3768. failed, switched to @command{gzip}.
  3769. @end defvr
  3770. @defvr {warning} record-size
  3771. @cindex @samp{Record size = %lu blocks}, warning message
  3772. @samp{Record size = %lu blocks}
  3773. @end defvr
  3774. @node Incremental Extraction Warnings
  3775. @subsection Keywords controlling incremental extraction
  3776. These keywords control warnings that may appear when extracting from
  3777. incremental archives.
  3778. @defvr {warning} rename-directory
  3779. @cindex @samp{%s: Directory has been renamed from %s}, warning message
  3780. @cindex @samp{%s: Directory has been renamed}, warning message
  3781. @samp{%s: Directory has been renamed from %s}
  3782. @*@samp{%s: Directory has been renamed}
  3783. @end defvr
  3784. @defvr {warning} new-directory
  3785. @cindex @samp{%s: Directory is new}, warning message
  3786. @samp{%s: Directory is new}
  3787. @end defvr
  3788. @defvr {warning} xdev
  3789. @cindex @samp{%s: directory is on a different device: not purging}, warning message
  3790. @samp{%s: directory is on a different device: not purging}
  3791. @end defvr
  3792. @defvr {warning} bad-dumpdir
  3793. @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
  3794. @samp{Malformed dumpdir: 'X' never used}
  3795. @end defvr
  3796. @node Warning Classes
  3797. @subsection Warning Classes
  3798. These convenience keywords define @dfn{warning classes}. When used,
  3799. they affect several warnings at once.
  3800. @defvr {warning} all
  3801. Enable all warning messages.
  3802. @end defvr
  3803. @defvr {warning} none
  3804. Disable all warning messages.
  3805. @end defvr
  3806. @defvr {warning} verbose
  3807. A shorthand for all messages enabled when @option{--verbose}
  3808. (@pxref{verbose tutorial}) is in effect. These are:
  3809. @code{decompress-program}, @code{existing-file}, @code{new-directory},
  3810. @code{record-size}, @code{rename-directory}.
  3811. @end defvr
  3812. @node Warning Defaults
  3813. @subsection Default Warning Settings
  3814. @GNUTAR default settings correspond to:
  3815. @example
  3816. --warning=all --warning=no-verbose --warning=no-missing-zero-blocks
  3817. @end example
  3818. @node interactive
  3819. @section Asking for Confirmation During Operations
  3820. @cindex Interactive operation
  3821. Typically, @command{tar} carries out a command without stopping for
  3822. further instructions. In some situations however, you may want to
  3823. exclude some files and archive members from the operation (for instance
  3824. if disk or storage space is tight). You can do this by excluding
  3825. certain files automatically (@pxref{Choosing}), or by performing
  3826. an operation interactively, using the @option{--interactive} (@option{-w}) option.
  3827. @command{tar} also accepts @option{--confirmation} for this option.
  3828. @opindex interactive
  3829. When the @option{--interactive} (@option{-w}) option is specified, before
  3830. reading, writing, or deleting files, @command{tar} first prints a message
  3831. for each such file, telling what operation it intends to take, then asks
  3832. for confirmation on the terminal. The actions which require
  3833. confirmation include adding a file to the archive, extracting a file
  3834. from the archive, deleting a file from the archive, and deleting a file
  3835. from disk. To confirm the action, you must type a line of input
  3836. beginning with @samp{y}. If your input line begins with anything other
  3837. than @samp{y}, @command{tar} skips that file.
  3838. If @command{tar} is reading the archive from the standard input,
  3839. @command{tar} opens the file @file{/dev/tty} to support the interactive
  3840. communications.
  3841. Verbose output is normally sent to standard output, separate from
  3842. other error messages. However, if the archive is produced directly
  3843. on standard output, then verbose output is mixed with errors on
  3844. @code{stderr}. Producing the archive on standard output may be used
  3845. as a way to avoid using disk space, when the archive is soon to be
  3846. consumed by another process reading it, say. Some people felt the need
  3847. of producing an archive on stdout, still willing to segregate between
  3848. verbose output and error output. A possible approach would be using a
  3849. named pipe to receive the archive, and having the consumer process to
  3850. read from that named pipe. This has the advantage of letting standard
  3851. output free to receive verbose output, all separate from errors.
  3852. @node external
  3853. @section Running External Commands
  3854. Certain @GNUTAR{} operations imply running external commands that you
  3855. supply on the command line. One of such operations is checkpointing,
  3856. described above (@pxref{checkpoint exec}). Another example of this
  3857. feature is the @option{-I} option, which allows you to supply the
  3858. program to use for compressing or decompressing the archive
  3859. (@pxref{use-compress-program}).
  3860. Whenever such operation is requested, @command{tar} first splits the
  3861. supplied command into words much like the shell does. It then treats
  3862. the first word as the name of the program or the shell script to execute
  3863. and the rest of words as its command line arguments. The program,
  3864. unless given as an absolute file name, is searched in the shell's
  3865. @env{PATH}.
  3866. Any additional information is normally supplied to external commands
  3867. in environment variables, specific to each particular operation. For
  3868. example, the @option{--checkpoint-action=exec} option, defines the
  3869. @env{TAR_ARCHIVE} variable to the name of the archive being worked
  3870. upon. You can, should the need be, use these variables in the
  3871. command line of the external command. For example:
  3872. @smallexample
  3873. $ @kbd{tar -x -f archive.tar \
  3874. --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
  3875. @end smallexample
  3876. @noindent
  3877. This command prints for each checkpoint its number and the name of the
  3878. archive, using the same output line on the screen.
  3879. Notice the use of single quotes to prevent variable names from being
  3880. expanded by the shell when invoking @command{tar}.
  3881. @node operations
  3882. @chapter @GNUTAR{} Operations
  3883. @menu
  3884. * Basic tar::
  3885. * Advanced tar::
  3886. * create options::
  3887. * extract options::
  3888. * backup::
  3889. * looking ahead::
  3890. @end menu
  3891. @node Basic tar
  3892. @section Basic @GNUTAR{} Operations
  3893. The basic @command{tar} operations, @option{--create} (@option{-c}),
  3894. @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
  3895. @option{-x}), are currently presented and described in the tutorial
  3896. chapter of this manual. This section provides some complementary notes
  3897. for these operations.
  3898. @table @option
  3899. @xopindex{create, complementary notes}
  3900. @item --create
  3901. @itemx -c
  3902. Creating an empty archive would have some kind of elegance. One can
  3903. initialize an empty archive and later use @option{--append}
  3904. (@option{-r}) for adding all members. Some applications would not
  3905. welcome making an exception in the way of adding the first archive
  3906. member. On the other hand, many people reported that it is
  3907. dangerously too easy for @command{tar} to destroy a magnetic tape with
  3908. an empty archive@footnote{This is well described in @cite{Unix-haters
  3909. Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
  3910. Books, ISBN 1-56884-203-1.}. The two most common errors are:
  3911. @enumerate
  3912. @item
  3913. Mistakingly using @code{create} instead of @code{extract}, when the
  3914. intent was to extract the full contents of an archive. This error
  3915. is likely: keys @kbd{c} and @kbd{x} are right next to each other on
  3916. the QWERTY keyboard. Instead of being unpacked, the archive then
  3917. gets wholly destroyed. When users speak about @dfn{exploding} an
  3918. archive, they usually mean something else :-).
  3919. @item
  3920. Forgetting the argument to @code{file}, when the intent was to create
  3921. an archive with a single file in it. This error is likely because a
  3922. tired user can easily add the @kbd{f} key to the cluster of option
  3923. letters, by the mere force of habit, without realizing the full
  3924. consequence of doing so. The usual consequence is that the single
  3925. file, which was meant to be saved, is rather destroyed.
  3926. @end enumerate
  3927. So, recognizing the likelihood and the catastrophic nature of these
  3928. errors, @GNUTAR{} now takes some distance from elegance, and
  3929. cowardly refuses to create an archive when @option{--create} option is
  3930. given, there are no arguments besides options, and
  3931. @option{--files-from} (@option{-T}) option is @emph{not} used. To get
  3932. around the cautiousness of @GNUTAR{} and nevertheless create an
  3933. archive with nothing in it, one may still use, as the value for the
  3934. @option{--files-from} option, a file with no names in it, as shown in
  3935. the following commands:
  3936. @smallexample
  3937. @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
  3938. @kbd{tar -cf empty-archive.tar -T /dev/null}
  3939. @end smallexample
  3940. @xopindex{extract, complementary notes}
  3941. @item --extract
  3942. @itemx --get
  3943. @itemx -x
  3944. A socket is stored, within a @GNUTAR{} archive, as a pipe.
  3945. @item @option{--list} (@option{-t})
  3946. @GNUTAR{} now shows dates as @samp{1996-08-30},
  3947. while it used to show them as @samp{Aug 30 1996}. Preferably,
  3948. people should get used to ISO 8601 dates. Local American dates should
  3949. be made available again with full date localization support, once
  3950. ready. In the meantime, programs not being localizable for dates
  3951. should prefer international dates, that's really the way to go.
  3952. Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
  3953. are curious, it contains a detailed explanation of the ISO 8601 standard.
  3954. @end table
  3955. @node Advanced tar
  3956. @section Advanced @GNUTAR{} Operations
  3957. Now that you have learned the basics of using @GNUTAR{}, you may want
  3958. to learn about further ways in which @command{tar} can help you.
  3959. This chapter presents five, more advanced operations which you probably
  3960. won't use on a daily basis, but which serve more specialized functions.
  3961. We also explain the different styles of options and why you might want
  3962. to use one or another, or a combination of them in your @command{tar}
  3963. commands. Additionally, this chapter includes options which allow you to
  3964. define the output from @command{tar} more carefully, and provide help and
  3965. error correction in special circumstances.
  3966. @FIXME{check this after the chapter is actually revised to make sure
  3967. it still introduces the info in the chapter correctly : ).}
  3968. @menu
  3969. * Operations::
  3970. * append::
  3971. * update::
  3972. * concatenate::
  3973. * delete::
  3974. * compare::
  3975. @end menu
  3976. @node Operations
  3977. @subsection The Five Advanced @command{tar} Operations
  3978. @cindex basic operations
  3979. In the last chapter, you learned about the first three operations to
  3980. @command{tar}. This chapter presents the remaining five operations to
  3981. @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
  3982. @option{--delete}, and @option{--compare}.
  3983. You are not likely to use these operations as frequently as those
  3984. covered in the last chapter; however, since they perform specialized
  3985. functions, they are quite useful when you do need to use them. We
  3986. will give examples using the same directory and files that you created
  3987. in the last chapter. As you may recall, the directory is called
  3988. @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
  3989. and the two archive files you created are
  3990. @samp{collection.tar} and @samp{music.tar}.
  3991. We will also use the archive files @samp{afiles.tar} and
  3992. @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
  3993. @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
  3994. @samp{./birds}, @samp{baboon}, and @samp{./box}.
  3995. Unless we state otherwise, all practicing you do and examples you follow
  3996. in this chapter will take place in the @file{practice} directory that
  3997. you created in the previous chapter; see @ref{prepare for examples}.
  3998. (Below in this section, we will remind you of the state of the examples
  3999. where the last chapter left them.)
  4000. The five operations that we will cover in this chapter are:
  4001. @table @option
  4002. @item --append
  4003. @itemx -r
  4004. Add new entries to an archive that already exists.
  4005. @item --update
  4006. @itemx -u
  4007. Add more recent copies of archive members to the end of an archive, if
  4008. they exist.
  4009. @item --concatenate
  4010. @itemx --catenate
  4011. @itemx -A
  4012. Add one or more pre-existing archives to the end of another archive.
  4013. @item --delete
  4014. Delete items from an archive (does not work on tapes).
  4015. @item --compare
  4016. @itemx --diff
  4017. @itemx -d
  4018. Compare archive members to their counterparts in the file system.
  4019. @end table
  4020. @node append
  4021. @subsection How to Add Files to Existing Archives: @option{--append}
  4022. @cindex appending files to existing archive
  4023. @opindex append
  4024. If you want to add files to an existing archive, you don't need to
  4025. create a new archive; you can use @option{--append} (@option{-r}).
  4026. The archive must already exist in order to use @option{--append}. (A
  4027. related operation is the @option{--update} operation; you can use this
  4028. to add newer versions of archive members to an existing archive. To learn how to
  4029. do this with @option{--update}, @pxref{update}.)
  4030. If you use @option{--append} to add a file that has the same name as an
  4031. archive member to an archive containing that archive member, then the
  4032. old member is not deleted. What does happen, however, is somewhat
  4033. complex. @command{tar} @emph{allows} you to have infinite number of files
  4034. with the same name. Some operations treat these same-named members no
  4035. differently than any other set of archive members: for example, if you
  4036. view an archive with @option{--list} (@option{-t}), you will see all
  4037. of those members listed, with their data modification times, owners, etc.
  4038. Other operations don't deal with these members as perfectly as you might
  4039. prefer; if you were to use @option{--extract} to extract the archive,
  4040. only the most recently added copy of a member with the same name as
  4041. other members would end up in the working directory. This is because
  4042. @option{--extract} extracts an archive in the order the members appeared
  4043. in the archive; the most recently archived members will be extracted
  4044. last. Additionally, an extracted member will @emph{replace} a file of
  4045. the same name which existed in the directory already, and @command{tar}
  4046. will not prompt you about this@footnote{Unless you give it
  4047. @option{--keep-old-files} (or @option{--skip-old-files}) option, or
  4048. the disk copy is newer than the one in the archive and you invoke
  4049. @command{tar} with @option{--keep-newer-files} option.}. Thus, only
  4050. the most recently archived member will end up being extracted, as it
  4051. will replace the one extracted before it, and so on.
  4052. @cindex extracting @var{n}th copy of the file
  4053. @xopindex{occurrence, described}
  4054. There exists a special option that allows you to get around this
  4055. behavior and extract (or list) only a particular copy of the file.
  4056. This is @option{--occurrence} option. If you run @command{tar} with
  4057. this option, it will extract only the first copy of the file. You
  4058. may also give this option an argument specifying the number of
  4059. copy to be extracted. Thus, for example if the archive
  4060. @file{archive.tar} contained three copies of file @file{myfile}, then
  4061. the command
  4062. @smallexample
  4063. tar --extract --file archive.tar --occurrence=2 myfile
  4064. @end smallexample
  4065. @noindent
  4066. would extract only the second copy. @xref{Option
  4067. Summary,---occurrence}, for the description of @option{--occurrence}
  4068. option.
  4069. @FIXME{ hag -- you might want to incorporate some of the above into the
  4070. MMwtSN node; not sure. i didn't know how to make it simpler...
  4071. There are a few ways to get around this. Xref to Multiple Members
  4072. with the Same Name, maybe.}
  4073. @cindex Members, replacing with other members
  4074. @cindex Replacing members with other members
  4075. @xopindex{delete, using before --append}
  4076. If you want to replace an archive member, use @option{--delete} to
  4077. delete the member you want to remove from the archive, and then use
  4078. @option{--append} to add the member you want to be in the archive. Note
  4079. that you can not change the order of the archive; the most recently
  4080. added member will still appear last. In this sense, you cannot truly
  4081. ``replace'' one member with another. (Replacing one member with another
  4082. will not work on certain types of media, such as tapes; see @ref{delete}
  4083. and @ref{Media}, for more information.)
  4084. @menu
  4085. * appending files:: Appending Files to an Archive
  4086. * multiple::
  4087. @end menu
  4088. @node appending files
  4089. @subsubsection Appending Files to an Archive
  4090. @cindex Adding files to an Archive
  4091. @cindex Appending files to an Archive
  4092. @cindex Archives, Appending files to
  4093. @opindex append
  4094. The simplest way to add a file to an already existing archive is the
  4095. @option{--append} (@option{-r}) operation, which writes specified
  4096. files into the archive whether or not they are already among the
  4097. archived files.
  4098. When you use @option{--append}, you @emph{must} specify file name
  4099. arguments, as there is no default. If you specify a file that already
  4100. exists in the archive, another copy of the file will be added to the
  4101. end of the archive. As with other operations, the member names of the
  4102. newly added files will be exactly the same as their names given on the
  4103. command line. The @option{--verbose} (@option{-v}) option will print
  4104. out the names of the files as they are written into the archive.
  4105. @option{--append} cannot be performed on some tape drives, unfortunately,
  4106. due to deficiencies in the formats those tape drives use. The archive
  4107. must be a valid @command{tar} archive, or else the results of using this
  4108. operation will be unpredictable. @xref{Media}.
  4109. To demonstrate using @option{--append} to add a file to an archive,
  4110. create a file called @file{rock} in the @file{practice} directory.
  4111. Make sure you are in the @file{practice} directory. Then, run the
  4112. following @command{tar} command to add @file{rock} to
  4113. @file{collection.tar}:
  4114. @smallexample
  4115. $ @kbd{tar --append --file=collection.tar rock}
  4116. @end smallexample
  4117. @noindent
  4118. If you now use the @option{--list} (@option{-t}) operation, you will see that
  4119. @file{rock} has been added to the archive:
  4120. @smallexample
  4121. $ @kbd{tar --list --file=collection.tar}
  4122. -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
  4123. -rw-r--r-- me/user 21 1996-09-23 16:44 blues
  4124. -rw-r--r-- me/user 20 1996-09-23 16:44 folk
  4125. -rw-r--r-- me/user 20 1996-09-23 16:44 rock
  4126. @end smallexample
  4127. @node multiple
  4128. @subsubsection Multiple Members with the Same Name
  4129. @cindex members, multiple
  4130. @cindex multiple members
  4131. You can use @option{--append} (@option{-r}) to add copies of files
  4132. which have been updated since the archive was created. (However, we
  4133. do not recommend doing this since there is another @command{tar}
  4134. option called @option{--update}; @xref{update}, for more information.
  4135. We describe this use of @option{--append} here for the sake of
  4136. completeness.) When you extract the archive, the older version will
  4137. be effectively lost. This works because files are extracted from an
  4138. archive in the order in which they were archived. Thus, when the
  4139. archive is extracted, a file archived later in time will replace a
  4140. file of the same name which was archived earlier, even though the
  4141. older version of the file will remain in the archive unless you delete
  4142. all versions of the file.
  4143. Supposing you change the file @file{blues} and then append the changed
  4144. version to @file{collection.tar}. As you saw above, the original
  4145. @file{blues} is in the archive @file{collection.tar}. If you change the
  4146. file and append the new version of the file to the archive, there will
  4147. be two copies in the archive. When you extract the archive, the older
  4148. version of the file will be extracted first, and then replaced by the
  4149. newer version when it is extracted.
  4150. You can append the new, changed copy of the file @file{blues} to the
  4151. archive in this way:
  4152. @smallexample
  4153. $ @kbd{tar --append --verbose --file=collection.tar blues}
  4154. blues
  4155. @end smallexample
  4156. @noindent
  4157. Because you specified the @option{--verbose} option, @command{tar} has
  4158. printed the name of the file being appended as it was acted on. Now
  4159. list the contents of the archive:
  4160. @smallexample
  4161. $ @kbd{tar --list --verbose --file=collection.tar}
  4162. -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
  4163. -rw-r--r-- me/user 21 1996-09-23 16:44 blues
  4164. -rw-r--r-- me/user 20 1996-09-23 16:44 folk
  4165. -rw-r--r-- me/user 20 1996-09-23 16:44 rock
  4166. -rw-r--r-- me/user 58 1996-10-24 18:30 blues
  4167. @end smallexample
  4168. @noindent
  4169. The newest version of @file{blues} is now at the end of the archive
  4170. (note the different creation dates and file sizes). If you extract
  4171. the archive, the older version of the file @file{blues} will be
  4172. replaced by the newer version. You can confirm this by extracting
  4173. the archive and running @samp{ls} on the directory.
  4174. If you wish to extract the first occurrence of the file @file{blues}
  4175. from the archive, use @option{--occurrence} option, as shown in
  4176. the following example:
  4177. @smallexample
  4178. $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
  4179. -rw-r--r-- me/user 21 1996-09-23 16:44 blues
  4180. @end smallexample
  4181. @xref{Writing}, for more information on @option{--extract} and
  4182. see @ref{Option Summary, --occurrence}, for a description of
  4183. @option{--occurrence} option.
  4184. @node update
  4185. @subsection Updating an Archive
  4186. @cindex Updating an archive
  4187. @opindex update
  4188. In the previous section, you learned how to use @option{--append} to
  4189. add a file to an existing archive. A related operation is
  4190. @option{--update} (@option{-u}). The @option{--update} operation
  4191. updates a @command{tar} archive by comparing the date of the specified
  4192. archive members against the date of the file with the same name. If
  4193. the file has been modified more recently than the archive member, then
  4194. the newer version of the file is added to the archive (as with
  4195. @option{--append}).
  4196. Unfortunately, you cannot use @option{--update} with magnetic tape drives.
  4197. The operation will fail.
  4198. @FIXME{other examples of media on which --update will fail? need to ask
  4199. charles and/or mib/thomas/dave shevett..}
  4200. Both @option{--update} and @option{--append} work by adding to the end
  4201. of the archive. When you extract a file from the archive, only the
  4202. version stored last will wind up in the file system, unless you use
  4203. the @option{--backup} option. @xref{multiple}, for a detailed discussion.
  4204. @menu
  4205. * how to update::
  4206. @end menu
  4207. @node how to update
  4208. @subsubsection How to Update an Archive Using @option{--update}
  4209. @opindex update
  4210. You must use file name arguments with the @option{--update}
  4211. (@option{-u}) operation. If you don't specify any files,
  4212. @command{tar} won't act on any files and won't tell you that it didn't
  4213. do anything (which may end up confusing you).
  4214. @c note: the above parenthetical added because in fact, this
  4215. @c behavior just confused the author. :-)
  4216. To see the @option{--update} option at work, create a new file,
  4217. @file{classical}, in your practice directory, and some extra text to the
  4218. file @file{blues}, using any text editor. Then invoke @command{tar} with
  4219. the @samp{update} operation and the @option{--verbose} (@option{-v})
  4220. option specified, using the names of all the files in the @file{practice}
  4221. directory as file name arguments:
  4222. @smallexample
  4223. $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
  4224. blues
  4225. classical
  4226. $
  4227. @end smallexample
  4228. @noindent
  4229. Because we have specified verbose mode, @command{tar} prints out the names
  4230. of the files it is working on, which in this case are the names of the
  4231. files that needed to be updated. If you run @samp{tar --list} and look
  4232. at the archive, you will see @file{blues} and @file{classical} at its
  4233. end. There will be a total of two versions of the member @samp{blues};
  4234. the one at the end will be newer and larger, since you added text before
  4235. updating it.
  4236. The reason @command{tar} does not overwrite the older file when updating
  4237. it is that writing to the middle of a section of tape is a difficult
  4238. process. Tapes are not designed to go backward. @xref{Media}, for more
  4239. information about tapes.
  4240. @option{--update} (@option{-u}) is not suitable for performing backups for two
  4241. reasons: it does not change directory content entries, and it
  4242. lengthens the archive every time it is used. The @GNUTAR{}
  4243. options intended specifically for backups are more
  4244. efficient. If you need to run backups, please consult @ref{Backups}.
  4245. @node concatenate
  4246. @subsection Combining Archives with @option{--concatenate}
  4247. @cindex Adding archives to an archive
  4248. @cindex Concatenating Archives
  4249. @opindex concatenate
  4250. @opindex catenate
  4251. @c @cindex @option{-A} described
  4252. Sometimes it may be convenient to add a second archive onto the end of
  4253. an archive rather than adding individual files to the archive. To add
  4254. one or more archives to the end of another archive, you should use the
  4255. @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
  4256. To use @option{--concatenate}, give the first archive with
  4257. @option{--file} option and name the rest of archives to be
  4258. concatenated on the command line. The members, and their member
  4259. names, will be copied verbatim from those archives to the first
  4260. one@footnote{This can cause multiple members to have the same name. For
  4261. information on how this affects reading the archive, see @ref{multiple}.}.
  4262. The new, concatenated archive will be called by the same name as the
  4263. one given with the @option{--file} option. As usual, if you omit
  4264. @option{--file}, @command{tar} will use the value of the environment
  4265. variable @env{TAPE}, or, if this has not been set, the default archive name.
  4266. @FIXME{There is no way to specify a new name...}
  4267. To demonstrate how @option{--concatenate} works, create two small archives
  4268. called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
  4269. files from @file{practice}:
  4270. @smallexample
  4271. $ @kbd{tar -cvf bluesrock.tar blues rock}
  4272. blues
  4273. rock
  4274. $ @kbd{tar -cvf folkjazz.tar folk jazz}
  4275. folk
  4276. jazz
  4277. @end smallexample
  4278. @noindent
  4279. If you like, you can run @samp{tar --list} to make sure the archives
  4280. contain what they are supposed to:
  4281. @smallexample
  4282. $ @kbd{tar -tvf bluesrock.tar}
  4283. -rw-r--r-- melissa/user 105 1997-01-21 19:42 blues
  4284. -rw-r--r-- melissa/user 33 1997-01-20 15:34 rock
  4285. $ @kbd{tar -tvf jazzfolk.tar}
  4286. -rw-r--r-- melissa/user 20 1996-09-23 16:44 folk
  4287. -rw-r--r-- melissa/user 65 1997-01-30 14:15 jazz
  4288. @end smallexample
  4289. We can concatenate these two archives with @command{tar}:
  4290. @smallexample
  4291. $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
  4292. @end smallexample
  4293. If you now list the contents of the @file{bluesrock.tar}, you will see
  4294. that now it also contains the archive members of @file{jazzfolk.tar}:
  4295. @smallexample
  4296. $ @kbd{tar --list --file=bluesrock.tar}
  4297. blues
  4298. rock
  4299. folk
  4300. jazz
  4301. @end smallexample
  4302. When you use @option{--concatenate}, the source and target archives must
  4303. already exist and must have been created using compatible format
  4304. parameters. Notice, that @command{tar} does not check whether the
  4305. archives it concatenates have compatible formats, it does not
  4306. even check if the files are really tar archives.
  4307. Like @option{--append} (@option{-r}), this operation cannot be performed on some
  4308. tape drives, due to deficiencies in the formats those tape drives use.
  4309. @cindex @code{concatenate} vs @command{cat}
  4310. @cindex @command{cat} vs @code{concatenate}
  4311. It may seem more intuitive to you to want or try to use @command{cat} to
  4312. concatenate two archives instead of using the @option{--concatenate}
  4313. operation; after all, @command{cat} is the utility for combining files.
  4314. However, @command{tar} archives incorporate an end-of-file marker which
  4315. must be removed if the concatenated archives are to be read properly as
  4316. one archive. @option{--concatenate} removes the end-of-archive marker
  4317. from the target archive before each new archive is appended. If you use
  4318. @command{cat} to combine the archives, the result will not be a valid
  4319. @command{tar} format archive. If you need to retrieve files from an
  4320. archive that was added to using the @command{cat} utility, use the
  4321. @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
  4322. information on dealing with archives improperly combined using the
  4323. @command{cat} shell utility.
  4324. @node delete
  4325. @subsection Removing Archive Members Using @option{--delete}
  4326. @cindex Deleting files from an archive
  4327. @cindex Removing files from an archive
  4328. @opindex delete
  4329. You can remove members from an archive by using the @option{--delete}
  4330. option. Specify the name of the archive with @option{--file}
  4331. (@option{-f}) and then specify the names of the members to be deleted;
  4332. if you list no member names, nothing will be deleted. The
  4333. @option{--verbose} option will cause @command{tar} to print the names
  4334. of the members as they are deleted. As with @option{--extract}, you
  4335. must give the exact member names when using @samp{tar --delete}.
  4336. @option{--delete} will remove all versions of the named file from the
  4337. archive. The @option{--delete} operation can run very slowly.
  4338. Unlike other operations, @option{--delete} has no short form.
  4339. @cindex Tapes, using @option{--delete} and
  4340. @cindex Deleting from tape archives
  4341. This operation will rewrite the archive. You can only use
  4342. @option{--delete} on an archive if the archive device allows you to
  4343. write to any point on the media, such as a disk; because of this, it
  4344. does not work on magnetic tapes. Do not try to delete an archive member
  4345. from a magnetic tape; the action will not succeed, and you will be
  4346. likely to scramble the archive and damage your tape. There is no safe
  4347. way (except by completely re-writing the archive) to delete files from
  4348. most kinds of magnetic tape. @xref{Media}.
  4349. To delete all versions of the file @file{blues} from the archive
  4350. @file{collection.tar} in the @file{practice} directory, make sure you
  4351. are in that directory, and then,
  4352. @smallexample
  4353. $ @kbd{tar --list --file=collection.tar}
  4354. blues
  4355. folk
  4356. jazz
  4357. rock
  4358. $ @kbd{tar --delete --file=collection.tar blues}
  4359. $ @kbd{tar --list --file=collection.tar}
  4360. folk
  4361. jazz
  4362. rock
  4363. @end smallexample
  4364. @FIXME{Check if the above listing is actually produced after running
  4365. all the examples on collection.tar.}
  4366. The @option{--delete} option has been reported to work properly when
  4367. @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
  4368. @node compare
  4369. @subsection Comparing Archive Members with the File System
  4370. @cindex Verifying the currency of an archive
  4371. @opindex compare
  4372. The @option{--compare} (@option{-d}), or @option{--diff} operation compares
  4373. specified archive members against files with the same names, and then
  4374. reports differences in file size, mode, owner, modification date and
  4375. contents. You should @emph{only} specify archive member names, not file
  4376. names. If you do not name any members, then @command{tar} will compare the
  4377. entire archive. If a file is represented in the archive but does not
  4378. exist in the file system, @command{tar} reports a difference.
  4379. You have to specify the record size of the archive when modifying an
  4380. archive with a non-default record size.
  4381. @command{tar} ignores files in the file system that do not have
  4382. corresponding members in the archive.
  4383. The following example compares the archive members @file{rock},
  4384. @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
  4385. files of the same name in the file system. (Note that there is no file,
  4386. @file{funk}; @command{tar} will report an error message.)
  4387. @smallexample
  4388. $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
  4389. rock
  4390. blues
  4391. tar: funk not found in archive
  4392. @end smallexample
  4393. The spirit behind the @option{--compare} (@option{--diff},
  4394. @option{-d}) option is to check whether the archive represents the
  4395. current state of files on disk, more than validating the integrity of
  4396. the archive media. For this latter goal, see @ref{verify}.
  4397. @node create options
  4398. @section Options Used by @option{--create}
  4399. @xopindex{create, additional options}
  4400. The previous chapter described the basics of how to use
  4401. @option{--create} (@option{-c}) to create an archive from a set of files.
  4402. @xref{create}. This section described advanced options to be used with
  4403. @option{--create}.
  4404. @menu
  4405. * override:: Overriding File Metadata.
  4406. * Extended File Attributes::
  4407. * Ignore Failed Read::
  4408. @end menu
  4409. @node override
  4410. @subsection Overriding File Metadata
  4411. As described above, a @command{tar} archive keeps, for each member it contains,
  4412. its @dfn{metadata}, such as modification time, mode and ownership of
  4413. the file. @GNUTAR{} allows to replace these data with other values
  4414. when adding files to the archive. The options described in this
  4415. section affect creation of archives of any type. For POSIX archives,
  4416. see also @ref{PAX keywords}, for additional ways of controlling
  4417. metadata, stored in the archive.
  4418. @table @option
  4419. @opindex mode
  4420. @item --mode=@var{permissions}
  4421. When adding files to an archive, @command{tar} will use
  4422. @var{permissions} for the archive members, rather than the permissions
  4423. from the files. @var{permissions} can be specified either as an octal
  4424. number or as symbolic permissions, like with
  4425. @command{chmod} (@xref{File permissions, Permissions, File
  4426. permissions, fileutils, @acronym{GNU} file utilities}. This reference
  4427. also has useful information for those not being overly familiar with
  4428. the UNIX permission system). Using latter syntax allows for
  4429. more flexibility. For example, the value @samp{a+rw} adds read and write
  4430. permissions for everybody, while retaining executable bits on directories
  4431. or on any other file already marked as executable:
  4432. @smallexample
  4433. $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
  4434. @end smallexample
  4435. @item --mtime=@var{date}
  4436. @opindex mtime
  4437. When adding files to an archive, @command{tar} uses @var{date} as
  4438. the modification time of members when creating archives, instead of
  4439. their actual modification times. The argument @var{date} can be
  4440. either a textual date representation in almost arbitrary format
  4441. (@pxref{Date input formats}) or a name of an existing file, starting
  4442. with @samp{/} or @samp{.}. In the latter case, the modification time
  4443. of that file is used.
  4444. The following example sets the modification date to 00:00:00 @sc{utc} on
  4445. January 1, 1970:
  4446. @smallexample
  4447. $ @kbd{tar -c -f archive.tar --mtime='@@0' .}
  4448. @end smallexample
  4449. @noindent
  4450. When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
  4451. converts the specified date back to a textual form and compares it
  4452. with the one given with @option{--mtime}.
  4453. If the two forms differ, @command{tar} prints both forms in a message,
  4454. to help the user check that the right date is being used.
  4455. For example:
  4456. @smallexample
  4457. $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
  4458. tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
  4459. 13:06:29.152478
  4460. @dots{}
  4461. @end smallexample
  4462. @noindent
  4463. When used with @option{--clamp-mtime} @GNUTAR{} sets the
  4464. modification date to @var{date} only on files whose actual modification
  4465. date is later than @var{date}. This makes it easier to build
  4466. reproducible archives given a common timestamp for generated files
  4467. while still retaining the original timestamps of untouched files.
  4468. @xref{Reproducibility}.
  4469. @smallexample
  4470. $ @kbd{tar -c -f archive.tar --clamp-mtime --mtime="$SOURCE_EPOCH" .}
  4471. @end smallexample
  4472. @item --owner=@var{user}
  4473. @opindex owner
  4474. Specifies that @command{tar} should use @var{user} as the owner of members
  4475. when creating archives, instead of the user associated with the source
  4476. file.
  4477. If @var{user} contains a colon, it is taken to be of the form
  4478. @var{name}:@var{id} where a nonempty @var{name} specifies the user
  4479. name and a nonempty @var{id} specifies the decimal numeric user
  4480. @acronym{ID}. If @var{user} does not contain a colon, it is taken to
  4481. be a user number if it is one or more decimal digits; otherwise it is
  4482. taken to be a user name.
  4483. If a name is given but no number, the number is inferred from the
  4484. current host's user database if possible, and the file's user number
  4485. is used otherwise. If a number is given but no name, the name is
  4486. inferred from the number if possible, and an empty name is used
  4487. otherwise. If both name and number are given, the user database is
  4488. not consulted, and the name and number need not be valid on the
  4489. current host.
  4490. There is no value indicating a missing number, and @samp{0} usually means
  4491. @code{root}. Some people like to force @samp{0} as the value to offer in
  4492. their distributions for the owner of files, because the @code{root} user is
  4493. anonymous anyway, so that might as well be the owner of anonymous
  4494. archives. For example:
  4495. @smallexample
  4496. $ @kbd{tar -c -f archive.tar --owner=0 .}
  4497. @end smallexample
  4498. @noindent
  4499. or:
  4500. @smallexample
  4501. $ @kbd{tar -c -f archive.tar --owner=root .}
  4502. @end smallexample
  4503. @item --group=@var{group}
  4504. @opindex group
  4505. Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
  4506. rather than the group from the source file. As with @option{--owner},
  4507. the argument @var{group} can be an existing group symbolic name, or a
  4508. decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
  4509. @end table
  4510. The @option{--owner} and @option{--group} options affect all files
  4511. added to the archive. @GNUTAR{} provides also two options that allow
  4512. for more detailed control over owner translation:
  4513. @table @option
  4514. @item --owner-map=@var{file}
  4515. Read UID translation map from @var{file}.
  4516. When reading, empty lines are ignored. The @samp{#} sign, unless
  4517. quoted, introduces a comment, which extends to the end of the line.
  4518. Each nonempty line defines mapping for a single UID. It must consist
  4519. of two fields separated by any amount of whitespace. The first field
  4520. defines original username and UID. It can be a valid user name or
  4521. a valid UID prefixed with a plus sign. In both cases the
  4522. corresponding UID or user name is inferred from the current host's
  4523. user database.
  4524. The second field defines the UID and username to map the original one
  4525. to. Its format can be the same as described above. Otherwise, it can
  4526. have the form @var{newname}:@var{newuid}, in which case neither
  4527. @var{newname} nor @var{newuid} are required to be valid as per the
  4528. user database.
  4529. For example, consider the following file:
  4530. @example
  4531. +10 bin
  4532. smith root:0
  4533. @end example
  4534. @noindent
  4535. Given this file, each input file that is owner by UID 10 will be
  4536. stored in archive with owner name @samp{bin} and owner UID
  4537. corresponding to @samp{bin}. Each file owned by user @samp{smith}
  4538. will be stored with owner name @samp{root} and owner ID 0. Other
  4539. files will remain unchanged.
  4540. When used together with @option{--owner-map}, the @option{--owner}
  4541. option affects only files whose owner is not listed in the map file.
  4542. @item --group-map=@var{file}
  4543. Read GID translation map from @var{file}.
  4544. The format of @var{file} is the same as for @option{--owner-map}
  4545. option:
  4546. Each nonempty line defines mapping for a single GID. It must consist
  4547. of two fields separated by any amount of whitespace. The first field
  4548. defines original group name and GID. It can be a valid group name or
  4549. a valid GID prefixed with a plus sign. In both cases the
  4550. corresponding GID or user name is inferred from the current host's
  4551. group database.
  4552. The second field defines the GID and group name to map the original one
  4553. to. Its format can be the same as described above. Otherwise, it can
  4554. have the form @var{newname}:@var{newgid}, in which case neither
  4555. @var{newname} nor @var{newgid} are required to be valid as per the
  4556. group database.
  4557. When used together with @option{--group-map}, the @option{--group}
  4558. option affects only files whose owner group is not rewritten using the
  4559. map file.
  4560. @end table
  4561. @node Extended File Attributes
  4562. @subsection Extended File Attributes
  4563. Extended file attributes are name-value pairs that can be
  4564. associated with each node in a file system. Despite the fact that
  4565. POSIX.1e draft which proposed them has been withdrawn, the extended
  4566. file attributes are supported by many file systems. @GNUTAR{} can
  4567. store extended file attributes along with the files. This feature is
  4568. controlled by the following command line arguments:
  4569. @table @option
  4570. @item --xattrs
  4571. Enable extended attributes support. When used with @option{--create},
  4572. this option instructs @GNUTAR{} to store extended file attribute in the
  4573. created archive. This implies POSIX.1-2001 archive format
  4574. (@option{--format=pax}).
  4575. When used with @option{--extract}, this option tells @command{tar},
  4576. for each file extracted, to read stored attributes from the archive
  4577. and to apply them to the file.
  4578. @item --no-xattrs
  4579. Disable extended attributes support. This is the default.
  4580. @end table
  4581. Attribute names are strings prefixed by a @dfn{namespace} name and a dot.
  4582. Currently, four namespaces exist: @samp{user}, @samp{trusted},
  4583. @samp{security} and @samp{system}. By default, when @option{--xattrs}
  4584. is used, all names are stored in the archive (with @option{--create}),
  4585. but only @samp{user} namespace is extracted (if using @option{--extract}).
  4586. The reason for this behavior is that any other, system defined attributes
  4587. don't provide us sufficient compatibility promise. Storing all attributes
  4588. is safe operation for the archiving purposes. Though extracting those
  4589. (often security related) attributes on a different system than originally
  4590. archived can lead to extraction failures, or even misinterpretations.
  4591. This behavior can be controlled using the following options:
  4592. @table @option
  4593. @item --xattrs-exclude=@var{pattern}
  4594. Specify exclude pattern for extended attributes.
  4595. @item --xattrs-include=@var{pattern}
  4596. Specify include pattern for extended attributes.
  4597. @end table
  4598. Here, the @var{pattern} is a globbing pattern. For example, the
  4599. following command:
  4600. @example
  4601. $ @kbd{tar --xattrs --xattrs-exclude='user.*' -cf a.tar .}
  4602. @end example
  4603. will include in the archive @file{a.tar} all attributes, except those
  4604. from the @samp{user} namespace.
  4605. Users shall check the attributes are binary compatible with the target system
  4606. before any other namespace is extracted with an explicit
  4607. @option{--xattrs-include} option.
  4608. Any number of these options can be given, thereby creating lists of
  4609. include and exclude patterns.
  4610. When both options are used, first @option{--xattrs-include} is applied
  4611. to select the set of attribute names to keep, and then
  4612. @option{--xattrs-exclude} is applied to the resulting set. In other
  4613. words, only those attributes will be stored, whose names match one
  4614. of the regexps in @option{--xattrs-include} and don't match any of
  4615. the regexps from @option{--xattrs-exclude}.
  4616. When listing the archive, if both @option{--xattrs} and
  4617. @option{--verbose} options are given, files that have extended
  4618. attributes are marked with an asterisk following their permission
  4619. mask. For example:
  4620. @example
  4621. -rw-r--r--* smith/users 110 2016-03-16 16:07 file
  4622. @end example
  4623. When two or more @option{--verbose} options are given, a detailed
  4624. listing of extended attributes is printed after each file entry. Each
  4625. attribute is listed on a separate line, which begins with two spaces
  4626. and the letter @samp{x} indicating extended attribute. It is followed
  4627. by a colon, length of the attribute and its name, e.g.:
  4628. @example
  4629. -rw-r--r--* smith/users 110 2016-03-16 16:07 file
  4630. x: 7 user.mime_type
  4631. x: 32 trusted.md5sum
  4632. @end example
  4633. File access control lists (@dfn{ACL}) are another actively used feature
  4634. proposed by the POSIX.1e standard. Each ACL consists of a set of ACL
  4635. entries, each of which describes the access permissions on the file for
  4636. an individual user or a group of users as a combination of read, write
  4637. and search/execute permissions.
  4638. Whether or not to use ACLs is controlled by the following two options:
  4639. @table @option
  4640. @item --acls
  4641. Enable POSIX ACLs support. When used with @option{--create},
  4642. this option instructs @GNUTAR{} to store ACLs in the
  4643. created archive. This implies POSIX.1-2001 archive format
  4644. (@option{--format=pax}).
  4645. When used with @option{--extract}, this option tells @command{tar},
  4646. to restore ACLs for each file extracted (provided they are present
  4647. in the archive).
  4648. @item --no-acls
  4649. Disable POSIX ACLs support. This is the default.
  4650. @end table
  4651. When listing the archive, if both @option{--acls} and
  4652. @option{--verbose} options are given, files that have ACLs are marked
  4653. with a plus sign following their permission mask. For example:
  4654. @example
  4655. -rw-r--r--+ smith/users 110 2016-03-16 16:07 file
  4656. @end example
  4657. When two or more @option{--verbose} options are given, a detailed
  4658. listing of ACL is printed after each file entry:
  4659. @example
  4660. @group
  4661. -rw-r--r--+ smith/users 110 2016-03-16 16:07 file
  4662. a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r--
  4663. @end group
  4664. @end example
  4665. @dfn{Security-Enhanced Linux} (@dfn{SELinux} for short) is a Linux
  4666. kernel security module that provides a mechanism for supporting access
  4667. control security policies, including so-called mandatory access
  4668. controls (@dfn{MAC}). Support for SELinux attributes is controlled by
  4669. the following command line options:
  4670. @table @option
  4671. @item --selinux
  4672. Enable the SELinux context support.
  4673. @item --no-selinux
  4674. Disable SELinux context support.
  4675. @end table
  4676. @node Ignore Failed Read
  4677. @subsection Ignore Failed Read
  4678. @table @option
  4679. @item --ignore-failed-read
  4680. @opindex ignore-failed-read
  4681. Do not exit with nonzero if there are mild problems while reading.
  4682. @end table
  4683. This option has effect only during creation. It instructs tar to
  4684. treat as mild conditions any missing or unreadable files (directories),
  4685. or files that change while reading.
  4686. Such failures don't affect the program exit code, and the
  4687. corresponding diagnostic messages are marked as warnings, not errors.
  4688. These warnings can be suppressed using the
  4689. @option{--warning=failed-read} option (@pxref{warnings}).
  4690. @node extract options
  4691. @section Options Used by @option{--extract}
  4692. @cindex options for use with @option{--extract}
  4693. @xopindex{extract, additional options}
  4694. The previous chapter showed how to use @option{--extract} to extract
  4695. an archive into the file system. Various options cause @command{tar} to
  4696. extract more information than just file contents, such as the owner,
  4697. the permissions, the modification date, and so forth. This section
  4698. presents options to be used with @option{--extract} when certain special
  4699. considerations arise. You may review the information presented in
  4700. @ref{extract} for more basic information about the
  4701. @option{--extract} operation.
  4702. @menu
  4703. * Reading:: Options to Help Read Archives
  4704. * Writing:: Changing How @command{tar} Writes Files
  4705. * Scarce:: Coping with Scarce Resources
  4706. @end menu
  4707. @node Reading
  4708. @subsection Options to Help Read Archives
  4709. @cindex Options when reading archives
  4710. @cindex Reading incomplete records
  4711. @cindex Records, incomplete
  4712. @opindex read-full-records
  4713. Normally, @command{tar} will request data in full record increments from
  4714. an archive storage device. If the device cannot return a full record,
  4715. @command{tar} will report an error. However, some devices do not always
  4716. return full records, or do not require the last record of an archive to
  4717. be padded out to the next record boundary. To keep reading until you
  4718. obtain a full record, or to accept an incomplete record if it contains
  4719. an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
  4720. in conjunction with the @option{--extract} or @option{--list} operations.
  4721. @xref{Blocking}.
  4722. The @option{--read-full-records} (@option{-B}) option is turned on by default when
  4723. @command{tar} reads an archive from standard input, or from a remote
  4724. machine. This is because on @acronym{BSD} Unix systems, attempting to read a
  4725. pipe returns however much happens to be in the pipe, even if it is
  4726. less than was requested. If this option were not enabled, @command{tar}
  4727. would fail as soon as it read an incomplete record from the pipe.
  4728. If you're not sure of the blocking factor of an archive, you can
  4729. read the archive by specifying @option{--read-full-records} (@option{-B}) and
  4730. @option{--blocking-factor=@var{512-size}} (@option{-b
  4731. @var{512-size}}), using a blocking factor larger than what the archive
  4732. uses. This lets you avoid having to determine the blocking factor
  4733. of an archive. @xref{Blocking Factor}.
  4734. @menu
  4735. * read full records::
  4736. * Ignore Zeros::
  4737. @end menu
  4738. @node read full records
  4739. @unnumberedsubsubsec Reading Full Records
  4740. @FIXME{need sentence or so of intro here}
  4741. @table @option
  4742. @opindex read-full-records
  4743. @item --read-full-records
  4744. @item -B
  4745. Use in conjunction with @option{--extract} (@option{--get},
  4746. @option{-x}) to read an archive which contains incomplete records, or
  4747. one which has a blocking factor less than the one specified.
  4748. @end table
  4749. @node Ignore Zeros
  4750. @unnumberedsubsubsec Ignoring Blocks of Zeros
  4751. @cindex End-of-archive blocks, ignoring
  4752. @cindex Ignoring end-of-archive blocks
  4753. @opindex ignore-zeros
  4754. Normally, @command{tar} stops reading when it encounters a block of zeros
  4755. between file entries (which usually indicates the end of the archive).
  4756. @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
  4757. completely read an archive which contains a block of zeros before the
  4758. end (i.e., a damaged archive, or one that was created by concatenating
  4759. several archives together). This option also suppresses warnings
  4760. about missing or incomplete zero blocks at the end of the archive.
  4761. This can be turned on, if the need be, using the
  4762. @option{--warning=alone-zero-block --warning=missing-zero-blocks}
  4763. options (@pxref{warnings}).
  4764. The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
  4765. versions of @command{tar} write garbage after the end-of-archive entry,
  4766. since that part of the media is never supposed to be read. @GNUTAR{}
  4767. does not write after the end of an archive, but seeks to
  4768. maintain compatibility among archiving utilities.
  4769. @table @option
  4770. @item --ignore-zeros
  4771. @itemx -i
  4772. To ignore blocks of zeros (i.e., end-of-archive entries) which may be
  4773. encountered while reading an archive. Use in conjunction with
  4774. @option{--extract} or @option{--list}.
  4775. @end table
  4776. @node Writing
  4777. @subsection Changing How @command{tar} Writes Files
  4778. @UNREVISED{}
  4779. @FIXME{Introductory paragraph}
  4780. @menu
  4781. * Dealing with Old Files::
  4782. * Overwrite Old Files::
  4783. * Keep Old Files::
  4784. * Keep Newer Files::
  4785. * Unlink First::
  4786. * Recursive Unlink::
  4787. * Data Modification Times::
  4788. * Setting Access Permissions::
  4789. * Directory Modification Times and Permissions::
  4790. * Writing to Standard Output::
  4791. * Writing to an External Program::
  4792. * remove files::
  4793. @end menu
  4794. @node Dealing with Old Files
  4795. @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
  4796. @xopindex{overwrite-dir, introduced}
  4797. When extracting files, if @command{tar} discovers that the extracted
  4798. file already exists, it normally replaces the file by removing it before
  4799. extracting it, to prevent confusion in the presence of hard or symbolic
  4800. links. (If the existing file is a symbolic link, it is removed, not
  4801. followed.) However, if a directory cannot be removed because it is
  4802. nonempty, @command{tar} normally overwrites its metadata (ownership,
  4803. permission, etc.). The @option{--overwrite-dir} option enables this
  4804. default behavior. To be more cautious and preserve the metadata of
  4805. such a directory, use the @option{--no-overwrite-dir} option.
  4806. @cindex Overwriting old files, prevention
  4807. @xopindex{keep-old-files, introduced}
  4808. To be even more cautious and prevent existing files from being replaced, use
  4809. the @option{--keep-old-files} (@option{-k}) option. It causes
  4810. @command{tar} to refuse to replace or update a file that already
  4811. exists, i.e., a file with the same name as an archive member prevents
  4812. extraction of that archive member. Instead, it reports an error. For
  4813. example:
  4814. @example
  4815. $ @kbd{ls}
  4816. blues
  4817. $ @kbd{tar -x -k -f archive.tar}
  4818. tar: blues: Cannot open: File exists
  4819. tar: Exiting with failure status due to previous errors
  4820. @end example
  4821. @xopindex{skip-old-files, introduced}
  4822. If you wish to preserve old files untouched, but don't want
  4823. @command{tar} to treat them as errors, use the
  4824. @option{--skip-old-files} option. This option causes @command{tar} to
  4825. silently skip extracting over existing files.
  4826. @xopindex{overwrite, introduced}
  4827. To be more aggressive about altering existing files, use the
  4828. @option{--overwrite} option. It causes @command{tar} to overwrite
  4829. existing files and to follow existing symbolic links when extracting.
  4830. @cindex Protecting old files
  4831. Some people argue that @GNUTAR{} should not hesitate
  4832. to overwrite files with other files when extracting. When extracting
  4833. a @command{tar} archive, they expect to see a faithful copy of the
  4834. state of the file system when the archive was created. It is debatable
  4835. that this would always be a proper behavior. For example, suppose one
  4836. has an archive in which @file{usr/local} is a link to
  4837. @file{usr/local2}. Since then, maybe the site removed the link and
  4838. renamed the whole hierarchy from @file{/usr/local2} to
  4839. @file{/usr/local}. Such things happen all the time. I guess it would
  4840. not be welcome at all that @GNUTAR{} removes the
  4841. whole hierarchy just to make room for the link to be reinstated
  4842. (unless it @emph{also} simultaneously restores the full
  4843. @file{/usr/local2}, of course!) @GNUTAR{} is indeed
  4844. able to remove a whole hierarchy to reestablish a symbolic link, for
  4845. example, but @emph{only if} @option{--recursive-unlink} is specified
  4846. to allow this behavior. In any case, single files are silently
  4847. removed.
  4848. @xopindex{unlink-first, introduced}
  4849. Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
  4850. some cases by causing @command{tar} to remove files unconditionally
  4851. before extracting them.
  4852. @node Overwrite Old Files
  4853. @unnumberedsubsubsec Overwrite Old Files
  4854. @table @option
  4855. @opindex overwrite
  4856. @item --overwrite
  4857. Overwrite existing files and directory metadata when extracting files
  4858. from an archive.
  4859. This causes @command{tar} to write extracted files into the file system without
  4860. regard to the files already on the system; i.e., files with the same
  4861. names as archive members are overwritten when the archive is extracted.
  4862. It also causes @command{tar} to extract the ownership, permissions,
  4863. and time stamps onto any preexisting files or directories.
  4864. If the name of a corresponding file name is a symbolic link, the file
  4865. pointed to by the symbolic link will be overwritten instead of the
  4866. symbolic link itself (if this is possible). Moreover, special devices,
  4867. empty directories and even symbolic links are automatically removed if
  4868. they are in the way of extraction.
  4869. Be careful when using the @option{--overwrite} option, particularly when
  4870. combined with the @option{--absolute-names} (@option{-P}) option, as this combination
  4871. can change the contents, ownership or permissions of any file on your
  4872. system. Also, many systems do not take kindly to overwriting files that
  4873. are currently being executed.
  4874. @opindex overwrite-dir
  4875. @item --overwrite-dir
  4876. Overwrite the metadata of directories when extracting files from an
  4877. archive, but remove other files before extracting.
  4878. @end table
  4879. @node Keep Old Files
  4880. @unnumberedsubsubsec Keep Old Files
  4881. @GNUTAR{} provides two options to control its actions in a situation
  4882. when it is about to extract a file which already exists on disk.
  4883. @table @option
  4884. @opindex keep-old-files
  4885. @item --keep-old-files
  4886. @itemx -k
  4887. Do not replace existing files from archive. When such a file is
  4888. encountered, @command{tar} issues an error message. Upon end of
  4889. extraction, @command{tar} exits with code 2 (@pxref{exit status}).
  4890. @item --skip-old-files
  4891. Do not replace existing files from archive, but do not treat that
  4892. as error. Such files are silently skipped and do not affect
  4893. @command{tar} exit status.
  4894. Additional verbosity can be obtained using @option{--warning=existing-file}
  4895. together with that option (@pxref{warnings}).
  4896. @end table
  4897. @node Keep Newer Files
  4898. @unnumberedsubsubsec Keep Newer Files
  4899. @table @option
  4900. @opindex keep-newer-files
  4901. @item --keep-newer-files
  4902. Do not replace existing files that are newer than their archive
  4903. copies. This option is meaningless with @option{--list} (@option{-t}).
  4904. @end table
  4905. @node Unlink First
  4906. @unnumberedsubsubsec Unlink First
  4907. @table @option
  4908. @opindex unlink-first
  4909. @item --unlink-first
  4910. @itemx -U
  4911. Remove files before extracting over them.
  4912. This can make @command{tar} run a bit faster if you know in advance
  4913. that the extracted files all need to be removed. Normally this option
  4914. slows @command{tar} down slightly, so it is disabled by default.
  4915. @end table
  4916. @node Recursive Unlink
  4917. @unnumberedsubsubsec Recursive Unlink
  4918. @table @option
  4919. @opindex recursive-unlink
  4920. @item --recursive-unlink
  4921. When this option is specified, try removing files and directory hierarchies
  4922. before extracting over them. @emph{This is a dangerous option!}
  4923. @end table
  4924. If you specify the @option{--recursive-unlink} option,
  4925. @command{tar} removes @emph{anything} that keeps you from extracting a file
  4926. as far as current permissions will allow it. This could include removal
  4927. of the contents of a full directory hierarchy.
  4928. @node Data Modification Times
  4929. @unnumberedsubsubsec Setting Data Modification Times
  4930. @cindex Data modification times of extracted files
  4931. @cindex Modification times of extracted files
  4932. Normally, @command{tar} sets the data modification times of extracted
  4933. files to the corresponding times recorded for the files in the archive, but
  4934. limits the permissions of extracted files by the current @code{umask}
  4935. setting.
  4936. To set the data modification times of extracted files to the time when
  4937. the files were extracted, use the @option{--touch} (@option{-m}) option in
  4938. conjunction with @option{--extract} (@option{--get}, @option{-x}).
  4939. @table @option
  4940. @opindex touch
  4941. @item --touch
  4942. @itemx -m
  4943. Sets the data modification time of extracted archive members to the time
  4944. they were extracted, not the time recorded for them in the archive.
  4945. Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
  4946. @end table
  4947. @node Setting Access Permissions
  4948. @unnumberedsubsubsec Setting Access Permissions
  4949. @cindex Permissions of extracted files
  4950. @cindex Modes of extracted files
  4951. To set the modes (access permissions) of extracted files to those
  4952. recorded for those files in the archive, use @option{--same-permissions}
  4953. in conjunction with the @option{--extract} (@option{--get},
  4954. @option{-x}) operation.
  4955. @table @option
  4956. @opindex preserve-permissions
  4957. @opindex same-permissions
  4958. @item --preserve-permissions
  4959. @itemx --same-permissions
  4960. @c @itemx --ignore-umask
  4961. @itemx -p
  4962. Set modes of extracted archive members to those recorded in the
  4963. archive, instead of current umask settings. Use in conjunction with
  4964. @option{--extract} (@option{--get}, @option{-x}).
  4965. @end table
  4966. @node Directory Modification Times and Permissions
  4967. @unnumberedsubsubsec Directory Modification Times and Permissions
  4968. After successfully extracting a file member, @GNUTAR{} normally
  4969. restores its permissions and modification times, as described in the
  4970. previous sections. This cannot be done for directories, because
  4971. after extracting a directory @command{tar} will almost certainly
  4972. extract files into that directory and this will cause the directory
  4973. modification time to be updated. Moreover, restoring that directory
  4974. permissions may not permit file creation within it. Thus, restoring
  4975. directory permissions and modification times must be delayed at least
  4976. until all files have been extracted into that directory. @GNUTAR{}
  4977. restores directories using the following approach.
  4978. The extracted directories are created with the mode specified in the
  4979. archive, as modified by the umask of the user, which gives sufficient
  4980. permissions to allow file creation. The meta-information about the
  4981. directory is recorded in the temporary list of directories. When
  4982. preparing to extract next archive member, @GNUTAR{} checks if the
  4983. directory prefix of this file contains the remembered directory. If
  4984. it does not, the program assumes that all files have been extracted
  4985. into that directory, restores its modification time and permissions
  4986. and removes its entry from the internal list. This approach allows
  4987. to correctly restore directory meta-information in the majority of
  4988. cases, while keeping memory requirements sufficiently small. It is
  4989. based on the fact, that most @command{tar} archives use the predefined
  4990. order of members: first the directory, then all the files and
  4991. subdirectories in that directory.
  4992. However, this is not always true. The most important exception are
  4993. incremental archives (@pxref{Incremental Dumps}). The member order in
  4994. an incremental archive is reversed: first all directory members are
  4995. stored, followed by other (non-directory) members. So, when extracting
  4996. from incremental archives, @GNUTAR{} alters the above procedure. It
  4997. remembers all restored directories, and restores their meta-data
  4998. only after the entire archive has been processed. Notice, that you do
  4999. not need to specify any special options for that, as @GNUTAR{}
  5000. automatically detects archives in incremental format.
  5001. There may be cases, when such processing is required for normal archives
  5002. too. Consider the following example:
  5003. @smallexample
  5004. @group
  5005. $ @kbd{tar --no-recursion -cvf archive \
  5006. foo foo/file1 bar bar/file foo/file2}
  5007. foo/
  5008. foo/file1
  5009. bar/
  5010. bar/file
  5011. foo/file2
  5012. @end group
  5013. @end smallexample
  5014. During the normal operation, after encountering @file{bar}
  5015. @GNUTAR{} will assume that all files from the directory @file{foo}
  5016. were already extracted and will therefore restore its timestamp and
  5017. permission bits. However, after extracting @file{foo/file2} the
  5018. directory timestamp will be offset again.
  5019. To correctly restore directory meta-information in such cases, use
  5020. the @option{--delay-directory-restore} command line option:
  5021. @table @option
  5022. @opindex delay-directory-restore
  5023. @item --delay-directory-restore
  5024. Delays restoring of the modification times and permissions of extracted
  5025. directories until the end of extraction. This way, correct
  5026. meta-information is restored even if the archive has unusual member
  5027. ordering.
  5028. @opindex no-delay-directory-restore
  5029. @item --no-delay-directory-restore
  5030. Cancel the effect of the previous @option{--delay-directory-restore}.
  5031. Use this option if you have used @option{--delay-directory-restore} in
  5032. @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
  5033. temporarily disable it.
  5034. @end table
  5035. @node Writing to Standard Output
  5036. @unnumberedsubsubsec Writing to Standard Output
  5037. @cindex Writing extracted files to standard output
  5038. @cindex Standard output, writing extracted files to
  5039. To write the extracted files to the standard output, instead of
  5040. creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
  5041. conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
  5042. extracting files to send them through a pipe, and do not need to
  5043. preserve them in the file system. If you extract multiple members,
  5044. they appear on standard output concatenated, in the order they are
  5045. found in the archive.
  5046. @table @option
  5047. @opindex to-stdout
  5048. @item --to-stdout
  5049. @itemx -O
  5050. Writes files to the standard output. Use only in conjunction with
  5051. @option{--extract} (@option{--get}, @option{-x}). When this option is
  5052. used, instead of creating the files specified, @command{tar} writes
  5053. the contents of the files extracted to its standard output. This may
  5054. be useful if you are only extracting the files in order to send them
  5055. through a pipe. This option is meaningless with @option{--list}
  5056. (@option{-t}).
  5057. @end table
  5058. This can be useful, for example, if you have a tar archive containing
  5059. a big file and don't want to store the file on disk before processing
  5060. it. You can use a command like this:
  5061. @smallexample
  5062. tar -xOzf foo.tgz bigfile | process
  5063. @end smallexample
  5064. or even like this if you want to process the concatenation of the files:
  5065. @smallexample
  5066. tar -xOzf foo.tgz bigfile1 bigfile2 | process
  5067. @end smallexample
  5068. However, @option{--to-command} may be more convenient for use with
  5069. multiple files. See the next section.
  5070. @node Writing to an External Program
  5071. @unnumberedsubsubsec Writing to an External Program
  5072. You can instruct @command{tar} to send the contents of each extracted
  5073. file to the standard input of an external program:
  5074. @table @option
  5075. @opindex to-command
  5076. @item --to-command=@var{command}
  5077. Extract files and pipe their contents to the standard input of
  5078. @var{command}. When this option is used, instead of creating the
  5079. files specified, @command{tar} invokes @var{command} and pipes the
  5080. contents of the files to its standard output. The @var{command} may
  5081. contain command line arguments (see @ref{external, Running External Commands},
  5082. for more detail).
  5083. Notice, that @var{command} is executed once for each regular file
  5084. extracted. Non-regular files (directories, etc.)@: are ignored when this
  5085. option is used.
  5086. @end table
  5087. The command can obtain the information about the file it processes
  5088. from the following environment variables:
  5089. @table @env
  5090. @vrindex TAR_FILETYPE, to-command environment
  5091. @item TAR_FILETYPE
  5092. Type of the file. It is a single letter with the following meaning:
  5093. @multitable @columnfractions 0.10 0.90
  5094. @item f @tab Regular file
  5095. @item d @tab Directory
  5096. @item l @tab Symbolic link
  5097. @item h @tab Hard link
  5098. @item b @tab Block device
  5099. @item c @tab Character device
  5100. @end multitable
  5101. Currently only regular files are supported.
  5102. @vrindex TAR_MODE, to-command environment
  5103. @item TAR_MODE
  5104. File mode, an octal number.
  5105. @vrindex TAR_FILENAME, to-command environment
  5106. @item TAR_FILENAME
  5107. The name of the file.
  5108. @vrindex TAR_REALNAME, to-command environment
  5109. @item TAR_REALNAME
  5110. Name of the file as stored in the archive.
  5111. @vrindex TAR_UNAME, to-command environment
  5112. @item TAR_UNAME
  5113. Name of the file owner.
  5114. @vrindex TAR_GNAME, to-command environment
  5115. @item TAR_GNAME
  5116. Name of the file owner group.
  5117. @vrindex TAR_ATIME, to-command environment
  5118. @item TAR_ATIME
  5119. Time of last access. It is a decimal number, representing seconds
  5120. since the Epoch. If the archive provides times with nanosecond
  5121. precision, the nanoseconds are appended to the timestamp after a
  5122. decimal point.
  5123. @vrindex TAR_MTIME, to-command environment
  5124. @item TAR_MTIME
  5125. Time of last modification.
  5126. @vrindex TAR_CTIME, to-command environment
  5127. @item TAR_CTIME
  5128. Time of last status change.
  5129. @vrindex TAR_SIZE, to-command environment
  5130. @item TAR_SIZE
  5131. Size of the file.
  5132. @vrindex TAR_UID, to-command environment
  5133. @item TAR_UID
  5134. UID of the file owner.
  5135. @vrindex TAR_GID, to-command environment
  5136. @item TAR_GID
  5137. GID of the file owner.
  5138. @end table
  5139. Additionally, the following variables contain information about
  5140. tar mode and the archive being processed:
  5141. @table @env
  5142. @vrindex TAR_VERSION, to-command environment
  5143. @item TAR_VERSION
  5144. @GNUTAR{} version number.
  5145. @vrindex TAR_ARCHIVE, to-command environment
  5146. @item TAR_ARCHIVE
  5147. The name of the archive @command{tar} is processing.
  5148. @vrindex TAR_BLOCKING_FACTOR, to-command environment
  5149. @item TAR_BLOCKING_FACTOR
  5150. Current blocking factor (@pxref{Blocking}).
  5151. @vrindex TAR_VOLUME, to-command environment
  5152. @item TAR_VOLUME
  5153. Ordinal number of the volume @command{tar} is processing.
  5154. @vrindex TAR_FORMAT, to-command environment
  5155. @item TAR_FORMAT
  5156. Format of the archive being processed. @xref{Formats}, for a complete
  5157. list of archive format names.
  5158. @end table
  5159. These variables are defined prior to executing the command, so you can
  5160. pass them as arguments, if you prefer. For example, if the command
  5161. @var{proc} takes the member name and size as its arguments, then you
  5162. could do:
  5163. @smallexample
  5164. $ @kbd{tar -x -f archive.tar \
  5165. --to-command='proc $TAR_FILENAME $TAR_SIZE'}
  5166. @end smallexample
  5167. @noindent
  5168. Notice single quotes to prevent variable names from being expanded by
  5169. the shell when invoking @command{tar}.
  5170. If @var{command} exits with a non-0 status, @command{tar} will print
  5171. an error message similar to the following:
  5172. @smallexample
  5173. tar: 2345: Child returned status 1
  5174. @end smallexample
  5175. Here, @samp{2345} is the PID of the finished process.
  5176. If this behavior is not wanted, use @option{--ignore-command-error}:
  5177. @table @option
  5178. @opindex ignore-command-error
  5179. @item --ignore-command-error
  5180. Ignore exit codes of subprocesses. Notice that if the program
  5181. exits on signal or otherwise terminates abnormally, the error message
  5182. will be printed even if this option is used.
  5183. @opindex no-ignore-command-error
  5184. @item --no-ignore-command-error
  5185. Cancel the effect of any previous @option{--ignore-command-error}
  5186. option. This option is useful if you have set
  5187. @option{--ignore-command-error} in @env{TAR_OPTIONS}
  5188. (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
  5189. @end table
  5190. @node remove files
  5191. @unnumberedsubsubsec Removing Files
  5192. @FIXME{The section is too terse. Something more to add? An example,
  5193. maybe?}
  5194. @table @option
  5195. @opindex remove-files
  5196. @item --remove-files
  5197. Remove files after adding them to the archive.
  5198. @end table
  5199. @node Scarce
  5200. @subsection Coping with Scarce Resources
  5201. @UNREVISED{}
  5202. @cindex Small memory
  5203. @cindex Running out of space
  5204. @menu
  5205. * Starting File::
  5206. * Same Order::
  5207. @end menu
  5208. @node Starting File
  5209. @unnumberedsubsubsec Starting File
  5210. @table @option
  5211. @opindex starting-file
  5212. @item --starting-file=@var{name}
  5213. @itemx -K @var{name}
  5214. Starts an operation in the middle of an archive. Use in conjunction
  5215. with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
  5216. @end table
  5217. @cindex Middle of the archive, starting in the
  5218. If a previous attempt to extract files failed due to lack of disk
  5219. space, you can use @option{--starting-file=@var{name}} (@option{-K
  5220. @var{name}}) to start extracting only after member @var{name} of the
  5221. archive. This assumes, of course, that there is now free space, or
  5222. that you are now extracting into a different file system. (You could
  5223. also choose to suspend @command{tar}, remove unnecessary files from
  5224. the file system, and then resume the same @command{tar} operation.
  5225. In this case, @option{--starting-file} is not necessary.) See also
  5226. @ref{interactive}, and @ref{exclude}.
  5227. @node Same Order
  5228. @unnumberedsubsubsec Same Order
  5229. @table @option
  5230. @cindex Large lists of file names on small machines
  5231. @opindex same-order
  5232. @opindex preserve-order
  5233. @item --same-order
  5234. @itemx --preserve-order
  5235. @itemx -s
  5236. To process large lists of file names on machines with small amounts of
  5237. memory. Use in conjunction with @option{--compare} (@option{--diff},
  5238. @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
  5239. (@option{--get}, @option{-x}).
  5240. @end table
  5241. The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
  5242. names to be listed or extracted is sorted in the same order as the
  5243. files in the archive. This allows a large list of names to be used,
  5244. even on a small machine that would not otherwise be able to hold all
  5245. the names in memory at the same time. Such a sorted list can easily be
  5246. created by running @samp{tar -t} on the archive and editing its output.
  5247. This option is probably never needed on modern computer systems.
  5248. @node backup
  5249. @section Backup options
  5250. @cindex backup options
  5251. @GNUTAR{} offers options for making backups of files
  5252. before writing new versions. These options control the details of
  5253. these backups. They may apply to the archive itself before it is
  5254. created or rewritten, as well as individual extracted members. Other
  5255. @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
  5256. and @command{mv}, for example) offer similar options.
  5257. Backup options may prove unexpectedly useful when extracting archives
  5258. containing many members having identical name, or when extracting archives
  5259. on systems having file name limitations, making different members appear
  5260. as having similar names through the side-effect of name truncation.
  5261. @FIXME{This is true only if we have a good scheme for truncated backup names,
  5262. which I'm not sure at all: I suspect work is needed in this area.}
  5263. When any existing file is backed up before being overwritten by extraction,
  5264. then clashing files are automatically be renamed to be unique, and the
  5265. true name is kept for only the last file of a series of clashing files.
  5266. By using verbose mode, users may track exactly what happens.
  5267. At the detail level, some decisions are still experimental, and may
  5268. change in the future, we are waiting comments from our users. So, please
  5269. do not learn to depend blindly on the details of the backup features.
  5270. For example, currently, directories themselves are never renamed through
  5271. using these options, so, extracting a file over a directory still has
  5272. good chances to fail. Also, backup options apply to created archives,
  5273. not only to extracted members. For created archives, backups will not
  5274. be attempted when the archive is a block or character device, or when it
  5275. refers to a remote file.
  5276. For the sake of simplicity and efficiency, backups are made by renaming old
  5277. files prior to creation or extraction, and not by copying. The original
  5278. name is restored if the file creation fails. If a failure occurs after a
  5279. partial extraction of a file, both the backup and the partially extracted
  5280. file are kept.
  5281. @table @samp
  5282. @item --backup[=@var{method}]
  5283. @opindex backup
  5284. @vindex VERSION_CONTROL
  5285. @cindex backups
  5286. Back up files that are about to be overwritten or removed.
  5287. Without this option, the original versions are destroyed.
  5288. Use @var{method} to determine the type of backups made.
  5289. If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
  5290. environment variable. And if @env{VERSION_CONTROL} is not set,
  5291. use the @samp{existing} method.
  5292. @vindex version-control @r{Emacs variable}
  5293. This option corresponds to the Emacs variable @samp{version-control};
  5294. the same values for @var{method} are accepted as in Emacs. This option
  5295. also allows more descriptive names. The valid @var{method}s are:
  5296. @table @samp
  5297. @item t
  5298. @itemx numbered
  5299. @cindex numbered @r{backup method}
  5300. Always make numbered backups.
  5301. @item nil
  5302. @itemx existing
  5303. @cindex existing @r{backup method}
  5304. Make numbered backups of files that already have them, simple backups
  5305. of the others.
  5306. @item never
  5307. @itemx simple
  5308. @cindex simple @r{backup method}
  5309. Always make simple backups.
  5310. @end table
  5311. @item --suffix=@var{suffix}
  5312. @opindex suffix
  5313. @cindex backup suffix
  5314. @vindex SIMPLE_BACKUP_SUFFIX
  5315. Append @var{suffix} to each backup file made with @option{--backup}. If this
  5316. option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
  5317. environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
  5318. set, the default is @samp{~}, just as in Emacs.
  5319. @end table
  5320. @node looking ahead
  5321. @section Looking Ahead: The Rest of this Manual
  5322. You have now seen how to use all eight of the operations available to
  5323. @command{tar}, and a number of the possible options. The next chapter
  5324. explains how to choose and change file and archive names, how to use
  5325. files to store names of other files which you can then call as
  5326. arguments to @command{tar} (this can help you save time if you expect to
  5327. archive the same list of files a number of times), and so forth.
  5328. @FIXME{in case it's not obvious, i'm making this up in some sense
  5329. based on my limited memory of what the next chapter *really* does. i
  5330. just wanted to flesh out this final section a little bit so i'd
  5331. remember to stick it in here. :-)}
  5332. If there are too many files to conveniently list on the command line,
  5333. you can list the names in a file, and @command{tar} will read that file.
  5334. @xref{files}.
  5335. There are various ways of causing @command{tar} to skip over some files,
  5336. and not archive them. @xref{Choosing}.
  5337. @node Backups
  5338. @chapter Performing Backups and Restoring Files
  5339. @cindex backups
  5340. @GNUTAR{} is distributed along with the scripts for performing backups
  5341. and restores. Even if there is a good chance those scripts may be
  5342. satisfying to you, they are not the only scripts or methods available for doing
  5343. backups and restore. You may well create your own, or use more
  5344. sophisticated packages dedicated to that purpose.
  5345. Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
  5346. Automatic Network Disk Archiver), a backup system developed by James
  5347. da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
  5348. This is free software, and it is available from @uref{http://www.amanda.org}.
  5349. @FIXME{
  5350. Here is a possible plan for a future documentation about the backuping
  5351. scripts which are provided within the @GNUTAR{}
  5352. distribution.
  5353. @itemize @bullet
  5354. @item dumps
  5355. @itemize @minus
  5356. @item what are dumps
  5357. @item different levels of dumps
  5358. @itemize +
  5359. @item full dump = dump everything
  5360. @item level 1, level 2 dumps etc
  5361. A level @var{n} dump dumps everything changed since the last level
  5362. @var{n}-1 dump (?)
  5363. @end itemize
  5364. @item how to use scripts for dumps (ie, the concept)
  5365. @itemize +
  5366. @item scripts to run after editing backup specs (details)
  5367. @end itemize
  5368. @item Backup Specs, what is it.
  5369. @itemize +
  5370. @item how to customize
  5371. @item actual text of script [/sp/dump/backup-specs]
  5372. @end itemize
  5373. @item Problems
  5374. @itemize +
  5375. @item rsh doesn't work
  5376. @item rtape isn't installed
  5377. @item (others?)
  5378. @end itemize
  5379. @item the @option{--incremental} option of tar
  5380. @item tapes
  5381. @itemize +
  5382. @item write protection
  5383. @item types of media, different sizes and types, useful for different things
  5384. @item files and tape marks
  5385. one tape mark between files, two at end.
  5386. @item positioning the tape
  5387. MT writes two at end of write,
  5388. backspaces over one when writing again.
  5389. @end itemize
  5390. @end itemize
  5391. @end itemize
  5392. }
  5393. This chapter documents both the provided shell scripts and @command{tar}
  5394. options which are more specific to usage as a backup tool.
  5395. To @dfn{back up} a file system means to create archives that contain
  5396. all the files in that file system. Those archives can then be used to
  5397. restore any or all of those files (for instance if a disk crashes or a
  5398. file is accidentally deleted). File system @dfn{backups} are also
  5399. called @dfn{dumps}.
  5400. @menu
  5401. * Full Dumps:: Using @command{tar} to Perform Full Dumps
  5402. * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
  5403. * Backup Levels:: Levels of Backups
  5404. * Backup Parameters:: Setting Parameters for Backups and Restoration
  5405. * Scripted Backups:: Using the Backup Scripts
  5406. * Scripted Restoration:: Using the Restore Script
  5407. @end menu
  5408. @node Full Dumps
  5409. @section Using @command{tar} to Perform Full Dumps
  5410. @UNREVISED{}
  5411. @cindex full dumps
  5412. @cindex dumps, full
  5413. @cindex corrupted archives
  5414. Full dumps should only be made when no other people or programs
  5415. are modifying files in the file system. If files are modified while
  5416. @command{tar} is making the backup, they may not be stored properly in
  5417. the archive, in which case you won't be able to restore them if you
  5418. have to. (Files not being modified are written with no trouble, and do
  5419. not corrupt the entire archive.)
  5420. You will want to use the @option{--label=@var{archive-label}}
  5421. (@option{-V @var{archive-label}}) option to give the archive a
  5422. volume label, so you can tell what this archive is even if the label
  5423. falls off the tape, or anything like that.
  5424. Unless the file system you are dumping is guaranteed to fit on
  5425. one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
  5426. Make sure you have enough tapes on hand to complete the backup.
  5427. If you want to dump each file system separately you will need to use
  5428. the @option{--one-file-system} option to prevent
  5429. @command{tar} from crossing file system boundaries when storing
  5430. (sub)directories.
  5431. The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
  5432. option is not needed, since this is a complete copy of everything in
  5433. the file system, and a full restore from this backup would only be
  5434. done onto a completely
  5435. empty disk.
  5436. Unless you are in a hurry, and trust the @command{tar} program (and your
  5437. tapes), it is a good idea to use the @option{--verify} (@option{-W})
  5438. option, to make sure your files really made it onto the dump properly.
  5439. This will also detect cases where the file was modified while (or just
  5440. after) it was being archived. Not all media (notably cartridge tapes)
  5441. are capable of being verified, unfortunately.
  5442. @node Incremental Dumps
  5443. @section Using @command{tar} to Perform Incremental Dumps
  5444. @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
  5445. stores additional metadata so that exact state of the file system
  5446. can be restored when extracting the archive.
  5447. @GNUTAR{} currently offers two options for handling incremental
  5448. backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
  5449. @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
  5450. @xopindex{listed-incremental, described}
  5451. The option @option{--listed-incremental} instructs tar to operate on
  5452. an incremental archive with additional metadata stored in a standalone
  5453. file, called a @dfn{snapshot file}. The purpose of this file is to help
  5454. determine which files have been changed, added or deleted since the
  5455. last backup, so that the next incremental backup will contain only
  5456. modified files. The name of the snapshot file is given as an argument
  5457. to the option:
  5458. @table @option
  5459. @item --listed-incremental=@var{file}
  5460. @itemx -g @var{file}
  5461. Handle incremental backups with snapshot data in @var{file}.
  5462. @end table
  5463. To create an incremental backup, you would use
  5464. @option{--listed-incremental} together with @option{--create}
  5465. (@pxref{create}). For example:
  5466. @smallexample
  5467. $ @kbd{tar --create \
  5468. --file=archive.1.tar \
  5469. --listed-incremental=/var/log/usr.snar \
  5470. /usr}
  5471. @end smallexample
  5472. This will create in @file{archive.1.tar} an incremental backup of
  5473. the @file{/usr} file system, storing additional metadata in the file
  5474. @file{/var/log/usr.snar}. If this file does not exist, it will be
  5475. created. The created archive will then be a @dfn{level 0 backup};
  5476. please see the next section for more on backup levels.
  5477. Otherwise, if the file @file{/var/log/usr.snar} exists, it
  5478. determines which files are modified. In this case only these files will be
  5479. stored in the archive. Suppose, for example, that after running the
  5480. above command, you delete file @file{/usr/doc/old} and create
  5481. directory @file{/usr/local/db} with the following contents:
  5482. @smallexample
  5483. $ @kbd{ls /usr/local/db}
  5484. /usr/local/db/data
  5485. /usr/local/db/index
  5486. @end smallexample
  5487. Some time later you create another incremental backup. You will
  5488. then see:
  5489. @smallexample
  5490. $ @kbd{tar --create \
  5491. --file=archive.2.tar \
  5492. --listed-incremental=/var/log/usr.snar \
  5493. /usr}
  5494. tar: usr/local/db: Directory is new
  5495. usr/local/db/
  5496. usr/local/db/data
  5497. usr/local/db/index
  5498. @end smallexample
  5499. @noindent
  5500. The created archive @file{archive.2.tar} will contain only these
  5501. three members. This archive is called a @dfn{level 1 backup}. Notice
  5502. that @file{/var/log/usr.snar} will be updated with the new data, so if
  5503. you plan to create more @samp{level 1} backups, it is necessary to
  5504. create a working copy of the snapshot file before running
  5505. @command{tar}. The above example will then be modified as follows:
  5506. @smallexample
  5507. $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
  5508. $ @kbd{tar --create \
  5509. --file=archive.2.tar \
  5510. --listed-incremental=/var/log/usr.snar-1 \
  5511. /usr}
  5512. @end smallexample
  5513. @anchor{--level=0}
  5514. @xopindex{level, described}
  5515. You can force @samp{level 0} backups either by removing the snapshot
  5516. file before running @command{tar}, or by supplying the
  5517. @option{--level=0} option, e.g.:
  5518. @smallexample
  5519. $ @kbd{tar --create \
  5520. --file=archive.2.tar \
  5521. --listed-incremental=/var/log/usr.snar-0 \
  5522. --level=0 \
  5523. /usr}
  5524. @end smallexample
  5525. Incremental dumps depend crucially on time stamps, so the results are
  5526. unreliable if you modify a file's time stamps during dumping (e.g.,
  5527. with the @option{--atime-preserve=replace} option), or if you set the clock
  5528. backwards.
  5529. @anchor{device numbers}
  5530. @cindex Device numbers, using in incremental backups
  5531. Metadata stored in snapshot files include device numbers, which,
  5532. obviously are supposed to be non-volatile values. However, it turns
  5533. out that @acronym{NFS} devices have undependable values when an automounter
  5534. gets in the picture. This can lead to a great deal of spurious
  5535. redumping in incremental dumps, so it is somewhat useless to compare
  5536. two @acronym{NFS} devices numbers over time. The solution implemented
  5537. currently is to consider all @acronym{NFS} devices as being equal
  5538. when it comes to comparing directories; this is fairly gross, but
  5539. there does not seem to be a better way to go.
  5540. Apart from using @acronym{NFS}, there are a number of cases where
  5541. relying on device numbers can cause spurious redumping of unmodified
  5542. files. For example, this occurs when archiving @acronym{LVM} snapshot
  5543. volumes. To avoid this, use @option{--no-check-device} option:
  5544. @table @option
  5545. @xopindex{no-check-device, described}
  5546. @item --no-check-device
  5547. Do not rely on device numbers when preparing a list of changed files
  5548. for an incremental dump.
  5549. @xopindex{check-device, described}
  5550. @item --check-device
  5551. Use device numbers when preparing a list of changed files
  5552. for an incremental dump. This is the default behavior. The purpose
  5553. of this option is to undo the effect of the @option{--no-check-device}
  5554. if it was given in @env{TAR_OPTIONS} environment variable
  5555. (@pxref{TAR_OPTIONS}).
  5556. @end table
  5557. There is also another way to cope with changing device numbers. It is
  5558. described in detail in @ref{Fixing Snapshot Files}.
  5559. Note that incremental archives use @command{tar} extensions and may
  5560. not be readable by non-@acronym{GNU} versions of the @command{tar} program.
  5561. @xopindex{listed-incremental, using with @option{--extract}}
  5562. @xopindex{extract, using with @option{--listed-incremental}}
  5563. To extract from the incremental dumps, use
  5564. @option{--listed-incremental} together with @option{--extract}
  5565. option (@pxref{extracting files}). In this case, @command{tar} does
  5566. not need to access snapshot file, since all the data necessary for
  5567. extraction are stored in the archive itself. So, when extracting, you
  5568. can give whatever argument to @option{--listed-incremental}, the usual
  5569. practice is to use @option{--listed-incremental=/dev/null}.
  5570. Alternatively, you can use @option{--incremental}, which needs no
  5571. arguments. In general, @option{--incremental} (@option{-G}) can be
  5572. used as a shortcut for @option{--listed-incremental} when listing or
  5573. extracting incremental backups (for more information regarding this
  5574. option, @pxref{incremental-op}).
  5575. When extracting from the incremental backup @GNUTAR{} attempts to
  5576. restore the exact state the file system had when the archive was
  5577. created. In particular, it will @emph{delete} those files in the file
  5578. system that did not exist in their directories when the archive was
  5579. created. If you have created several levels of incremental files,
  5580. then in order to restore the exact contents the file system had when
  5581. the last level was created, you will need to restore from all backups
  5582. in turn. Continuing our example, to restore the state of @file{/usr}
  5583. file system, one would do@footnote{Notice, that since both archives
  5584. were created without @option{-P} option (@pxref{absolute}), these
  5585. commands should be run from the root file system.}:
  5586. @smallexample
  5587. $ @kbd{tar --extract \
  5588. --listed-incremental=/dev/null \
  5589. --file archive.1.tar}
  5590. $ @kbd{tar --extract \
  5591. --listed-incremental=/dev/null \
  5592. --file archive.2.tar}
  5593. @end smallexample
  5594. To list the contents of an incremental archive, use @option{--list}
  5595. (@pxref{list}), as usual. To obtain more information about the
  5596. archive, use @option{--listed-incremental} or @option{--incremental}
  5597. combined with two @option{--verbose} options@footnote{Two
  5598. @option{--verbose} options were selected to avoid breaking usual
  5599. verbose listing output (@option{--list --verbose}) when using in
  5600. scripts.
  5601. @xopindex{incremental, using with @option{--list}}
  5602. @xopindex{listed-incremental, using with @option{--list}}
  5603. @xopindex{list, using with @option{--incremental}}
  5604. @xopindex{list, using with @option{--listed-incremental}}
  5605. Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
  5606. contents of the DUMPDIR header (with terminating nulls) when
  5607. @option{--incremental} or @option{--listed-incremental} option was
  5608. given, no matter what the verbosity level. This behavior, and,
  5609. especially, the binary output it produced were considered inconvenient
  5610. and were changed in version 1.16.}:
  5611. @smallexample
  5612. @kbd{tar --list --incremental --verbose --verbose --file archive.tar}
  5613. @end smallexample
  5614. This command will print, for each directory in the archive, the list
  5615. of files in that directory at the time the archive was created. This
  5616. information is put out in a format which is both human-readable and
  5617. unambiguous for a program: each file name is printed as
  5618. @smallexample
  5619. @var{x} @var{file}
  5620. @end smallexample
  5621. @noindent
  5622. where @var{x} is a letter describing the status of the file: @samp{Y}
  5623. if the file is present in the archive, @samp{N} if the file is not
  5624. included in the archive, or a @samp{D} if the file is a directory (and
  5625. is included in the archive). @xref{Dumpdir}, for the detailed
  5626. description of dumpdirs and status codes. Each such
  5627. line is terminated by a newline character. The last line is followed
  5628. by an additional newline to indicate the end of the data.
  5629. @anchor{incremental-op}The option @option{--incremental} (@option{-G})
  5630. gives the same behavior as @option{--listed-incremental} when used
  5631. with @option{--list} and @option{--extract} options. When used with
  5632. @option{--create} option, it creates an incremental archive without
  5633. creating snapshot file. Thus, it is impossible to create several
  5634. levels of incremental backups with @option{--incremental} option.
  5635. @node Backup Levels
  5636. @section Levels of Backups
  5637. An archive containing all the files in the file system is called a
  5638. @dfn{full backup} or @dfn{full dump}. You could insure your data by
  5639. creating a full dump every day. This strategy, however, would waste a
  5640. substantial amount of archive media and user time, as unchanged files
  5641. are daily re-archived.
  5642. It is more efficient to do a full dump only occasionally. To back up
  5643. files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
  5644. one} dump archives all the files that have changed since the last full
  5645. dump.
  5646. A typical dump strategy would be to perform a full dump once a week,
  5647. and a level one dump once a day. This means some versions of files
  5648. will in fact be archived more than once, but this dump strategy makes
  5649. it possible to restore a file system to within one day of accuracy by
  5650. only extracting two archives---the last weekly (full) dump and the
  5651. last daily (level one) dump. The only information lost would be in
  5652. files changed or created since the last daily backup. (Doing dumps
  5653. more than once a day is usually not worth the trouble.)
  5654. @GNUTAR{} comes with scripts you can use to do full
  5655. and level-one (actually, even level-two and so on) dumps. Using
  5656. scripts (shell programs) to perform backups and restoration is a
  5657. convenient and reliable alternative to typing out file name lists
  5658. and @command{tar} commands by hand.
  5659. Before you use these scripts, you need to edit the file
  5660. @file{backup-specs}, which specifies parameters used by the backup
  5661. scripts and by the restore script. This file is usually located
  5662. in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
  5663. detailed description. Once the backup parameters are set, you can
  5664. perform backups or restoration by running the appropriate script.
  5665. The name of the backup script is @code{backup}. The name of the
  5666. restore script is @code{restore}. The following sections describe
  5667. their use in detail.
  5668. @emph{Please Note:} The backup and restoration scripts are
  5669. designed to be used together. While it is possible to restore files by
  5670. hand from an archive which was created using a backup script, and to create
  5671. an archive by hand which could then be extracted using the restore script,
  5672. it is easier to use the scripts. @xref{Incremental Dumps}, before
  5673. making such an attempt.
  5674. @node Backup Parameters
  5675. @section Setting Parameters for Backups and Restoration
  5676. The file @file{backup-specs} specifies backup parameters for the
  5677. backup and restoration scripts provided with @command{tar}. You must
  5678. edit @file{backup-specs} to fit your system configuration and schedule
  5679. before using these scripts.
  5680. Syntactically, @file{backup-specs} is a shell script, containing
  5681. mainly variable assignments. However, any valid shell construct
  5682. is allowed in this file. Particularly, you may wish to define
  5683. functions within that script (e.g., see @code{RESTORE_BEGIN} below).
  5684. For more information about shell script syntax, please refer to
  5685. @url{https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html,
  5686. the definition of the Shell Command Language}. See also
  5687. @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
  5688. The shell variables controlling behavior of @code{backup} and
  5689. @code{restore} are described in the following subsections.
  5690. @menu
  5691. * General-Purpose Variables::
  5692. * Magnetic Tape Control::
  5693. * User Hooks::
  5694. * backup-specs example:: An Example Text of @file{Backup-specs}
  5695. @end menu
  5696. @node General-Purpose Variables
  5697. @subsection General-Purpose Variables
  5698. @defvr {Backup variable} ADMINISTRATOR
  5699. The user name of the backup administrator. @code{Backup} scripts
  5700. sends a backup report to this address.
  5701. @end defvr
  5702. @defvr {Backup variable} BACKUP_HOUR
  5703. The hour at which the backups are done. This can be a number from 0
  5704. to 23, or the time specification in form @var{hours}:@var{minutes},
  5705. or the string @samp{now}.
  5706. This variable is used by @code{backup}. Its value may be overridden
  5707. using @option{--time} option (@pxref{Scripted Backups}).
  5708. @end defvr
  5709. @defvr {Backup variable} TAPE_FILE
  5710. The device @command{tar} writes the archive to. If @var{TAPE_FILE}
  5711. is a remote archive (@pxref{remote-dev}), backup script will suppose
  5712. that your @command{mt} is able to access remote devices. If @var{RSH}
  5713. (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
  5714. invocations of @command{mt}.
  5715. @end defvr
  5716. @defvr {Backup variable} BLOCKING
  5717. The blocking factor @command{tar} will use when writing the dump archive.
  5718. @xref{Blocking Factor}.
  5719. @end defvr
  5720. @defvr {Backup variable} BACKUP_DIRS
  5721. A list of file systems to be dumped (for @code{backup}), or restored
  5722. (for @code{restore}). You can include any directory
  5723. name in the list --- subdirectories on that file system will be
  5724. included, regardless of how they may look to other networked machines.
  5725. Subdirectories on other file systems will be ignored.
  5726. The host name specifies which host to run @command{tar} on, and should
  5727. normally be the host that actually contains the file system. However,
  5728. the host machine must have @GNUTAR{} installed, and
  5729. must be able to access the directory containing the backup scripts and
  5730. their support files using the same file name that is used on the
  5731. machine where the scripts are run (i.e., what @command{pwd} will print
  5732. when in that directory on that machine). If the host that contains
  5733. the file system does not have this capability, you can specify another
  5734. host as long as it can access the file system through @acronym{NFS}.
  5735. If the list of file systems is very long you may wish to put it
  5736. in a separate file. This file is usually named
  5737. @file{/etc/backup/dirs}, but this name may be overridden in
  5738. @file{backup-specs} using @code{DIRLIST} variable.
  5739. @end defvr
  5740. @defvr {Backup variable} DIRLIST
  5741. The name of the file that contains a list of file systems to backup
  5742. or restore. By default it is @file{/etc/backup/dirs}.
  5743. @end defvr
  5744. @defvr {Backup variable} BACKUP_FILES
  5745. A list of individual files to be dumped (for @code{backup}), or restored
  5746. (for @code{restore}). These should be accessible from the machine on
  5747. which the backup script is run.
  5748. If the list of individual files is very long you may wish to store it
  5749. in a separate file. This file is usually named
  5750. @file{/etc/backup/files}, but this name may be overridden in
  5751. @file{backup-specs} using @code{FILELIST} variable.
  5752. @end defvr
  5753. @defvr {Backup variable} FILELIST
  5754. The name of the file that contains a list of individual files to backup
  5755. or restore. By default it is @file{/etc/backup/files}.
  5756. @end defvr
  5757. @defvr {Backup variable} MT
  5758. Full file name of @command{mt} binary.
  5759. @end defvr
  5760. @defvr {Backup variable} RSH
  5761. @anchor{RSH}
  5762. Full file name of @command{rsh} binary or its equivalent. You may wish to
  5763. set it to @code{ssh}, to improve security. In this case you will have
  5764. to use public key authentication.
  5765. @end defvr
  5766. @defvr {Backup variable} RSH_COMMAND
  5767. Full file name of @command{rsh} binary on remote machines. This will
  5768. be passed via @option{--rsh-command} option to the remote invocation
  5769. of @GNUTAR{}.
  5770. @end defvr
  5771. @defvr {Backup variable} VOLNO_FILE
  5772. Name of temporary file to hold volume numbers. This needs to be accessible
  5773. by all the machines which have file systems to be dumped.
  5774. @end defvr
  5775. @defvr {Backup variable} XLIST
  5776. Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
  5777. located on the remote machine and containing the list of files to
  5778. be excluded from the backup. Exclude file lists are searched in
  5779. /etc/tar-backup directory. A common use for exclude file lists
  5780. is to exclude files containing security-sensitive information
  5781. (e.g., @file{/etc/shadow} from backups).
  5782. This variable affects only @code{backup}.
  5783. @end defvr
  5784. @defvr {Backup variable} SLEEP_TIME
  5785. Time to sleep between dumps of any two successive file systems
  5786. This variable affects only @code{backup}.
  5787. @end defvr
  5788. @defvr {Backup variable} DUMP_REMIND_SCRIPT
  5789. Script to be run when it's time to insert a new tape in for the next
  5790. volume. Administrators may want to tailor this script for their site.
  5791. If this variable isn't set, @GNUTAR{} will display its built-in
  5792. prompt, and will expect confirmation from the console. For the
  5793. description of the default prompt, see @ref{change volume prompt}.
  5794. @end defvr
  5795. @defvr {Backup variable} SLEEP_MESSAGE
  5796. Message to display on the terminal while waiting for dump time. Usually
  5797. this will just be some literal text.
  5798. @end defvr
  5799. @defvr {Backup variable} TAR
  5800. Full file name of the @GNUTAR{} executable. If this is not set, backup
  5801. scripts will search @command{tar} in the current shell path.
  5802. @end defvr
  5803. @node Magnetic Tape Control
  5804. @subsection Magnetic Tape Control
  5805. Backup scripts access tape device using special @dfn{hook functions}.
  5806. These functions take a single argument --- the name of the tape
  5807. device. Their names are kept in the following variables:
  5808. @defvr {Backup variable} MT_BEGIN
  5809. The name of @dfn{begin} function. This function is called before
  5810. accessing the drive. By default it retensions the tape:
  5811. @smallexample
  5812. MT_BEGIN=mt_begin
  5813. mt_begin() @{
  5814. mt -f "$1" retension
  5815. @}
  5816. @end smallexample
  5817. @end defvr
  5818. @defvr {Backup variable} MT_REWIND
  5819. The name of @dfn{rewind} function. The default definition is as
  5820. follows:
  5821. @smallexample
  5822. MT_REWIND=mt_rewind
  5823. mt_rewind() @{
  5824. mt -f "$1" rewind
  5825. @}
  5826. @end smallexample
  5827. @end defvr
  5828. @defvr {Backup variable} MT_OFFLINE
  5829. The name of the function switching the tape off line. By default
  5830. it is defined as follows:
  5831. @smallexample
  5832. MT_OFFLINE=mt_offline
  5833. mt_offline() @{
  5834. mt -f "$1" offl
  5835. @}
  5836. @end smallexample
  5837. @end defvr
  5838. @defvr {Backup variable} MT_STATUS
  5839. The name of the function used to obtain the status of the archive device,
  5840. including error count. Default definition:
  5841. @smallexample
  5842. MT_STATUS=mt_status
  5843. mt_status() @{
  5844. mt -f "$1" status
  5845. @}
  5846. @end smallexample
  5847. @end defvr
  5848. @node User Hooks
  5849. @subsection User Hooks
  5850. @dfn{User hooks} are shell functions executed before and after
  5851. each @command{tar} invocation. Thus, there are @dfn{backup
  5852. hooks}, which are executed before and after dumping each file
  5853. system, and @dfn{restore hooks}, executed before and
  5854. after restoring a file system. Each user hook is a shell function
  5855. taking four arguments:
  5856. @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
  5857. Its arguments are:
  5858. @table @var
  5859. @item level
  5860. Current backup or restore level.
  5861. @item host
  5862. Name or IP address of the host machine being dumped or restored.
  5863. @item fs
  5864. Full file name of the file system being dumped or restored.
  5865. @item fsname
  5866. File system name with directory separators replaced with colons. This
  5867. is useful, e.g., for creating unique files.
  5868. @end table
  5869. @end deffn
  5870. Following variables keep the names of user hook functions:
  5871. @defvr {Backup variable} DUMP_BEGIN
  5872. Dump begin function. It is executed before dumping the file system.
  5873. @end defvr
  5874. @defvr {Backup variable} DUMP_END
  5875. Executed after dumping the file system.
  5876. @end defvr
  5877. @defvr {Backup variable} RESTORE_BEGIN
  5878. Executed before restoring the file system.
  5879. @end defvr
  5880. @defvr {Backup variable} RESTORE_END
  5881. Executed after restoring the file system.
  5882. @end defvr
  5883. @node backup-specs example
  5884. @subsection An Example Text of @file{Backup-specs}
  5885. The following is an example of @file{backup-specs}:
  5886. @smallexample
  5887. # site-specific parameters for file system backup.
  5888. ADMINISTRATOR=friedman
  5889. BACKUP_HOUR=1
  5890. TAPE_FILE=/dev/nrsmt0
  5891. # Use @code{ssh} instead of the less secure @code{rsh}
  5892. RSH=/usr/bin/ssh
  5893. RSH_COMMAND=/usr/bin/ssh
  5894. # Override MT_STATUS function:
  5895. my_status() @{
  5896. mts -t $TAPE_FILE
  5897. @}
  5898. MT_STATUS=my_status
  5899. # Disable MT_OFFLINE function
  5900. MT_OFFLINE=:
  5901. BLOCKING=124
  5902. BACKUP_DIRS="
  5903. albert:/fs/fsf
  5904. apple-gunkies:/gd
  5905. albert:/fs/gd2
  5906. albert:/fs/gp
  5907. geech:/usr/jla
  5908. churchy:/usr/roland
  5909. albert:/
  5910. albert:/usr
  5911. apple-gunkies:/
  5912. apple-gunkies:/usr
  5913. gnu:/hack
  5914. gnu:/u
  5915. apple-gunkies:/com/mailer/gnu
  5916. apple-gunkies:/com/archive/gnu"
  5917. BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
  5918. @end smallexample
  5919. @node Scripted Backups
  5920. @section Using the Backup Scripts
  5921. The syntax for running a backup script is:
  5922. @smallexample
  5923. backup --level=@var{level} --time=@var{time}
  5924. @end smallexample
  5925. The @option{--level} option requests the dump level. Thus, to produce
  5926. a full dump, specify @code{--level=0} (this is the default, so
  5927. @option{--level} may be omitted if its value is
  5928. @code{0})@footnote{For backward compatibility, the @code{backup} will also
  5929. try to deduce the requested dump level from the name of the
  5930. script itself. If the name consists of a string @samp{level-}
  5931. followed by a single decimal digit, that digit is taken as
  5932. the dump level number. Thus, you may create a link from @code{backup}
  5933. to @code{level-1} and then run @code{level-1} whenever you need to
  5934. create a level one dump.}.
  5935. The @option{--time} option determines when should the backup be
  5936. run. @var{Time} may take three forms:
  5937. @table @asis
  5938. @item @var{hh}:@var{mm}
  5939. The dump must be run at @var{hh} hours @var{mm} minutes.
  5940. @item @var{hh}
  5941. The dump must be run at @var{hh} hours.
  5942. @item now
  5943. The dump must be run immediately.
  5944. @end table
  5945. You should start a script with a tape or disk mounted. Once you
  5946. start a script, it prompts you for new tapes or disks as it
  5947. needs them. Media volumes don't have to correspond to archive
  5948. files --- a multi-volume archive can be started in the middle of a
  5949. tape that already contains the end of another multi-volume archive.
  5950. The @code{restore} script prompts for media by its archive volume,
  5951. so to avoid an error message you should keep track of which tape
  5952. (or disk) contains which volume of the archive (@pxref{Scripted
  5953. Restoration}).
  5954. The backup scripts write two files on the file system. The first is a
  5955. record file in @file{/etc/tar-backup/}, which is used by the scripts
  5956. to store and retrieve information about which files were dumped. This
  5957. file is not meant to be read by humans, and should not be deleted by
  5958. them. @xref{Snapshot Files}, for a more detailed explanation of this
  5959. file.
  5960. The second file is a log file containing the names of the file systems
  5961. and files dumped, what time the backup was made, and any error
  5962. messages that were generated, as well as how much space was left in
  5963. the media volume after the last volume of the archive was written.
  5964. You should check this log file after every backup. The file name is
  5965. @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
  5966. represents current date, and @var{n} represents current dump level number.
  5967. The script also prints the name of each system being dumped to the
  5968. standard output.
  5969. Following is the full list of options accepted by @code{backup}
  5970. script:
  5971. @table @option
  5972. @item -l @var{level}
  5973. @itemx --level=@var{level}
  5974. Do backup level @var{level} (default 0).
  5975. @item -f
  5976. @itemx --force
  5977. Force backup even if today's log file already exists.
  5978. @item -v[@var{level}]
  5979. @itemx --verbose[=@var{level}]
  5980. Set verbosity level. The higher the level is, the more debugging
  5981. information will be output during execution. Default @var{level}
  5982. is 100, which means the highest debugging level.
  5983. @item -t @var{start-time}
  5984. @itemx --time=@var{start-time}
  5985. Wait till @var{time}, then do backup.
  5986. @item -h
  5987. @itemx --help
  5988. Display short help message and exit.
  5989. @item -V
  5990. @itemx --version
  5991. Display information about the program's name, version, origin and legal
  5992. status, all on standard output, and then exit successfully.
  5993. @end table
  5994. @node Scripted Restoration
  5995. @section Using the Restore Script
  5996. To restore files that were archived using a scripted backup, use the
  5997. @code{restore} script. Its usage is quite straightforward. In the
  5998. simplest form, invoke @code{restore --all}, it will
  5999. then restore all the file systems and files specified in
  6000. @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
  6001. You may select the file systems (and/or files) to restore by
  6002. giving @code{restore} a list of @dfn{patterns} in its command
  6003. line. For example, running
  6004. @smallexample
  6005. restore 'albert:*'
  6006. @end smallexample
  6007. @noindent
  6008. will restore all file systems on the machine @samp{albert}. A more
  6009. complicated example:
  6010. @smallexample
  6011. restore 'albert:*' '*:/var'
  6012. @end smallexample
  6013. @noindent
  6014. This command will restore all file systems on the machine @samp{albert}
  6015. as well as @file{/var} file system on all machines.
  6016. By default @code{restore} will start restoring files from the lowest
  6017. available dump level (usually zero) and will continue through
  6018. all available dump levels. There may be situations where such a
  6019. thorough restore is not necessary. For example, you may wish to
  6020. restore only files from the recent level one backup. To do so,
  6021. use @option{--level} option, as shown in the example below:
  6022. @smallexample
  6023. restore --level=1
  6024. @end smallexample
  6025. The full list of options accepted by @code{restore} follows:
  6026. @table @option
  6027. @item -a
  6028. @itemx --all
  6029. Restore all file systems and files specified in @file{backup-specs}.
  6030. @item -l @var{level}
  6031. @itemx --level=@var{level}
  6032. Start restoring from the given backup level, instead of the default 0.
  6033. @item -v[@var{level}]
  6034. @itemx --verbose[=@var{level}]
  6035. Set verbosity level. The higher the level is, the more debugging
  6036. information will be output during execution. Default @var{level}
  6037. is 100, which means the highest debugging level.
  6038. @item -h
  6039. @itemx --help
  6040. Display short help message and exit.
  6041. @item -V
  6042. @itemx --version
  6043. Display information about the program's name, version, origin and legal
  6044. status, all on standard output, and then exit successfully.
  6045. @end table
  6046. You should start the restore script with the media containing the
  6047. first volume of the archive mounted. The script will prompt for other
  6048. volumes as they are needed. If the archive is on tape, you don't need
  6049. to rewind the tape to to its beginning---if the tape head is
  6050. positioned past the beginning of the archive, the script will rewind
  6051. the tape as needed. @xref{Tape Positioning}, for a discussion of tape
  6052. positioning.
  6053. @quotation
  6054. @strong{Warning:} The script will delete files from the active file
  6055. system if they were not in the file system when the archive was made.
  6056. @end quotation
  6057. @xref{Incremental Dumps}, for an explanation of how the script makes
  6058. that determination.
  6059. @node Choosing
  6060. @chapter Choosing Files and Names for @command{tar}
  6061. Certain options to @command{tar} enable you to specify a name for your
  6062. archive. Other options let you decide which files to include or exclude
  6063. from the archive, based on when or whether files were modified, whether
  6064. the file names do or don't match specified patterns, or whether files
  6065. are in specified directories.
  6066. This chapter discusses these options in detail.
  6067. @menu
  6068. * file:: Choosing the Archive's Name
  6069. * Selecting Archive Members::
  6070. * files:: Reading Names from a File
  6071. * exclude:: Excluding Some Files
  6072. * wildcards:: Wildcards Patterns and Matching
  6073. * quoting styles:: Ways of Quoting Special Characters in Names
  6074. * transform:: Modifying File and Member Names
  6075. * after:: Operating Only on New Files
  6076. * recurse:: Descending into Directories
  6077. * one:: Crossing File System Boundaries
  6078. @end menu
  6079. @node file
  6080. @section Choosing and Naming Archive Files
  6081. @cindex Naming an archive
  6082. @cindex Archive Name
  6083. @cindex Choosing an archive file
  6084. @cindex Where is the archive?
  6085. @opindex file
  6086. By default, @command{tar} uses an archive file name that was compiled when
  6087. it was built on the system; usually this name refers to some physical
  6088. tape drive on the machine. However, the person who installed @command{tar}
  6089. on the system may not have set the default to a meaningful value as far as
  6090. most users are concerned. As a result, you will usually want to tell
  6091. @command{tar} where to find (or create) the archive. The
  6092. @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
  6093. option allows you to either specify or name a file to use as the archive
  6094. instead of the default archive file location.
  6095. @table @option
  6096. @xopindex{file, short description}
  6097. @item --file=@var{archive-name}
  6098. @itemx -f @var{archive-name}
  6099. Name the archive to create or operate on. Use in conjunction with
  6100. any operation.
  6101. @end table
  6102. For example, in this @command{tar} command,
  6103. @smallexample
  6104. $ @kbd{tar -cvf collection.tar blues folk jazz}
  6105. @end smallexample
  6106. @noindent
  6107. @file{collection.tar} is the name of the archive. It must directly
  6108. follow the @option{-f} option, since whatever directly follows @option{-f}
  6109. @emph{will} end up naming the archive. If you neglect to specify an
  6110. archive name, you may end up overwriting a file in the working directory
  6111. with the archive you create since @command{tar} will use this file's name
  6112. for the archive name.
  6113. An archive can be saved as a file in the file system, sent through a
  6114. pipe or over a network, or written to an I/O device such as a tape,
  6115. floppy disk, or CD write drive.
  6116. @cindex Writing new archives
  6117. @cindex Archive creation
  6118. If you do not name the archive, @command{tar} uses the value of the
  6119. environment variable @env{TAPE} as the file name for the archive. If
  6120. that is not available, @command{tar} uses a default, compiled-in archive
  6121. name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
  6122. @cindex Standard input and output
  6123. @cindex tar to standard input and output
  6124. If you use @file{-} as an @var{archive-name}, @command{tar} reads the
  6125. archive from standard input (when listing or extracting files), or
  6126. writes it to standard output (when creating an archive). If you use
  6127. @file{-} as an @var{archive-name} when modifying an archive,
  6128. @command{tar} reads the original archive from its standard input and
  6129. writes the entire new archive to its standard output.
  6130. The following example is a convenient way of copying directory
  6131. hierarchy from @file{sourcedir} to @file{targetdir}.
  6132. @smallexample
  6133. $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
  6134. @end smallexample
  6135. The @option{-C} option allows to avoid using subshells:
  6136. @smallexample
  6137. $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
  6138. @end smallexample
  6139. In both examples above, the leftmost @command{tar} invocation archives
  6140. the contents of @file{sourcedir} to the standard output, while the
  6141. rightmost one reads this archive from its standard input and
  6142. extracts it. The @option{-p} option tells it to restore permissions
  6143. of the extracted files.
  6144. @cindex Remote devices
  6145. @cindex tar to a remote device
  6146. @anchor{remote-dev}
  6147. To specify an archive file on a device attached to a remote machine,
  6148. use the following:
  6149. @smallexample
  6150. @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
  6151. @end smallexample
  6152. @noindent
  6153. @command{tar} will set up the remote connection, if possible, and
  6154. prompt you for a username and password. If you use
  6155. @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
  6156. will attempt to set up the remote connection using your username
  6157. as the username on the remote machine.
  6158. @cindex Local and remote archives
  6159. @anchor{local and remote archives}
  6160. If the archive file name includes a colon (@samp{:}), then it is assumed
  6161. to be a file on another machine. If the archive file is
  6162. @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
  6163. host @var{host}. The remote host is accessed using the @command{rsh}
  6164. program, with a username of @var{user}. If the username is omitted
  6165. (along with the @samp{@@} sign), then your user name will be used.
  6166. (This is the normal @command{rsh} behavior.) It is necessary for the
  6167. remote machine, in addition to permitting your @command{rsh} access, to
  6168. have the @file{rmt} program installed (this command is included in
  6169. the @GNUTAR{} distribution and by default is installed under
  6170. @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
  6171. installation prefix). If you need to use a file whose name includes a
  6172. colon, then the remote tape drive behavior
  6173. can be inhibited by using the @option{--force-local} option.
  6174. When the archive is being created to @file{/dev/null}, @GNUTAR{}
  6175. tries to minimize input and output operations. The Amanda backup
  6176. system, when used with @GNUTAR{}, has an initial sizing pass which
  6177. uses this feature.
  6178. @node Selecting Archive Members
  6179. @section Selecting Archive Members
  6180. @cindex Specifying files to act on
  6181. @cindex Specifying archive members
  6182. @dfn{File Name arguments} specify which files in the file system
  6183. @command{tar} operates on, when creating or adding to an archive, or which
  6184. archive members @command{tar} operates on, when reading or deleting from
  6185. an archive. @xref{Operations}.
  6186. To specify file names, you can include them as the last arguments on
  6187. the command line, as follows:
  6188. @smallexample
  6189. @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
  6190. @end smallexample
  6191. If a file name begins with dash (@samp{-}), precede it with
  6192. @option{--add-file} option to prevent it from being treated as an
  6193. option.
  6194. @anchor{input name quoting}
  6195. By default @GNUTAR{} attempts to @dfn{unquote} each file or member
  6196. name, replacing @dfn{escape sequences} according to the following
  6197. table:
  6198. @multitable @columnfractions 0.20 0.60
  6199. @headitem Escape @tab Replaced with
  6200. @item \a @tab Audible bell (@acronym{ASCII} 7)
  6201. @item \b @tab Backspace (@acronym{ASCII} 8)
  6202. @item \f @tab Form feed (@acronym{ASCII} 12)
  6203. @item \n @tab New line (@acronym{ASCII} 10)
  6204. @item \r @tab Carriage return (@acronym{ASCII} 13)
  6205. @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
  6206. @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
  6207. @item \? @tab @acronym{ASCII} 127
  6208. @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
  6209. of up to 3 digits)
  6210. @end multitable
  6211. A backslash followed by any other symbol is retained.
  6212. This default behavior is controlled by the following command line
  6213. option:
  6214. @table @option
  6215. @opindex unquote
  6216. @item --unquote
  6217. Enable unquoting input file or member names (default).
  6218. @opindex no-unquote
  6219. @item --no-unquote
  6220. Disable unquoting input file or member names.
  6221. @end table
  6222. If you specify a directory name as a file name argument, all the files
  6223. in that directory are operated on by @command{tar}.
  6224. If you do not specify files, @command{tar} behavior differs depending
  6225. on the operation mode as described below:
  6226. When @command{tar} is invoked with @option{--create} (@option{-c}),
  6227. @command{tar} will stop immediately, reporting the following:
  6228. @smallexample
  6229. @group
  6230. $ @kbd{tar cf a.tar}
  6231. tar: Cowardly refusing to create an empty archive
  6232. Try 'tar --help' or 'tar --usage' for more information.
  6233. @end group
  6234. @end smallexample
  6235. If you specify either @option{--list} (@option{-t}) or
  6236. @option{--extract} (@option{--get}, @option{-x}), @command{tar}
  6237. operates on all the archive members in the archive.
  6238. If run with @option{--diff} option, tar will compare the archive with
  6239. the contents of the current working directory.
  6240. If you specify any other operation, @command{tar} does nothing.
  6241. By default, @command{tar} takes file names from the command line. However,
  6242. there are other ways to specify file or member names, or to modify the
  6243. manner in which @command{tar} selects the files or members upon which to
  6244. operate. In general, these methods work both for specifying the names
  6245. of files and archive members.
  6246. @node files
  6247. @section Reading Names from a File
  6248. @cindex Reading file names from a file
  6249. @cindex Lists of file names
  6250. @cindex File Name arguments, alternatives
  6251. @cindex @command{find}, using with @command{tar}
  6252. Instead of giving the names of files or archive members on the command
  6253. line, you can put the names into a file, and then use the
  6254. @option{--files-from=@var{file-of-names}} (@option{-T
  6255. @var{file-of-names}}) option to @command{tar}. Give the name of the
  6256. file which contains the list of files to include as the argument to
  6257. @option{--files-from}. In the list, the file names should be separated by
  6258. newlines. You will frequently use this option when you have generated
  6259. the list of files to archive with the @command{find} utility.
  6260. @table @option
  6261. @opindex files-from
  6262. @item --files-from=@var{file-name}
  6263. @itemx -T @var{file-name}
  6264. Get names to extract or create from file @var{file-name}.
  6265. @end table
  6266. If you give a single dash as a file name for @option{--files-from}, (i.e.,
  6267. you specify either @code{--files-from=-} or @code{-T -}), then the file
  6268. names are read from standard input.
  6269. Unless you are running @command{tar} with @option{--create}, you cannot use
  6270. both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
  6271. command.
  6272. Any number of @option{-T} options can be given in the command line.
  6273. The following example shows how to use @command{find} to generate a list of
  6274. files smaller than 400 blocks in length@footnote{A file system block
  6275. is usually 512 bytes, so this amounts to 200K. Use the @samp{c}
  6276. suffix to specify size in @emph{bytes}. Also, when using
  6277. GNU find, you can specify other size units, such as @samp{k},
  6278. @samp{m}, etc. @xref{Size,,,find.info,GNU Findutils}, for details.} and put that list into a file
  6279. called @file{small-files}. You can then use the @option{-T} option to
  6280. @command{tar} to specify the files from that file, @file{small-files}, to
  6281. create the archive @file{little.tgz}. (The @option{-z} option to
  6282. @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
  6283. more information.)
  6284. @smallexample
  6285. $ @kbd{find . -size -400 -print > small-files}
  6286. $ @kbd{tar -c -v -z -T small-files -f little.tgz}
  6287. @end smallexample
  6288. @noindent
  6289. By default, each line read from the file list is first stripped off
  6290. any leading and trailing whitespace. If the resulting string begins
  6291. with @samp{-} character, it is considered a @command{tar} option and is
  6292. processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
  6293. recognized only @option{-C} option in file lists, and only if the
  6294. option and its argument occupied two consecutive lines.}. Only a
  6295. subset of @GNUTAR{} options is allowed for use in file lists. For
  6296. a list of such options, @ref{Position-Sensitive Options}.
  6297. For example, the common use of this feature is to change to another
  6298. directory by specifying @option{-C} option:
  6299. @smallexample
  6300. @group
  6301. $ @kbd{cat list}
  6302. -C/etc
  6303. passwd
  6304. hosts
  6305. -C/lib
  6306. libc.a
  6307. $ @kbd{tar -c -f foo.tar --files-from list}
  6308. @end group
  6309. @end smallexample
  6310. @noindent
  6311. In this example, @command{tar} will first switch to @file{/etc}
  6312. directory and add files @file{passwd} and @file{hosts} to the
  6313. archive. Then it will change to @file{/lib} directory and will archive
  6314. the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
  6315. contain:
  6316. @smallexample
  6317. @group
  6318. $ @kbd{tar tf foo.tar}
  6319. passwd
  6320. hosts
  6321. libc.a
  6322. @end group
  6323. @end smallexample
  6324. Note, that any options used in the file list remain in effect for the
  6325. rest of the command line. For example, using the same @file{list}
  6326. file as above, the following command
  6327. @smallexample
  6328. $ @kbd{tar -c -f foo.tar --files-from list libcurses.a}
  6329. @end smallexample
  6330. @noindent
  6331. will look for file @file{libcurses.a} in the directory @file{/lib},
  6332. because it was used with the last @option{-C} option
  6333. (@pxref{Position-Sensitive Options}).
  6334. @anchor{verbatim-files-from}
  6335. @opindex verbatim-files-from
  6336. If such option handling is undesirable, use the
  6337. @option{--verbatim-files-from} option. When this option is in effect,
  6338. each line read from the file list is treated as a file name. Notice,
  6339. that this means, in particular, that no whitespace trimming is
  6340. performed.
  6341. @anchor{no-verbatim-files-from}
  6342. @opindex no-verbatim-files-from
  6343. The @option{--verbatim-files-from} affects all @option{-T} options
  6344. that follow it in the command line. The default behavior can be
  6345. restored using @option{--no-verbatim-files-from} option.
  6346. @opindex add-file
  6347. To disable option handling for a single file name, use the
  6348. @option{--add-file} option, e.g.: @code{--add-file=--my-file}.
  6349. You can use any @GNUTAR{} command line options in the file list file,
  6350. including @option{--files-from} option itself. This allows for
  6351. including contents of a file list into another file list file.
  6352. Note however, that options that control file list processing, such as
  6353. @option{--verbatim-files-from} or @option{--null} won't affect the
  6354. file they appear in. They will affect next @option{--files-from}
  6355. option, if there is any.
  6356. @menu
  6357. * nul::
  6358. @end menu
  6359. @node nul
  6360. @subsection @code{NUL}-Terminated File Names
  6361. @cindex File names, terminated by @code{NUL}
  6362. @cindex @code{NUL}-terminated file names
  6363. The @option{--null} option causes
  6364. @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
  6365. to read file names terminated by a @code{NUL} instead of a newline, so
  6366. files whose names contain newlines can be archived using
  6367. @option{--files-from}.
  6368. @table @option
  6369. @xopindex{null, described}
  6370. @item --null
  6371. Only consider @code{NUL}-terminated file names, instead of files that
  6372. terminate in a newline.
  6373. @xopindex{no-null, described}
  6374. @item --no-null
  6375. Undo the effect of any previous @option{--null} option.
  6376. @end table
  6377. The @option{--null} option is just like the one in @acronym{GNU}
  6378. @command{xargs} and @command{cpio}, and is useful with the
  6379. @option{-print0} predicate of @acronym{GNU} @command{find}. In
  6380. @command{tar}, @option{--null} also disables special handling for
  6381. file names that begin with dash (similar to
  6382. @option{--verbatim-files-from} option).
  6383. This example shows how to use @command{find} to generate a list of files
  6384. larger than 800 blocks in length and put that list into a file called
  6385. @file{long-files}. The @option{-print0} option to @command{find} is just
  6386. like @option{-print}, except that it separates files with a @code{NUL}
  6387. rather than with a newline. You can then run @command{tar} with both the
  6388. @option{--null} and @option{-T} options to specify that @command{tar} gets the
  6389. files from that file, @file{long-files}, to create the archive
  6390. @file{big.tgz}. The @option{--null} option to @command{tar} will cause
  6391. @command{tar} to recognize the @code{NUL} separator between files.
  6392. @smallexample
  6393. $ @kbd{find . -size +800 -print0 > long-files}
  6394. $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
  6395. @end smallexample
  6396. The @option{--no-null} option can be used if you need to read both
  6397. @code{NUL}-terminated and newline-terminated files on the same command line.
  6398. For example, if @file{flist} is a newline-terminated file, then the
  6399. following command can be used to combine it with the above command:
  6400. @smallexample
  6401. @group
  6402. $ @kbd{find . -size +800 -print0 |
  6403. tar -c -f big.tar --null -T - --no-null -T flist}
  6404. @end group
  6405. @end smallexample
  6406. This example uses short options for typographic reasons, to avoid
  6407. very long lines.
  6408. @GNUTAR{} is tries to automatically detect @code{NUL}-terminated file
  6409. lists, so in many cases it is safe to use them even without the
  6410. @option{--null} option. In this case @command{tar} will print a
  6411. warning and continue reading such a file as if @option{--null} were
  6412. actually given:
  6413. @smallexample
  6414. @group
  6415. $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
  6416. tar: -: file name read contains nul character
  6417. @end group
  6418. @end smallexample
  6419. The null terminator, however, remains in effect only for this
  6420. particular file, any following @option{-T} options will assume
  6421. newline termination. Of course, the null autodetection applies
  6422. to these eventual surplus @option{-T} options as well.
  6423. @node exclude
  6424. @section Excluding Some Files
  6425. @cindex File names, excluding files by
  6426. @cindex Excluding files by name and pattern
  6427. @cindex Excluding files by file system
  6428. @opindex exclude
  6429. @opindex exclude-from
  6430. To avoid operating on files whose names match a particular pattern,
  6431. use the @option{--exclude} or @option{--exclude-from} options.
  6432. @table @option
  6433. @opindex exclude
  6434. @item --exclude=@var{pattern}
  6435. Causes @command{tar} to ignore files that match the @var{pattern}.
  6436. @end table
  6437. @findex exclude
  6438. The @option{--exclude=@var{pattern}} option prevents any file or
  6439. member whose name matches the shell wildcard (@var{pattern}) from
  6440. being operated on.
  6441. For example, to create an archive with all the contents of the directory
  6442. @file{src} except for files whose names end in @file{.o}, use the
  6443. command @samp{tar -cf src.tar --exclude='*.o' src}.
  6444. You may give multiple @option{--exclude} options.
  6445. @table @option
  6446. @opindex exclude-from
  6447. @item --exclude-from=@var{file}
  6448. @itemx -X @var{file}
  6449. Causes @command{tar} to ignore files that match the patterns listed in
  6450. @var{file}.
  6451. @end table
  6452. @findex exclude-from
  6453. Use the @option{--exclude-from} option to read a
  6454. list of patterns, one per line, from @var{file}; @command{tar} will
  6455. ignore files matching those patterns. Thus if @command{tar} is
  6456. called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
  6457. single line @file{*.o}, no files whose names end in @file{.o} will be
  6458. added to the archive.
  6459. Notice, that lines from @var{file} are read verbatim. One of the
  6460. frequent errors is leaving some extra whitespace after a file name,
  6461. which is difficult to catch using text editors.
  6462. However, empty lines are OK.
  6463. @cindex VCS, excluding patterns from ignore files
  6464. @cindex VCS, ignore files
  6465. @cindex CVS, ignore files
  6466. @cindex Git, ignore files
  6467. @cindex Bazaar, ignore files
  6468. @cindex Mercurial, ignore files
  6469. When archiving directories that are under some version control system (VCS),
  6470. it is often convenient to read exclusion patterns from this VCS'
  6471. ignore files (e.g. @file{.cvsignore}, @file{.gitignore}, etc.) The
  6472. following options provide such possibility:
  6473. @table @option
  6474. @anchor{exclude-vcs-ignores}
  6475. @opindex exclude-vcs-ignores
  6476. @item --exclude-vcs-ignores
  6477. Before archiving a directory, see if it contains any of the following
  6478. files: @file{cvsignore}, @file{.gitignore}, @file{.bzrignore}, or
  6479. @file{.hgignore}. If so, read ignore patterns from these files.
  6480. The patterns are treated much as the corresponding VCS would treat
  6481. them, i.e.:
  6482. @table @file
  6483. @findex .cvsignore
  6484. @item .cvsignore
  6485. Contains shell-style globbing patterns that apply only to the
  6486. directory where this file resides. No comments are allowed in the
  6487. file. Empty lines are ignored.
  6488. @findex .gitignore
  6489. @item .gitignore
  6490. Contains shell-style globbing patterns. Applies to the directory
  6491. where @file{.gitfile} is located and all its subdirectories.
  6492. Any line beginning with a @samp{#} is a comment. Backslash escapes
  6493. the comment character.
  6494. @findex .bzrignore
  6495. @item .bzrignore
  6496. Contains shell globbing-patterns and regular expressions (if prefixed
  6497. with @samp{RE:}@footnote{According to the Bazaar docs,
  6498. globbing-patterns are Korn-shell style and regular expressions are
  6499. perl-style. As of @GNUTAR{} version @value{VERSION}, these are
  6500. treated as shell-style globs and POSIX extended regexps. This will be
  6501. fixed in future releases.}. Patterns affect the directory and all its
  6502. subdirectories.
  6503. Any line beginning with a @samp{#} is a comment.
  6504. @findex .hgignore
  6505. @item .hgignore
  6506. Contains POSIX regular expressions@footnote{Support for perl-style
  6507. regexps will appear in future releases.}. The line @samp{syntax:
  6508. glob} switches to shell globbing patterns. The line @samp{syntax:
  6509. regexp} switches back. Comments begin with a @samp{#}. Patterns
  6510. affect the directory and all its subdirectories.
  6511. @end table
  6512. @opindex exclude-ignore
  6513. @item --exclude-ignore=@var{file}
  6514. Before dumping a directory, @command{tar} checks if it contains
  6515. @var{file}. If so, exclusion patterns are read from this file.
  6516. The patterns affect only the directory itself.
  6517. @opindex exclude-ignore-recursive
  6518. @item --exclude-ignore-recursive=@var{file}
  6519. Same as @option{--exclude-ignore}, except that the patterns read
  6520. affect both the directory where @var{file} resides and all its
  6521. subdirectories.
  6522. @end table
  6523. @table @option
  6524. @cindex version control system, excluding files
  6525. @cindex VCS, excluding files
  6526. @cindex SCCS, excluding files
  6527. @cindex RCS, excluding files
  6528. @cindex CVS, excluding files
  6529. @cindex SVN, excluding files
  6530. @cindex git, excluding files
  6531. @cindex Bazaar, excluding files
  6532. @cindex Arch, excluding files
  6533. @cindex Mercurial, excluding files
  6534. @cindex Darcs, excluding files
  6535. @anchor{exclude-vcs}
  6536. @opindex exclude-vcs
  6537. @item --exclude-vcs
  6538. Exclude files and directories used by following version control
  6539. systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
  6540. @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
  6541. As of version @value{VERSION}, the following files are excluded:
  6542. @itemize @bullet
  6543. @item @file{CVS/}, and everything under it
  6544. @item @file{RCS/}, and everything under it
  6545. @item @file{SCCS/}, and everything under it
  6546. @item @file{.git/}, and everything under it
  6547. @item @file{.gitignore}
  6548. @item @file{.gitmodules}
  6549. @item @file{.gitattributes}
  6550. @item @file{.cvsignore}
  6551. @item @file{.svn/}, and everything under it
  6552. @item @file{.arch-ids/}, and everything under it
  6553. @item @file{@{arch@}/}, and everything under it
  6554. @item @file{=RELEASE-ID}
  6555. @item @file{=meta-update}
  6556. @item @file{=update}
  6557. @item @file{.bzr}
  6558. @item @file{.bzrignore}
  6559. @item @file{.bzrtags}
  6560. @item @file{.hg}
  6561. @item @file{.hgignore}
  6562. @item @file{.hgrags}
  6563. @item @file{_darcs}
  6564. @end itemize
  6565. @opindex exclude-backups
  6566. @item --exclude-backups
  6567. Exclude backup and lock files. This option causes exclusion of files
  6568. that match the following shell globbing patterns:
  6569. @table @asis
  6570. @item .#*
  6571. @item *~
  6572. @item #*#
  6573. @end table
  6574. @end table
  6575. @findex exclude-caches
  6576. When creating an archive, the @option{--exclude-caches} option family
  6577. causes @command{tar} to exclude all directories that contain a @dfn{cache
  6578. directory tag}. A cache directory tag is a short file with the
  6579. well-known name @file{CACHEDIR.TAG} and having a standard header
  6580. specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
  6581. Various applications write cache directory tags into directories they
  6582. use to hold regenerable, non-precious data, so that such data can be
  6583. more easily excluded from backups.
  6584. There are three @samp{exclude-caches} options, each providing a different
  6585. exclusion semantics:
  6586. @table @option
  6587. @opindex exclude-caches
  6588. @item --exclude-caches
  6589. Do not archive the contents of the directory, but archive the
  6590. directory itself and the @file{CACHEDIR.TAG} file.
  6591. @opindex exclude-caches-under
  6592. @item --exclude-caches-under
  6593. Do not archive the contents of the directory, nor the
  6594. @file{CACHEDIR.TAG} file, archive only the directory itself.
  6595. @opindex exclude-caches-all
  6596. @item --exclude-caches-all
  6597. Omit directories containing @file{CACHEDIR.TAG} file entirely.
  6598. @end table
  6599. @findex exclude-tag
  6600. Another option family, @option{--exclude-tag}, provides a generalization of
  6601. this concept. It takes a single argument, a file name to look for.
  6602. Any directory that contains this file will be excluded from the dump.
  6603. Similarly to @samp{exclude-caches}, there are three options in this
  6604. option family:
  6605. @table @option
  6606. @opindex exclude-tag
  6607. @item --exclude-tag=@var{file}
  6608. Do not dump the contents of the directory, but dump the
  6609. directory itself and the @var{file}.
  6610. @opindex exclude-tag-under
  6611. @item --exclude-tag-under=@var{file}
  6612. Do not dump the contents of the directory, nor the
  6613. @var{file}, archive only the directory itself.
  6614. @opindex exclude-tag-all
  6615. @item --exclude-tag-all=@var{file}
  6616. Omit directories containing @var{file} file entirely.
  6617. @end table
  6618. Multiple @option{--exclude-tag*} options can be given.
  6619. For example, given this directory:
  6620. @smallexample
  6621. @group
  6622. $ @kbd{find dir}
  6623. dir
  6624. dir/blues
  6625. dir/jazz
  6626. dir/folk
  6627. dir/folk/tagfile
  6628. dir/folk/sanjuan
  6629. dir/folk/trote
  6630. @end group
  6631. @end smallexample
  6632. The @option{--exclude-tag} will produce the following:
  6633. @smallexample
  6634. $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
  6635. dir/
  6636. dir/blues
  6637. dir/jazz
  6638. dir/folk/
  6639. tar: dir/folk/: contains a cache directory tag tagfile;
  6640. contents not dumped
  6641. dir/folk/tagfile
  6642. @end smallexample
  6643. Both the @file{dir/folk} directory and its tagfile are preserved in
  6644. the archive, however the rest of files in this directory are not.
  6645. Now, using the @option{--exclude-tag-under} option will exclude
  6646. @file{tagfile} from the dump, while still preserving the directory
  6647. itself, as shown in this example:
  6648. @smallexample
  6649. $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
  6650. dir/
  6651. dir/blues
  6652. dir/jazz
  6653. dir/folk/
  6654. ./tar: dir/folk/: contains a cache directory tag tagfile;
  6655. contents not dumped
  6656. @end smallexample
  6657. Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
  6658. directory entirely:
  6659. @smallexample
  6660. $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
  6661. dir/
  6662. dir/blues
  6663. dir/jazz
  6664. ./tar: dir/folk/: contains a cache directory tag tagfile;
  6665. directory not dumped
  6666. @end smallexample
  6667. @menu
  6668. * problems with exclude::
  6669. @end menu
  6670. @node problems with exclude
  6671. @unnumberedsubsec Problems with Using the @code{exclude} Options
  6672. @xopindex{exclude, potential problems with}
  6673. Some users find @samp{exclude} options confusing. Here are some common
  6674. pitfalls:
  6675. @itemize @bullet
  6676. @item
  6677. The main operating mode of @command{tar} does not act on a file name
  6678. explicitly listed on the command line, if one of its file name
  6679. components is excluded. In the example above, if
  6680. you create an archive and exclude files that end with @samp{*.o}, but
  6681. explicitly name the file @samp{dir.o/foo} after all the options have been
  6682. listed, @samp{dir.o/foo} will be excluded from the archive.
  6683. @item
  6684. You can sometimes confuse the meanings of @option{--exclude} and
  6685. @option{--exclude-from}. Be careful: use @option{--exclude} when files
  6686. to be excluded are given as a pattern on the command line. Use
  6687. @option{--exclude-from} to introduce the name of a file which contains
  6688. a list of patterns, one per line; each of these patterns can exclude
  6689. zero, one, or many files.
  6690. @item
  6691. When you use @option{--exclude=@var{pattern}}, be sure to quote the
  6692. @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
  6693. like @samp{*}. If you do not do this, the shell might expand the
  6694. @samp{*} itself using files at hand, so @command{tar} might receive a
  6695. list of files instead of one pattern, or none at all, making the
  6696. command somewhat illegal. This might not correspond to what you want.
  6697. For example, write:
  6698. @smallexample
  6699. $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
  6700. @end smallexample
  6701. @noindent
  6702. rather than:
  6703. @smallexample
  6704. # @emph{Wrong!}
  6705. $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
  6706. @end smallexample
  6707. @item
  6708. You must use use shell syntax, or globbing, rather than @code{regexp}
  6709. syntax, when using exclude options in @command{tar}. If you try to use
  6710. @code{regexp} syntax to describe files to be excluded, your command
  6711. might fail.
  6712. @item
  6713. @FIXME{The change in semantics must have occurred before 1.11,
  6714. so I doubt if it is worth mentioning at all. Anyway, should at
  6715. least specify in which version the semantics changed.}
  6716. In earlier versions of @command{tar}, what is now the
  6717. @option{--exclude-from} option was called @option{--exclude} instead.
  6718. Now, @option{--exclude} applies to patterns listed on the command
  6719. line and @option{--exclude-from} applies to patterns listed in a
  6720. file.
  6721. @end itemize
  6722. @node wildcards
  6723. @section Wildcards Patterns and Matching
  6724. @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
  6725. @samp{*} or @samp{?} for example, are replaced and expanded into all
  6726. existing files matching the given pattern. @GNUTAR{} can use wildcard
  6727. patterns for matching (or globbing) archive members when extracting
  6728. from or listing an archive. Wildcard patterns are also used for
  6729. verifying volume labels of @command{tar} archives. This section has the
  6730. purpose of explaining wildcard syntax for @command{tar}.
  6731. @FIXME{the next few paragraphs need work.}
  6732. A @var{pattern} should be written according to shell syntax, using wildcard
  6733. characters to effect globbing. Most characters in the pattern stand
  6734. for themselves in the matched string, and case is significant: @samp{a}
  6735. will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
  6736. pattern matches any single character in the matched string. The character
  6737. @samp{*} in the pattern matches zero, one, or more single characters in
  6738. the matched string. The character @samp{\} says to take the following
  6739. character of the pattern @emph{literally}; it is useful when one needs to
  6740. match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
  6741. The character @samp{[}, up to the matching @samp{]}, introduces a character
  6742. class. A @dfn{character class} is a list of acceptable characters
  6743. for the next single character of the matched string. For example,
  6744. @samp{[abcde]} would match any of the first five letters of the alphabet.
  6745. Note that within a character class, all of the ``special characters''
  6746. listed above other than @samp{\} lose their special meaning; for example,
  6747. @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
  6748. @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
  6749. the characters @samp{-} and @samp{]} must either come @emph{first} or
  6750. @emph{last} in a character class.)
  6751. @cindex Excluding characters from a character class
  6752. @cindex Character class, excluding characters from
  6753. If the first character of the class after the opening @samp{[}
  6754. is @samp{!} or @samp{^}, then the meaning of the class is reversed.
  6755. Rather than listing character to match, it lists those characters which
  6756. are @emph{forbidden} as the next single character of the matched string.
  6757. Other characters of the class stand for themselves. The special
  6758. construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
  6759. letters, is meant to represent all characters between @var{a} and
  6760. @var{e}, inclusive.
  6761. @FIXME{need to add a sentence or so here to make this clear for those
  6762. who don't have dan around.}
  6763. Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
  6764. special for wildcard matches. However, if a pattern completely matches
  6765. a directory prefix of a matched string, then it matches the full matched
  6766. string: thus, excluding a directory also excludes all the files beneath it.
  6767. @menu
  6768. * controlling pattern-matching::
  6769. @end menu
  6770. @node controlling pattern-matching
  6771. @unnumberedsubsec Controlling Pattern-Matching
  6772. For the purposes of this section, we call @dfn{exclusion members} all
  6773. member names obtained while processing @option{--exclude} and
  6774. @option{--exclude-from} options, and @dfn{inclusion members} those
  6775. member names that were given in the command line or read from the file
  6776. specified with @option{--files-from} option.
  6777. These two pairs of member lists are used in the following operations:
  6778. @option{--diff}, @option{--extract}, @option{--list},
  6779. @option{--update}.
  6780. There are no inclusion members in create mode (@option{--create} and
  6781. @option{--append}), since in this mode the names obtained from the
  6782. command line refer to @emph{files}, not archive members.
  6783. By default, inclusion members are compared with archive members
  6784. literally @footnote{Notice that earlier @GNUTAR{} versions used
  6785. globbing for inclusion members, which contradicted to UNIX98
  6786. specification and was not documented. @xref{Changes}, for more
  6787. information on this and other changes.} and exclusion members are
  6788. treated as globbing patterns. For example:
  6789. @smallexample
  6790. @group
  6791. $ @kbd{tar tf foo.tar}
  6792. a.c
  6793. b.c
  6794. a.txt
  6795. [remarks]
  6796. # @i{Member names are used verbatim:}
  6797. $ @kbd{tar -xf foo.tar -v '[remarks]'}
  6798. [remarks]
  6799. # @i{Exclude member names are globbed:}
  6800. $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
  6801. a.txt
  6802. [remarks]
  6803. @end group
  6804. @end smallexample
  6805. This behavior can be altered by using the following options:
  6806. @table @option
  6807. @opindex wildcards
  6808. @item --wildcards
  6809. Treat all member names as wildcards.
  6810. @opindex no-wildcards
  6811. @item --no-wildcards
  6812. Treat all member names as literal strings.
  6813. @end table
  6814. Thus, to extract files whose names end in @samp{.c}, you can use:
  6815. @smallexample
  6816. $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
  6817. a.c
  6818. b.c
  6819. @end smallexample
  6820. @noindent
  6821. Notice quoting of the pattern to prevent the shell from interpreting
  6822. it.
  6823. The effect of @option{--wildcards} option is canceled by
  6824. @option{--no-wildcards}. This can be used to pass part of
  6825. the command line arguments verbatim and other part as globbing
  6826. patterns. For example, the following invocation:
  6827. @smallexample
  6828. $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
  6829. @end smallexample
  6830. @noindent
  6831. instructs @command{tar} to extract from @file{foo.tar} all files whose
  6832. names end in @samp{.txt} and the file named @file{[remarks]}.
  6833. Normally, a pattern matches a name if an initial subsequence of the
  6834. name's components matches the pattern, where @samp{*}, @samp{?}, and
  6835. @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
  6836. and wildcards can match @samp{/}.
  6837. Other than optionally stripping leading @samp{/} from names
  6838. (@pxref{absolute}), patterns and names are used as-is. For
  6839. example, trailing @samp{/} is not trimmed from a user-specified name
  6840. before deciding whether to exclude it.
  6841. However, this matching procedure can be altered by the options listed
  6842. below. These options accumulate. For example:
  6843. @smallexample
  6844. --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
  6845. @end smallexample
  6846. @noindent
  6847. ignores case when excluding @samp{makefile}, but not when excluding
  6848. @samp{readme}.
  6849. @table @option
  6850. @anchor{anchored patterns}
  6851. @opindex anchored
  6852. @opindex no-anchored
  6853. @item --anchored
  6854. @itemx --no-anchored
  6855. If anchored, a pattern must match an initial subsequence
  6856. of the name's components. Otherwise, the pattern can match any
  6857. subsequence. Default is @option{--no-anchored} for exclusion members
  6858. and @option{--anchored} inclusion members.
  6859. @anchor{case-insensitive matches}
  6860. @opindex ignore-case
  6861. @opindex no-ignore-case
  6862. @item --ignore-case
  6863. @itemx --no-ignore-case
  6864. When ignoring case, upper-case patterns match lower-case names and vice versa.
  6865. When not ignoring case (the default), matching is case-sensitive.
  6866. @opindex wildcards-match-slash
  6867. @opindex no-wildcards-match-slash
  6868. @item --wildcards-match-slash
  6869. @itemx --no-wildcards-match-slash
  6870. When wildcards match slash (the default for exclusion members), a
  6871. wildcard like @samp{*} in the pattern can match a @samp{/} in the
  6872. name. Otherwise, @samp{/} is matched only by @samp{/}.
  6873. @end table
  6874. The @option{--recursion} and @option{--no-recursion} options
  6875. (@pxref{recurse}) also affect how member patterns are interpreted. If
  6876. recursion is in effect, a pattern matches a name if it matches any of
  6877. the name's parent directories.
  6878. The following table summarizes pattern-matching default values:
  6879. @multitable @columnfractions .3 .7
  6880. @headitem Members @tab Default settings
  6881. @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
  6882. @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
  6883. @end multitable
  6884. @node quoting styles
  6885. @section Quoting Member Names
  6886. When displaying member names, @command{tar} takes care to avoid
  6887. ambiguities caused by certain characters. This is called @dfn{name
  6888. quoting}. The characters in question are:
  6889. @itemize @bullet
  6890. @item Non-printable control characters:
  6891. @anchor{escape sequences}
  6892. @multitable @columnfractions 0.20 0.10 0.60
  6893. @headitem Character @tab @acronym{ASCII} @tab Character name
  6894. @item \a @tab 7 @tab Audible bell
  6895. @item \b @tab 8 @tab Backspace
  6896. @item \f @tab 12 @tab Form feed
  6897. @item \n @tab 10 @tab New line
  6898. @item \r @tab 13 @tab Carriage return
  6899. @item \t @tab 9 @tab Horizontal tabulation
  6900. @item \v @tab 11 @tab Vertical tabulation
  6901. @end multitable
  6902. @item Space (@acronym{ASCII} 32)
  6903. @item Single and double quotes (@samp{'} and @samp{"})
  6904. @item Backslash (@samp{\})
  6905. @end itemize
  6906. The exact way @command{tar} uses to quote these characters depends on
  6907. the @dfn{quoting style}. The default quoting style, called
  6908. @dfn{escape} (see below), uses backslash notation to represent control
  6909. characters and backslash.
  6910. @GNUTAR{} offers seven distinct quoting styles, which can be selected
  6911. using @option{--quoting-style} option:
  6912. @table @option
  6913. @item --quoting-style=@var{style}
  6914. @opindex quoting-style
  6915. Sets quoting style. Valid values for @var{style} argument are:
  6916. literal, shell, shell-always, c, escape, locale, clocale.
  6917. @end table
  6918. These styles are described in detail below. To illustrate their
  6919. effect, we will use an imaginary tar archive @file{arch.tar}
  6920. containing the following members:
  6921. @smallexample
  6922. @group
  6923. # 1. Contains horizontal tabulation character.
  6924. a tab
  6925. # 2. Contains newline character
  6926. a
  6927. newline
  6928. # 3. Contains a space
  6929. a space
  6930. # 4. Contains double quotes
  6931. a"double"quote
  6932. # 5. Contains single quotes
  6933. a'single'quote
  6934. # 6. Contains a backslash character:
  6935. a\backslash
  6936. @end group
  6937. @end smallexample
  6938. Here is how usual @command{ls} command would have listed them, if they
  6939. had existed in the current working directory:
  6940. @smallexample
  6941. @group
  6942. $ @kbd{ls}
  6943. a\ttab
  6944. a\nnewline
  6945. a\ space
  6946. a"double"quote
  6947. a'single'quote
  6948. a\\backslash
  6949. @end group
  6950. @end smallexample
  6951. Quoting styles:
  6952. @table @samp
  6953. @item literal
  6954. No quoting, display each character as is:
  6955. @smallexample
  6956. @group
  6957. $ @kbd{tar tf arch.tar --quoting-style=literal}
  6958. ./
  6959. ./a space
  6960. ./a'single'quote
  6961. ./a"double"quote
  6962. ./a\backslash
  6963. ./a tab
  6964. ./a
  6965. newline
  6966. @end group
  6967. @end smallexample
  6968. @item shell
  6969. Display characters the same way Bourne shell does:
  6970. control characters, except @samp{\t} and @samp{\n}, are printed using
  6971. backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
  6972. single quote is printed as @samp{\'}. If a name contains any quoted
  6973. characters, it is enclosed in single quotes. In particular, if a name
  6974. contains single quotes, it is printed as several single-quoted strings:
  6975. @smallexample
  6976. @group
  6977. $ @kbd{tar tf arch.tar --quoting-style=shell}
  6978. ./
  6979. './a space'
  6980. './a'\''single'\''quote'
  6981. './a"double"quote'
  6982. './a\backslash'
  6983. './a tab'
  6984. './a
  6985. newline'
  6986. @end group
  6987. @end smallexample
  6988. @item shell-always
  6989. Same as @samp{shell}, but the names are always enclosed in single
  6990. quotes:
  6991. @smallexample
  6992. @group
  6993. $ @kbd{tar tf arch.tar --quoting-style=shell-always}
  6994. './'
  6995. './a space'
  6996. './a'\''single'\''quote'
  6997. './a"double"quote'
  6998. './a\backslash'
  6999. './a tab'
  7000. './a
  7001. newline'
  7002. @end group
  7003. @end smallexample
  7004. @item c
  7005. Use the notation of the C programming language. All names are
  7006. enclosed in double quotes. Control characters are quoted using
  7007. backslash notations, double quotes are represented as @samp{\"},
  7008. backslash characters are represented as @samp{\\}. Single quotes and
  7009. spaces are not quoted:
  7010. @smallexample
  7011. @group
  7012. $ @kbd{tar tf arch.tar --quoting-style=c}
  7013. "./"
  7014. "./a space"
  7015. "./a'single'quote"
  7016. "./a\"double\"quote"
  7017. "./a\\backslash"
  7018. "./a\ttab"
  7019. "./a\nnewline"
  7020. @end group
  7021. @end smallexample
  7022. @item escape
  7023. Control characters are printed using backslash notation, and a
  7024. backslash as @samp{\\}. This is the default quoting style, unless it
  7025. was changed when configured the package.
  7026. @smallexample
  7027. @group
  7028. $ @kbd{tar tf arch.tar --quoting-style=escape}
  7029. ./
  7030. ./a space
  7031. ./a'single'quote
  7032. ./a"double"quote
  7033. ./a\\backslash
  7034. ./a\ttab
  7035. ./a\nnewline
  7036. @end group
  7037. @end smallexample
  7038. @item locale
  7039. Control characters, single quote and backslash are printed using
  7040. backslash notation. All names are quoted using left and right
  7041. quotation marks, appropriate to the current locale. If it does not
  7042. define quotation marks, use @samp{'} as left and as right
  7043. quotation marks. Any occurrences of the right quotation mark in a
  7044. name are escaped with @samp{\}, for example:
  7045. For example:
  7046. @smallexample
  7047. @group
  7048. $ @kbd{tar tf arch.tar --quoting-style=locale}
  7049. './'
  7050. './a space'
  7051. './a\'single\'quote'
  7052. './a"double"quote'
  7053. './a\\backslash'
  7054. './a\ttab'
  7055. './a\nnewline'
  7056. @end group
  7057. @end smallexample
  7058. @item clocale
  7059. Same as @samp{locale}, but @samp{"} is used for both left and right
  7060. quotation marks, if not provided by the currently selected locale:
  7061. @smallexample
  7062. @group
  7063. $ @kbd{tar tf arch.tar --quoting-style=clocale}
  7064. "./"
  7065. "./a space"
  7066. "./a'single'quote"
  7067. "./a\"double\"quote"
  7068. "./a\\backslash"
  7069. "./a\ttab"
  7070. "./a\nnewline"
  7071. @end group
  7072. @end smallexample
  7073. @end table
  7074. You can specify which characters should be quoted in addition to those
  7075. implied by the current quoting style:
  7076. @table @option
  7077. @item --quote-chars=@var{string}
  7078. Always quote characters from @var{string}, even if the selected
  7079. quoting style would not quote them.
  7080. @end table
  7081. For example, using @samp{escape} quoting (compare with the usual
  7082. escape listing above):
  7083. @smallexample
  7084. @group
  7085. $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
  7086. ./
  7087. ./a\ space
  7088. ./a'single'quote
  7089. ./a\"double\"quote
  7090. ./a\\backslash
  7091. ./a\ttab
  7092. ./a\nnewline
  7093. @end group
  7094. @end smallexample
  7095. To disable quoting of such additional characters, use the following
  7096. option:
  7097. @table @option
  7098. @item --no-quote-chars=@var{string}
  7099. Remove characters listed in @var{string} from the list of quoted
  7100. characters set by the previous @option{--quote-chars} option.
  7101. @end table
  7102. This option is particularly useful if you have added
  7103. @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
  7104. and wish to disable it for the current invocation.
  7105. Note, that @option{--no-quote-chars} does @emph{not} disable those
  7106. characters that are quoted by default in the selected quoting style.
  7107. @node transform
  7108. @section Modifying File and Member Names
  7109. @command{Tar} archives contain detailed information about files stored
  7110. in them and full file names are part of that information. When
  7111. storing a file to an archive, its file name is recorded in it,
  7112. along with the actual file contents. When restoring from an archive,
  7113. a file is created on disk with exactly the same name as that stored
  7114. in the archive. In the majority of cases this is the desired behavior
  7115. of a file archiver. However, there are some cases when it is not.
  7116. First of all, it is often unsafe to extract archive members with
  7117. absolute file names or those that begin with a @file{../}. @GNUTAR{}
  7118. takes special precautions when extracting such names and provides a
  7119. special option for handling them, which is described in
  7120. @ref{absolute}.
  7121. Secondly, you may wish to extract file names without some leading
  7122. directory components, or with otherwise modified names. In other
  7123. cases it is desirable to store files under differing names in the
  7124. archive.
  7125. @GNUTAR{} provides several options for these needs.
  7126. @table @option
  7127. @opindex strip-components
  7128. @item --strip-components=@var{number}
  7129. Strip given @var{number} of leading components from file names before
  7130. extraction.
  7131. @end table
  7132. For example, suppose you have archived whole @file{/usr} hierarchy to
  7133. a tar archive named @file{usr.tar}. Among other files, this archive
  7134. contains @file{usr/include/stdlib.h}, which you wish to extract to
  7135. the current working directory. To do so, you type:
  7136. @smallexample
  7137. $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
  7138. @end smallexample
  7139. The option @option{--strip=2} instructs @command{tar} to strip the
  7140. two leading components (@file{usr/} and @file{include/}) off the file
  7141. name.
  7142. If you add the @option{--verbose} (@option{-v}) option to the invocation
  7143. above, you will note that the verbose listing still contains the
  7144. full file name, with the two removed components still in place. This
  7145. can be inconvenient, so @command{tar} provides a special option for
  7146. altering this behavior:
  7147. @anchor{show-transformed-names}
  7148. @table @option
  7149. @opindex show-transformed-names
  7150. @item --show-transformed-names
  7151. Display file or member names with all requested transformations
  7152. applied.
  7153. @end table
  7154. @noindent
  7155. For example:
  7156. @smallexample
  7157. @group
  7158. $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
  7159. usr/include/stdlib.h
  7160. $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
  7161. stdlib.h
  7162. @end group
  7163. @end smallexample
  7164. Notice that in both cases the file @file{stdlib.h} is extracted to the
  7165. current working directory, @option{--show-transformed-names} affects
  7166. only the way its name is displayed.
  7167. This option is especially useful for verifying whether the invocation
  7168. will have the desired effect. Thus, before running
  7169. @smallexample
  7170. $ @kbd{tar -x --strip=@var{n}}
  7171. @end smallexample
  7172. @noindent
  7173. it is often advisable to run
  7174. @smallexample
  7175. $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
  7176. @end smallexample
  7177. @noindent
  7178. to make sure the command will produce the intended results.
  7179. In case you need to apply more complex modifications to the file name,
  7180. @GNUTAR{} provides a general-purpose transformation option:
  7181. @table @option
  7182. @opindex transform
  7183. @opindex xform
  7184. @item --transform=@var{expression}
  7185. @itemx --xform=@var{expression}
  7186. Modify file names using supplied @var{expression}.
  7187. @end table
  7188. @noindent
  7189. The @var{expression} is a @command{sed}-like replace expression of the
  7190. form:
  7191. @smallexample
  7192. s/@var{regexp}/@var{replace}/[@var{flags}]
  7193. @end smallexample
  7194. @noindent
  7195. where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
  7196. replacement for each file name part that matches @var{regexp}. Both
  7197. @var{regexp} and @var{replace} are described in detail in
  7198. @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
  7199. Any delimiter can be used in lieu of @samp{/}, the only requirement being
  7200. that it be used consistently throughout the expression. For example,
  7201. the following two expressions are equivalent:
  7202. @smallexample
  7203. @group
  7204. s/one/two/
  7205. s,one,two,
  7206. @end group
  7207. @end smallexample
  7208. Changing delimiters is often useful when the @var{regex} contains
  7209. slashes. For example, it is more convenient to write @code{s,/,-,} than
  7210. @code{s/\//-/}.
  7211. As in @command{sed}, you can give several replace expressions,
  7212. separated by a semicolon.
  7213. Supported @var{flags} are:
  7214. @table @samp
  7215. @item g
  7216. Apply the replacement to @emph{all} matches to the @var{regexp}, not
  7217. just the first.
  7218. @item i
  7219. Use case-insensitive matching.
  7220. @item x
  7221. @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
  7222. regexps, Extended regular expressions, Extended regular expressions,
  7223. sed, GNU sed}).
  7224. @item @var{number}
  7225. Only replace the @var{number}th match of the @var{regexp}.
  7226. Note: the @acronym{POSIX} standard does not specify what should happen
  7227. when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
  7228. follows the GNU @command{sed} implementation in this regard, so
  7229. the interaction is defined to be: ignore matches before the
  7230. @var{number}th, and then match and replace all matches from the
  7231. @var{number}th on.
  7232. @end table
  7233. In addition, several @dfn{transformation scope} flags are supported,
  7234. that control to what files transformations apply. These are:
  7235. @table @samp
  7236. @item r
  7237. Apply transformation to regular archive members.
  7238. @item R
  7239. Do not apply transformation to regular archive members.
  7240. @item s
  7241. Apply transformation to symbolic link targets.
  7242. @item S
  7243. Do not apply transformation to symbolic link targets.
  7244. @item h
  7245. Apply transformation to hard link targets.
  7246. @item H
  7247. Do not apply transformation to hard link targets.
  7248. @end table
  7249. Default is @samp{rsh}, which means to apply transformations to both archive
  7250. members and targets of symbolic and hard links.
  7251. Default scope flags can also be changed using @samp{flags=} statement
  7252. in the transform expression. The flags set this way remain in force
  7253. until next @samp{flags=} statement or end of expression, whichever
  7254. occurs first. For example:
  7255. @smallexample
  7256. --transform 'flags=S;s|^|/usr/local/|'
  7257. @end smallexample
  7258. Here are several examples of @option{--transform} usage:
  7259. @enumerate
  7260. @item Extract @file{usr/} hierarchy into @file{usr/local/}:
  7261. @smallexample
  7262. $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
  7263. @end smallexample
  7264. @item Strip two leading directory components (equivalent to
  7265. @option{--strip-components=2}):
  7266. @smallexample
  7267. $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
  7268. @end smallexample
  7269. @item Convert each file name to lower case:
  7270. @smallexample
  7271. $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
  7272. @end smallexample
  7273. @item Prepend @file{/prefix/} to each file name:
  7274. @smallexample
  7275. $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
  7276. @end smallexample
  7277. @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
  7278. to each archive member:
  7279. @smallexample
  7280. $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
  7281. @end smallexample
  7282. @end enumerate
  7283. Notice the use of flags in the last example. The @file{/lib}
  7284. directory often contains many symbolic links to files within it.
  7285. It may look, for example, like this:
  7286. @smallexample
  7287. $ @kbd{ls -l}
  7288. drwxr-xr-x root/root 0 2008-07-08 16:20 /lib/
  7289. -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
  7290. lrwxrwxrwx root/root 0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
  7291. ...
  7292. @end smallexample
  7293. Using the expression @samp{s,^,/usr/local/,} would mean adding
  7294. @samp{/usr/local} to both regular archive members and to link
  7295. targets. In this case, @file{/lib/libc.so.6} would become:
  7296. @smallexample
  7297. /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
  7298. @end smallexample
  7299. This is definitely not desired. To avoid this, the @samp{S} flag
  7300. is used, which excludes symbolic link targets from filename
  7301. transformations. The result is:
  7302. @smallexample
  7303. $ @kbd{tar --transform 's,^,/usr/local/,S' -c -v -f arch.tar \
  7304. --show-transformed /lib}
  7305. drwxr-xr-x root/root 0 2008-07-08 16:20 /usr/local/lib/
  7306. -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
  7307. lrwxrwxrwx root/root 0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
  7308. -> libc-2.3.2.so
  7309. @end smallexample
  7310. Unlike @option{--strip-components}, @option{--transform} can be used
  7311. in any @GNUTAR{} operation mode. For example, the following command
  7312. adds files to the archive while replacing the leading @file{usr/}
  7313. component with @file{var/}:
  7314. @smallexample
  7315. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
  7316. @end smallexample
  7317. To test @option{--transform} effect we suggest using
  7318. @option{--show-transformed-names} option:
  7319. @smallexample
  7320. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
  7321. --verbose --show-transformed-names /}
  7322. @end smallexample
  7323. If both @option{--strip-components} and @option{--transform} are used
  7324. together, then @option{--transform} is applied first, and the required
  7325. number of components is then stripped from its result.
  7326. You can use as many @option{--transform} options in a single command
  7327. line as you want. The specified expressions will then be applied in
  7328. order of their appearance. For example, the following two invocations
  7329. are equivalent:
  7330. @smallexample
  7331. $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
  7332. --transform='s,/usr/local,/usr/,'}
  7333. $ @kbd{tar -cf arch.tar \
  7334. --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
  7335. @end smallexample
  7336. @node after
  7337. @section Operating Only on New Files
  7338. @cindex Excluding file by age
  7339. @cindex Data Modification time, excluding files by
  7340. @cindex Modification time, excluding files by
  7341. @cindex Age, excluding files by
  7342. The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
  7343. @option{-N @var{date}}) option causes @command{tar} to only work on
  7344. files whose data modification or status change times are newer than
  7345. the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
  7346. it is taken to be a file name; the data modification time of that file
  7347. is used as the date. If you use this option when creating or appending
  7348. to an archive, the archive will only include new files. If you use
  7349. @option{--after-date} when extracting an archive, @command{tar} will
  7350. only extract files newer than the @var{date} you specify.
  7351. If you want @command{tar} to make the date comparison based only on
  7352. modification of the file's data (rather than status
  7353. changes), then use the @option{--newer-mtime=@var{date}} option.
  7354. @cindex --after-date and --update compared
  7355. @cindex --newer-mtime and --update compared
  7356. You may use these options with any operation. Note that these options
  7357. differ from the @option{--update} (@option{-u}) operation in that they
  7358. allow you to specify a particular date against which @command{tar} can
  7359. compare when deciding whether or not to archive the files.
  7360. @table @option
  7361. @opindex after-date
  7362. @opindex newer
  7363. @item --after-date=@var{date}
  7364. @itemx --newer=@var{date}
  7365. @itemx -N @var{date}
  7366. Only store files newer than @var{date}.
  7367. Acts on files only if their data modification or status change times are
  7368. later than @var{date}. Use in conjunction with any operation.
  7369. If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
  7370. name; the data modification time of that file is used as the date.
  7371. @opindex newer-mtime
  7372. @item --newer-mtime=@var{date}
  7373. Act like @option{--after-date}, but look only at data modification times.
  7374. @end table
  7375. These options limit @command{tar} to operate only on files which have
  7376. been modified after the date specified. A file's status is considered to have
  7377. changed if its contents have been modified, or if its owner,
  7378. permissions, and so forth, have been changed. (For more information on
  7379. how to specify a date, see @ref{Date input formats}; remember that the
  7380. entire date argument must be quoted if it contains any spaces.)
  7381. Gurus would say that @option{--after-date} tests both the data
  7382. modification time (@code{mtime}, the time the contents of the file
  7383. were last modified) and the status change time (@code{ctime}, the time
  7384. the file's status was last changed: owner, permissions, etc.@:)
  7385. fields, while @option{--newer-mtime} tests only the @code{mtime}
  7386. field.
  7387. To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
  7388. @code{ctime} and processes the file if either one is more recent than
  7389. @var{date}, while @option{--newer-mtime} checks only @code{mtime} and
  7390. disregards @code{ctime}. Neither option uses @code{atime} (the last time the
  7391. contents of the file were looked at).
  7392. Date specifiers can have embedded spaces. Because of this, you may need
  7393. to quote date arguments to keep the shell from parsing them as separate
  7394. arguments. For example, the following command will add to the archive
  7395. all the files modified less than two days ago:
  7396. @smallexample
  7397. $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
  7398. @end smallexample
  7399. When any of these options is used with the option @option{--verbose}
  7400. (@pxref{verbose tutorial}) @GNUTAR{} converts the specified
  7401. date back to a textual form and compares that with the
  7402. one given with the option. If the two forms differ, @command{tar}
  7403. prints both forms in a message, to help the user check that the right
  7404. date is being used. For example:
  7405. @smallexample
  7406. @group
  7407. $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
  7408. tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
  7409. 13:19:37.232434
  7410. @end group
  7411. @end smallexample
  7412. @quotation
  7413. @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
  7414. should not be used for incremental backups. @xref{Incremental Dumps},
  7415. for proper way of creating incremental backups.
  7416. @end quotation
  7417. @node recurse
  7418. @section Descending into Directories
  7419. @cindex Avoiding recursion in directories
  7420. @cindex Descending directories, avoiding
  7421. @cindex Directories, avoiding recursion
  7422. @cindex Recursion in directories, avoiding
  7423. Usually, @command{tar} will recursively explore all directories (either
  7424. those given on the command line or through the @option{--files-from}
  7425. option) for the various files they contain. However, you may not always
  7426. want @command{tar} to act this way.
  7427. @opindex no-recursion
  7428. @cindex @command{find}, using with @command{tar}
  7429. The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
  7430. into specified directories. If you specify @option{--no-recursion}, you can
  7431. use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
  7432. utility for hunting through levels of directories to
  7433. construct a list of file names which you could then pass to @command{tar}.
  7434. @command{find} allows you to be more selective when choosing which files to
  7435. archive; see @ref{files}, for more information on using @command{find} with
  7436. @command{tar}.
  7437. @table @option
  7438. @item --no-recursion
  7439. Prevents @command{tar} from recursively descending directories.
  7440. @opindex recursion
  7441. @item --recursion
  7442. Requires @command{tar} to recursively descend directories.
  7443. This is the default.
  7444. @end table
  7445. When you use @option{--no-recursion}, @GNUTAR{} grabs
  7446. directory entries themselves, but does not descend on them
  7447. recursively. Many people use @command{find} for locating files they
  7448. want to back up, and since @command{tar} @emph{usually} recursively
  7449. descends on directories, they have to use the @samp{@w{-not -type d}}
  7450. test in their @command{find} invocation (@pxref{Type, Type, Type test,
  7451. find, Finding Files}), as they usually do not want all the files in a
  7452. directory. They then use the @option{--files-from} option to archive
  7453. the files located via @command{find}.
  7454. The problem when restoring files archived in this manner is that the
  7455. directories themselves are not in the archive; so the
  7456. @option{--same-permissions} (@option{--preserve-permissions},
  7457. @option{-p}) option does not affect them---while users might really
  7458. like it to. Specifying @option{--no-recursion} is a way to tell
  7459. @command{tar} to grab only the directory entries given to it, adding
  7460. no new files on its own. To summarize, if you use @command{find} to
  7461. create a list of files to be stored in an archive, use it as follows:
  7462. @smallexample
  7463. @group
  7464. $ @kbd{find @var{dir} @var{tests} | \
  7465. tar -cf @var{archive} --no-recursion -T -}
  7466. @end group
  7467. @end smallexample
  7468. The @option{--no-recursion} option also applies when extracting: it
  7469. causes @command{tar} to extract only the matched directory entries, not
  7470. the files under those directories.
  7471. The @option{--no-recursion} option also affects how globbing patterns
  7472. are interpreted (@pxref{controlling pattern-matching}).
  7473. The @option{--no-recursion} and @option{--recursion} options apply to
  7474. later options and operands, and can be overridden by later occurrences
  7475. of @option{--no-recursion} and @option{--recursion}. For example:
  7476. @smallexample
  7477. $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
  7478. @end smallexample
  7479. @noindent
  7480. creates an archive with one entry for @file{grape}, and the recursive
  7481. contents of @file{grape/concord}, but no entries under @file{grape}
  7482. other than @file{grape/concord}.
  7483. @node one
  7484. @section Crossing File System Boundaries
  7485. @cindex File system boundaries, not crossing
  7486. @command{tar} will normally automatically cross file system boundaries in
  7487. order to archive files which are part of a directory tree. You can
  7488. change this behavior by running @command{tar} and specifying
  7489. @option{--one-file-system}. This option only affects files that are
  7490. archived because they are in a directory that is being archived;
  7491. @command{tar} will still archive files explicitly named on the command line
  7492. or through @option{--files-from}, regardless of where they reside.
  7493. @table @option
  7494. @opindex one-file-system
  7495. @item --one-file-system
  7496. Prevents @command{tar} from crossing file system boundaries when
  7497. archiving. Use in conjunction with any write operation.
  7498. @end table
  7499. The @option{--one-file-system} option causes @command{tar} to modify its
  7500. normal behavior in archiving the contents of directories. If a file in
  7501. a directory is not on the same file system as the directory itself, then
  7502. @command{tar} will not archive that file. If the file is a directory
  7503. itself, @command{tar} will not archive anything beneath it; in other words,
  7504. @command{tar} will not cross mount points.
  7505. This option is useful for making full or incremental archival backups of
  7506. a file system. If this option is used in conjunction with
  7507. @option{--verbose} (@option{-v}), files that are excluded are
  7508. mentioned by name on the standard error.
  7509. @menu
  7510. * directory:: Changing Directory
  7511. * absolute:: Absolute File Names
  7512. @end menu
  7513. @node directory
  7514. @subsection Changing the Working Directory
  7515. @FIXME{need to read over this node now for continuity; i've switched
  7516. things around some.}
  7517. @cindex Changing directory mid-stream
  7518. @cindex Directory, changing mid-stream
  7519. @cindex Working directory, specifying
  7520. To change the working directory in the middle of a list of file names,
  7521. either on the command line or in a file specified using
  7522. @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
  7523. This will change the working directory to the specified directory
  7524. after that point in the list.
  7525. @table @option
  7526. @opindex directory
  7527. @item --directory=@var{directory}
  7528. @itemx -C @var{directory}
  7529. Changes the working directory in the middle of a command line.
  7530. @end table
  7531. For example,
  7532. @smallexample
  7533. $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
  7534. @end smallexample
  7535. @noindent
  7536. will place the files @file{grape} and @file{prune} from the current
  7537. directory into the archive @file{jams.tar}, followed by the file
  7538. @file{cherry} from the directory @file{food}. This option is especially
  7539. useful when you have several widely separated files that you want to
  7540. store in the same archive.
  7541. Note that the file @file{cherry} is recorded in the archive under the
  7542. precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
  7543. archive will contain three files that all appear to have come from the
  7544. same directory; if the archive is extracted with plain @samp{tar
  7545. --extract}, all three files will be written in the current directory.
  7546. Contrast this with the command,
  7547. @smallexample
  7548. $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
  7549. @end smallexample
  7550. @noindent
  7551. which records the third file in the archive under the name
  7552. @file{red/cherry} so that, if the archive is extracted using
  7553. @samp{tar --extract}, the third file will be written in a subdirectory
  7554. named @file{red}.
  7555. You can use the @option{--directory} option to make the archive
  7556. independent of the original name of the directory holding the files.
  7557. The following command places the files @file{/etc/passwd},
  7558. @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
  7559. @file{foo.tar}:
  7560. @smallexample
  7561. $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
  7562. @end smallexample
  7563. @noindent
  7564. However, the names of the archive members will be exactly what they were
  7565. on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
  7566. They will not appear to be related by file name to the original
  7567. directories where those files were located.
  7568. Note that @option{--directory} options are interpreted consecutively. If
  7569. @option{--directory} specifies a relative file name, it is interpreted
  7570. relative to the then current directory, which might not be the same as
  7571. the original current working directory of @command{tar}, due to a previous
  7572. @option{--directory} option.
  7573. When using @option{--files-from} (@pxref{files}), you can put various
  7574. @command{tar} options (including @option{-C}) in the file list. Notice,
  7575. however, that in this case the option and its argument may not be
  7576. separated by whitespace. If you use short option, its argument must
  7577. either follow the option letter immediately, without any intervening
  7578. whitespace, or occupy the next line. Otherwise, if you use long
  7579. option, separate its argument by an equal sign.
  7580. For instance, the file list for the above example will be:
  7581. @smallexample
  7582. @group
  7583. -C/etc
  7584. passwd
  7585. hosts
  7586. --directory=/lib
  7587. libc.a
  7588. @end group
  7589. @end smallexample
  7590. @noindent
  7591. To use it, you would invoke @command{tar} as follows:
  7592. @smallexample
  7593. $ @kbd{tar -c -f foo.tar --files-from list}
  7594. @end smallexample
  7595. The interpretation of options in file lists is disabled by
  7596. @option{--verbatim-files-from} and @option{--null} options.
  7597. @node absolute
  7598. @subsection Absolute File Names
  7599. @cindex absolute file names
  7600. @cindex file names, absolute
  7601. By default, @GNUTAR{} drops a leading @samp{/} on
  7602. input or output, and complains about file names containing a @file{..}
  7603. component. There is an option that turns off this behavior:
  7604. @table @option
  7605. @opindex absolute-names
  7606. @item --absolute-names
  7607. @itemx -P
  7608. Do not strip leading slashes from file names, and permit file names
  7609. containing a @file{..} file name component.
  7610. @end table
  7611. When @command{tar} extracts archive members from an archive, it strips any
  7612. leading slashes (@samp{/}) from the member name. This causes absolute
  7613. member names in the archive to be treated as relative file names. This
  7614. allows you to have such members extracted wherever you want, instead of
  7615. being restricted to extracting the member in the exact directory named
  7616. in the archive. For example, if the archive member has the name
  7617. @file{/etc/passwd}, @command{tar} will extract it as if the name were
  7618. really @file{etc/passwd}.
  7619. File names containing @file{..} can cause problems when extracting, so
  7620. @command{tar} normally warns you about such files when creating an
  7621. archive, and rejects attempts to extracts such files.
  7622. Other @command{tar} programs do not do this. As a result, if you
  7623. create an archive whose member names start with a slash, they will be
  7624. difficult for other people with a non-@GNUTAR{}
  7625. program to use. Therefore, @GNUTAR{} also strips
  7626. leading slashes from member names when putting members into the
  7627. archive. For example, if you ask @command{tar} to add the file
  7628. @file{/bin/ls} to an archive, it will do so, but the member name will
  7629. be @file{bin/ls}@footnote{A side effect of this is that when
  7630. @option{--create} is used with @option{--verbose} the resulting output
  7631. is not, generally speaking, the same as the one you'd get running
  7632. @kbd{tar --list} command. This may be important if you use some
  7633. scripts for comparing both outputs. @xref{listing member and file names},
  7634. for the information on how to handle this case.}.
  7635. Symbolic links containing @file{..} or leading @samp{/} can also cause
  7636. problems when extracting, so @command{tar} normally extracts them last;
  7637. it may create empty files as placeholders during extraction.
  7638. If you use the @option{--absolute-names} (@option{-P}) option,
  7639. @command{tar} will do none of these transformations.
  7640. To archive or extract files relative to the root directory, specify
  7641. the @option{--absolute-names} (@option{-P}) option.
  7642. Normally, @command{tar} acts on files relative to the working
  7643. directory---ignoring superior directory names when archiving, and
  7644. ignoring leading slashes when extracting.
  7645. When you specify @option{--absolute-names} (@option{-P}),
  7646. @command{tar} stores file names including all superior directory
  7647. names, and preserves leading slashes. If you only invoked
  7648. @command{tar} from the root directory you would never need the
  7649. @option{--absolute-names} option, but using this option
  7650. may be more convenient than switching to root.
  7651. @FIXME{Should be an example in the tutorial/wizardry section using this
  7652. to transfer files between systems.}
  7653. @table @option
  7654. @item --absolute-names
  7655. Preserves full file names (including superior directory names) when
  7656. archiving and extracting files.
  7657. @end table
  7658. @command{tar} prints out a message about removing the @samp{/} from
  7659. file names. This message appears once per @GNUTAR{}
  7660. invocation. It represents something which ought to be told; ignoring
  7661. what it means can cause very serious surprises, later.
  7662. Some people, nevertheless, do not want to see this message. Wanting to
  7663. play really dangerously, one may of course redirect @command{tar} standard
  7664. error to the sink. For example, under @command{sh}:
  7665. @smallexample
  7666. $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
  7667. @end smallexample
  7668. @noindent
  7669. Another solution, both nicer and simpler, would be to change to
  7670. the @file{/} directory first, and then avoid absolute notation.
  7671. For example:
  7672. @smallexample
  7673. $ @kbd{tar -c -f archive.tar -C / home}
  7674. @end smallexample
  7675. @xref{Integrity}, for some of the security-related implications
  7676. of using this option.
  7677. @include parse-datetime.texi
  7678. @node Formats
  7679. @chapter Controlling the Archive Format
  7680. @cindex Tar archive formats
  7681. Due to historical reasons, there are several formats of tar archives.
  7682. All of them are based on the same principles, but have some subtle
  7683. differences that often make them incompatible with each other.
  7684. GNU tar is able to create and handle archives in a variety of formats.
  7685. The most frequently used formats are (in alphabetical order):
  7686. @table @asis
  7687. @item gnu
  7688. Format used by @GNUTAR{} versions up to 1.13.25. This format derived
  7689. from an early @acronym{POSIX} standard, adding some improvements such as
  7690. sparse file handling and incremental archives. Unfortunately these
  7691. features were implemented in a way incompatible with other archive
  7692. formats.
  7693. Archives in @samp{gnu} format are able to hold file names of unlimited
  7694. length.
  7695. @item oldgnu
  7696. Format used by @GNUTAR{} of versions prior to 1.12.
  7697. @item v7
  7698. Archive format, compatible with the V7 implementation of tar. This
  7699. format imposes a number of limitations. The most important of them
  7700. are:
  7701. @enumerate
  7702. @item
  7703. File names and symbolic links can contain at most 100 bytes.
  7704. @item
  7705. File sizes must be less than 8 GiB (@math{2^33} bytes = 8,589,934,592 bytes).
  7706. @item
  7707. It is impossible to store special files (block and character
  7708. devices, fifos etc.)
  7709. @item
  7710. UIDs and GIDs must be less than @math{2^21} (2,097,152).
  7711. @item
  7712. V7 archives do not contain symbolic ownership information (user
  7713. and group name of the file owner).
  7714. @end enumerate
  7715. This format has traditionally been used by Automake when producing
  7716. Makefiles. This practice will change in the future, in the meantime,
  7717. however this means that projects containing file names more than 100
  7718. bytes long will not be able to use @GNUTAR{} @value{VERSION} and
  7719. Automake prior to 1.9.
  7720. @item ustar
  7721. Archive format defined by @acronym{POSIX.1-1988} and later. It stores
  7722. symbolic ownership information. It is also able to store
  7723. special files. However, it imposes several restrictions as well:
  7724. @enumerate
  7725. @item
  7726. File names can contain at most 255 bytes.
  7727. @item
  7728. File names longer than 100 bytes must be split at a directory separator in
  7729. two parts, the first being at most 155 bytes long.
  7730. So, in most cases file names must be a bit shorter than 255 bytes.
  7731. @item
  7732. Symbolic links can contain at most 100 bytes.
  7733. @item
  7734. Files can contain at most 8 GiB (@math{2^33} bytes = 8,589,934,592 bytes).
  7735. @item
  7736. UIDs, GIDs, device major numbers, and device minor numbers
  7737. must be less than @math{2^21} (2,097,152).
  7738. @end enumerate
  7739. @item star
  7740. The format used by the late J@"org Schilling's @command{star}
  7741. implementation. @GNUTAR{} is able to read @samp{star} archives but
  7742. currently does not produce them.
  7743. @item posix
  7744. The format defined by @acronym{POSIX.1-2001} and later. This is the
  7745. most flexible and feature-rich format. It does not impose arbitrary
  7746. restrictions on file sizes or file name lengths. This format is more
  7747. recent, so some @command{tar} implementations cannot handle it properly.
  7748. However, any @command{tar} implementation able to read @samp{ustar}
  7749. archives should be able to read most @samp{posix} archives as well,
  7750. except that it will extract any additional information (such as long
  7751. file names) as extra plain text files.
  7752. This archive format will be the default format for future versions
  7753. of @GNUTAR{}.
  7754. @end table
  7755. The following table summarizes the limitations of each of these
  7756. formats:
  7757. @multitable @columnfractions .10 .20 .20 .20 .20
  7758. @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
  7759. @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  7760. @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  7761. @item v7 @tab 2097151 @tab 8 GiB @minus{} 1 @tab 99 @tab n/a
  7762. @item ustar @tab 2097151 @tab 8 GiB @minus{} 1 @tab 255 @tab 21
  7763. @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
  7764. @end multitable
  7765. The default format for @GNUTAR{} is defined at compilation
  7766. time. You may check it by running @command{tar --help}, and examining
  7767. the last lines of its output. Usually, @GNUTAR{} is configured
  7768. to create archives in @samp{gnu} format, however, a future version will
  7769. switch to @samp{posix}.
  7770. @menu
  7771. * Compression:: Using Less Space through Compression
  7772. * Attributes:: Handling File Attributes
  7773. * Portability:: Making @command{tar} Archives More Portable
  7774. * Reproducibility:: Making @command{tar} Archives More Reproducible
  7775. * cpio:: Comparison of @command{tar} and @command{cpio}
  7776. @end menu
  7777. @node Compression
  7778. @section Using Less Space through Compression
  7779. @menu
  7780. * gzip:: Creating and Reading Compressed Archives
  7781. * sparse:: Archiving Sparse Files
  7782. @end menu
  7783. @node gzip
  7784. @subsection Creating and Reading Compressed Archives
  7785. @cindex Compressed archives
  7786. @cindex Storing archives in compressed format
  7787. @cindex gzip
  7788. @cindex bzip2
  7789. @cindex lzip
  7790. @cindex lzma
  7791. @cindex lzop
  7792. @cindex compress
  7793. @cindex zstd
  7794. @GNUTAR{} is able to create and read compressed archives. It supports
  7795. a wide variety of compression programs, namely: @command{gzip},
  7796. @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
  7797. @command{zstd}, @command{xz} and traditional @command{compress}. The
  7798. latter is supported mostly for backward compatibility, and we recommend
  7799. against using it, because it is by far less effective than the other
  7800. compression programs@footnote{It also had patent problems in the past.}.
  7801. Creating a compressed archive is simple: you just specify a
  7802. @dfn{compression option} along with the usual archive creation
  7803. commands. Available compression options are summarized in the
  7804. table below:
  7805. @multitable @columnfractions 0.4 0.2 0.4
  7806. @headitem Long @tab Short @tab Archive format
  7807. @item @option{--gzip} @tab @option{-z} @tab @command{gzip}
  7808. @item @option{--bzip2} @tab @option{-j} @tab @command{bzip2}
  7809. @item @option{--xz} @tab @option{-J} @tab @command{xz}
  7810. @item @option{--lzip} @tab @tab @command{lzip}
  7811. @item @option{--lzma} @tab @tab @command{lzma}
  7812. @item @option{--lzop} @tab @tab @command{lzop}
  7813. @item @option{--zstd} @tab @tab @command{zstd}
  7814. @item @option{--compress} @tab @option{-Z} @tab @command{compress}
  7815. @end multitable
  7816. For example:
  7817. @smallexample
  7818. $ @kbd{tar czf archive.tar.gz .}
  7819. @end smallexample
  7820. You can also let @GNUTAR{} select the compression program based on
  7821. the suffix of the archive file name. This is done using
  7822. @option{--auto-compress} (@option{-a}) command line option. For
  7823. example, the following invocation will use @command{bzip2} for
  7824. compression:
  7825. @smallexample
  7826. $ @kbd{tar caf archive.tar.bz2 .}
  7827. @end smallexample
  7828. @noindent
  7829. whereas the following one will use @command{lzma}:
  7830. @smallexample
  7831. $ @kbd{tar caf archive.tar.lzma .}
  7832. @end smallexample
  7833. For a complete list of file name suffixes recognized by @GNUTAR{},
  7834. see @ref{auto-compress}.
  7835. Reading compressed archive is even simpler: you don't need to specify
  7836. any additional options as @GNUTAR{} recognizes its format
  7837. automatically. Thus, the following commands will list and extract the
  7838. archive created in previous example:
  7839. @smallexample
  7840. # List the compressed archive
  7841. $ @kbd{tar tf archive.tar.gz}
  7842. # Extract the compressed archive
  7843. $ @kbd{tar xf archive.tar.gz}
  7844. @end smallexample
  7845. The format recognition algorithm is based on @dfn{signatures}, a
  7846. special byte sequences in the beginning of file, that are specific for
  7847. certain compression formats. If this approach fails, @command{tar}
  7848. falls back to using archive name suffix to determine its format
  7849. (@pxref{auto-compress}, for a list of recognized suffixes).
  7850. @anchor{alternative decompression programs}
  7851. @cindex alternative decompression programs
  7852. Some compression programs are able to handle different compression
  7853. formats. @GNUTAR{} uses this, if the principal decompressor for the
  7854. given format is not available. For example, if @command{compress} is
  7855. not installed, @command{tar} will try to use @command{gzip}. As of
  7856. version @value{VERSION} the following alternatives are
  7857. tried@footnote{To verbosely trace the decompressor selection, use the
  7858. @option{--warning=decompress-program} option
  7859. (@pxref{warnings,decompress-program}).}:
  7860. @multitable @columnfractions 0.3 0.3 0.3
  7861. @headitem Format @tab Main decompressor @tab Alternatives
  7862. @item compress @tab compress @tab gzip
  7863. @item lzma @tab lzma @tab xz
  7864. @item bzip2 @tab bzip2 @tab lbzip2
  7865. @end multitable
  7866. The only case when you have to specify a decompression option while
  7867. reading the archive is when reading from a pipe or from a tape drive
  7868. that does not support random access. However, in this case @GNUTAR{}
  7869. will indicate which option you should use. For example:
  7870. @smallexample
  7871. $ @kbd{cat archive.tar.gz | tar tf -}
  7872. tar: Archive is compressed. Use -z option
  7873. tar: Error is not recoverable: exiting now
  7874. @end smallexample
  7875. If you see such diagnostics, just add the suggested option to the
  7876. invocation of @GNUTAR{}:
  7877. @smallexample
  7878. $ @kbd{cat archive.tar.gz | tar tzf -}
  7879. @end smallexample
  7880. Notice also, that there are several restrictions on operations on
  7881. compressed archives. First of all, compressed archives cannot be
  7882. modified, i.e., you cannot update (@option{--update}, alias @option{-u})
  7883. them or delete (@option{--delete}) members from them or
  7884. add (@option{--append}, alias @option{-r}) members to them. Likewise, you
  7885. cannot append another @command{tar} archive to a compressed archive using
  7886. @option{--concatenate} (@option{-A}). Secondly, multi-volume
  7887. archives cannot be compressed.
  7888. The following options allow to select a particular compressor program:
  7889. @table @option
  7890. @opindex gzip
  7891. @opindex ungzip
  7892. @item -z
  7893. @itemx --gzip
  7894. @itemx --ungzip
  7895. Filter the archive through @command{gzip}.
  7896. @opindex xz
  7897. @item -J
  7898. @itemx --xz
  7899. Filter the archive through @code{xz}.
  7900. @item -j
  7901. @itemx --bzip2
  7902. Filter the archive through @code{bzip2}.
  7903. @opindex lzip
  7904. @item --lzip
  7905. Filter the archive through @command{lzip}.
  7906. @opindex lzma
  7907. @item --lzma
  7908. Filter the archive through @command{lzma}.
  7909. @opindex lzop
  7910. @item --lzop
  7911. Filter the archive through @command{lzop}.
  7912. @opindex zstd
  7913. @item --zstd
  7914. Filter the archive through @command{zstd}.
  7915. @opindex compress
  7916. @opindex uncompress
  7917. @item -Z
  7918. @itemx --compress
  7919. @itemx --uncompress
  7920. Filter the archive through @command{compress}.
  7921. @end table
  7922. When any of these options is given, @GNUTAR{} searches the compressor
  7923. binary in the current path and invokes it. The name of the compressor
  7924. program is specified at compilation time using a corresponding
  7925. @option{--with-@var{compname}} option to @command{configure}, e.g.
  7926. @option{--with-bzip2} to select a specific @command{bzip2} binary.
  7927. @xref{lbzip2}, for a detailed discussion.
  7928. The output produced by @command{tar --help} shows the actual
  7929. compressor names along with each of these options.
  7930. You can use any of these options on physical devices (tape drives,
  7931. etc.)@: and remote files as well as on normal files; data to or from
  7932. such devices or remote files is reblocked by another copy of the
  7933. @command{tar} program to enforce the specified (or default) record
  7934. size. The default compression parameters are used.
  7935. You can override them by using the @option{-I} option (see
  7936. below), e.g.:
  7937. @smallexample
  7938. $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
  7939. @end smallexample
  7940. @noindent
  7941. A more traditional way to do this is to use a pipe:
  7942. @smallexample
  7943. $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
  7944. @end smallexample
  7945. @cindex corrupted archives
  7946. Compressed archives are easily corrupted, because compressed files
  7947. have little redundancy. The adaptive nature of the
  7948. compression scheme means that the compression tables are implicitly
  7949. spread all over the archive. If you lose a few blocks, the dynamic
  7950. construction of the compression tables becomes unsynchronized, and there
  7951. is little chance that you could recover later in the archive.
  7952. Other compression options provide better control over creating
  7953. compressed archives. These are:
  7954. @table @option
  7955. @anchor{auto-compress}
  7956. @opindex auto-compress
  7957. @item --auto-compress
  7958. @itemx -a
  7959. Select a compression program to use by the archive file name
  7960. suffix. The following suffixes are recognized:
  7961. @multitable @columnfractions 0.3 0.6
  7962. @headitem Suffix @tab Compression program
  7963. @item @samp{.gz} @tab @command{gzip}
  7964. @item @samp{.tgz} @tab @command{gzip}
  7965. @item @samp{.taz} @tab @command{gzip}
  7966. @item @samp{.Z} @tab @command{compress}
  7967. @item @samp{.taZ} @tab @command{compress}
  7968. @item @samp{.bz2} @tab @command{bzip2}
  7969. @item @samp{.tz2} @tab @command{bzip2}
  7970. @item @samp{.tbz2} @tab @command{bzip2}
  7971. @item @samp{.tbz} @tab @command{bzip2}
  7972. @item @samp{.lz} @tab @command{lzip}
  7973. @item @samp{.lzma} @tab @command{lzma}
  7974. @item @samp{.tlz} @tab @command{lzma}
  7975. @item @samp{.lzo} @tab @command{lzop}
  7976. @item @samp{.xz} @tab @command{xz}
  7977. @item @samp{.zst} @tab @command{zstd}
  7978. @item @samp{.tzst} @tab @command{zstd}
  7979. @end multitable
  7980. @anchor{use-compress-program}
  7981. @opindex use-compress-program
  7982. @item --use-compress-program=@var{command}
  7983. @itemx -I=@var{command}
  7984. Use external compression program @var{command}. Use this option if you
  7985. want to specify options for the compression program, or if you
  7986. are not happy with the compression program associated with the suffix
  7987. at compile time, or if you have a compression program that @GNUTAR{}
  7988. does not support. The @var{command} argument is a valid command
  7989. invocation, as you would type it at the command line prompt, with any
  7990. additional options as needed. Enclose it in quotes if it contains
  7991. white space (@pxref{external, Running External Commands}).
  7992. The @var{command} should follow two conventions:
  7993. First, when invoked without additional options, it should read data
  7994. from standard input, compress it and output it on standard output.
  7995. Secondly, if invoked with the additional @option{-d} option, it should
  7996. do exactly the opposite, i.e., read the compressed data from the
  7997. standard input and produce uncompressed data on the standard output.
  7998. The latter requirement means that you must not use the @option{-d}
  7999. option as a part of the @var{command} itself.
  8000. @end table
  8001. @cindex gpg, using with tar
  8002. @cindex gnupg, using with tar
  8003. @cindex Using encrypted archives
  8004. The @option{--use-compress-program} option, in particular, lets you
  8005. implement your own filters, not necessarily dealing with
  8006. compression/decompression. For example, suppose you wish to implement
  8007. PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
  8008. gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
  8009. Manual}). The following script does that:
  8010. @smallexample
  8011. @group
  8012. #! /bin/sh
  8013. case $1 in
  8014. -d) gpg --decrypt - | gzip -d -c;;
  8015. '') gzip -c | gpg -s;;
  8016. *) echo "Unknown option $1">&2; exit 1;;
  8017. esac
  8018. @end group
  8019. @end smallexample
  8020. Suppose you name it @file{gpgz} and save it somewhere in your
  8021. @env{PATH}. Then the following command will create a compressed
  8022. archive signed with your private key:
  8023. @smallexample
  8024. $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
  8025. @end smallexample
  8026. @noindent
  8027. Likewise, the command below will list its contents:
  8028. @smallexample
  8029. $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
  8030. @end smallexample
  8031. @ignore
  8032. The above is based on the following discussion:
  8033. I have one question, or maybe it's a suggestion if there isn't a way
  8034. to do it now. I would like to use @option{--gzip}, but I'd also like
  8035. the output to be fed through a program like @acronym{GNU}
  8036. @command{ecc} (actually, right now that's @samp{exactly} what I'd like
  8037. to use :-)), basically adding ECC protection on top of compression.
  8038. It seems as if this should be quite easy to do, but I can't work out
  8039. exactly how to go about it. Of course, I can pipe the standard output
  8040. of @command{tar} through @command{ecc}, but then I lose (though I
  8041. haven't started using it yet, I confess) the ability to have
  8042. @command{tar} use @command{rmt} for it's I/O (I think).
  8043. I think the most straightforward thing would be to let me specify a
  8044. general set of filters outboard of compression (preferably ordered,
  8045. so the order can be automatically reversed on input operations, and
  8046. with the options they require specifiable), but beggars shouldn't be
  8047. choosers and anything you decide on would be fine with me.
  8048. By the way, I like @command{ecc} but if (as the comments say) it can't
  8049. deal with loss of block sync, I'm tempted to throw some time at adding
  8050. that capability. Supposing I were to actually do such a thing and
  8051. get it (apparently) working, do you accept contributed changes to
  8052. utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
  8053. Isn't that exactly the role of the
  8054. @option{--use-compress-prog=@var{program}} option?
  8055. I never tried it myself, but I suspect you may want to write a
  8056. @var{prog} script or program able to filter stdin to stdout to
  8057. way you want. It should recognize the @option{-d} option, for when
  8058. extraction is needed rather than creation.
  8059. It has been reported that if one writes compressed data (through the
  8060. @option{--gzip} or @option{--compress} options) to a DLT and tries to use
  8061. the DLT compression mode, the data will actually get bigger and one will
  8062. end up with less space on the tape.
  8063. @end ignore
  8064. @menu
  8065. * lbzip2:: Using lbzip2 with @GNUTAR{}.
  8066. @end menu
  8067. @node lbzip2
  8068. @subsubsection Using lbzip2 with @GNUTAR{}.
  8069. @cindex lbzip2
  8070. @cindex Laszlo Ersek
  8071. @command{Lbzip2} is a multithreaded utility for handling
  8072. @samp{bzip2} compression, written by Laszlo Ersek. It makes use of
  8073. multiple processors to speed up its operation and in general works
  8074. considerably faster than @command{bzip2}. For a detailed description
  8075. of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
  8076. @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
  8077. lbzip2: parallel bzip2 utility}.
  8078. Recent versions of @command{lbzip2} are mostly command line compatible
  8079. with @command{bzip2}, which makes it possible to automatically invoke
  8080. it via the @option{--bzip2} @GNUTAR{} command line option. To do so,
  8081. @GNUTAR{} must be configured with the @option{--with-bzip2} command
  8082. line option, like this:
  8083. @smallexample
  8084. $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
  8085. @end smallexample
  8086. Once configured and compiled this way, @command{tar --help} will show the
  8087. following:
  8088. @smallexample
  8089. @group
  8090. $ @kbd{tar --help | grep -- --bzip2}
  8091. -j, --bzip2 filter the archive through lbzip2
  8092. @end group
  8093. @end smallexample
  8094. @noindent
  8095. which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
  8096. @node sparse
  8097. @subsection Archiving Sparse Files
  8098. @cindex Sparse Files
  8099. Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
  8100. in a file is a section of the file's contents which was never written.
  8101. The contents of a hole reads as all zeros. On many operating systems,
  8102. actual disk storage is not allocated for holes, but they are counted
  8103. in the length of the file. If you archive such a file, @command{tar}
  8104. could create an archive longer than the original. To have @command{tar}
  8105. attempt to recognize the holes in a file, use @option{--sparse}
  8106. (@option{-S}). When you use this option, then, for any file using
  8107. less disk space than would be expected from its length, @command{tar}
  8108. searches the file for holes. It then records in the archive for the file where
  8109. the holes (consecutive stretches of zeros) are, and only archives the
  8110. ``real contents'' of the file. On extraction (using @option{--sparse} is not
  8111. needed on extraction) any such files have also holes created wherever the holes
  8112. were found. Thus, if you use @option{--sparse}, @command{tar} archives won't
  8113. take more space than the original.
  8114. @GNUTAR{} uses two methods for detecting holes in sparse files. These
  8115. methods are described later in this subsection.
  8116. @table @option
  8117. @opindex sparse
  8118. @item -S
  8119. @itemx --sparse
  8120. This option instructs @command{tar} to test each file for sparseness
  8121. before attempting to archive it. If the file is found to be sparse it
  8122. is treated specially, thus allowing to decrease the amount of space
  8123. used by its image in the archive.
  8124. This option is meaningful only when creating or updating archives. It
  8125. has no effect on extraction.
  8126. @end table
  8127. Consider using @option{--sparse} when performing file system backups,
  8128. to avoid archiving the expanded forms of files stored sparsely in the
  8129. system.
  8130. Even if your system has no sparse files currently, some may be
  8131. created in the future. If you use @option{--sparse} while making file
  8132. system backups as a matter of course, you can be assured the archive
  8133. will never take more space on the media than the files take on disk
  8134. (otherwise, archiving a disk filled with sparse files might take
  8135. hundreds of tapes). @xref{Incremental Dumps}.
  8136. However, be aware that @option{--sparse} option may present a serious
  8137. drawback. Namely, in order to determine the positions of holes in a file
  8138. @command{tar} may have to read it before trying to archive it, so in total
  8139. the file may be read @strong{twice}. This may happen when your OS or your FS
  8140. does not support @dfn{SEEK_HOLE/SEEK_DATA} feature in @dfn{lseek} (See
  8141. @option{--hole-detection}, below).
  8142. @cindex sparse formats, defined
  8143. When using @samp{POSIX} archive format, @GNUTAR{} is able to store
  8144. sparse files using in three distinct ways, called @dfn{sparse
  8145. formats}. A sparse format is identified by its @dfn{number},
  8146. consisting, as usual of two decimal numbers, delimited by a dot. By
  8147. default, format @samp{1.0} is used. If, for some reason, you wish to
  8148. use an earlier format, you can select it using
  8149. @option{--sparse-version} option.
  8150. @table @option
  8151. @opindex sparse-version
  8152. @item --sparse-version=@var{version}
  8153. Select the format to store sparse files in. Valid @var{version} values
  8154. are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
  8155. for a detailed description of each format.
  8156. @end table
  8157. Using @option{--sparse-format} option implies @option{--sparse}.
  8158. @table @option
  8159. @opindex hole-detection
  8160. @cindex hole detection
  8161. @item --hole-detection=@var{method}
  8162. Enforce concrete hole detection method. Before the real contents of sparse
  8163. file are stored, @command{tar} needs to gather knowledge about file
  8164. sparseness. This is because it needs to have the file's map of holes
  8165. stored into tar header before it starts archiving the file contents.
  8166. Currently, two methods of hole detection are implemented:
  8167. @itemize @bullet
  8168. @item @option{--hole-detection=seek}
  8169. Seeking the file for data and holes. It uses enhancement of the @code{lseek}
  8170. system call (@code{SEEK_HOLE} and @code{SEEK_DATA}) which is able to
  8171. reuse file system knowledge about sparse file contents - so the
  8172. detection is usually very fast. To use this feature, your file system
  8173. and operating system must support it. At the time of this writing
  8174. (2015) this feature, in spite of not being accepted by POSIX, is
  8175. fairly widely supported by different operating systems.
  8176. @item @option{--hole-detection=raw}
  8177. Reading byte-by-byte the whole sparse file before the archiving. This
  8178. method detects holes like consecutive stretches of zeroes. Comparing to
  8179. the previous method, it is usually much slower, although more
  8180. portable.
  8181. @end itemize
  8182. @end table
  8183. When no @option{--hole-detection} option is given, @command{tar} uses
  8184. the @samp{seek}, if supported by the operating system.
  8185. Using @option{--hole-detection} option implies @option{--sparse}.
  8186. @node Attributes
  8187. @section Handling File Attributes
  8188. @cindex attributes, files
  8189. @cindex file attributes
  8190. When @command{tar} reads files, it updates their access times. To
  8191. avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
  8192. reset the access time retroactively or avoid changing it in the first
  8193. place.
  8194. @table @option
  8195. @opindex atime-preserve
  8196. @item --atime-preserve
  8197. @itemx --atime-preserve=replace
  8198. @itemx --atime-preserve=system
  8199. Preserve the access times of files that are read. This works only for
  8200. files that you own, unless you have superuser privileges.
  8201. @option{--atime-preserve=replace} works on most systems, but it also
  8202. restores the data modification time and updates the status change
  8203. time. Hence it doesn't interact with incremental dumps nicely
  8204. (@pxref{Incremental Dumps}), and it can set access or data modification times
  8205. incorrectly if other programs access the file while @command{tar} is
  8206. running.
  8207. @option{--atime-preserve=system} avoids changing the access time in
  8208. the first place, if the operating system supports this.
  8209. Unfortunately, this may or may not work on any given operating system
  8210. or file system. If @command{tar} knows for sure it won't work, it
  8211. complains right away.
  8212. Currently @option{--atime-preserve} with no operand defaults to
  8213. @option{--atime-preserve=replace}, but this is intended to change to
  8214. @option{--atime-preserve=system} when the latter is better-supported.
  8215. @opindex touch
  8216. @item -m
  8217. @itemx --touch
  8218. Do not extract data modification time.
  8219. When this option is used, @command{tar} leaves the data modification times
  8220. of the files it extracts as the times when the files were extracted,
  8221. instead of setting it to the times recorded in the archive.
  8222. This option is meaningless with @option{--list} (@option{-t}).
  8223. @opindex same-owner
  8224. @item --same-owner
  8225. Create extracted files with the same ownership they have in the
  8226. archive.
  8227. This is the default behavior for the superuser,
  8228. so this option is meaningful only for non-root users, when @command{tar}
  8229. is executed on those systems able to give files away. This is
  8230. considered as a security flaw by many people, at least because it
  8231. makes quite difficult to correctly account users for the disk space
  8232. they occupy. Also, the @code{suid} or @code{sgid} attributes of
  8233. files are easily and silently lost when files are given away.
  8234. When writing an archive, @command{tar} writes the user @acronym{ID} and user name
  8235. separately. If it can't find a user name (because the user @acronym{ID} is not
  8236. in @file{/etc/passwd}), then it does not write one. When restoring,
  8237. it tries to look the name (if one was written) up in
  8238. @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
  8239. the archive instead.
  8240. @opindex no-same-owner
  8241. @item --no-same-owner
  8242. @itemx -o
  8243. Do not attempt to restore ownership when extracting. This is the
  8244. default behavior for ordinary users, so this option has an effect
  8245. only for the superuser.
  8246. @opindex numeric-owner
  8247. @item --numeric-owner
  8248. The @option{--numeric-owner} option allows (ANSI) archives to be written
  8249. without user/group name information or such information to be ignored
  8250. when extracting. It effectively disables the generation and/or use
  8251. of user/group name information. This option forces extraction using
  8252. the numeric ids from the archive, ignoring the names.
  8253. This is useful in certain circumstances, when restoring a backup from
  8254. an emergency floppy with different passwd/group files for example.
  8255. It is otherwise impossible to extract files with the right ownerships
  8256. if the password file in use during the extraction does not match the
  8257. one belonging to the file system(s) being extracted. This occurs,
  8258. for example, if you are restoring your files after a major crash and
  8259. had booted from an emergency floppy with no password file or put your
  8260. disk into another machine to do the restore.
  8261. The numeric ids are @emph{always} saved into @command{tar} archives.
  8262. The identifying names are added at create time when provided by the
  8263. system, unless @option{--format=oldgnu} is used. Numeric ids could be
  8264. used when moving archives between a collection of machines using
  8265. a centralized management for attribution of numeric ids to users
  8266. and groups. This is often made through using the NIS capabilities.
  8267. When making a @command{tar} file for distribution to other sites, it
  8268. is sometimes cleaner to use a single owner for all files in the
  8269. distribution, and nicer to specify the write permission bits of the
  8270. files as stored in the archive independently of their actual value on
  8271. the file system. The way to prepare a clean distribution is usually
  8272. to have some Makefile rule creating a directory, copying all needed
  8273. files in that directory, then setting ownership and permissions as
  8274. wanted (there are a lot of possible schemes), and only then making a
  8275. @command{tar} archive out of this directory, before cleaning
  8276. everything out. Of course, we could add a lot of options to
  8277. @GNUTAR{} for fine tuning permissions and ownership.
  8278. This is not the good way, I think. @GNUTAR{} is
  8279. already crowded with options and moreover, the approach just explained
  8280. gives you a great deal of control already.
  8281. @xopindex{same-permissions, short description}
  8282. @xopindex{preserve-permissions, short description}
  8283. @item -p
  8284. @itemx --same-permissions
  8285. @itemx --preserve-permissions
  8286. Extract all protection information.
  8287. This option causes @command{tar} to set the modes (access permissions) of
  8288. extracted files exactly as recorded in the archive. If this option
  8289. is not used, the current @code{umask} setting limits the permissions
  8290. on extracted files. This option is by default enabled when
  8291. @command{tar} is executed by a superuser.
  8292. This option is meaningless with @option{--list} (@option{-t}).
  8293. @end table
  8294. @node Portability
  8295. @section Making @command{tar} Archives More Portable
  8296. Creating a @command{tar} archive on a particular system that is meant to be
  8297. useful later on many other machines and with other versions of @command{tar}
  8298. is more challenging than you might think. @command{tar} archive formats
  8299. have been evolving since the first versions of Unix. Many such formats
  8300. are around, and are not always compatible with each other. This section
  8301. discusses a few problems, and gives some advice about making @command{tar}
  8302. archives more portable.
  8303. One golden rule is simplicity. For example, limit your @command{tar}
  8304. archives to contain only regular files and directories, avoiding
  8305. other kind of special files. Do not attempt to save sparse files or
  8306. contiguous files as such. Let's discuss a few more problems, in turn.
  8307. @FIXME{Discuss GNU extensions (incremental backups, multi-volume
  8308. archives and archive labels) in GNU and PAX formats.}
  8309. @menu
  8310. * Portable Names:: Portable Names
  8311. * dereference:: Symbolic Links
  8312. * hard links:: Hard Links
  8313. * old:: Old V7 Archives
  8314. * ustar:: Ustar Archives
  8315. * gnu:: GNU and old GNU format archives.
  8316. * posix:: @acronym{POSIX} archives
  8317. * Checksumming:: Checksumming Problems
  8318. * Large or Negative Values:: Large files, negative time stamps, etc.
  8319. * Other Tars:: How to Extract GNU-Specific Data Using
  8320. Other @command{tar} Implementations
  8321. @end menu
  8322. @node Portable Names
  8323. @subsection Portable Names
  8324. Use portable file and member names. A name is portable if it contains
  8325. only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
  8326. @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
  8327. contain @samp{/-}. Avoid deep directory nesting. For portability to
  8328. old Unix hosts, limit your file name components to 14 characters or
  8329. less.
  8330. If you intend to have your @command{tar} archives to be read on
  8331. case-insensitive file systems like FAT32,
  8332. you should not rely on case distinction for file names.
  8333. @node dereference
  8334. @subsection Symbolic Links
  8335. @cindex File names, using symbolic links
  8336. @cindex Symbolic link as file name
  8337. @opindex dereference
  8338. Normally, when @command{tar} archives a symbolic link, it writes a
  8339. block to the archive naming the target of the link. In that way, the
  8340. @command{tar} archive is a faithful record of the file system contents.
  8341. When @option{--dereference} (@option{-h}) is used with
  8342. @option{--create} (@option{-c}), @command{tar} archives the files
  8343. symbolic links point to, instead of
  8344. the links themselves.
  8345. When creating portable archives, use @option{--dereference}
  8346. (@option{-h}): some systems do not support
  8347. symbolic links, and moreover, your distribution might be unusable if
  8348. it contains unresolved symbolic links.
  8349. When reading from an archive, the @option{--dereference} (@option{-h})
  8350. option causes @command{tar} to follow an already-existing symbolic
  8351. link when @command{tar} writes or reads a file named in the archive.
  8352. Ordinarily, @command{tar} does not follow such a link, though it may
  8353. remove the link before writing a new file. @xref{Dealing with Old
  8354. Files}.
  8355. The @option{--dereference} option is unsafe if an untrusted user can
  8356. modify directories while @command{tar} is running. @xref{Security}.
  8357. @node hard links
  8358. @subsection Hard Links
  8359. @cindex File names, using hard links
  8360. @cindex hard links, dereferencing
  8361. @cindex dereferencing hard links
  8362. Normally, when @command{tar} archives a hard link, it writes a
  8363. block to the archive naming the target of the link (a @samp{1} type
  8364. block). In that way, the actual file contents is stored in file only
  8365. once. For example, consider the following two files:
  8366. @smallexample
  8367. @group
  8368. $ ls -l
  8369. -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
  8370. -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
  8371. @end group
  8372. @end smallexample
  8373. Here, @file{jeden} is a link to @file{one}. When archiving this
  8374. directory with a verbose level 2, you will get an output similar to
  8375. the following:
  8376. @smallexample
  8377. $ tar cvvf ../archive.tar .
  8378. drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
  8379. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
  8380. hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
  8381. @end smallexample
  8382. The last line shows that, instead of storing two copies of the file,
  8383. @command{tar} stored it only once, under the name @file{jeden}, and
  8384. stored file @file{one} as a hard link to this file.
  8385. It may be important to know that all hard links to the given file are
  8386. stored in the archive. For example, this may be necessary for exact
  8387. reproduction of the file system. The following option does that:
  8388. @table @option
  8389. @xopindex{check-links, described}
  8390. @item --check-links
  8391. @itemx -l
  8392. Check the number of links dumped for each processed file. If this
  8393. number does not match the total number of hard links for the file, print
  8394. a warning message.
  8395. @end table
  8396. For example, trying to archive only file @file{jeden} with this option
  8397. produces the following diagnostics:
  8398. @smallexample
  8399. $ tar -c -f ../archive.tar -l jeden
  8400. tar: Missing links to 'jeden'.
  8401. @end smallexample
  8402. Although creating special records for hard links helps keep a faithful
  8403. record of the file system contents and makes archives more compact, it
  8404. may present some difficulties when extracting individual members from
  8405. the archive. For example, trying to extract file @file{one} from the
  8406. archive created in previous examples produces, in the absence of file
  8407. @file{jeden}:
  8408. @smallexample
  8409. $ tar xf archive.tar ./one
  8410. tar: ./one: Cannot hard link to './jeden': No such file or directory
  8411. tar: Error exit delayed from previous errors
  8412. @end smallexample
  8413. The reason for this behavior is that @command{tar} cannot seek back in
  8414. the archive to the previous member (in this case, @file{one}), to
  8415. extract it@footnote{There are plans to fix this in future releases.}.
  8416. If you wish to avoid such problems at the cost of a bigger archive,
  8417. use the following option:
  8418. @table @option
  8419. @xopindex{hard-dereference, described}
  8420. @item --hard-dereference
  8421. Dereference hard links and store the files they refer to.
  8422. @end table
  8423. For example, trying this option on our two sample files, we get two
  8424. copies in the archive, each of which can then be extracted
  8425. independently of the other:
  8426. @smallexample
  8427. @group
  8428. $ tar -c -vv -f ../archive.tar --hard-dereference .
  8429. drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
  8430. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
  8431. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
  8432. @end group
  8433. @end smallexample
  8434. @node old
  8435. @subsection Old V7 Archives
  8436. @cindex Format, old style
  8437. @cindex Old style format
  8438. @cindex Old style archives
  8439. @cindex v7 archive format
  8440. Certain old versions of @command{tar} cannot handle additional
  8441. information recorded by newer @command{tar} programs. To create an
  8442. archive in V7 format (not ANSI), which can be read by these old
  8443. versions, specify the @option{--format=v7} option in
  8444. conjunction with the @option{--create} (@option{-c}) (@command{tar} also
  8445. accepts @option{--portability} or @option{--old-archive} for this
  8446. option). When you specify it,
  8447. @command{tar} leaves out information about directories, pipes, fifos,
  8448. contiguous files, and device files, and specifies file ownership by
  8449. group and user IDs instead of group and user names.
  8450. When updating an archive, do not use @option{--format=v7}
  8451. unless the archive was created using this option.
  8452. In most cases, a @emph{new} format archive can be read by an @emph{old}
  8453. @command{tar} program without serious trouble, so this option should
  8454. seldom be needed. On the other hand, most modern @command{tar}s are
  8455. able to read old format archives, so it might be safer for you to
  8456. always use @option{--format=v7} for your distributions. Notice,
  8457. however, that @samp{ustar} format is a better alternative, as it is
  8458. free from many of @samp{v7}'s drawbacks.
  8459. @node ustar
  8460. @subsection Ustar Archive Format
  8461. @cindex ustar archive format
  8462. The archive format defined by the @acronym{POSIX}.1-1988 specification is
  8463. called @code{ustar}. Although it is more flexible than the V7 format, it
  8464. still has many restrictions (@pxref{Formats,ustar}, for the detailed
  8465. description of @code{ustar} format). Along with V7 format,
  8466. @code{ustar} format is a good choice for archives intended to be read
  8467. with other implementations of @command{tar}.
  8468. To create an archive in @code{ustar} format, use the @option{--format=ustar}
  8469. option in conjunction with @option{--create} (@option{-c}).
  8470. @node gnu
  8471. @subsection @acronym{GNU} and old @GNUTAR{} format
  8472. @cindex GNU archive format
  8473. @cindex Old GNU archive format
  8474. @GNUTAR{} was based on an early draft of the
  8475. @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
  8476. @command{tar}, such as the support for file names longer than 100
  8477. characters, use portions of the @command{tar} header record which were
  8478. specified in that @acronym{POSIX} draft as unused. Subsequent changes in
  8479. @acronym{POSIX} have allocated the same parts of the header record for
  8480. other purposes. As a result, @GNUTAR{} format is
  8481. incompatible with the current @acronym{POSIX} specification, and with
  8482. @command{tar} programs that follow it.
  8483. In the majority of cases, @command{tar} will be configured to create
  8484. this format by default. This will change in future releases, since
  8485. we plan to make @samp{POSIX} format the default.
  8486. To force creation a @GNUTAR{} archive, use option
  8487. @option{--format=gnu}.
  8488. @node posix
  8489. @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
  8490. @cindex POSIX archive format
  8491. @cindex PAX archive format
  8492. Starting from version 1.14 @GNUTAR{} features full support for
  8493. @acronym{POSIX.1-2001} archives.
  8494. A @acronym{POSIX} conformant archive will be created if @command{tar}
  8495. was given @option{--format=posix} (@option{--format=pax}) option. No
  8496. special option is required to read and extract from a @acronym{POSIX}
  8497. archive.
  8498. @menu
  8499. * PAX keywords:: Controlling Extended Header Keywords.
  8500. @end menu
  8501. @node PAX keywords
  8502. @subsubsection Controlling Extended Header Keywords
  8503. @table @option
  8504. @opindex pax-option
  8505. @item --pax-option=@var{keyword-list}
  8506. Handle keywords in @acronym{PAX} extended headers. This option is
  8507. equivalent to @option{-o} option of the @command{pax} utility.
  8508. @end table
  8509. @var{Keyword-list} is a comma-separated
  8510. list of keyword options, each keyword option taking one of
  8511. the following forms:
  8512. @table @code
  8513. @item delete=@var{pattern}
  8514. When used with one of archive-creation commands,
  8515. this option instructs @command{tar} to omit from extended header records
  8516. that it produces any keywords matching the string @var{pattern}.
  8517. If the pattern contains shell metacharacters like @samp{*}, it should
  8518. be quoted to prevent the shell from expanding the pattern before
  8519. @command{tar} sees it.
  8520. When used in extract or list mode, this option instructs tar
  8521. to ignore any keywords matching the given @var{pattern} in the extended
  8522. header records. In both cases, matching is performed using the pattern
  8523. matching notation described in @acronym{POSIX 1003.2}, 3.13
  8524. (@pxref{wildcards}). For example:
  8525. @smallexample
  8526. --pax-option 'delete=security.*'
  8527. @end smallexample
  8528. would suppress security-related information.
  8529. @item exthdr.name=@var{string}
  8530. This keyword allows user control over the name that is written into the
  8531. ustar header blocks for the extended headers. The name is obtained
  8532. from @var{string} after making the following substitutions:
  8533. @multitable @columnfractions .25 .55
  8534. @headitem Meta-character @tab Replaced By
  8535. @item %d @tab The directory name of the file, equivalent to the
  8536. result of the @command{dirname} utility on the translated file name.
  8537. @item %f @tab The name of the file with the directory information
  8538. stripped, equivalent to the result of the @command{basename} utility
  8539. on the translated file name.
  8540. @item %p @tab The process @acronym{ID} of the @command{tar} process.
  8541. @item %% @tab A @samp{%} character.
  8542. @end multitable
  8543. Any other @samp{%} characters in @var{string} produce undefined
  8544. results.
  8545. If no option @samp{exthdr.name=string} is specified, @command{tar}
  8546. will use the following default value:
  8547. @smallexample
  8548. %d/PaxHeaders/%f
  8549. @end smallexample
  8550. This default helps make the archive more reproducible.
  8551. @xref{Reproducibility}. @acronym{POSIX} recommends using
  8552. @samp{%d/PaxHeaders.%p/%f} instead, which means the two archives
  8553. created with the same set of options and containing the same set
  8554. of files will be byte-to-byte different. This default will be used
  8555. if the environment variable @env{POSIXLY_CORRECT} is set.
  8556. @item exthdr.mtime=@var{value}
  8557. This keyword defines the value of the @samp{mtime} field that
  8558. is written into the ustar header blocks for the extended headers.
  8559. By default, the @samp{mtime} field is set to the modification time
  8560. of the archive member described by that extended header (or to the
  8561. value of the @option{--mtime} option, if supplied).
  8562. @item globexthdr.name=@var{string}
  8563. This keyword allows user control over the name that is written into
  8564. the ustar header blocks for global extended header records. The name
  8565. is obtained from the contents of @var{string}, after making
  8566. the following substitutions:
  8567. @multitable @columnfractions .25 .55
  8568. @headitem Meta-character @tab Replaced By
  8569. @item %n @tab An integer that represents the
  8570. sequence number of the global extended header record in the archive,
  8571. starting at 1.
  8572. @item %p @tab The process @acronym{ID} of the @command{tar} process.
  8573. @item %% @tab A @samp{%} character.
  8574. @end multitable
  8575. Any other @samp{%} characters in @var{string} produce undefined results.
  8576. If no option @samp{globexthdr.name=string} is specified, @command{tar}
  8577. will use the following default value:
  8578. @smallexample
  8579. $TMPDIR/GlobalHead.%n
  8580. @end smallexample
  8581. If the environment variable @env{POSIXLY_CORRECT} is set, the
  8582. following value is used instead:
  8583. @smallexample
  8584. $TMPDIR/GlobalHead.%p.%n
  8585. @end smallexample
  8586. In both cases, @samp{$TMPDIR} stands for the value of the @var{TMPDIR}
  8587. environment variable. If @var{TMPDIR} is not set, @command{tar}
  8588. uses @samp{/tmp}.
  8589. @item globexthdr.mtime=@var{value}
  8590. This keyword defines the value of the @samp{mtime} field that
  8591. is written into the ustar header blocks for the global extended headers.
  8592. By default, the @samp{mtime} field is set to the time when
  8593. @command{tar} was invoked.
  8594. @item @var{keyword}=@var{value}
  8595. When used with one of archive-creation commands, these keyword/value pairs
  8596. will be included at the beginning of the archive in a global extended
  8597. header record. When used with one of archive-reading commands,
  8598. @command{tar} will behave as if it has encountered these keyword/value
  8599. pairs at the beginning of the archive in a global extended header
  8600. record.
  8601. @item @var{keyword}:=@var{value}
  8602. When used with one of archive-creation commands, these keyword/value pairs
  8603. will be included as records at the beginning of an extended header for
  8604. each file. This is effectively equivalent to @var{keyword}=@var{value}
  8605. form except that it creates no global extended header records.
  8606. When used with one of archive-reading commands, @command{tar} will
  8607. behave as if these keyword/value pairs were included as records at the
  8608. end of each extended header; thus, they will override any global or
  8609. file-specific extended header record keywords of the same names.
  8610. For example, in the command:
  8611. @smallexample
  8612. tar --format=posix --create \
  8613. --file archive --pax-option gname:=user .
  8614. @end smallexample
  8615. the group name will be forced to a new value for all files
  8616. stored in the archive.
  8617. @end table
  8618. In any of the forms described above, the @var{value} may be
  8619. a string enclosed in curly braces. In that case, the string
  8620. between the braces is understood either as a textual time
  8621. representation, as described in @ref{Date input formats}, or a name of
  8622. the existing file, starting with @samp{/} or @samp{.}. In the latter
  8623. case, the modification time of that file is used.
  8624. For example, to set all modification times to the current date, you
  8625. use the following option:
  8626. @smallexample
  8627. --pax-option 'mtime:=@{now@}'
  8628. @end smallexample
  8629. @cindex archives, binary equivalent
  8630. @cindex binary equivalent archives, creating
  8631. As another example, the following option helps make the archive
  8632. more reproducible. @xref{Reproducibility}
  8633. @smallexample
  8634. --pax-option delete=atime
  8635. @end smallexample
  8636. @noindent
  8637. If you extract files from such an archive and recreate the archive
  8638. from them, you will also need to eliminate changes due to ctime:
  8639. @smallexample
  8640. --pax-option 'delete=atime,delete=ctime'
  8641. @end smallexample
  8642. Normally @command{tar} saves an mtime value with subsecond resolution
  8643. in an extended header for any file with a timestamp that is not on a
  8644. one-second boundary. This is in addition to the traditional mtime
  8645. timestamp in the header block. Although you can suppress subsecond
  8646. timestamp resolution with @option{--pax-option delete=mtime},
  8647. this hack will not work for timestamps before 1970 or after 2242-03-16
  8648. 12:56:31 @sc{utc}.
  8649. If the environment variable @env{POSIXLY_CORRECT} is set, two POSIX
  8650. archives created using the same options on the same set of files might
  8651. not be byte-to-byte equivalent even with the above options. This is
  8652. because the POSIX default for extended header names includes
  8653. the @command{tar} process @acronym{ID}, which typically differs at each
  8654. run. To produce byte-to-byte equivalent archives in this case, either
  8655. unset @env{POSIXLY_CORRECT}, or use the following option, which can be
  8656. combined with the above options:
  8657. @smallexample
  8658. --pax-option exthdr.name=%d/PaxHeaders/%f
  8659. @end smallexample
  8660. @node Checksumming
  8661. @subsection Checksumming Problems
  8662. SunOS and HP-UX @command{tar} fail to accept archives created using
  8663. @GNUTAR{} and containing non-@acronym{ASCII} file names, that
  8664. is, file names having characters with the eighth bit set, because they
  8665. use signed checksums, while @GNUTAR{} uses unsigned
  8666. checksums while creating archives, as per @acronym{POSIX} standards. On
  8667. reading, @GNUTAR{} computes both checksums and accepts either of them.
  8668. It is somewhat worrying that a lot of people may go
  8669. around doing backup of their files using faulty (or at least
  8670. non-standard) software, not learning about it until it's time to
  8671. restore their missing files with an incompatible file extractor, or
  8672. vice versa.
  8673. @GNUTAR{} computes checksums both ways, and accepts either of them
  8674. on read, so @acronym{GNU} tar can read Sun tapes even with their
  8675. wrong checksums. @GNUTAR{} produces the standard
  8676. checksum, however, raising incompatibilities with Sun. That is to
  8677. say, @GNUTAR{} has not been modified to
  8678. @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
  8679. I've been told that more recent Sun @command{tar} now read standard
  8680. archives, so maybe Sun did a similar patch, after all?
  8681. The story seems to be that when Sun first imported @command{tar}
  8682. sources on their system, they recompiled it without realizing that
  8683. the checksums were computed differently, because of a change in
  8684. the default signing of @code{char}'s in their compiler. So they
  8685. started computing checksums wrongly. When they later realized their
  8686. mistake, they merely decided to stay compatible with it, and with
  8687. themselves afterwards. Presumably, but I do not really know, HP-UX
  8688. has chosen their @command{tar} archives to be compatible with Sun's.
  8689. The current standards do not favor Sun @command{tar} format. In any
  8690. case, it now falls on the shoulders of SunOS and HP-UX users to get
  8691. a @command{tar} able to read the good archives they receive.
  8692. @node Large or Negative Values
  8693. @subsection Large or Negative Values
  8694. @cindex large values
  8695. @cindex future time stamps
  8696. @cindex negative time stamps
  8697. @UNREVISED{}
  8698. The above sections suggest to use @samp{oldest possible} archive
  8699. format if in doubt. However, sometimes it is not possible. If you
  8700. attempt to archive a file whose metadata cannot be represented using
  8701. required format, @GNUTAR{} will print error message and ignore such a
  8702. file. You will than have to switch to a format that is able to
  8703. handle such values. The format summary table (@pxref{Formats}) will
  8704. help you to do so.
  8705. In particular, when trying to archive files 8 GiB or larger, or with
  8706. timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
  8707. 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
  8708. @acronym{POSIX} archive formats. When considering which format to
  8709. choose, bear in mind that the @acronym{GNU} format uses
  8710. two's-complement base-256 notation to store values that do not fit
  8711. into standard @acronym{ustar} range. Such archives can generally be
  8712. read only by a @GNUTAR{} implementation. Moreover, they sometimes
  8713. cannot be correctly restored on another hosts even by @GNUTAR{}. For
  8714. example, using two's complement representation for negative time
  8715. stamps that assumes a signed 32-bit @code{time_t} generates archives
  8716. that are not portable to hosts with differing @code{time_t}
  8717. representations.
  8718. On the other hand, @acronym{POSIX} archives, generally speaking, can
  8719. be extracted by any tar implementation that understands older
  8720. @acronym{ustar} format. The exceptions are files 8 GiB or larger,
  8721. or files dated before 1970-01-01 00:00:00 or after 2242-03-16
  8722. 12:56:31 @sc{utc}
  8723. @FIXME{Describe how @acronym{POSIX} archives are extracted by non
  8724. POSIX-aware tars.}
  8725. @node Other Tars
  8726. @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
  8727. In previous sections you became acquainted with various quirks
  8728. necessary to make your archives portable. Sometimes you may need to
  8729. extract archives containing GNU-specific members using some
  8730. third-party @command{tar} implementation or an older version of
  8731. @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
  8732. but if it is for some reason impossible, this section will explain
  8733. how to cope without it.
  8734. When we speak about @dfn{GNU-specific} members we mean two classes of
  8735. them: members split between the volumes of a multi-volume archive and
  8736. sparse members. You will be able to always recover such members if
  8737. the archive is in PAX format. In addition split members can be
  8738. recovered from archives in old GNU format. The following subsections
  8739. describe the required procedures in detail.
  8740. @menu
  8741. * Split Recovery:: Members Split Between Volumes
  8742. * Sparse Recovery:: Sparse Members
  8743. @end menu
  8744. @node Split Recovery
  8745. @subsubsection Extracting Members Split Between Volumes
  8746. @cindex Multi-volume archives, extracting using non-GNU tars
  8747. If a member is split between several volumes of an old GNU format archive
  8748. most third party @command{tar} implementation will fail to extract
  8749. it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
  8750. This program is available from
  8751. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
  8752. home page}. It concatenates several archive volumes into a single
  8753. valid archive. For example, if you have three volumes named from
  8754. @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
  8755. extract them using a third-party @command{tar}:
  8756. @smallexample
  8757. $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
  8758. @end smallexample
  8759. @cindex Multi-volume archives in PAX format, extracting using non-GNU tars
  8760. You could use this approach for most (although not all) PAX
  8761. format archives as well. However, extracting split members from a PAX
  8762. archive is a much easier task, because PAX volumes are constructed in
  8763. such a way that each part of a split member is extracted to a
  8764. different file by @command{tar} implementations that are not aware of
  8765. GNU extensions. More specifically, the very first part retains its
  8766. original name, and all subsequent parts are named using the pattern:
  8767. @smallexample
  8768. %d/GNUFileParts/%f.%n
  8769. @end smallexample
  8770. @noindent
  8771. where symbols preceded by @samp{%} are @dfn{macro characters} that
  8772. have the following meaning:
  8773. @multitable @columnfractions .25 .55
  8774. @headitem Meta-character @tab Replaced By
  8775. @item %d @tab The directory name of the file, equivalent to the
  8776. result of the @command{dirname} utility on its full name.
  8777. @item %f @tab The file name of the file, equivalent to the result
  8778. of the @command{basename} utility on its full name.
  8779. @item %p @tab The process @acronym{ID} of the @command{tar} process that
  8780. created the archive.
  8781. @item %n @tab Ordinal number of this particular part.
  8782. @end multitable
  8783. For example, if the file @file{var/longfile} was split during archive
  8784. creation between three volumes, then the member names will be:
  8785. @smallexample
  8786. var/longfile
  8787. var/GNUFileParts/longfile.1
  8788. var/GNUFileParts/longfile.2
  8789. @end smallexample
  8790. When you extract your archive using a third-party @command{tar}, these
  8791. files will be created on your disk, and the only thing you will need
  8792. to do to restore your file in its original form is concatenate them in
  8793. the proper order, for example:
  8794. @smallexample
  8795. @group
  8796. $ @kbd{cd var}
  8797. $ @kbd{cat GNUFileParts/longfile.1 \
  8798. GNUFileParts/longfile.2 >> longfile}
  8799. $ rm -f GNUFileParts
  8800. @end group
  8801. @end smallexample
  8802. Notice, that if the @command{tar} implementation you use supports PAX
  8803. format archives, it will probably emit warnings about unknown keywords
  8804. during extraction. They will look like this:
  8805. @smallexample
  8806. @group
  8807. Tar file too small
  8808. Unknown extended header keyword 'GNU.volume.filename' ignored.
  8809. Unknown extended header keyword 'GNU.volume.size' ignored.
  8810. Unknown extended header keyword 'GNU.volume.offset' ignored.
  8811. @end group
  8812. @end smallexample
  8813. @noindent
  8814. You can safely ignore these warnings.
  8815. If your @command{tar} implementation is not PAX-aware, you will get
  8816. more warnings and more files generated on your disk, e.g.:
  8817. @smallexample
  8818. @group
  8819. $ @kbd{tar xf vol-1.tar}
  8820. var/PaxHeaders/longfile: Unknown file type 'x', extracted as
  8821. normal file
  8822. Unexpected EOF in archive
  8823. $ @kbd{tar xf vol-2.tar}
  8824. tmp/GlobalHead.1: Unknown file type 'g', extracted as normal file
  8825. GNUFileParts/PaxHeaders/sparsefile.1: Unknown file type
  8826. 'x', extracted as normal file
  8827. @end group
  8828. @end smallexample
  8829. Ignore these warnings. The @file{PaxHeaders.*} directories created
  8830. will contain files with @dfn{extended header keywords} describing the
  8831. extracted files. You can delete them, unless they describe sparse
  8832. members. Read further to learn more about them.
  8833. @node Sparse Recovery
  8834. @subsubsection Extracting Sparse Members
  8835. @cindex sparse files, extracting with non-GNU tars
  8836. Any @command{tar} implementation will be able to extract sparse members from a
  8837. PAX archive. However, the extracted files will be @dfn{condensed},
  8838. i.e., any zero blocks will be removed from them. When we restore such
  8839. a condensed file to its original form, by adding zero blocks (or
  8840. @dfn{holes}) back to their original locations, we call this process
  8841. @dfn{expanding} a compressed sparse file.
  8842. @pindex xsparse
  8843. To expand a file, you will need a simple auxiliary program called
  8844. @command{xsparse}. It is available in source form from
  8845. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
  8846. home page}.
  8847. @cindex sparse files v.1.0, extracting with non-GNU tars
  8848. Let's begin with archive members in @dfn{sparse format
  8849. version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
  8850. The condensed file will contain both file map and file data, so no
  8851. additional data will be needed to restore it. If the original file
  8852. name was @file{@var{dir}/@var{name}}, then the condensed file will be
  8853. named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
  8854. @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
  8855. @dfn{process @acronym{ID}} of the @command{tar} process which created the
  8856. archive (@pxref{PAX keywords}).}.
  8857. To expand a version 1.0 file, run @command{xsparse} as follows:
  8858. @smallexample
  8859. $ @kbd{xsparse @file{cond-file}}
  8860. @end smallexample
  8861. @noindent
  8862. where @file{cond-file} is the name of the condensed file. The utility
  8863. will deduce the name for the resulting expanded file using the
  8864. following algorithm:
  8865. @enumerate 1
  8866. @item If @file{cond-file} does not contain any directories,
  8867. @file{../cond-file} will be used;
  8868. @item If @file{cond-file} has the form
  8869. @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
  8870. are simple names, with no @samp{/} characters in them, the output file
  8871. name will be @file{@var{dir}/@var{name}}.
  8872. @item Otherwise, if @file{cond-file} has the form
  8873. @file{@var{dir}/@var{name}}, the output file name will be
  8874. @file{@var{name}}.
  8875. @end enumerate
  8876. In the unlikely case when this algorithm does not suit your needs,
  8877. you can explicitly specify output file name as a second argument to
  8878. the command:
  8879. @smallexample
  8880. $ @kbd{xsparse @file{cond-file} @file{out-file}}
  8881. @end smallexample
  8882. It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
  8883. first. In this mode, the command does not actually expand the file,
  8884. but verbosely lists all actions it would be taking to do so. The dry
  8885. run mode is enabled by @option{-n} command line argument:
  8886. @smallexample
  8887. @group
  8888. $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
  8889. Reading v.1.0 sparse map
  8890. Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
  8891. '/home/gray/sparsefile'
  8892. Finished dry run
  8893. @end group
  8894. @end smallexample
  8895. To actually expand the file, you would run:
  8896. @smallexample
  8897. $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
  8898. @end smallexample
  8899. @noindent
  8900. The program behaves the same way all UNIX utilities do: it will keep
  8901. quiet unless it has something important to tell you (e.g. an error
  8902. condition or something). If you wish it to produce verbose output,
  8903. similar to that from the dry run mode, use @option{-v} option:
  8904. @smallexample
  8905. @group
  8906. $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
  8907. Reading v.1.0 sparse map
  8908. Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
  8909. '/home/gray/sparsefile'
  8910. Done
  8911. @end group
  8912. @end smallexample
  8913. Additionally, if your @command{tar} implementation has extracted the
  8914. @dfn{extended headers} for this file, you can instruct @command{xstar}
  8915. to use them in order to verify the integrity of the expanded file.
  8916. The option @option{-x} sets the name of the extended header file to
  8917. use. Continuing our example:
  8918. @smallexample
  8919. @group
  8920. $ @kbd{xsparse -v -x /home/gray/PaxHeaders/sparsefile \
  8921. /home/gray/GNUSparseFile/sparsefile}
  8922. Reading extended header file
  8923. Found variable GNU.sparse.major = 1
  8924. Found variable GNU.sparse.minor = 0
  8925. Found variable GNU.sparse.name = sparsefile
  8926. Found variable GNU.sparse.realsize = 217481216
  8927. Reading v.1.0 sparse map
  8928. Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
  8929. '/home/gray/sparsefile'
  8930. Done
  8931. @end group
  8932. @end smallexample
  8933. @anchor{extracting sparse v0x}
  8934. @cindex sparse files v.0.1, extracting with non-GNU tars
  8935. @cindex sparse files v.0.0, extracting with non-GNU tars
  8936. An @dfn{extended header} is a special @command{tar} archive header
  8937. that precedes an archive member and contains a set of
  8938. @dfn{variables}, describing the member properties that cannot be
  8939. stored in the standard @code{ustar} header. While optional for
  8940. expanding sparse version 1.0 members, the use of extended headers is
  8941. mandatory when expanding sparse members in older sparse formats: v.0.0
  8942. and v.0.1 (The sparse formats are described in detail in @ref{Sparse
  8943. Formats}.) So, for these formats, the question is: how to obtain
  8944. extended headers from the archive?
  8945. If you use a @command{tar} implementation that does not support PAX
  8946. format, extended headers for each member will be extracted as a
  8947. separate file. If we represent the member name as
  8948. @file{@var{dir}/@var{name}}, then the extended header file will be
  8949. named @file{@var{dir}/@/PaxHeaders/@/@var{name}}.
  8950. Things become more difficult if your @command{tar} implementation
  8951. does support PAX headers, because in this case you will have to
  8952. manually extract the headers. We recommend the following algorithm:
  8953. @enumerate 1
  8954. @item
  8955. Consult the documentation of your @command{tar} implementation for an
  8956. option that prints @dfn{block numbers} along with the archive
  8957. listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
  8958. @command{star} has @option{-block-number}.
  8959. @item
  8960. Obtain verbose listing using the @samp{block number} option, and
  8961. find block numbers of the sparse member in question and the member
  8962. immediately following it. For example, running @command{star} on our
  8963. archive we obtain:
  8964. @smallexample
  8965. @group
  8966. $ @kbd{star -t -v -block-number -f arc.tar}
  8967. @dots{}
  8968. star: Unknown extended header keyword 'GNU.sparse.size' ignored.
  8969. star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
  8970. star: Unknown extended header keyword 'GNU.sparse.name' ignored.
  8971. star: Unknown extended header keyword 'GNU.sparse.map' ignored.
  8972. block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
  8973. block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
  8974. @dots{}
  8975. @end group
  8976. @end smallexample
  8977. @noindent
  8978. (as usual, ignore the warnings about unknown keywords.)
  8979. @item
  8980. Let @var{size} be the size of the sparse member, @var{Bs} be its block number
  8981. and @var{Bn} be the block number of the next member.
  8982. Compute:
  8983. @smallexample
  8984. @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
  8985. @end smallexample
  8986. @noindent
  8987. This number gives the size of the extended header part in tar @dfn{blocks}.
  8988. In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
  8989. = 7}.
  8990. @item
  8991. Use @command{dd} to extract the headers:
  8992. @smallexample
  8993. @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
  8994. @end smallexample
  8995. @noindent
  8996. where @var{archive} is the archive name, @var{hname} is a name of the
  8997. file to store the extended header in, @var{Bs} and @var{N} are
  8998. computed in previous steps.
  8999. In our example, this command will be
  9000. @smallexample
  9001. $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
  9002. @end smallexample
  9003. @end enumerate
  9004. Finally, you can expand the condensed file, using the obtained header:
  9005. @smallexample
  9006. @group
  9007. $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
  9008. Reading extended header file
  9009. Found variable GNU.sparse.size = 217481216
  9010. Found variable GNU.sparse.numblocks = 208
  9011. Found variable GNU.sparse.name = sparsefile
  9012. Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
  9013. Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
  9014. Done
  9015. @end group
  9016. @end smallexample
  9017. @node Reproducibility
  9018. @section Making @command{tar} Archives More Reproducible
  9019. Sometimes it is important for an archive to be reproducible,
  9020. so that one can be easily verify it to have been derived solely from its input.
  9021. However, two archives created by @GNUTAR{} from two sets of input
  9022. files normally might differ even if the input files have the same
  9023. contents and @GNUTAR{} was invoked the same way on both sets of input.
  9024. This can happen if the inputs have different modification dates or
  9025. other metadata, or if the input directories' entries are in different orders.
  9026. To avoid this problem when creating an archive, and thus make the
  9027. archive reproducible, you can run @GNUTAR{} in the C locale with
  9028. some or all of the following options:
  9029. @table @option
  9030. @item --sort=name
  9031. Omit irrelevant information about directory entry order.
  9032. @item --format=posix
  9033. Avoid problems with large files or files with unusual timestamps.
  9034. This also enables @option{--pax-option} options mentioned below.
  9035. @item --pax-option='exthdr.name=%d/PaxHeaders/%f'
  9036. Omit the process ID of @command{tar}.
  9037. This option is needed only if @env{POSIXLY_CORRECT} is set in the environment.
  9038. @item --pax-option='delete=atime,delete=ctime'
  9039. Omit irrelevant information about file access or status change time.
  9040. @item --clamp-mtime --mtime="$SOURCE_EPOCH"
  9041. Omit irrelevant information about file timestamps after
  9042. @samp{$SOURCE_EPOCH}, which should be a time no less than any
  9043. timestamp of any source file.
  9044. @item --numeric-owner
  9045. Omit irrelevant information about user and group names.
  9046. @item --owner=0
  9047. @itemx --group=0
  9048. Omit irrelevant information about file ownership and group.
  9049. @item --mode='go+u,go-w'
  9050. Omit irrelevant information about file permissions.
  9051. @end table
  9052. When creating a reproducible archive from version-controlled source files,
  9053. it can be useful to set each file's modification time
  9054. to be that of its last commit, so that the timestamps
  9055. are reproducible from the version-control repository.
  9056. If these timestamps are all on integer second boundaries, and if you use
  9057. @option{--format=posix --pax-option='delete=atime,delete=ctime'
  9058. --clamp-mtime --mtime="$SOURCE_EPOCH"}
  9059. where @code{$SOURCE_EPOCH} is the the time of the most recent commit,
  9060. and if all non-source files have timestamps greater than @code{$SOURCE_EPOCH},
  9061. then @GNUTAR{} should generate an archive in @acronym{ustar} format,
  9062. since no POSIX features will be needed and the archive will be in the
  9063. @acronym{ustar} subset of @acronym{posix} format.
  9064. Also, if compressing, use a reproducible compression format; e.g.,
  9065. with @command{gzip} you should use the @option{--no-name} (@option{-n}) option.
  9066. Here is an example set of shell commands to produce a reproducible
  9067. tarball with @command{git} and @command{gzip}, which you can tailor to
  9068. your project's needs.
  9069. @example
  9070. function get_commit_time() @{
  9071. TZ=UTC0 git log -1 \
  9072. --format=tformat:%cd \
  9073. --date=format:%Y-%m-%dT%H:%M:%SZ \
  9074. "$@@"
  9075. @}
  9076. SOURCE_EPOCH=$(get_commit_time)
  9077. git ls-files | while read -r file; do
  9078. commit_time=$(get_commit_time -- "$file") &&
  9079. touch -cmd $commit_time -- "$file"
  9080. done
  9081. TARFLAGS="
  9082. --sort=name --format=posix
  9083. --pax-option=exthdr.name=%d/PaxHeaders/%f
  9084. --pax-option=delete=atime,delete=ctime
  9085. --clamp-mtime --mtime=$SOURCE_EPOCH
  9086. --numeric-owner --owner=0 --group=0
  9087. --mode=go+u,go-w
  9088. "
  9089. GZIPFLAGS="
  9090. --no-name --best
  9091. "
  9092. LC_ALL=C tar $TARFLAGS -cf - FILES |
  9093. gzip $GZIPFLAGS > ARCHIVE.tgz
  9094. @end example
  9095. @node cpio
  9096. @section Comparison of @command{tar} and @command{cpio}
  9097. @UNREVISED{}
  9098. @FIXME{Reorganize the following material}
  9099. The @command{cpio} archive formats, like @command{tar}, do have maximum
  9100. file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
  9101. length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
  9102. file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
  9103. with arbitrary file name lengths, but other @command{cpio} implementations
  9104. may crash unexplainedly trying to read them.
  9105. @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
  9106. @command{cpio} doesn't handle symbolic links in the form in which it comes
  9107. in System V prior to SVR4, and some vendors may have added symlinks
  9108. to their system without enhancing @command{cpio} to know about them.
  9109. Others may have enhanced it in a way other than the way I did it
  9110. at Sun, and which was adopted by AT&T (and which is, I think, also
  9111. present in the @command{cpio} that Berkeley picked up from AT&T and put
  9112. into a later @acronym{BSD} release---I think I gave them my changes).
  9113. (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
  9114. can handle @command{tar} format input, and write it on output, and it
  9115. probably handles symbolic links. They may not have bothered doing
  9116. anything to enhance @command{tar} as a result.)
  9117. @command{cpio} handles special files; traditional @command{tar} doesn't.
  9118. @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
  9119. @command{cpio} comes only with System III, System V, and later @acronym{BSD}
  9120. (4.3-tahoe and later).
  9121. @command{tar}'s way of handling multiple hard links to a file can handle
  9122. file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
  9123. @command{cpio}s way requires you to play some games (in its ``binary''
  9124. format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
  9125. they're 18 bits---it would have to play games with the "file system @acronym{ID}"
  9126. field of the header to make sure that the file system @acronym{ID}/i-number pairs
  9127. of different files were always different), and I don't know which
  9128. @command{cpio}s, if any, play those games. Those that don't might get
  9129. confused and think two files are the same file when they're not, and
  9130. make hard links between them.
  9131. @command{tar}s way of handling multiple hard links to a file places only
  9132. one copy of the link on the tape, but the name attached to that copy
  9133. is the @emph{only} one you can use to retrieve the file; @command{cpio}s
  9134. way puts one copy for every link, but you can retrieve it using any
  9135. of the names.
  9136. @quotation
  9137. What type of check sum (if any) is used, and how is this calculated.
  9138. @end quotation
  9139. See the attached manual pages for @command{tar} and @command{cpio} format.
  9140. @command{tar} uses a checksum which is the sum of all the bytes in the
  9141. @command{tar} header for a file; @command{cpio} uses no checksum.
  9142. @quotation
  9143. If anyone knows why @command{cpio} was made when @command{tar} was present
  9144. at the unix scene,
  9145. @end quotation
  9146. It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
  9147. generally-available version of UNIX had @command{tar} at the time. I don't
  9148. know whether any version that was generally available @emph{within AT&T}
  9149. had @command{tar}, or, if so, whether the people within AT&T who did
  9150. @command{cpio} knew about it.
  9151. On restore, if there is a corruption on a tape @command{tar} will stop at
  9152. that point, while @command{cpio} will skip over it and try to restore the
  9153. rest of the files.
  9154. The main difference is just in the command syntax and header format.
  9155. @command{tar} is a little more tape-oriented in that everything is blocked
  9156. to start on a record boundary.
  9157. @quotation
  9158. Is there any differences between the ability to recover crashed
  9159. archives between the two of them. (Is there any chance of recovering
  9160. crashed archives at all.)
  9161. @end quotation
  9162. Theoretically it should be easier under @command{tar} since the blocking
  9163. lets you find a header with some variation of @samp{dd skip=@var{nn}}.
  9164. However, modern @command{cpio}'s and variations have an option to just
  9165. search for the next file header after an error with a reasonable chance
  9166. of resyncing. However, lots of tape driver software won't allow you to
  9167. continue past a media error which should be the only reason for getting
  9168. out of sync unless a file changed sizes while you were writing the
  9169. archive.
  9170. @quotation
  9171. If anyone knows why @command{cpio} was made when @command{tar} was present
  9172. at the unix scene, please tell me about this too.
  9173. @end quotation
  9174. Probably because it is more media efficient (by not blocking everything
  9175. and using only the space needed for the headers where @command{tar}
  9176. always uses 512 bytes per file header) and it knows how to archive
  9177. special files.
  9178. You might want to look at the freely available alternatives. The
  9179. major ones are @command{afio}, @GNUTAR{}, and
  9180. @command{pax}, each of which have their own extensions with some
  9181. backwards compatibility.
  9182. Sparse files were @command{tar}red as sparse files (which you can
  9183. easily test, because the resulting archive gets smaller, and
  9184. @acronym{GNU} @command{cpio} can no longer read it).
  9185. @node Media
  9186. @chapter Tapes and Other Archive Media
  9187. @UNREVISED{}
  9188. A few special cases about tape handling warrant more detailed
  9189. description. These special cases are discussed below.
  9190. Many complexities surround the use of @command{tar} on tape drives. Since
  9191. the creation and manipulation of archives located on magnetic tape was
  9192. the original purpose of @command{tar}, it contains many features making
  9193. such manipulation easier.
  9194. Archives are usually written on dismountable media---tape cartridges,
  9195. mag tapes, or floppy disks.
  9196. The amount of data a tape or disk holds depends not only on its size,
  9197. but also on how it is formatted. A 2400 foot long reel of mag tape
  9198. holds 40 megabytes of data when formatted at 1600 bits per inch. The
  9199. physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
  9200. Magnetic media are re-usable---once the archive on a tape is no longer
  9201. needed, the archive can be erased and the tape or disk used over.
  9202. Media quality does deteriorate with use, however. Most tapes or disks
  9203. should be discarded when they begin to produce data errors. EXABYTE
  9204. tape cartridges should be discarded when they generate an @dfn{error
  9205. count} (number of non-usable bits) of more than 10k.
  9206. Magnetic media are written and erased using magnetic fields, and
  9207. should be protected from such fields to avoid damage to stored data.
  9208. Sticking a floppy disk to a filing cabinet using a magnet is probably
  9209. not a good idea.
  9210. @menu
  9211. * Device:: Device selection and switching
  9212. * Remote Tape Server::
  9213. * Common Problems and Solutions::
  9214. * Blocking:: Blocking
  9215. * Many:: Many archives on one tape
  9216. * Using Multiple Tapes:: Using Multiple Tapes
  9217. * label:: Including a Label in the Archive
  9218. * verify::
  9219. * Write Protection::
  9220. @end menu
  9221. @node Device
  9222. @section Device Selection and Switching
  9223. @UNREVISED{}
  9224. @table @option
  9225. @item -f [@var{hostname}:]@var{file}
  9226. @itemx --file=[@var{hostname}:]@var{file}
  9227. Use archive file or device @var{file} on @var{hostname}.
  9228. @end table
  9229. This option is used to specify the file name of the archive @command{tar}
  9230. works on.
  9231. If the file name is @samp{-}, @command{tar} reads the archive from standard
  9232. input (when listing or extracting), or writes it to standard output
  9233. (when creating). If the @samp{-} file name is given when updating an
  9234. archive, @command{tar} will read the original archive from its standard
  9235. input, and will write the entire new archive to its standard output.
  9236. If the file name contains a @samp{:}, it is interpreted as
  9237. @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
  9238. sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
  9239. either case, @command{tar} will invoke the command @command{rsh} (or
  9240. @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
  9241. machine. If you give an alternate login name, it will be given to the
  9242. @command{rsh}.
  9243. Naturally, the remote machine must have an executable
  9244. @command{/usr/libexec/rmt}. This program is free software from the
  9245. University of California, and a copy of the source code can be found
  9246. with the sources for @command{tar}; it's compiled and installed by default.
  9247. The exact path to this utility is determined when configuring the package.
  9248. It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
  9249. your installation prefix. This location may also be overridden at
  9250. runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
  9251. ---rmt-command}, for detailed description of this option. @xref{Remote
  9252. Tape Server}, for the description of @command{rmt} command).
  9253. If this option is not given, but the environment variable @env{TAPE}
  9254. is set, its value is used; otherwise, old versions of @command{tar}
  9255. used a default archive name (which was picked when @command{tar} was
  9256. compiled). The default is normally set up to be the @dfn{first} tape
  9257. drive or other transportable I/O medium on the system.
  9258. Starting with version 1.11.5, @GNUTAR{} uses
  9259. standard input and standard output as the default device, and I will
  9260. not try anymore supporting automatic device detection at installation
  9261. time. This was failing really in too many cases, it was hopeless.
  9262. This is now completely left to the installer to override standard
  9263. input and standard output for default device, if this seems
  9264. preferable. Further, I think @emph{most} actual usages of
  9265. @command{tar} are done with pipes or disks, not really tapes,
  9266. cartridges or diskettes.
  9267. Some users think that using standard input and output is running
  9268. after trouble. This could lead to a nasty surprise on your screen if
  9269. you forget to specify an output file name---especially if you are going
  9270. through a network or terminal server capable of buffering large amounts
  9271. of output. We had so many bug reports in that area of configuring
  9272. default tapes automatically, and so many contradicting requests, that
  9273. we finally consider the problem to be portably intractable. We could
  9274. of course use something like @samp{/dev/tape} as a default, but this
  9275. is @emph{also} running after various kind of trouble, going from hung
  9276. processes to accidental destruction of real tapes. After having seen
  9277. all this mess, using standard input and output as a default really
  9278. sounds like the only clean choice left, and a very useful one too.
  9279. @GNUTAR{} reads and writes archive in records, I
  9280. suspect this is the main reason why block devices are preferred over
  9281. character devices. Most probably, block devices are more efficient
  9282. too. The installer could also check for @samp{DEFTAPE} in
  9283. @file{<sys/mtio.h>}.
  9284. @table @option
  9285. @xopindex{force-local, short description}
  9286. @item --force-local
  9287. Archive file is local even if it contains a colon.
  9288. @opindex rsh-command
  9289. @item --rsh-command=@var{command}
  9290. Use remote @var{command} instead of @command{rsh}. This option exists
  9291. so that people who use something other than the standard @command{rsh}
  9292. (e.g., a Kerberized @command{rsh}) can access a remote device.
  9293. When this command is not used, the shell command found when
  9294. the @command{tar} program was installed is used instead. This is
  9295. the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
  9296. @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
  9297. The installer may have overridden this by defining the environment
  9298. variable @env{RSH} @emph{at installation time}.
  9299. @item -[0-7][lmh]
  9300. Specify drive and density.
  9301. @xopindex{multi-volume, short description}
  9302. @item -M
  9303. @itemx --multi-volume
  9304. Create/list/extract multi-volume archive.
  9305. This option causes @command{tar} to write a @dfn{multi-volume} archive---one
  9306. that may be larger than will fit on the medium used to hold it.
  9307. @xref{Multi-Volume Archives}.
  9308. @xopindex{tape-length, short description}
  9309. @item -L @var{num}
  9310. @itemx --tape-length=@var{size}[@var{suf}]
  9311. Change tape after writing @var{size} units of data. Unless @var{suf} is
  9312. given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
  9313. 1024} bytes. The following suffixes alter this behavior:
  9314. @float Table, size-suffixes
  9315. @caption{Size Suffixes}
  9316. @multitable @columnfractions 0.2 0.3 0.3
  9317. @headitem Suffix @tab Units @tab Byte Equivalent
  9318. @item b @tab Blocks @tab @var{size} x 512
  9319. @item B @tab Kilobytes @tab @var{size} x 1024
  9320. @item c @tab Bytes @tab @var{size}
  9321. @item G @tab Gigabytes @tab @var{size} x 1024^3
  9322. @item K @tab Kilobytes @tab @var{size} x 1024
  9323. @item k @tab Kilobytes @tab @var{size} x 1024
  9324. @item M @tab Megabytes @tab @var{size} x 1024^2
  9325. @item P @tab Petabytes @tab @var{size} x 1024^5
  9326. @item T @tab Terabytes @tab @var{size} x 1024^4
  9327. @item w @tab Words @tab @var{size} x 2
  9328. @end multitable
  9329. @end float
  9330. This option might be useful when your tape drivers do not properly
  9331. detect end of physical tapes. By being slightly conservative on the
  9332. maximum tape length, you might avoid the problem entirely.
  9333. @xopindex{info-script, short description}
  9334. @xopindex{new-volume-script, short description}
  9335. @item -F @var{command}
  9336. @itemx --info-script=@var{command}
  9337. @itemx --new-volume-script=@var{command}
  9338. Execute @var{command} at end of each tape. This implies
  9339. @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
  9340. description of this option.
  9341. @end table
  9342. @node Remote Tape Server
  9343. @section Remote Tape Server
  9344. @cindex remote tape drive
  9345. @pindex rmt
  9346. In order to access the tape drive on a remote machine, @command{tar}
  9347. uses the remote tape server written at the University of California at
  9348. Berkeley. The remote tape server must be installed as
  9349. @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
  9350. want to use. @command{tar} calls @command{rmt} by running an
  9351. @command{rsh} or @command{remsh} to the remote machine, optionally
  9352. using a different login name if one is supplied.
  9353. A copy of the source for the remote tape server is provided. Its
  9354. source code can be freely distributed. It is compiled and
  9355. installed by default.
  9356. @cindex absolute file names
  9357. Unless you use the @option{--absolute-names} (@option{-P}) option,
  9358. @GNUTAR{} will not allow you to create an archive that contains
  9359. absolute file names (a file name beginning with @samp{/}). If you try,
  9360. @command{tar} will automatically remove the leading @samp{/} from the
  9361. file names it stores in the archive. It will also type a warning
  9362. message telling you what it is doing.
  9363. When reading an archive that was created with a different
  9364. @command{tar} program, @GNUTAR{} automatically
  9365. extracts entries in the archive which have absolute file names as if
  9366. the file names were not absolute. This is an important feature. A
  9367. visitor here once gave a @command{tar} tape to an operator to restore;
  9368. the operator used Sun @command{tar} instead of @GNUTAR{},
  9369. and the result was that it replaced large portions of
  9370. our @file{/bin} and friends with versions from the tape; needless to
  9371. say, we were unhappy about having to recover the file system from
  9372. backup tapes.
  9373. For example, if the archive contained a file @file{/usr/bin/computoy},
  9374. @GNUTAR{} would extract the file to @file{usr/bin/computoy},
  9375. relative to the current directory. If you want to extract the files in
  9376. an archive to the same absolute names that they had when the archive
  9377. was created, you should do a @samp{cd /} before extracting the files
  9378. from the archive, or you should either use the @option{--absolute-names}
  9379. option, or use the command @samp{tar -C / @dots{}}.
  9380. @cindex Ultrix 3.1 and write failure
  9381. Some versions of Unix (Ultrix 3.1 is known to have this problem),
  9382. can claim that a short write near the end of a tape succeeded,
  9383. when it actually failed. This will result in the -M option not
  9384. working correctly. The best workaround at the moment is to use a
  9385. significantly larger blocking factor than the default 20.
  9386. In order to update an archive, @command{tar} must be able to backspace the
  9387. archive in order to reread or rewrite a record that was just read (or
  9388. written). This is currently possible only on two kinds of files: normal
  9389. disk files (or any other file that can be backspaced with @samp{lseek}),
  9390. and industry-standard 9-track magnetic tape (or any other kind of tape
  9391. that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
  9392. This means that the @option{--append}, @option{--concatenate}, and
  9393. @option{--delete} commands will not work on any other kind of file.
  9394. Some media simply cannot be backspaced, which means these commands and
  9395. options will never be able to work on them. These non-backspacing
  9396. media include pipes and cartridge tape drives.
  9397. Some other media can be backspaced, and @command{tar} will work on them
  9398. once @command{tar} is modified to do so.
  9399. Archives created with the @option{--multi-volume}, @option{--label}, and
  9400. @option{--incremental} (@option{-G}) options may not be readable by other version
  9401. of @command{tar}. In particular, restoring a file that was split over
  9402. a volume boundary will require some careful work with @command{dd}, if
  9403. it can be done at all. Other versions of @command{tar} may also create
  9404. an empty file whose name is that of the volume header. Some versions
  9405. of @command{tar} may create normal files instead of directories archived
  9406. with the @option{--incremental} (@option{-G}) option.
  9407. @node Common Problems and Solutions
  9408. @section Some Common Problems and their Solutions
  9409. @ifclear PUBLISH
  9410. @format
  9411. errors from system:
  9412. permission denied
  9413. no such file or directory
  9414. not owner
  9415. errors from @command{tar}:
  9416. directory checksum error
  9417. header format error
  9418. errors from media/system:
  9419. i/o error
  9420. device busy
  9421. @end format
  9422. @end ifclear
  9423. @node Blocking
  9424. @section Blocking
  9425. @cindex block
  9426. @cindex record
  9427. @dfn{Block} and @dfn{record} terminology is rather confused, and it
  9428. is also confusing to the expert reader. On the other hand, readers
  9429. who are new to the field have a fresh mind, and they may safely skip
  9430. the next two paragraphs, as the remainder of this manual uses those
  9431. two terms in a quite consistent way.
  9432. John Gilmore, the writer of the public domain @command{tar} from which
  9433. @GNUTAR{} was originally derived, wrote (June 1995):
  9434. @quotation
  9435. The nomenclature of tape drives comes from IBM, where I believe
  9436. they were invented for the IBM 650 or so. On IBM mainframes, what
  9437. is recorded on tape are tape blocks. The logical organization of
  9438. data is into records. There are various ways of putting records into
  9439. blocks, including @code{F} (fixed sized records), @code{V} (variable
  9440. sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
  9441. to a block), @code{VB} (variable size records, @var{n} to a block),
  9442. @code{VSB} (variable spanned blocked: variable sized records that can
  9443. occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
  9444. parameter specified this to the operating system.
  9445. The Unix man page on @command{tar} was totally confused about this.
  9446. When I wrote @code{PD TAR}, I used the historically correct terminology
  9447. (@command{tar} writes data records, which are grouped into blocks).
  9448. It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
  9449. here), and now Fran@,{c}ois has migrated that terminology back
  9450. into the source code too.
  9451. @end quotation
  9452. The term @dfn{physical block} means the basic transfer chunk from or
  9453. to a device, after which reading or writing may stop without anything
  9454. being lost. In this manual, the term @dfn{block} usually refers to
  9455. a disk physical block, @emph{assuming} that each disk block is 512
  9456. bytes in length. It is true that some disk devices have different
  9457. physical blocks, but @command{tar} ignore these differences in its own
  9458. format, which is meant to be portable, so a @command{tar} block is always
  9459. 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
  9460. The term @dfn{logical block} often represents the basic chunk of
  9461. allocation of many disk blocks as a single entity, which the operating
  9462. system treats somewhat atomically; this concept is only barely used
  9463. in @GNUTAR{}.
  9464. The term @dfn{physical record} is another way to speak of a physical
  9465. block, those two terms are somewhat interchangeable. In this manual,
  9466. the term @dfn{record} usually refers to a tape physical block,
  9467. @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
  9468. It is true that archives may be put on disk or used with pipes,
  9469. but nevertheless, @command{tar} tries to read and write the archive one
  9470. @dfn{record} at a time, whatever the medium in use. One record is made
  9471. up of an integral number of blocks, and this operation of putting many
  9472. disk blocks into a single tape block is called @dfn{reblocking}, or
  9473. more simply, @dfn{blocking}. The term @dfn{logical record} refers to
  9474. the logical organization of many characters into something meaningful
  9475. to the application. The term @dfn{unit record} describes a small set
  9476. of characters which are transmitted whole to or by the application,
  9477. and often refers to a line of text. Those two last terms are unrelated
  9478. to what we call a @dfn{record} in @GNUTAR{}.
  9479. When writing to tapes, @command{tar} writes the contents of the archive
  9480. in chunks known as @dfn{records}. To change the default blocking
  9481. factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
  9482. @var{512-size}}) option. Each record will then be composed of
  9483. @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
  9484. @xref{Standard}.) Each file written to the archive uses at least one
  9485. full record. As a result, using a larger record size can result in
  9486. more wasted space for small files. On the other hand, a larger record
  9487. size can often be read and written much more efficiently.
  9488. Further complicating the problem is that some tape drives ignore the
  9489. blocking entirely. For these, a larger record size can still improve
  9490. performance (because the software layers above the tape drive still
  9491. honor the blocking), but not as dramatically as on tape drives that
  9492. honor blocking.
  9493. When reading an archive, @command{tar} can usually figure out the
  9494. record size on itself. When this is the case, and a non-standard
  9495. record size was used when the archive was created, @command{tar} will
  9496. print a message about a non-standard blocking factor, and then operate
  9497. normally@footnote{If this message is not needed, you can turn it off
  9498. using the @option{--warning=no-record-size} option.}. On some tape
  9499. devices, however, @command{tar} cannot figure out the record size
  9500. itself. On most of those, you can specify a blocking factor (with
  9501. @option{--blocking-factor}) larger than the actual blocking factor,
  9502. and then use the @option{--read-full-records} (@option{-B}) option.
  9503. (If you specify a blocking factor with @option{--blocking-factor} and
  9504. don't use the @option{--read-full-records} option, then @command{tar}
  9505. will not attempt to figure out the recording size itself.) On some
  9506. devices, you must always specify the record size exactly with
  9507. @option{--blocking-factor} when reading, because @command{tar} cannot
  9508. figure it out. In any case, use @option{--list} (@option{-t}) before
  9509. doing any extractions to see whether @command{tar} is reading the archive
  9510. correctly.
  9511. @command{tar} blocks are all fixed size (512 bytes), and its scheme for
  9512. putting them into records is to put a whole number of them (one or
  9513. more) into each record. @command{tar} records are all the same size;
  9514. at the end of the file there's a block containing all zeros, which
  9515. is how you tell that the remainder of the last record(s) are garbage.
  9516. In a standard @command{tar} file (no options), the block size is 512
  9517. and the record size is 10240, for a blocking factor of 20. What the
  9518. @option{--blocking-factor} option does is sets the blocking factor,
  9519. changing the record size while leaving the block size at 512 bytes.
  9520. 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
  9521. most tape drives these days prefer much bigger records in order to
  9522. stream and not waste tape. When writing tapes for myself, some tend
  9523. to use a factor of the order of 2048, say, giving a record size of
  9524. around one megabyte.
  9525. If you use a blocking factor larger than 20, older @command{tar}
  9526. programs might not be able to read the archive, so we recommend this
  9527. as a limit to use in practice. @GNUTAR{}, however,
  9528. will support arbitrarily large record sizes, limited only by the
  9529. amount of virtual memory or the physical characteristics of the tape
  9530. device.
  9531. @menu
  9532. * Format Variations:: Format Variations
  9533. * Blocking Factor:: The Blocking Factor of an Archive
  9534. @end menu
  9535. @node Format Variations
  9536. @subsection Format Variations
  9537. @cindex Format Parameters
  9538. @cindex Format Options
  9539. @cindex Options, archive format specifying
  9540. @cindex Options, format specifying
  9541. @UNREVISED{}
  9542. Format parameters specify how an archive is written on the archive
  9543. media. The best choice of format parameters will vary depending on
  9544. the type and number of files being archived, and on the media used to
  9545. store the archive.
  9546. To specify format parameters when accessing or creating an archive,
  9547. you can use the options described in the following sections.
  9548. If you do not specify any format parameters, @command{tar} uses
  9549. default parameters. You cannot modify a compressed archive.
  9550. If you create an archive with the @option{--blocking-factor} option
  9551. specified (@pxref{Blocking Factor}), you must specify that
  9552. blocking-factor when operating on the archive. @xref{Formats}, for other
  9553. examples of format parameter considerations.
  9554. @node Blocking Factor
  9555. @subsection The Blocking Factor of an Archive
  9556. @cindex Blocking Factor
  9557. @cindex Record Size
  9558. @cindex Number of blocks per record
  9559. @cindex Number of bytes per record
  9560. @cindex Bytes per record
  9561. @cindex Blocks per record
  9562. @UNREVISED{}
  9563. @opindex blocking-factor
  9564. The data in an archive is grouped into blocks, which are 512 bytes.
  9565. Blocks are read and written in whole number multiples called
  9566. @dfn{records}. The number of blocks in a record (i.e., the size of a
  9567. record in units of 512 bytes) is called the @dfn{blocking factor}.
  9568. The @option{--blocking-factor=@var{512-size}} (@option{-b
  9569. @var{512-size}}) option specifies the blocking factor of an archive.
  9570. The default blocking factor is typically 20 (i.e., 10240 bytes), but
  9571. can be specified at installation. To find out the blocking factor of
  9572. an existing archive, use @samp{tar --list --file=@var{archive-name}}.
  9573. This may not work on some devices.
  9574. Records are separated by gaps, which waste space on the archive media.
  9575. If you are archiving on magnetic tape, using a larger blocking factor
  9576. (and therefore larger records) provides faster throughput and allows you
  9577. to fit more data on a tape (because there are fewer gaps). If you are
  9578. archiving on cartridge, a very large blocking factor (say 126 or more)
  9579. greatly increases performance. A smaller blocking factor, on the other
  9580. hand, may be useful when archiving small files, to avoid archiving lots
  9581. of nulls as @command{tar} fills out the archive to the end of the record.
  9582. In general, the ideal record size depends on the size of the
  9583. inter-record gaps on the tape you are using, and the average size of the
  9584. files you are archiving. @xref{create}, for information on
  9585. writing archives.
  9586. @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
  9587. Archives with blocking factors larger than 20 cannot be read
  9588. by very old versions of @command{tar}, or by some newer versions
  9589. of @command{tar} running on old machines with small address spaces.
  9590. With @GNUTAR{}, the blocking factor of an archive is limited
  9591. only by the maximum record size of the device containing the archive,
  9592. or by the amount of available virtual memory.
  9593. Also, on some systems, not using adequate blocking factors, as sometimes
  9594. imposed by the device drivers, may yield unexpected diagnostics. For
  9595. example, this has been reported:
  9596. @smallexample
  9597. Cannot write to /dev/dlt: Invalid argument
  9598. @end smallexample
  9599. @noindent
  9600. In such cases, it sometimes happen that the @command{tar} bundled by
  9601. the system is aware of block size idiosyncrasies, while @GNUTAR{}
  9602. requires an explicit specification for the block size,
  9603. which it cannot guess. This yields some people to consider
  9604. @GNUTAR{} is misbehaving, because by comparison,
  9605. @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
  9606. for example, might resolve the problem.
  9607. If you use a non-default blocking factor when you create an archive, you
  9608. must specify the same blocking factor when you modify that archive. Some
  9609. archive devices will also require you to specify the blocking factor when
  9610. reading that archive, however this is not typically the case. Usually, you
  9611. can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
  9612. reports a non-default record size and then lists the archive members as
  9613. it would normally. To extract files from an archive with a non-standard
  9614. blocking factor (particularly if you're not sure what the blocking factor
  9615. is), you can usually use the @option{--read-full-records} (@option{-B}) option while
  9616. specifying a blocking factor larger then the blocking factor of the archive
  9617. (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
  9618. @xref{list}, for more information on the @option{--list} (@option{-t})
  9619. operation. @xref{Reading}, for a more detailed explanation of that option.
  9620. @table @option
  9621. @item --blocking-factor=@var{number}
  9622. @itemx -b @var{number}
  9623. Specifies the blocking factor of an archive. Can be used with any
  9624. operation, but is usually not necessary with @option{--list} (@option{-t}).
  9625. @end table
  9626. Device blocking
  9627. @table @option
  9628. @item -b @var{blocks}
  9629. @itemx --blocking-factor=@var{blocks}
  9630. Set record size to @math{@var{blocks}*512} bytes.
  9631. This option is used to specify a @dfn{blocking factor} for the archive.
  9632. When reading or writing the archive, @command{tar}, will do reads and writes
  9633. of the archive in records of @math{@var{block}*512} bytes. This is true
  9634. even when the archive is compressed. Some devices requires that all
  9635. write operations be a multiple of a certain size, and so, @command{tar}
  9636. pads the archive out to the next record boundary.
  9637. The default blocking factor is set when @command{tar} is compiled, and is
  9638. typically 20. Blocking factors larger than 20 cannot be read by very
  9639. old versions of @command{tar}, or by some newer versions of @command{tar}
  9640. running on old machines with small address spaces.
  9641. With a magnetic tape, larger records give faster throughput and fit
  9642. more data on a tape (because there are fewer inter-record gaps).
  9643. If the archive is in a disk file or a pipe, you may want to specify
  9644. a smaller blocking factor, since a large one will result in a large
  9645. number of null bytes at the end of the archive.
  9646. When writing cartridge or other streaming tapes, a much larger
  9647. blocking factor (say 126 or more) will greatly increase performance.
  9648. However, you must specify the same blocking factor when reading or
  9649. updating the archive.
  9650. Apparently, Exabyte drives have a physical block size of 8K bytes.
  9651. If we choose our blocksize as a multiple of 8k bytes, then the problem
  9652. seems to disappear. Id est, we are using block size of 112 right
  9653. now, and we haven't had the problem since we switched@dots{}
  9654. With @GNUTAR{} the blocking factor is limited only
  9655. by the maximum record size of the device containing the archive, or by
  9656. the amount of available virtual memory.
  9657. However, deblocking or reblocking is virtually avoided in a special
  9658. case which often occurs in practice, but which requires all the
  9659. following conditions to be simultaneously true:
  9660. @itemize @bullet
  9661. @item
  9662. the archive is subject to a compression option,
  9663. @item
  9664. the archive is not handled through standard input or output, nor
  9665. redirected nor piped,
  9666. @item
  9667. the archive is directly handled to a local disk, instead of any special
  9668. device,
  9669. @item
  9670. @option{--blocking-factor} is not explicitly specified on the @command{tar}
  9671. invocation.
  9672. @end itemize
  9673. If the output goes directly to a local disk, and not through
  9674. stdout, then the last write is not extended to a full record size.
  9675. Otherwise, reblocking occurs. Here are a few other remarks on this
  9676. topic:
  9677. @itemize @bullet
  9678. @item
  9679. @command{gzip} will complain about trailing garbage if asked to
  9680. uncompress a compressed archive on tape, there is an option to turn
  9681. the message off, but it breaks the regularity of simply having to use
  9682. @samp{@var{prog} -d} for decompression. It would be nice if gzip was
  9683. silently ignoring any number of trailing zeros. I'll ask Jean-loup
  9684. Gailly, by sending a copy of this message to him.
  9685. @item
  9686. @command{compress} does not show this problem, but as Jean-loup pointed
  9687. out to Michael, @samp{compress -d} silently adds garbage after
  9688. the result of decompression, which tar ignores because it already
  9689. recognized its end-of-file indicator. So this bug may be safely
  9690. ignored.
  9691. @item
  9692. @samp{gzip -d -q} will be silent about the trailing zeros indeed,
  9693. but will still return an exit status of 2 which tar reports in turn.
  9694. @command{tar} might ignore the exit status returned, but I hate doing
  9695. that, as it weakens the protection @command{tar} offers users against
  9696. other possible problems at decompression time. If @command{gzip} was
  9697. silently skipping trailing zeros @emph{and} also avoiding setting the
  9698. exit status in this innocuous case, that would solve this situation.
  9699. @item
  9700. @command{tar} should become more solid at not stopping to read a pipe at
  9701. the first null block encountered. This inelegantly breaks the pipe.
  9702. @command{tar} should rather drain the pipe out before exiting itself.
  9703. @end itemize
  9704. @xopindex{ignore-zeros, short description}
  9705. @item -i
  9706. @itemx --ignore-zeros
  9707. Ignore blocks of zeros in archive (means EOF).
  9708. The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
  9709. of zeros in the archive. Normally a block of zeros indicates the
  9710. end of the archive, but when reading a damaged archive, or one which
  9711. was created by concatenating several archives together, this option
  9712. allows @command{tar} to read the entire archive. This option is not on
  9713. by default because many versions of @command{tar} write garbage after
  9714. the zeroed blocks.
  9715. Note that this option causes @command{tar} to read to the end of the
  9716. archive file, which may sometimes avoid problems when multiple files
  9717. are stored on a single physical tape.
  9718. @xopindex{read-full-records, short description}
  9719. @item -B
  9720. @itemx --read-full-records
  9721. Reblock as we read (for reading 4.2@acronym{BSD} pipes).
  9722. If @option{--read-full-records} is used, @command{tar}
  9723. will not panic if an attempt to read a record from the archive does
  9724. not return a full record. Instead, @command{tar} will keep reading
  9725. until it has obtained a full
  9726. record.
  9727. This option is turned on by default when @command{tar} is reading
  9728. an archive from standard input, or from a remote machine. This is
  9729. because on @acronym{BSD} Unix systems, a read of a pipe will return however
  9730. much happens to be in the pipe, even if it is less than @command{tar}
  9731. requested. If this option was not used, @command{tar} would fail as
  9732. soon as it read an incomplete record from the pipe.
  9733. This option is also useful with the commands for updating an archive.
  9734. @end table
  9735. Tape blocking
  9736. @FIXME{Appropriate options should be moved here from elsewhere.}
  9737. @cindex blocking factor
  9738. @cindex tape blocking
  9739. When handling various tapes or cartridges, you have to take care of
  9740. selecting a proper blocking, that is, the number of disk blocks you
  9741. put together as a single tape block on the tape, without intervening
  9742. tape gaps. A @dfn{tape gap} is a small landing area on the tape
  9743. with no information on it, used for decelerating the tape to a
  9744. full stop, and for later regaining the reading or writing speed.
  9745. When the tape driver starts reading a record, the record has to
  9746. be read whole without stopping, as a tape gap is needed to stop the
  9747. tape motion without losing information.
  9748. @cindex Exabyte blocking
  9749. @cindex DAT blocking
  9750. Using higher blocking (putting more disk blocks per tape block) will use
  9751. the tape more efficiently as there will be less tape gaps. But reading
  9752. such tapes may be more difficult for the system, as more memory will be
  9753. required to receive at once the whole record. Further, if there is a
  9754. reading error on a huge record, this is less likely that the system will
  9755. succeed in recovering the information. So, blocking should not be too
  9756. low, nor it should be too high. @command{tar} uses by default a blocking of
  9757. 20 for historical reasons, and it does not really matter when reading or
  9758. writing to disk. Current tape technology would easily accommodate higher
  9759. blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
  9760. We were told that for some DLT drives, the blocking should be a multiple
  9761. of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
  9762. Other manufacturers may use different recommendations for the same tapes.
  9763. This might also depends of the buffering techniques used inside modern
  9764. tape controllers. Some imposes a minimum blocking, or a maximum blocking.
  9765. Others request blocking to be some exponent of two.
  9766. So, there is no fixed rule for blocking. But blocking at read time
  9767. should ideally be the same as blocking used at write time. At one place
  9768. I know, with a wide variety of equipment, they found it best to use a
  9769. blocking of 32 to guarantee that their tapes are fully interchangeable.
  9770. I was also told that, for recycled tapes, prior erasure (by the same
  9771. drive unit that will be used to create the archives) sometimes lowers
  9772. the error rates observed at rewriting time.
  9773. I might also use @option{--number-blocks} instead of
  9774. @option{--block-number}, so @option{--block} will then expand to
  9775. @option{--blocking-factor} unambiguously.
  9776. @node Many
  9777. @section Many Archives on One Tape
  9778. @FIXME{Appropriate options should be moved here from elsewhere.}
  9779. @findex ntape @r{device}
  9780. Most tape devices have two entries in the @file{/dev} directory, or
  9781. entries that come in pairs, which differ only in the minor number for
  9782. this device. Let's take for example @file{/dev/tape}, which often
  9783. points to the only or usual tape device of a given system. There might
  9784. be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
  9785. name is the @emph{rewinding} version of the device, while the name
  9786. having @samp{nr} in it is the @emph{no rewinding} version of the same
  9787. device.
  9788. A rewinding tape device will bring back the tape to its beginning point
  9789. automatically when this device is opened or closed. Since @command{tar}
  9790. opens the archive file before using it and closes it afterwards, this
  9791. means that a simple:
  9792. @smallexample
  9793. $ @kbd{tar cf /dev/tape @var{directory}}
  9794. @end smallexample
  9795. @noindent
  9796. will reposition the tape to its beginning both prior and after saving
  9797. @var{directory} contents to it, thus erasing prior tape contents and
  9798. making it so that any subsequent write operation will destroy what has
  9799. just been saved.
  9800. @cindex tape positioning
  9801. So, a rewinding device is normally meant to hold one and only one file.
  9802. If you want to put more than one @command{tar} archive on a given tape, you
  9803. will need to avoid using the rewinding version of the tape device. You
  9804. will also have to pay special attention to tape positioning. Errors in
  9805. positioning may overwrite the valuable data already on your tape. Many
  9806. people, burnt by past experiences, will only use rewinding devices and
  9807. limit themselves to one file per tape, precisely to avoid the risk of
  9808. such errors. Be fully aware that writing at the wrong position on a
  9809. tape loses all information past this point and most probably until the
  9810. end of the tape, and this destroyed information @emph{cannot} be
  9811. recovered.
  9812. To save @var{directory-1} as a first archive at the beginning of a
  9813. tape, and leave that tape ready for a second archive, you should use:
  9814. @smallexample
  9815. $ @kbd{mt -f /dev/nrtape rewind}
  9816. $ @kbd{tar cf /dev/nrtape @var{directory-1}}
  9817. @end smallexample
  9818. @cindex tape marks
  9819. @dfn{Tape marks} are special magnetic patterns written on the tape
  9820. media, which are later recognizable by the reading hardware. These
  9821. marks are used after each file, when there are many on a single tape.
  9822. An empty file (that is to say, two tape marks in a row) signal the
  9823. logical end of the tape, after which no file exist. Usually,
  9824. non-rewinding tape device drivers will react to the close request issued
  9825. by @command{tar} by first writing two tape marks after your archive, and by
  9826. backspacing over one of these. So, if you remove the tape at that time
  9827. from the tape drive, it is properly terminated. But if you write
  9828. another file at the current position, the second tape mark will be
  9829. erased by the new information, leaving only one tape mark between files.
  9830. So, you may now save @var{directory-2} as a second archive after the
  9831. first on the same tape by issuing the command:
  9832. @smallexample
  9833. $ @kbd{tar cf /dev/nrtape @var{directory-2}}
  9834. @end smallexample
  9835. @noindent
  9836. and so on for all the archives you want to put on the same tape.
  9837. Another usual case is that you do not write all the archives the same
  9838. day, and you need to remove and store the tape between two archive
  9839. sessions. In general, you must remember how many files are already
  9840. saved on your tape. Suppose your tape already has 16 files on it, and
  9841. that you are ready to write the 17th. You have to take care of skipping
  9842. the first 16 tape marks before saving @var{directory-17}, say, by using
  9843. these commands:
  9844. @smallexample
  9845. $ @kbd{mt -f /dev/nrtape rewind}
  9846. $ @kbd{mt -f /dev/nrtape fsf 16}
  9847. $ @kbd{tar cf /dev/nrtape @var{directory-17}}
  9848. @end smallexample
  9849. In all the previous examples, we put aside blocking considerations, but
  9850. you should do the proper things for that as well. @xref{Blocking}.
  9851. @menu
  9852. * Tape Positioning:: Tape Positions and Tape Marks
  9853. * mt:: The @command{mt} Utility
  9854. @end menu
  9855. @node Tape Positioning
  9856. @subsection Tape Positions and Tape Marks
  9857. @UNREVISED{}
  9858. Just as archives can store more than one file from the file system,
  9859. tapes can store more than one archive file. To keep track of where
  9860. archive files (or any other type of file stored on tape) begin and
  9861. end, tape archive devices write magnetic @dfn{tape marks} on the
  9862. archive media. Tape drives write one tape mark between files,
  9863. two at the end of all the file entries.
  9864. If you think of data as a series of records "rrrr"'s, and tape marks as
  9865. "*"'s, a tape might look like the following:
  9866. @smallexample
  9867. rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
  9868. @end smallexample
  9869. Tape devices read and write tapes using a read/write @dfn{tape
  9870. head}---a physical part of the device which can only access one
  9871. point on the tape at a time. When you use @command{tar} to read or
  9872. write archive data from a tape device, the device will begin reading
  9873. or writing from wherever on the tape the tape head happens to be,
  9874. regardless of which archive or what part of the archive the tape
  9875. head is on. Before writing an archive, you should make sure that no
  9876. data on the tape will be overwritten (unless it is no longer needed).
  9877. Before reading an archive, you should make sure the tape head is at
  9878. the beginning of the archive you want to read. You can do it manually
  9879. via @code{mt} utility (@pxref{mt}). The @code{restore} script does
  9880. that automatically (@pxref{Scripted Restoration}).
  9881. If you want to add new archive file entries to a tape, you should
  9882. advance the tape to the end of the existing file entries, backspace
  9883. over the last tape mark, and write the new archive file. If you were
  9884. to add two archives to the example above, the tape might look like the
  9885. following:
  9886. @smallexample
  9887. rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
  9888. @end smallexample
  9889. @node mt
  9890. @subsection The @command{mt} Utility
  9891. @UNREVISED{}
  9892. @FIXME{Is it true that this only works on non-block devices?
  9893. should explain the difference, (fixed or variable).}
  9894. @xref{Blocking Factor}.
  9895. You can use the @command{mt} utility to advance or rewind a tape past a
  9896. specified number of archive files on the tape. This will allow you
  9897. to move to the beginning of an archive before extracting or reading
  9898. it, or to the end of all the archives before writing a new one.
  9899. @FIXME{Why isn't there an "advance 'til you find two tape marks
  9900. together"?}
  9901. The syntax of the @command{mt} command is:
  9902. @smallexample
  9903. @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
  9904. @end smallexample
  9905. where @var{tapename} is the name of the tape device, @var{number} is
  9906. the number of times an operation is performed (with a default of one),
  9907. and @var{operation} is one of the following:
  9908. @FIXME{is there any use for record operations?}
  9909. @table @option
  9910. @item eof
  9911. @itemx weof
  9912. Writes @var{number} tape marks at the current position on the tape.
  9913. @item fsf
  9914. Moves tape position forward @var{number} files.
  9915. @item bsf
  9916. Moves tape position back @var{number} files.
  9917. @item rewind
  9918. Rewinds the tape. (Ignores @var{number}.)
  9919. @item offline
  9920. @itemx rewoff1
  9921. Rewinds the tape and takes the tape device off-line. (Ignores @var{number}.)
  9922. @item status
  9923. Prints status information about the tape unit.
  9924. @end table
  9925. If you don't specify a @var{tapename}, @command{mt} uses the environment
  9926. variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
  9927. the default device specified in your @file{sys/mtio.h} file
  9928. (@code{DEFTAPE} variable). If this is not defined, the program will
  9929. display a descriptive error message and exit with code 1.
  9930. @command{mt} returns a 0 exit status when the operation(s) were
  9931. successful, 1 if the command was unrecognized, and 2 if an operation
  9932. failed.
  9933. @node Using Multiple Tapes
  9934. @section Using Multiple Tapes
  9935. Often you might want to write a large archive, one larger than will fit
  9936. on the actual tape you are using. In such a case, you can run multiple
  9937. @command{tar} commands, but this can be inconvenient, particularly if you
  9938. are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
  9939. Therefore, @command{tar} provides a special mode for creating
  9940. multi-volume archives.
  9941. @dfn{Multi-volume} archive is a single @command{tar} archive, stored
  9942. on several media volumes of fixed size. Although in this section we will
  9943. often call @samp{volume} a @dfn{tape}, there is absolutely no
  9944. requirement for multi-volume archives to be stored on tapes. Instead,
  9945. they can use whatever media type the user finds convenient, they can
  9946. even be located on files.
  9947. When creating a multi-volume archive, @GNUTAR{} continues to fill
  9948. current volume until it runs out of space, then it switches to
  9949. next volume (usually the operator is queried to replace the tape on
  9950. this point), and continues working on the new volume. This operation
  9951. continues until all requested files are dumped. If @GNUTAR{} detects
  9952. end of media while dumping a file, such a file is archived in split
  9953. form. Some very big files can even be split across several volumes.
  9954. Each volume is itself a valid @GNUTAR{} archive, so it can be read
  9955. without any special options. Consequently any file member residing
  9956. entirely on one volume can be extracted or otherwise operated upon
  9957. without needing the other volume. Sure enough, to extract a split
  9958. member you would need all volumes its parts reside on.
  9959. Multi-volume archives suffer from several limitations. In particular,
  9960. they cannot be compressed.
  9961. @GNUTAR{} is able to create multi-volume archives of two formats
  9962. (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
  9963. @menu
  9964. * Multi-Volume Archives:: Archives Longer than One Tape or Disk
  9965. * Tape Files:: Tape Files
  9966. * Tarcat:: Concatenate Volumes into a Single Archive
  9967. @end menu
  9968. @node Multi-Volume Archives
  9969. @subsection Archives Longer than One Tape or Disk
  9970. @cindex Multi-volume archives
  9971. @opindex multi-volume
  9972. To create an archive that is larger than will fit on a single unit of
  9973. the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
  9974. the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
  9975. archive can be manipulated like any other archive (provided the
  9976. @option{--multi-volume} option is specified), but is stored on more
  9977. than one tape or file.
  9978. When you specify @option{--multi-volume}, @command{tar} does not report an
  9979. error when it comes to the end of an archive volume (when reading), or
  9980. the end of the media (when writing). Instead, it prompts you to load
  9981. a new storage volume. If the archive is on a magnetic tape, you
  9982. should change tapes when you see the prompt; if the archive is on a
  9983. floppy disk, you should change disks; etc.
  9984. @table @option
  9985. @item --multi-volume
  9986. @itemx -M
  9987. Creates a multi-volume archive, when used in conjunction with
  9988. @option{--create} (@option{-c}). To perform any other operation on a multi-volume
  9989. archive, specify @option{--multi-volume} in conjunction with that
  9990. operation.
  9991. For example:
  9992. @smallexample
  9993. $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
  9994. @end smallexample
  9995. @end table
  9996. The method @command{tar} uses to detect end of tape is not perfect, and
  9997. fails on some operating systems or on some devices. If @command{tar}
  9998. cannot detect the end of the tape itself, you can use
  9999. @option{--tape-length} option to inform it about the capacity of the
  10000. tape:
  10001. @anchor{tape-length}
  10002. @table @option
  10003. @opindex tape-length
  10004. @item --tape-length=@var{size}[@var{suf}]
  10005. @itemx -L @var{size}[@var{suf}]
  10006. Set maximum length of a volume. The @var{suf}, if given, specifies
  10007. units in which @var{size} is expressed, e.g. @samp{2M} mean 2
  10008. megabytes (@pxref{size-suffixes}, for a list of allowed size
  10009. suffixes). Without @var{suf}, units of 1024 bytes (kilobyte) are
  10010. assumed.
  10011. This option selects @option{--multi-volume} automatically. For example:
  10012. @smallexample
  10013. $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
  10014. @end smallexample
  10015. @noindent
  10016. or, which is equivalent:
  10017. @smallexample
  10018. $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
  10019. @end smallexample
  10020. @end table
  10021. @anchor{change volume prompt}
  10022. When @GNUTAR{} comes to the end of a storage media, it asks you to
  10023. change the volume. The built-in prompt for POSIX locale
  10024. is@footnote{If you run @GNUTAR{} under a different locale, the
  10025. translation to the locale's language will be used.}:
  10026. @smallexample
  10027. Prepare volume #@var{n} for '@var{archive}' and hit return:
  10028. @end smallexample
  10029. @noindent
  10030. where @var{n} is the ordinal number of the volume to be created and
  10031. @var{archive} is archive file or device name.
  10032. When prompting for a new tape, @command{tar} accepts any of the following
  10033. responses:
  10034. @table @kbd
  10035. @item ?
  10036. Request @command{tar} to explain possible responses.
  10037. @item q
  10038. Request @command{tar} to exit immediately.
  10039. @item n @var{file-name}
  10040. Request @command{tar} to write the next volume on the file @var{file-name}.
  10041. @item !
  10042. Request @command{tar} to run a subshell. This option can be disabled
  10043. by giving @option{--restrict} command line option to
  10044. @command{tar}@footnote{@xref{--restrict}, for more information about
  10045. this option.}.
  10046. @item y
  10047. Request @command{tar} to begin writing the next volume.
  10048. @end table
  10049. (You should only type @samp{y} after you have changed the tape;
  10050. otherwise @command{tar} will write over the volume it just finished.)
  10051. @cindex Volume number file
  10052. @cindex volno file
  10053. @anchor{volno-file}
  10054. @opindex volno-file
  10055. The volume number used by @command{tar} in its tape-changing prompt
  10056. can be changed; if you give the
  10057. @option{--volno-file=@var{file-of-number}} option, then
  10058. @var{file-of-number} should be an non-existing file to be created, or
  10059. else, a file already containing a decimal number. That number will be
  10060. used as the volume number of the first volume written. When
  10061. @command{tar} is finished, it will rewrite the file with the
  10062. now-current volume number. (This does not change the volume number
  10063. written on a tape label, as per @ref{label}, it @emph{only} affects
  10064. the number used in the prompt.)
  10065. @cindex End-of-archive info script
  10066. @cindex Info script
  10067. @anchor{info-script}
  10068. @opindex info-script
  10069. @opindex new-volume-script
  10070. If you want more elaborate behavior than this, you can write a special
  10071. @dfn{new volume script}, that will be responsible for changing the
  10072. volume, and instruct @command{tar} to use it instead of its normal
  10073. prompting procedure:
  10074. @table @option
  10075. @item --info-script=@var{command}
  10076. @itemx --new-volume-script=@var{command}
  10077. @itemx -F @var{command}
  10078. Specify the command to invoke when switching volumes. The @var{command}
  10079. can be used to eject cassettes, or to broadcast messages such as
  10080. @samp{Someone please come change my tape} when performing unattended
  10081. backups.
  10082. @end table
  10083. The @var{command} can contain additional options, if such are needed.
  10084. @xref{external, Running External Commands}, for a detailed discussion
  10085. of the way @GNUTAR{} runs external commands. It inherits
  10086. @command{tar}'s shell environment. Additional data is passed to it
  10087. via the following environment variables:
  10088. @table @env
  10089. @vrindex TAR_VERSION, info script environment variable
  10090. @item TAR_VERSION
  10091. @GNUTAR{} version number.
  10092. @vrindex TAR_ARCHIVE, info script environment variable
  10093. @item TAR_ARCHIVE
  10094. The name of the archive @command{tar} is processing.
  10095. @vrindex TAR_BLOCKING_FACTOR, info script environment variable
  10096. @item TAR_BLOCKING_FACTOR
  10097. Current blocking factor (@pxref{Blocking}).
  10098. @vrindex TAR_VOLUME, info script environment variable
  10099. @item TAR_VOLUME
  10100. Ordinal number of the volume @command{tar} is about to start.
  10101. @vrindex TAR_SUBCOMMAND, info script environment variable
  10102. @item TAR_SUBCOMMAND
  10103. A short option describing the operation @command{tar} is executing.
  10104. @xref{Operations}, for a complete list of subcommand options.
  10105. @vrindex TAR_FORMAT, info script environment variable
  10106. @item TAR_FORMAT
  10107. Format of the archive being processed. @xref{Formats}, for a complete
  10108. list of archive format names.
  10109. @vrindex TAR_FD, info script environment variable
  10110. @item TAR_FD
  10111. File descriptor which can be used to communicate the new volume
  10112. name to @command{tar}.
  10113. @end table
  10114. These variables can be used in the @var{command} itself, provided that
  10115. they are properly quoted to prevent them from being expanded by the
  10116. shell that invokes @command{tar}.
  10117. The volume script can instruct @command{tar} to use new archive name,
  10118. by writing in to file descriptor @env{$TAR_FD} (see below for an example).
  10119. If the info script fails, @command{tar} exits; otherwise, it begins
  10120. writing the next volume.
  10121. If you want @command{tar} to cycle through a series of files or tape
  10122. drives, there are three approaches to choose from. First of all, you
  10123. can give @command{tar} multiple @option{--file} options. In this case
  10124. the specified files will be used, in sequence, as the successive
  10125. volumes of the archive. Only when the first one in the sequence needs
  10126. to be used again will @command{tar} prompt for a tape change (or run
  10127. the info script). For example, suppose someone has two tape drives on
  10128. a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
  10129. @GNUTAR{} to switch to the second drive when it needs to write the
  10130. second tape, and then back to the first tape, etc., just do either of:
  10131. @smallexample
  10132. $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
  10133. $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
  10134. @end smallexample
  10135. The second method is to use the @samp{n} response to the tape-change
  10136. prompt.
  10137. Finally, the most flexible approach is to use a volume script, that
  10138. writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
  10139. following volume script will create a series of archive files, named
  10140. @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
  10141. archive being created (as given by @option{--file} option) and
  10142. @var{vol} is the ordinal number of the archive being created:
  10143. @smallexample
  10144. @group
  10145. #! /bin/bash
  10146. # For this script it's advisable to use a shell, such as Bash,
  10147. # that supports a TAR_FD value greater than 9.
  10148. echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
  10149. name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
  10150. case $TAR_SUBCOMMAND in
  10151. -c) ;;
  10152. -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
  10153. ;;
  10154. *) exit 1
  10155. esac
  10156. echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
  10157. @end group
  10158. @end smallexample
  10159. The same script can be used while listing, comparing or extracting
  10160. from the created archive. For example:
  10161. @smallexample
  10162. @group
  10163. # @r{Create a multi-volume archive:}
  10164. $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
  10165. # @r{Extract from the created archive:}
  10166. $ @kbd{tar -x -f archive.tar -F new-volume .}
  10167. @end group
  10168. @end smallexample
  10169. @noindent
  10170. Notice, that the first command had to use @option{-L} option, since
  10171. otherwise @GNUTAR{} will end up writing everything to file
  10172. @file{archive.tar}.
  10173. You can read each individual volume of a multi-volume archive as if it
  10174. were an archive by itself. For example, to list the contents of one
  10175. volume, use @option{--list}, without @option{--multi-volume} specified.
  10176. To extract an archive member from one volume (assuming it is described
  10177. that volume), use @option{--extract}, again without
  10178. @option{--multi-volume}.
  10179. If an archive member is split across volumes (i.e., its entry begins on
  10180. one volume of the media and ends on another), you need to specify
  10181. @option{--multi-volume} to extract it successfully. In this case, you
  10182. should load the volume where the archive member starts, and use
  10183. @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
  10184. volumes as it needs them. @xref{extracting archives}, for more
  10185. information about extracting archives.
  10186. Multi-volume archives can be modified like any other archive. To add
  10187. files to a multi-volume archive, you need to only mount the last
  10188. volume of the archive media (and new volumes, if needed). For all
  10189. other operations, you need to use the entire archive.
  10190. If a multi-volume archive was labeled using
  10191. @option{--label=@var{archive-label}} (@pxref{label}) when it was
  10192. created, @command{tar} will not automatically label volumes which are
  10193. added later. To label subsequent volumes, specify
  10194. @option{--label=@var{archive-label}} again in conjunction with the
  10195. @option{--append}, @option{--update} or @option{--concatenate} operation.
  10196. Notice that multi-volume support is a GNU extension and the archives
  10197. created in this mode should be read only using @GNUTAR{}. If you
  10198. absolutely have to process such archives using a third-party @command{tar}
  10199. implementation, read @ref{Split Recovery}.
  10200. @node Tape Files
  10201. @subsection Tape Files
  10202. @cindex labeling archives
  10203. @opindex label
  10204. @UNREVISED{}
  10205. To give the archive a name which will be recorded in it, use the
  10206. @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
  10207. option. This will write a special block identifying
  10208. @var{volume-label} as the name of the archive to the front of the
  10209. archive which will be displayed when the archive is listed with
  10210. @option{--list}. If you are creating a multi-volume archive with
  10211. @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
  10212. volume label will have @samp{Volume @var{nnn}} appended to the name
  10213. you give, where @var{nnn} is the number of the volume of the archive.
  10214. If you use the @option{--label=@var{volume-label}} option when
  10215. reading an archive, it checks to make sure the label on the tape
  10216. matches the one you gave. @xref{label}.
  10217. When @command{tar} writes an archive to tape, it creates a single
  10218. tape file. If multiple archives are written to the same tape, one
  10219. after the other, they each get written as separate tape files. When
  10220. extracting, it is necessary to position the tape at the right place
  10221. before running @command{tar}. To do this, use the @command{mt} command.
  10222. For more information on the @command{mt} command and on the organization
  10223. of tapes into a sequence of tape files, see @ref{mt}.
  10224. People seem to often do:
  10225. @smallexample
  10226. @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
  10227. @end smallexample
  10228. or such, for pushing a common date in all volumes or an archive set.
  10229. @node Tarcat
  10230. @subsection Concatenate Volumes into a Single Archive
  10231. @pindex tarcat
  10232. Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
  10233. archive to a single @command{tar} archive. Simply concatenating all
  10234. volumes into one will not work, since each volume carries an additional
  10235. information at the beginning. @GNUTAR{} is shipped with the shell
  10236. script @command{tarcat} designed for this purpose.
  10237. The script takes a list of files comprising a multi-volume archive
  10238. and creates the resulting archive at the standard output. For example:
  10239. @smallexample
  10240. @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
  10241. @end smallexample
  10242. The script implements a simple heuristics to determine the format of
  10243. the first volume file and to decide how to process the rest of the
  10244. files. However, it makes no attempt to verify whether the files are
  10245. given in order or even if they are valid @command{tar} archives.
  10246. It uses @command{dd} and does not filter its standard error, so you
  10247. will usually see lots of spurious messages.
  10248. @FIXME{The script is not installed. Should we install it?}
  10249. @node label
  10250. @section Including a Label in the Archive
  10251. @cindex Labeling an archive
  10252. @cindex Labels on the archive media
  10253. @cindex Labeling multi-volume archives
  10254. @opindex label
  10255. To avoid problems caused by misplaced paper labels on the archive
  10256. media, you can include a @dfn{label} entry --- an archive member which
  10257. contains the name of the archive --- in the archive itself. Use the
  10258. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  10259. option@footnote{Until version 1.10, that option was called
  10260. @option{--volume}, but is not available under that name anymore.} in
  10261. conjunction with the @option{--create} operation to include a label
  10262. entry in the archive as it is being created.
  10263. @table @option
  10264. @item --label=@var{archive-label}
  10265. @itemx -V @var{archive-label}
  10266. Includes an @dfn{archive-label} at the beginning of the archive when
  10267. the archive is being created, when used in conjunction with the
  10268. @option{--create} operation. Checks to make sure the archive label
  10269. matches the one specified (when used in conjunction with any other
  10270. operation).
  10271. @end table
  10272. If you create an archive using both
  10273. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  10274. and @option{--multi-volume} (@option{-M}), each volume of the archive
  10275. will have an archive label of the form @samp{@var{archive-label}
  10276. Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
  10277. next, and so on. @xref{Using Multiple Tapes}, for information on
  10278. creating multiple volume archives.
  10279. @cindex Volume label, listing
  10280. @cindex Listing volume label
  10281. The volume label will be displayed by @option{--list} along with
  10282. the file contents. If verbose display is requested, it will also be
  10283. explicitly marked as in the example below:
  10284. @smallexample
  10285. @group
  10286. $ @kbd{tar --verbose --list --file=iamanarchive}
  10287. V--------- 0/0 0 1992-03-07 12:01 iamalabel--Volume Header--
  10288. -rw-r--r-- ringo/user 40 1990-05-21 13:30 iamafilename
  10289. @end group
  10290. @end smallexample
  10291. @opindex test-label
  10292. @anchor{--test-label option}
  10293. However, @option{--list} option will cause listing entire
  10294. contents of the archive, which may be undesirable (for example, if the
  10295. archive is stored on a tape). You can request checking only the volume
  10296. label by specifying @option{--test-label} option. This option reads only the
  10297. first block of an archive, so it can be used with slow storage
  10298. devices. For example:
  10299. @smallexample
  10300. @group
  10301. $ @kbd{tar --test-label --file=iamanarchive}
  10302. iamalabel
  10303. @end group
  10304. @end smallexample
  10305. If @option{--test-label} is used with one or more command line
  10306. arguments, @command{tar} compares the volume label with each
  10307. argument. It exits with code 0 if a match is found, and with code 1
  10308. otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
  10309. mismatch with an exit code 2 and printed a spurious diagnostics on
  10310. stderr.}. No output is displayed, unless you also used the
  10311. @option{--verbose} option. For example:
  10312. @smallexample
  10313. @group
  10314. $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
  10315. @result{} 0
  10316. $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
  10317. @result{} 1
  10318. @end group
  10319. @end smallexample
  10320. When used with the @option{--verbose} option, @command{tar}
  10321. prints the actual volume label (if any), and a verbose diagnostics in
  10322. case of a mismatch:
  10323. @smallexample
  10324. @group
  10325. $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
  10326. iamalabel
  10327. @result{} 0
  10328. $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
  10329. iamalabel
  10330. tar: Archive label mismatch
  10331. @result{} 1
  10332. @end group
  10333. @end smallexample
  10334. If you request any operation, other than @option{--create}, along
  10335. with using @option{--label} option, @command{tar} will first check if
  10336. the archive label matches the one specified and will refuse to proceed
  10337. if it does not. Use this as a safety precaution to avoid accidentally
  10338. overwriting existing archives. For example, if you wish to add files
  10339. to @file{archive}, presumably labeled with string @samp{My volume},
  10340. you will get:
  10341. @smallexample
  10342. @group
  10343. $ @kbd{tar -rf archive --label 'My volume' .}
  10344. tar: Archive not labeled to match 'My volume'
  10345. @end group
  10346. @end smallexample
  10347. @noindent
  10348. in case its label does not match. This will work even if
  10349. @file{archive} is not labeled at all.
  10350. Similarly, @command{tar} will refuse to list or extract the
  10351. archive if its label doesn't match the @var{archive-label}
  10352. specified. In those cases, @var{archive-label} argument is interpreted
  10353. as a globbing-style pattern which must match the actual magnetic
  10354. volume label. @xref{exclude}, for a precise description of how match
  10355. is attempted@footnote{Previous versions of @command{tar} used full
  10356. regular expression matching, or before that, only exact string
  10357. matching, instead of wildcard matchers. We decided for the sake of
  10358. simplicity to use a uniform matching device through
  10359. @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
  10360. the volume label matcher will also suffix @var{archive-label} by
  10361. @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
  10362. up. Since the volume numbering is automatically added in labels at
  10363. creation time, it sounded logical to equally help the user taking care
  10364. of it when the archive is being read.
  10365. You can also use @option{--label} to get a common information on
  10366. all tapes of a series. For having this information different in each
  10367. series created through a single script used on a regular basis, just
  10368. manage to get some date string as part of the label. For example:
  10369. @smallexample
  10370. @group
  10371. $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
  10372. $ @kbd{tar --create --file=/dev/tape --multi-volume \
  10373. --label="Daily backup for `date +%Y-%m-%d`"}
  10374. @end group
  10375. @end smallexample
  10376. Some more notes about volume labels:
  10377. @itemize @bullet
  10378. @item Each label has its own date and time, which corresponds
  10379. to the time when @GNUTAR{} initially attempted to write it,
  10380. often soon after the operator launches @command{tar} or types the
  10381. carriage return telling that the next tape is ready.
  10382. @item Comparing date labels to get an idea of tape throughput is
  10383. unreliable. It gives correct results only if the delays for rewinding
  10384. tapes and the operator switching them were negligible, which is
  10385. usually not the case.
  10386. @end itemize
  10387. @node verify
  10388. @section Verifying Data as It is Stored
  10389. @cindex Verifying a write operation
  10390. @cindex Double-checking a write operation
  10391. @table @option
  10392. @item -W
  10393. @itemx --verify
  10394. @opindex verify, short description
  10395. Attempt to verify the archive after writing.
  10396. @end table
  10397. This option causes @command{tar} to verify the archive after writing it.
  10398. Each volume is checked after it is written, and any discrepancies
  10399. are recorded on the standard error output.
  10400. Verification requires that the archive be on a back-space-able medium.
  10401. This means pipes, some cartridge tape drives, and some other devices
  10402. cannot be verified.
  10403. You can insure the accuracy of an archive by comparing files in the
  10404. system with archive members. @command{tar} can compare an archive to the
  10405. file system as the archive is being written, to verify a write
  10406. operation, or can compare a previously written archive, to insure that
  10407. it is up to date.
  10408. @xopindex{verify, using with @option{--create}}
  10409. @xopindex{create, using with @option{--verify}}
  10410. To check for discrepancies in an archive immediately after it is
  10411. written, use the @option{--verify} (@option{-W}) option in conjunction with
  10412. the @option{--create} operation. When this option is
  10413. specified, @command{tar} checks archive members against their counterparts
  10414. in the file system, and reports discrepancies on the standard error.
  10415. To verify an archive, you must be able to read it from before the end
  10416. of the last written entry. This option is useful for detecting data
  10417. errors on some tapes. Archives written to pipes, some cartridge tape
  10418. drives, and some other devices cannot be verified.
  10419. One can explicitly compare an already made archive with the file
  10420. system by using the @option{--compare} (@option{--diff}, @option{-d})
  10421. option, instead of using the more automatic @option{--verify} option.
  10422. @xref{compare}.
  10423. Note that these two options have a slightly different intent. The
  10424. @option{--compare} option checks how identical are the logical contents of some
  10425. archive with what is on your disks, while the @option{--verify} option is
  10426. really for checking if the physical contents agree and if the recording
  10427. media itself is of dependable quality. So, for the @option{--verify}
  10428. operation, @command{tar} tries to defeat all in-memory cache pertaining to
  10429. the archive, while it lets the speed optimization undisturbed for the
  10430. @option{--compare} option. If you nevertheless use @option{--compare} for
  10431. media verification, you may have to defeat the in-memory cache yourself,
  10432. maybe by opening and reclosing the door latch of your recording unit,
  10433. forcing some doubt in your operating system about the fact this is really
  10434. the same volume as the one just written or read.
  10435. The @option{--verify} option would not be necessary if drivers were indeed
  10436. able to detect dependably all write failures. This sometimes require many
  10437. magnetic heads, some able to read after the writes occurred. One would
  10438. not say that drivers unable to detect all cases are necessarily flawed,
  10439. as long as programming is concerned.
  10440. The @option{--verify} (@option{-W}) option will not work in
  10441. conjunction with the @option{--multi-volume} (@option{-M}) option or
  10442. the @option{--append} (@option{-r}), @option{--update} (@option{-u})
  10443. and @option{--delete} operations. @xref{Operations}, for more
  10444. information on these operations.
  10445. Also, since @command{tar} normally strips leading @samp{/} from file
  10446. names (@pxref{absolute}), a command like @samp{tar --verify -cf
  10447. /tmp/foo.tar /etc} will work as desired only if the working directory is
  10448. @file{/}, as @command{tar} uses the archive's relative member names
  10449. (e.g., @file{etc/motd}) when verifying the archive.
  10450. @node Write Protection
  10451. @section Write Protection
  10452. Almost all tapes and diskettes, and in a few rare cases, even disks can
  10453. be @dfn{write protected}, to protect data on them from being changed.
  10454. Once an archive is written, you should write protect the media to prevent
  10455. the archive from being accidentally overwritten or deleted. (This will
  10456. protect the archive from being changed with a tape or floppy drive---it
  10457. will not protect it from magnet fields or other physical hazards.)
  10458. The write protection device itself is usually an integral part of the
  10459. physical media, and can be a two position (write enabled/write
  10460. disabled) switch, a notch which can be popped out or covered, a ring
  10461. which can be removed from the center of a tape reel, or some other
  10462. changeable feature.
  10463. @node Reliability and security
  10464. @chapter Reliability and Security
  10465. The @command{tar} command reads and writes files as any other
  10466. application does, and is subject to the usual caveats about
  10467. reliability and security. This section contains some commonsense
  10468. advice on the topic.
  10469. @menu
  10470. * Reliability::
  10471. * Security::
  10472. @end menu
  10473. @node Reliability
  10474. @section Reliability
  10475. Ideally, when @command{tar} is creating an archive, it reads from a
  10476. file system that is not being modified, and encounters no errors or
  10477. inconsistencies while reading and writing. If this is the case, the
  10478. archive should faithfully reflect what was read. Similarly, when
  10479. extracting from an archive, ideally @command{tar} ideally encounters
  10480. no errors and the extracted files faithfully reflect what was in the
  10481. archive.
  10482. However, when reading or writing real-world file systems, several
  10483. things can go wrong; these include permissions problems, corruption of
  10484. data, and race conditions.
  10485. @menu
  10486. * Permissions problems::
  10487. * Data corruption and repair::
  10488. * Race conditions::
  10489. @end menu
  10490. @node Permissions problems
  10491. @subsection Permissions Problems
  10492. If @command{tar} encounters errors while reading or writing files, it
  10493. normally reports an error and exits with nonzero status. The work it
  10494. does may therefore be incomplete. For example, when creating an
  10495. archive, if @command{tar} cannot read a file then it cannot copy the
  10496. file into the archive.
  10497. @node Data corruption and repair
  10498. @subsection Data Corruption and Repair
  10499. If an archive becomes corrupted by an I/O error, this may corrupt the
  10500. data in an extracted file. Worse, it may corrupt the file's metadata,
  10501. which may cause later parts of the archive to become misinterpreted.
  10502. An tar-format archive contains a checksum that most likely will detect
  10503. errors in the metadata, but it will not detect errors in the data.
  10504. If data corruption is a concern, you can compute and check your own
  10505. checksums of an archive by using other programs, such as
  10506. @command{cksum}.
  10507. When attempting to recover from a read error or data corruption in an
  10508. archive, you may need to skip past the questionable data and read the
  10509. rest of the archive. This requires some expertise in the archive
  10510. format and in other software tools.
  10511. @node Race conditions
  10512. @subsection Race conditions
  10513. If some other process is modifying the file system while @command{tar}
  10514. is reading or writing files, the result may well be inconsistent due
  10515. to race conditions. For example, if another process creates some
  10516. files in a directory while @command{tar} is creating an archive
  10517. containing the directory's files, @command{tar} may see some of the
  10518. files but not others, or it may see a file that is in the process of
  10519. being created. The resulting archive may not be a snapshot of the
  10520. file system at any point in time. If an application such as a
  10521. database system depends on an accurate snapshot, restoring from the
  10522. @command{tar} archive of a live file system may therefore break that
  10523. consistency and may break the application. The simplest way to avoid
  10524. the consistency issues is to avoid making other changes to the file
  10525. system while tar is reading it or writing it.
  10526. When creating an archive, several options are available to avoid race
  10527. conditions. Some hosts have a way of snapshotting a file system, or
  10528. of temporarily suspending all changes to a file system, by (say)
  10529. suspending the only virtual machine that can modify a file system; if
  10530. you use these facilities and have @command{tar -c} read from a
  10531. snapshot when creating an archive, you can avoid inconsistency
  10532. problems. More drastically, before starting @command{tar} you could
  10533. suspend or shut down all processes other than @command{tar} that have
  10534. access to the file system, or you could unmount the file system and
  10535. then mount it read-only.
  10536. When extracting from an archive, one approach to avoid race conditions
  10537. is to create a directory that no other process can write to, and
  10538. extract into that.
  10539. @node Security
  10540. @section Security
  10541. In some cases @command{tar} may be used in an adversarial situation,
  10542. where an untrusted user is attempting to gain information about or
  10543. modify otherwise-inaccessible files. Dealing with untrusted data
  10544. (that is, data generated by an untrusted user) typically requires
  10545. extra care, because even the smallest mistake in the use of
  10546. @command{tar} is more likely to be exploited by an adversary than by a
  10547. race condition.
  10548. @menu
  10549. * Privacy::
  10550. * Integrity::
  10551. * Live untrusted data::
  10552. * Security rules of thumb::
  10553. @end menu
  10554. @node Privacy
  10555. @subsection Privacy
  10556. Standard privacy concerns apply when using @command{tar}. For
  10557. example, suppose you are archiving your home directory into a file
  10558. @file{/archive/myhome.tar}. Any secret information in your home
  10559. directory, such as your SSH secret keys, are copied faithfully into
  10560. the archive. Therefore, if your home directory contains any file that
  10561. should not be read by some other user, the archive itself should be
  10562. not be readable by that user. And even if the archive's data are
  10563. inaccessible to untrusted users, its metadata (such as size or
  10564. last-modified date) may reveal some information about your home
  10565. directory; if the metadata are intended to be private, the archive's
  10566. parent directory should also be inaccessible to untrusted users.
  10567. One precaution is to create @file{/archive} so that it is not
  10568. accessible to any user, unless that user also has permission to access
  10569. all the files in your home directory.
  10570. Similarly, when extracting from an archive, take care that the
  10571. permissions of the extracted files are not more generous than what you
  10572. want. Even if the archive itself is readable only to you, files
  10573. extracted from it have their own permissions that may differ.
  10574. @node Integrity
  10575. @subsection Integrity
  10576. When creating archives, take care that they are not writable by a
  10577. untrusted user; otherwise, that user could modify the archive, and
  10578. when you later extract from the archive you will get incorrect data.
  10579. When @command{tar} extracts from an archive, by default it writes into
  10580. files relative to the working directory. If the archive was generated
  10581. by an untrusted user, that user therefore can write into any file
  10582. under the working directory. If the working directory contains a
  10583. symbolic link to another directory, the untrusted user can also write
  10584. into any file under the referenced directory. When extracting from an
  10585. untrusted archive, it is therefore good practice to create an empty
  10586. directory and run @command{tar} in that directory.
  10587. When extracting from two or more untrusted archives, each one should
  10588. be extracted independently, into different empty directories.
  10589. Otherwise, the first archive could create a symbolic link into an area
  10590. outside the working directory, and the second one could follow the
  10591. link and overwrite data that is not under the working directory. For
  10592. example, when restoring from a series of incremental dumps, the
  10593. archives should have been created by a trusted process, as otherwise
  10594. the incremental restores might alter data outside the working
  10595. directory.
  10596. If you use the @option{--absolute-names} (@option{-P}) option when
  10597. extracting, @command{tar} respects any file names in the archive, even
  10598. file names that begin with @file{/} or contain @file{..}. As this
  10599. lets the archive overwrite any file in your system that you can write,
  10600. the @option{--absolute-names} (@option{-P}) option should be used only
  10601. for trusted archives.
  10602. Conversely, with the @option{--keep-old-files} (@option{-k}) and
  10603. @option{--skip-old-files} options, @command{tar} refuses to replace
  10604. existing files when extracting. The difference between the two
  10605. options is that the former treats existing files as errors whereas the
  10606. latter just silently ignores them.
  10607. Finally, with the @option{--no-overwrite-dir} option, @command{tar}
  10608. refuses to replace the permissions or ownership of already-existing
  10609. directories. These options may help when extracting from untrusted
  10610. archives.
  10611. @node Live untrusted data
  10612. @subsection Dealing with Live Untrusted Data
  10613. Extra care is required when creating from or extracting into a file
  10614. system that is accessible to untrusted users. For example, superusers
  10615. who invoke @command{tar} must be wary about its actions being hijacked
  10616. by an adversary who is reading or writing the file system at the same
  10617. time that @command{tar} is operating.
  10618. When creating an archive from a live file system, @command{tar} is
  10619. vulnerable to denial-of-service attacks. For example, an adversarial
  10620. user could create the illusion of an indefinitely-deep directory
  10621. hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
  10622. @command{tar}, or the illusion of an indefinitely-long file by
  10623. creating a sparse file but arranging for blocks to be allocated just
  10624. before @command{tar} reads them. There is no easy way for
  10625. @command{tar} to distinguish these scenarios from legitimate uses, so
  10626. you may need to monitor @command{tar}, just as you'd need to monitor
  10627. any other system service, to detect such attacks.
  10628. While a superuser is extracting from an archive into a live file
  10629. system, an untrusted user might replace a directory with a symbolic
  10630. link, in hopes that @command{tar} will follow the symbolic link and
  10631. extract data into files that the untrusted user does not have access
  10632. to. Even if the archive was generated by the superuser, it may
  10633. contain a file such as @file{d/etc/passwd} that the untrusted user
  10634. earlier created in order to break in; if the untrusted user replaces
  10635. the directory @file{d/etc} with a symbolic link to @file{/etc} while
  10636. @command{tar} is running, @command{tar} will overwrite
  10637. @file{/etc/passwd}. This attack can be prevented by extracting into a
  10638. directory that is inaccessible to untrusted users.
  10639. Similar attacks via symbolic links are also possible when creating an
  10640. archive, if the untrusted user can modify an ancestor of a top-level
  10641. argument of @command{tar}. For example, an untrusted user that can
  10642. modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
  10643. - /home/eve/Documents/yesterday} by replacing
  10644. @file{/home/eve/Documents} with a symbolic link to some other
  10645. location. Attacks like these can be prevented by making sure that
  10646. untrusted users cannot modify any files that are top-level arguments
  10647. to @command{tar}, or any ancestor directories of these files.
  10648. @node Security rules of thumb
  10649. @subsection Security Rules of Thumb
  10650. This section briefly summarizes rules of thumb for avoiding security
  10651. pitfalls.
  10652. @itemize @bullet
  10653. @item
  10654. Protect archives at least as much as you protect any of the files
  10655. being archived.
  10656. @item
  10657. Extract from an untrusted archive only into an otherwise-empty
  10658. directory. This directory and its parent should be accessible only to
  10659. trusted users. For example:
  10660. @example
  10661. @group
  10662. $ @kbd{chmod go-rwx .}
  10663. $ @kbd{mkdir -m go-rwx dir}
  10664. $ @kbd{cd dir}
  10665. $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
  10666. @end group
  10667. @end example
  10668. As a corollary, do not do an incremental restore from an untrusted archive.
  10669. @item
  10670. Do not let untrusted users access files extracted from untrusted
  10671. archives without checking first for problems such as setuid programs.
  10672. @item
  10673. Do not let untrusted users modify directories that are ancestors of
  10674. top-level arguments of @command{tar}. For example, while you are
  10675. executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
  10676. untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
  10677. @item
  10678. Pay attention to the diagnostics and exit status of @command{tar}.
  10679. @item
  10680. When archiving live file systems, monitor running instances of
  10681. @command{tar} to detect denial-of-service attacks.
  10682. @item
  10683. Avoid unusual options such as @option{--absolute-names} (@option{-P}),
  10684. @option{--dereference} (@option{-h}), @option{--overwrite},
  10685. @option{--recursive-unlink}, and @option{--remove-files} unless you
  10686. understand their security implications.
  10687. @end itemize
  10688. @node Changes
  10689. @appendix Changes
  10690. This appendix lists some important user-visible changes between
  10691. various versions of @GNUTAR{}. An up-to-date version of this document
  10692. is available at
  10693. @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
  10694. @GNUTAR{} documentation page}.
  10695. @table @asis
  10696. @item Use of globbing patterns when listing and extracting.
  10697. Previous versions of GNU tar assumed shell-style globbing when
  10698. extracting from or listing an archive. For example:
  10699. @smallexample
  10700. $ @kbd{tar xf foo.tar '*.c'}
  10701. @end smallexample
  10702. would extract all files whose names end in @samp{.c}. This behavior
  10703. was not documented and was incompatible with traditional tar
  10704. implementations. Therefore, starting from version 1.15.91, GNU tar
  10705. no longer uses globbing by default. For example, the above invocation
  10706. is now interpreted as a request to extract from the archive the file
  10707. named @file{*.c}.
  10708. To facilitate transition to the new behavior for those users who got
  10709. used to the previous incorrect one, @command{tar} will print a warning
  10710. if it finds out that a requested member was not found in the archive
  10711. and its name looks like a globbing pattern. For example:
  10712. @smallexample
  10713. $ @kbd{tar xf foo.tar '*.c'}
  10714. tar: Pattern matching characters used in file names. Please,
  10715. tar: use --wildcards to enable pattern matching, or --no-wildcards to
  10716. tar: suppress this warning.
  10717. tar: *.c: Not found in archive
  10718. tar: Error exit delayed from previous errors
  10719. @end smallexample
  10720. To treat member names as globbing patterns, use the @option{--wildcards} option.
  10721. If you want to tar to mimic the behavior of versions prior to 1.15.91,
  10722. add this option to your @env{TAR_OPTIONS} variable.
  10723. @xref{wildcards}, for the detailed discussion of the use of globbing
  10724. patterns by @GNUTAR{}.
  10725. @item Use of short option @option{-o}.
  10726. Earlier versions of @GNUTAR{} understood @option{-o} command line
  10727. option as a synonym for @option{--old-archive}.
  10728. @GNUTAR{} starting from version 1.13.90 understands this option as
  10729. a synonym for @option{--no-same-owner}. This is compatible with
  10730. UNIX98 @command{tar} implementations.
  10731. However, to facilitate transition, @option{-o} option retains its
  10732. old semantics when it is used with one of archive-creation commands.
  10733. Users are encouraged to use @option{--format=oldgnu} instead.
  10734. It is especially important, since versions of @acronym{GNU} Automake
  10735. up to and including 1.8.4 invoke tar with this option to produce
  10736. distribution tarballs. @xref{Formats,v7}, for the detailed discussion
  10737. of this issue and its implications.
  10738. @xref{Options, tar-formats, Changing Automake's Behavior,
  10739. automake, GNU Automake}, for a description on how to use various
  10740. archive formats with @command{automake}.
  10741. Future versions of @GNUTAR{} will understand @option{-o} only as a
  10742. synonym for @option{--no-same-owner}.
  10743. @item Use of short option @option{-l}
  10744. Earlier versions of @GNUTAR{} understood @option{-l} option as a
  10745. synonym for @option{--one-file-system}. Since such usage contradicted
  10746. to UNIX98 specification and harmed compatibility with other
  10747. implementations, it was declared deprecated in version 1.14. However,
  10748. to facilitate transition to its new semantics, it was supported by
  10749. versions 1.15 and 1.15.90. The present use of @option{-l} as a short
  10750. variant of @option{--check-links} was introduced in version 1.15.91.
  10751. @item Use of options @option{--portability} and @option{--old-archive}
  10752. These options are deprecated. Please use @option{--format=v7} instead.
  10753. @item Use of option @option{--posix}
  10754. This option is deprecated. Please use @option{--format=posix} instead.
  10755. @end table
  10756. @node Recipes
  10757. @appendix Recipes
  10758. @include recipes.texi
  10759. @node Configuring Help Summary
  10760. @appendix Configuring Help Summary
  10761. Running @kbd{tar --help} displays the short @command{tar} option
  10762. summary (@pxref{help}). This summary is organized by @dfn{groups} of
  10763. semantically close options. The options within each group are printed
  10764. in the following order: a short option, eventually followed by a list
  10765. of corresponding long option names, followed by a short description of
  10766. the option. For example, here is an excerpt from the actual @kbd{tar
  10767. --help} output:
  10768. @verbatim
  10769. Main operation mode:
  10770. -A, --catenate, --concatenate append tar files to an archive
  10771. -c, --create create a new archive
  10772. -d, --diff, --compare find differences between archive and
  10773. file system
  10774. --delete delete from the archive
  10775. @end verbatim
  10776. @vrindex ARGP_HELP_FMT, environment variable
  10777. The exact visual representation of the help output is configurable via
  10778. @env{ARGP_HELP_FMT} environment variable. The value of this variable
  10779. is a comma-separated list of @dfn{format variable} assignments. There
  10780. are two kinds of format variables. An @dfn{offset variable} keeps the
  10781. offset of some part of help output text from the leftmost column on
  10782. the screen. A @dfn{boolean} variable is a flag that toggles some
  10783. output feature on or off. Depending on the type of the corresponding
  10784. variable, there are two kinds of assignments:
  10785. @table @asis
  10786. @item Offset assignment
  10787. The assignment to an offset variable has the following syntax:
  10788. @smallexample
  10789. @var{variable}=@var{value}
  10790. @end smallexample
  10791. @noindent
  10792. where @var{variable} is the variable name, and @var{value} is a
  10793. numeric value to be assigned to the variable.
  10794. @item Boolean assignment
  10795. To assign @code{true} value to a variable, simply put this variable name. To
  10796. assign @code{false} value, prefix the variable name with @samp{no-}. For
  10797. example:
  10798. @smallexample
  10799. @group
  10800. # Assign @code{true} value:
  10801. dup-args
  10802. # Assign @code{false} value:
  10803. no-dup-args
  10804. @end group
  10805. @end smallexample
  10806. @end table
  10807. Following variables are declared:
  10808. @deftypevr {Help Output} boolean dup-args
  10809. If true, arguments for an option are shown with both short and long
  10810. options, even when a given option has both forms, for example:
  10811. @smallexample
  10812. -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
  10813. @end smallexample
  10814. If false, then if an option has both short and long forms, the
  10815. argument is only shown with the long one, for example:
  10816. @smallexample
  10817. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10818. @end smallexample
  10819. @noindent
  10820. and a message indicating that the argument is applicable to both
  10821. forms is printed below the options. This message can be disabled
  10822. using @code{dup-args-note} (see below).
  10823. The default is false.
  10824. @end deftypevr
  10825. @deftypevr {Help Output} boolean dup-args-note
  10826. If this variable is true, which is the default, the following notice
  10827. is displayed at the end of the help output:
  10828. @quotation
  10829. Mandatory or optional arguments to long options are also mandatory or
  10830. optional for any corresponding short options.
  10831. @end quotation
  10832. Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
  10833. variables @code{dup-args} or @code{dup-args-note} should be set.
  10834. @end deftypevr
  10835. @deftypevr {Help Output} offset short-opt-col
  10836. Column in which short options start. Default is 2.
  10837. @smallexample
  10838. @group
  10839. $ @kbd{tar --help|grep ARCHIVE}
  10840. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10841. $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
  10842. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10843. @end group
  10844. @end smallexample
  10845. @end deftypevr
  10846. @deftypevr {Help Output} offset long-opt-col
  10847. Column in which long options start. Default is 6. For example:
  10848. @smallexample
  10849. @group
  10850. $ @kbd{tar --help|grep ARCHIVE}
  10851. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10852. $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
  10853. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10854. @end group
  10855. @end smallexample
  10856. @end deftypevr
  10857. @deftypevr {Help Output} offset doc-opt-col
  10858. Column in which @dfn{doc options} start. A doc option isn't actually
  10859. an option, but rather an arbitrary piece of documentation that is
  10860. displayed in much the same manner as the options. For example, in
  10861. the description of @option{--format} option:
  10862. @smallexample
  10863. @group
  10864. -H, --format=FORMAT create archive of the given format.
  10865. FORMAT is one of the following:
  10866. gnu GNU tar 1.13.x format
  10867. oldgnu GNU format as per tar <= 1.12
  10868. pax POSIX 1003.1-2001 (pax) format
  10869. posix same as pax
  10870. ustar POSIX 1003.1-1988 (ustar) format
  10871. v7 old V7 tar format
  10872. @end group
  10873. @end smallexample
  10874. @noindent
  10875. the format names are doc options. Thus, if you set
  10876. @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
  10877. will look as follows:
  10878. @smallexample
  10879. @group
  10880. -H, --format=FORMAT create archive of the given format.
  10881. FORMAT is one of the following:
  10882. gnu GNU tar 1.13.x format
  10883. oldgnu GNU format as per tar <= 1.12
  10884. pax POSIX 1003.1-2001 (pax) format
  10885. posix same as pax
  10886. ustar POSIX 1003.1-1988 (ustar) format
  10887. v7 old V7 tar format
  10888. @end group
  10889. @end smallexample
  10890. @end deftypevr
  10891. @deftypevr {Help Output} offset opt-doc-col
  10892. Column in which option description starts. Default is 29.
  10893. @smallexample
  10894. @group
  10895. $ @kbd{tar --help|grep ARCHIVE}
  10896. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10897. $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
  10898. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10899. $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
  10900. -f, --file=ARCHIVE
  10901. use archive file or device ARCHIVE
  10902. @end group
  10903. @end smallexample
  10904. @noindent
  10905. Notice, that the description starts on a separate line if
  10906. @code{opt-doc-col} value is too small.
  10907. @end deftypevr
  10908. @deftypevr {Help Output} offset header-col
  10909. Column in which @dfn{group headers} are printed. A group header is a
  10910. descriptive text preceding an option group. For example, in the
  10911. following text:
  10912. @verbatim
  10913. Main operation mode:
  10914. -A, --catenate, --concatenate append tar files to
  10915. an archive
  10916. -c, --create create a new archive
  10917. @end verbatim
  10918. @noindent
  10919. @samp{Main operation mode:} is the group header.
  10920. The default value is 1.
  10921. @end deftypevr
  10922. @deftypevr {Help Output} offset usage-indent
  10923. Indentation of wrapped usage lines. Affects @option{--usage}
  10924. output. Default is 12.
  10925. @end deftypevr
  10926. @deftypevr {Help Output} offset rmargin
  10927. Right margin of the text output. Used for wrapping.
  10928. @end deftypevr
  10929. @node Fixing Snapshot Files
  10930. @appendix Fixing Snapshot Files
  10931. @include tar-snapshot-edit.texi
  10932. @node Tar Internals
  10933. @appendix Tar Internals
  10934. @include intern.texi
  10935. @node Genfile
  10936. @appendix Genfile
  10937. @include genfile.texi
  10938. @node GNU Free Documentation License
  10939. @appendix GNU Free Documentation License
  10940. @include fdl.texi
  10941. @node Index of Command Line Options
  10942. @appendix Index of Command Line Options
  10943. This appendix contains an index of all @GNUTAR{} long command line
  10944. options. The options are listed without the preceding double-dash.
  10945. For a cross-reference of short command line options, see
  10946. @ref{Short Option Summary}.
  10947. @printindex op
  10948. @node Index
  10949. @appendix Index
  10950. @printindex cp
  10951. @summarycontents
  10952. @contents
  10953. @bye
  10954. @c Local variables:
  10955. @c texinfo-column-for-description: 32
  10956. @c End: