4
0

tar.texi 495 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552
  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, coreutils, GNU core 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{[email protected]} 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. Notice, that since @command{tar} operates on @dfn{records}, the number
  3307. of bytes reported can be rounded up to the nearest full record. This
  3308. can happen, in particular, when the last record in the archive is
  3309. partial. @xref{Blocking}.
  3310. Finally, when deleting from an archive, the @option{--totals} option
  3311. displays both numbers plus number of bytes removed from the archive:
  3312. @smallexample
  3313. @group
  3314. $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
  3315. Total bytes read: 9543680 (9.2MiB, 201MiB/s)
  3316. Total bytes written: 3829760 (3.7MiB, 81MiB/s)
  3317. Total bytes deleted: 1474048
  3318. @end group
  3319. @end smallexample
  3320. You can also obtain this information on request. When
  3321. @option{--totals} is used with an argument, this argument is
  3322. interpreted as a symbolic name of a signal, upon delivery of which the
  3323. statistics is to be printed:
  3324. @table @option
  3325. @item --totals=@var{signo}
  3326. Print statistics upon delivery of signal @var{signo}. Valid arguments
  3327. are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
  3328. @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
  3329. accepted.
  3330. @end table
  3331. Both forms of @option{--totals} option can be used simultaneously.
  3332. Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
  3333. extract all members from its default archive and print statistics
  3334. after finishing the extraction, as well as when receiving signal
  3335. @code{SIGUSR1}.
  3336. @anchor{Progress information}
  3337. @cindex Progress information
  3338. The @option{--checkpoint} option prints an occasional message
  3339. as @command{tar} reads or writes the archive. It is designed for
  3340. those who don't need the more detailed (and voluminous) output of
  3341. @option{--block-number} (@option{-R}), but do want visual confirmation
  3342. that @command{tar} is actually making forward progress. By default it
  3343. prints a message each 10 records read or written. This can be changed
  3344. by giving it a numeric argument after an equal sign:
  3345. @smallexample
  3346. $ @kbd{tar -c --checkpoint=1000} /var
  3347. tar: Write checkpoint 1000
  3348. tar: Write checkpoint 2000
  3349. tar: Write checkpoint 3000
  3350. @end smallexample
  3351. This example shows the default checkpoint message used by
  3352. @command{tar}. If you place a dot immediately after the equal
  3353. sign, it will print a @samp{.} at each checkpoint@footnote{This is
  3354. actually a shortcut for @option{--checkpoint=@var{n}
  3355. --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
  3356. @smallexample
  3357. $ @kbd{tar -c --checkpoint=.1000} /var
  3358. ...
  3359. @end smallexample
  3360. The @option{--checkpoint} option provides a flexible mechanism for
  3361. executing arbitrary actions upon hitting checkpoints, see the next
  3362. section (@pxref{checkpoints}), for more information on it.
  3363. @opindex show-omitted-dirs
  3364. @anchor{show-omitted-dirs}
  3365. The @option{--show-omitted-dirs} option, when reading an archive---with
  3366. @option{--list} or @option{--extract}, for example---causes a message
  3367. to be printed for each directory in the archive which is skipped.
  3368. This happens regardless of the reason for skipping: the directory might
  3369. not have been named on the command line (implicitly or explicitly),
  3370. it might be excluded by the use of the
  3371. @option{--exclude=@var{pattern}} option, or some other reason.
  3372. @opindex block-number
  3373. @cindex Block number where error occurred
  3374. @anchor{block-number}
  3375. If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
  3376. every message it would normally produce, the block number within the
  3377. archive where the message was triggered. Also, supplementary messages
  3378. are triggered when reading blocks full of NULs, or when hitting end of
  3379. file on the archive. As of now, if the archive is properly terminated
  3380. with a NUL block, the reading of the file may stop before end of file
  3381. is met, so the position of end of file will not usually show when
  3382. @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
  3383. drains the archive before exiting when reading the
  3384. archive from a pipe.
  3385. @cindex Error message, block number of
  3386. This option is especially useful when reading damaged archives, since
  3387. it helps pinpoint the damaged sections. It can also be used with
  3388. @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
  3389. choose among several backup tapes when retrieving a file later, in
  3390. favor of the tape where the file appears earliest (closest to the
  3391. front of the tape). @xref{backup}.
  3392. @node checkpoints
  3393. @section Checkpoints
  3394. @cindex checkpoints, defined
  3395. @opindex checkpoint
  3396. @opindex checkpoint-action
  3397. A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
  3398. the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
  3399. from the archive (a @dfn{read checkpoint}). Checkpoints allow to
  3400. periodically execute arbitrary actions.
  3401. The checkpoint facility is enabled using the following option:
  3402. @table @option
  3403. @xopindex{checkpoint, defined}
  3404. @item --checkpoint[=@var{n}]
  3405. Schedule checkpoints before writing or reading each @var{n}th record.
  3406. The default value for @var{n} is 10.
  3407. @end table
  3408. A list of arbitrary @dfn{actions} can be executed at each checkpoint.
  3409. These actions include: pausing, displaying textual messages, and
  3410. executing arbitrary external programs. Actions are defined using
  3411. the @option{--checkpoint-action} option.
  3412. @table @option
  3413. @xopindex{checkpoint-action, defined}
  3414. @item --checkpoint-action=@var{action}
  3415. Execute an @var{action} at each checkpoint.
  3416. @end table
  3417. @cindex @code{echo}, checkpoint action
  3418. The simplest value of @var{action} is @samp{echo}. It instructs
  3419. @command{tar} to display the default message on the standard error
  3420. stream upon arriving at each checkpoint. The default message is (in
  3421. @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
  3422. checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
  3423. Here, @var{n} represents ordinal number of the checkpoint.
  3424. In another locales, translated versions of this message are used.
  3425. This is the default action, so running:
  3426. @smallexample
  3427. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
  3428. @end smallexample
  3429. @noindent
  3430. is equivalent to:
  3431. @smallexample
  3432. $ @kbd{tar -c --checkpoint=1000} /var
  3433. @end smallexample
  3434. The @samp{echo} action also allows to supply a customized message.
  3435. You do so by placing an equals sign and the message right after it,
  3436. e.g.:
  3437. @smallexample
  3438. --checkpoint-action="echo=Hit %s checkpoint #%u"
  3439. @end smallexample
  3440. The @samp{%s} and @samp{%u} in the above example are
  3441. @dfn{format specifiers}. The @samp{%s} specifier is replaced with
  3442. the @dfn{type} of the checkpoint: @samp{write} or
  3443. @samp{read} (or a corresponding translated version in locales other
  3444. than @acronym{POSIX}). The @samp{%u} specifier is replaced with
  3445. the ordinal number of the checkpoint. Thus, the above example could
  3446. produce the following output when used with the @option{--create}
  3447. option:
  3448. @smallexample
  3449. tar: Hit write checkpoint #10
  3450. tar: Hit write checkpoint #20
  3451. tar: Hit write checkpoint #30
  3452. @end smallexample
  3453. The complete list of available format specifiers follows. Some of
  3454. them can take optional arguments. These arguments, if given, are
  3455. supplied in curly braces between the percent sign and the specifier
  3456. letter.
  3457. @table @samp
  3458. @item %s
  3459. Print type of the checkpoint (@samp{write} or @samp{read}).
  3460. @item %u
  3461. Print number of the checkpoint.
  3462. @item %@{r,w,d@}T
  3463. Print number of bytes transferred so far and approximate transfer
  3464. speed. Optional arguments supply prefixes to be used before number
  3465. of bytes read, written and deleted, correspondingly. If absent,
  3466. they default to @samp{R}. @samp{W}, @samp{D}. Any or all of them can
  3467. be omitted, so, that e.g. @samp{%@{@}T} means to print corresponding
  3468. statistics without any prefixes. Any surplus arguments, if present,
  3469. are silently ignored.
  3470. @example
  3471. $ @kbd{tar --delete -f f.tar --checkpoint-action=echo="#%u: %T" main.c}
  3472. tar: #1: R: 0 (0B, 0B/s),W: 0 (0B, 0B/s),D: 0
  3473. tar: #2: R: 10240 (10KiB, 19MiB/s),W: 0 (0B, 0B/s),D: 10240
  3474. @end example
  3475. @noindent
  3476. See also the @samp{totals} action, described below.
  3477. @item %@{@var{fmt}@}t
  3478. Output current local time using @var{fmt} as format for @command{strftime}
  3479. (@pxref{strftime, strftime,,strftime(3), strftime(3) man page}). The
  3480. @samp{@{@var{fmt}@}} part is optional. If not present, the default
  3481. format is @samp{%c}, i.e. the preferred date and time representation
  3482. for the current locale.
  3483. @item %@{@var{n}@}*
  3484. Pad output with spaces to the @var{n}th column. If the
  3485. @samp{@{@var{n}@}} part is omitted, the current screen width
  3486. is assumed.
  3487. @item %c
  3488. This is a shortcut for @samp{%@{%Y-%m-%d %H:%M:%S@}t: %ds, %@{read,wrote@}T%*\r},
  3489. intended mainly for use with @samp{ttyout} action (see below).
  3490. @end table
  3491. Aside from format expansion, the message string is subject to
  3492. @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
  3493. replaced with their corresponding @acronym{ASCII} characters
  3494. (@pxref{escape sequences}). E.g. the following action will produce an
  3495. audible bell and the message described above at each checkpoint:
  3496. @smallexample
  3497. --checkpoint-action='echo=\aHit %s checkpoint #%u'
  3498. @end smallexample
  3499. @cindex @code{bell}, checkpoint action
  3500. There is also a special action which produces an audible signal:
  3501. @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
  3502. @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
  3503. whereas @samp{echo='\a'} sends it to the standard error.
  3504. @cindex @code{ttyout}, checkpoint action
  3505. The @samp{ttyout=@var{string}} action outputs @var{string} to
  3506. @file{/dev/tty}, so it can be used even if the standard output is
  3507. redirected elsewhere. The @var{string} is subject to the same
  3508. modifications as with @samp{echo} action. In contrast to the latter,
  3509. @samp{ttyout} does not prepend @command{tar} executable name to the
  3510. string, nor does it output a newline after it. For example, the
  3511. following action will print the checkpoint message at the same screen
  3512. line, overwriting any previous message:
  3513. @smallexample
  3514. --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r"
  3515. @end smallexample
  3516. @noindent
  3517. Notice the use of @samp{%*} specifier to clear out any eventual
  3518. remains of the prior output line. As as more complex example,
  3519. consider this:
  3520. @smallexample
  3521. --checkpoint-action=ttyout='%@{%Y-%m-%d %H:%M:%S@}t (%d sec): #%u, %T%*\r'
  3522. @end smallexample
  3523. @noindent
  3524. This prints the current local time, number of seconds expired since
  3525. tar was started, the checkpoint ordinal number, transferred bytes and
  3526. average computed I/O speed.
  3527. @cindex @code{dot}, checkpoint action
  3528. Another available checkpoint action is @samp{dot} (or @samp{.}). It
  3529. instructs @command{tar} to print a single dot on the standard listing
  3530. stream, e.g.:
  3531. @smallexample
  3532. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
  3533. ...
  3534. @end smallexample
  3535. For compatibility with previous @GNUTAR{} versions, this action can
  3536. be abbreviated by placing a dot in front of the checkpoint frequency,
  3537. as shown in the previous section.
  3538. @cindex @code{totals}, checkpoint action
  3539. The @samp{totals} action prints the total number of bytes transferred
  3540. so far. The format of the data is the same as for the
  3541. @option{--totals} option (@pxref{totals}). See also @samp{%T} format
  3542. specifier of the @samp{echo} or @samp{ttyout} action.
  3543. @cindex @code{sleep}, checkpoint action
  3544. Yet another action, @samp{sleep}, pauses @command{tar} for a specified
  3545. amount of seconds. The following example will stop for 30 seconds at each
  3546. checkpoint:
  3547. @smallexample
  3548. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
  3549. @end smallexample
  3550. @anchor{checkpoint wait}
  3551. @cindex @code{wait}, checkpoint action
  3552. The @code{wait=@var{signo}} action stops further execution until the
  3553. signal @var{signo} is delivered. Valid values for @var{signo} are:
  3554. @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
  3555. @code{SIGUSR2}. The @samp{SIG} prefix is optional. For example:
  3556. @example
  3557. $ @kbd{tar -c -f arc --checkpoint=1000 --checkpoint-action wait=USR1 .}
  3558. @end example
  3559. In this example, @GNUTAR{} will stop archivation at each 1000th
  3560. checkpoint. wait until the @samp{SIGUSR1} signal is delivered,
  3561. and resume processing.
  3562. This action is used by the @command{genfile} utility to perform
  3563. modifications on the input files upon hitting certain checkpoints
  3564. (@pxref{Exec Mode, genfile}).
  3565. @anchor{checkpoint exec}
  3566. @cindex @code{exec}, checkpoint action
  3567. Finally, the @code{exec} action executes a given external command.
  3568. For example:
  3569. @smallexample
  3570. $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
  3571. @end smallexample
  3572. The supplied command can be any valid command invocation, with or
  3573. without additional command line arguments. If it does contain
  3574. arguments, don't forget to quote it to prevent it from being split by
  3575. the shell. @xref{external, Running External Commands}, for more detail.
  3576. The command gets a copy of @command{tar}'s environment plus the
  3577. following variables:
  3578. @table @env
  3579. @vrindex TAR_VERSION, checkpoint script environment
  3580. @item TAR_VERSION
  3581. @GNUTAR{} version number.
  3582. @vrindex TAR_ARCHIVE, checkpoint script environment
  3583. @item TAR_ARCHIVE
  3584. The name of the archive @command{tar} is processing.
  3585. @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
  3586. @item TAR_BLOCKING_FACTOR
  3587. Current blocking factor (@pxref{Blocking}).
  3588. @vrindex TAR_CHECKPOINT, checkpoint script environment
  3589. @item TAR_CHECKPOINT
  3590. Number of the checkpoint.
  3591. @vrindex TAR_SUBCOMMAND, checkpoint script environment
  3592. @item TAR_SUBCOMMAND
  3593. A short option describing the operation @command{tar} is executing.
  3594. @xref{Operations}, for a complete list of subcommand options.
  3595. @vrindex TAR_FORMAT, checkpoint script environment
  3596. @item TAR_FORMAT
  3597. Format of the archive being processed. @xref{Formats}, for a complete
  3598. list of archive format names.
  3599. @end table
  3600. These environment variables can also be passed as arguments to the
  3601. command, provided that they are properly escaped, for example:
  3602. @smallexample
  3603. @kbd{tar -c -f arc.tar \
  3604. --checkpoint-action='exec=/sbin/cpoint $TAR_CHECKPOINT'}
  3605. @end smallexample
  3606. @noindent
  3607. Notice single quotes to prevent variable names from being expanded by
  3608. the shell when invoking @command{tar}.
  3609. Any number of actions can be defined, by supplying several
  3610. @option{--checkpoint-action} options in the command line. For
  3611. example, the command below displays two messages, pauses
  3612. execution for 30 seconds and executes the @file{/sbin/cpoint} script:
  3613. @example
  3614. @group
  3615. $ @kbd{tar -c -f arc.tar \
  3616. --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
  3617. --checkpoint-action='echo=Sleeping for 30 seconds' \
  3618. --checkpoint-action='sleep=30' \
  3619. --checkpoint-action='exec=/sbin/cpoint'}
  3620. @end group
  3621. @end example
  3622. This example also illustrates the fact that
  3623. @option{--checkpoint-action} can be used without
  3624. @option{--checkpoint}. In this case, the default checkpoint frequency
  3625. (at each 10th record) is assumed.
  3626. @node warnings
  3627. @section Controlling Warning Messages
  3628. Sometimes, while performing the requested task, @GNUTAR{} notices
  3629. some conditions that are not exactly errors, but which the user
  3630. should be aware of. When this happens, @command{tar} issues a
  3631. @dfn{warning message} describing the condition. Warning messages
  3632. are output to the standard error and they do not affect the exit
  3633. code of @command{tar} command.
  3634. @xopindex{warning, explained}
  3635. @GNUTAR{} allows the user to suppress some or all of its warning
  3636. messages:
  3637. @table @option
  3638. @item --warning=@var{keyword}
  3639. Control display of the warning messages identified by @var{keyword}.
  3640. If @var{keyword} starts with the prefix @samp{no-}, such messages are
  3641. suppressed. Otherwise, they are enabled.
  3642. Multiple @option{--warning} options accumulate.
  3643. @end table
  3644. By default, @GNUTAR enables all messages, except those that are
  3645. enabled in verbose mode (@pxref{verbose tutorial}). @xref{Warning
  3646. Defaults}, for details.
  3647. The subsections below discuss allowed values for @var{keyword} along with the
  3648. warning messages they control.
  3649. @menu
  3650. * General Warnings:: Keywords applicable for @command{tar --create}.
  3651. * Archive Creation Warnings:: Keywords applicable for @command{tar --create}.
  3652. * Archive Extraction Warnings:: Keywords applicable for @command{tar --extract}.
  3653. * Incremental Extraction Warnings:: Keywords controlling incremental extraction.
  3654. * Warning Classes:: Convenience keywords control multiple warnings.
  3655. * Warning Defaults:: Default settings for warnings.
  3656. @end menu
  3657. @node General Warnings
  3658. @subsection Keywords controlling @command{tar} operation
  3659. These keywords control warnings that may appear in any @GNUTAR{}
  3660. operation mode:
  3661. @defvr {warning} filename-with-nuls
  3662. @cindex @samp{file name read contains nul character}, warning message
  3663. @samp{file name read contains nul character}
  3664. @end defvr
  3665. @defvr {warning} filename-with-nuls
  3666. @cindex @samp{file name read contains nul character}, warning message
  3667. @samp{%s: file name read contains nul character}
  3668. @end defvr
  3669. @defvr {warning} alone-zero-block
  3670. @cindex @samp{A lone zero block at}, warning message
  3671. @samp{A lone zero block at %s}. Notice, that this warning is
  3672. suppressed if @option{--ignore-zeros} is in effect (@pxref{Ignore
  3673. Zeros}).
  3674. @end defvr
  3675. @defvr {warning} missing-zero-blocks
  3676. @cindex @samp{Terminating zero blocks missing}, warning message.
  3677. @samp{Terminating zero blocks missing at %s}. This warning is
  3678. suppressed if @option{--ignore-zeros} is in effect (@pxref{Ignore
  3679. Zeros}).
  3680. @end defvr
  3681. @node Archive Creation Warnings
  3682. @subsection Keywords applicable for @command{tar --create}
  3683. The following keywords control messages that can be issued while
  3684. creating archives.
  3685. @defvr {warning} cachedir
  3686. @cindex @samp{contains a cache directory tag}, warning message
  3687. @samp{%s: contains a cache directory tag %s; %s}
  3688. @end defvr
  3689. @defvr {warning} file-shrank
  3690. @cindex @samp{File shrank by %s bytes}, warning message
  3691. @samp{%s: File shrank by %s bytes; padding with zeros}
  3692. @end defvr
  3693. @defvr {warning} xdev
  3694. @cindex @samp{file is on a different filesystem}, warning message
  3695. @samp{%s: file is on a different filesystem; not dumped}
  3696. @end defvr
  3697. @defvr {warning} file-ignored
  3698. @cindex @samp{Unknown file type; file ignored}, warning message
  3699. @cindex @samp{socket ignored}, warning message
  3700. @cindex @samp{door ignored}, warning message
  3701. @samp{%s: Unknown file type; file ignored}
  3702. @*@samp{%s: socket ignored}
  3703. @*@samp{%s: door ignored}
  3704. @end defvr
  3705. @defvr {warning} file-unchanged
  3706. @cindex @samp{file is unchanged; not dumped}, warning message
  3707. @samp{%s: file is unchanged; not dumped}
  3708. @end defvr
  3709. @defvr {warning} ignore-archive
  3710. @cindex @samp{archive cannot contain itself; not dumped}, warning message
  3711. @samp{%s: archive cannot contain itself; not dumped}
  3712. @end defvr
  3713. @defvr {warning} file-removed
  3714. @cindex @samp{File removed before we read it}, warning message
  3715. @samp{%s: File removed before we read it}
  3716. @end defvr
  3717. @defvr {warning} file-changed
  3718. @cindex @samp{file changed as we read it}, warning message
  3719. @samp{%s: file changed as we read it}
  3720. Suppresses warnings about read failures, which can occur if files
  3721. or directories are unreadable, or if they change while being read. This
  3722. keyword applies only if used together with the @option{--ignore-failed-read}
  3723. option. @xref{Ignore Failed Read}.
  3724. @end defvr
  3725. @node Archive Extraction Warnings
  3726. @subsection Keywords applicable for @command{tar --extract}
  3727. The following keywords control warnings that can be issued during
  3728. archive extraction.
  3729. @defvr {warning} existing-file
  3730. @cindex @samp{%s: skipping existing file}, warning message
  3731. @samp{%s: skipping existing file}
  3732. @end defvr
  3733. @defvr {warning} timestamp
  3734. @cindex @samp{implausibly old time stamp %s}, warning message
  3735. @cindex @samp{time stamp %s is %s s in the future}, warning message
  3736. @samp{%s: implausibly old time stamp %s}
  3737. @*@samp{%s: time stamp %s is %s s in the future}
  3738. @end defvr
  3739. @defvr {warning} contiguous-cast
  3740. @cindex @samp{Extracting contiguous files as regular files}, warning message
  3741. @samp{Extracting contiguous files as regular files}
  3742. @end defvr
  3743. @defvr {warning} symlink-cast
  3744. @samp{Attempting extraction of symbolic links as hard links}, warning message
  3745. @samp{Attempting extraction of symbolic links as hard links}
  3746. @end defvr
  3747. @defvr {warning} unknown-cast
  3748. @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
  3749. @samp{%s: Unknown file type '%c', extracted as normal file}
  3750. @end defvr
  3751. @defvr {warning} ignore-newer
  3752. @cindex @samp{Current %s is newer or same age}, warning message
  3753. @samp{Current %s is newer or same age}
  3754. @end defvr
  3755. @defvr {warning} unknown-keyword
  3756. @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
  3757. @samp{Ignoring unknown extended header keyword '%s'}
  3758. @end defvr
  3759. @defvr {warning} decompress-program
  3760. Controls verbose description of failures occurring when trying to run
  3761. alternative decompressor programs (@pxref{alternative decompression
  3762. programs}). This warning is disabled by default (unless
  3763. @option{--verbose} is used). A common example of what you can get
  3764. when using this warning is:
  3765. @smallexample
  3766. $ @kbd{tar --warning=decompress-program -x -f archive.Z}
  3767. tar (child): cannot run compress: No such file or directory
  3768. tar (child): trying gzip
  3769. @end smallexample
  3770. This means that @command{tar} first tried to decompress
  3771. @file{archive.Z} using @command{compress}, and, when that
  3772. failed, switched to @command{gzip}.
  3773. @end defvr
  3774. @defvr {warning} record-size
  3775. @cindex @samp{Record size = %lu blocks}, warning message
  3776. @samp{Record size = %lu blocks}
  3777. @end defvr
  3778. @node Incremental Extraction Warnings
  3779. @subsection Keywords controlling incremental extraction
  3780. These keywords control warnings that may appear when extracting from
  3781. incremental archives.
  3782. @defvr {warning} rename-directory
  3783. @cindex @samp{%s: Directory has been renamed from %s}, warning message
  3784. @cindex @samp{%s: Directory has been renamed}, warning message
  3785. @samp{%s: Directory has been renamed from %s}
  3786. @*@samp{%s: Directory has been renamed}
  3787. @end defvr
  3788. @defvr {warning} new-directory
  3789. @cindex @samp{%s: Directory is new}, warning message
  3790. @samp{%s: Directory is new}
  3791. @end defvr
  3792. @defvr {warning} xdev
  3793. @cindex @samp{%s: directory is on a different device: not purging}, warning message
  3794. @samp{%s: directory is on a different device: not purging}
  3795. @end defvr
  3796. @defvr {warning} bad-dumpdir
  3797. @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
  3798. @samp{Malformed dumpdir: 'X' never used}
  3799. @end defvr
  3800. @node Warning Classes
  3801. @subsection Warning Classes
  3802. These convenience keywords define @dfn{warning classes}. When used,
  3803. they affect several warnings at once.
  3804. @defvr {warning} all
  3805. Enable all warning messages.
  3806. @end defvr
  3807. @defvr {warning} none
  3808. Disable all warning messages.
  3809. @end defvr
  3810. @defvr {warning} verbose
  3811. A shorthand for all messages enabled when @option{--verbose}
  3812. (@pxref{verbose tutorial}) is in effect. These are:
  3813. @code{decompress-program}, @code{existing-file}, @code{new-directory},
  3814. @code{record-size}, @code{rename-directory}.
  3815. @end defvr
  3816. @node Warning Defaults
  3817. @subsection Default Warning Settings
  3818. @GNUTAR default settings correspond to:
  3819. @example
  3820. --warning=all --warning=no-verbose --warning=no-missing-zero-blocks
  3821. @end example
  3822. @node interactive
  3823. @section Asking for Confirmation During Operations
  3824. @cindex Interactive operation
  3825. Typically, @command{tar} carries out a command without stopping for
  3826. further instructions. In some situations however, you may want to
  3827. exclude some files and archive members from the operation (for instance
  3828. if disk or storage space is tight). You can do this by excluding
  3829. certain files automatically (@pxref{Choosing}), or by performing
  3830. an operation interactively, using the @option{--interactive} (@option{-w}) option.
  3831. @command{tar} also accepts @option{--confirmation} for this option.
  3832. @opindex interactive
  3833. When the @option{--interactive} (@option{-w}) option is specified, before
  3834. reading, writing, or deleting files, @command{tar} first prints a message
  3835. for each such file, telling what operation it intends to take, then asks
  3836. for confirmation on the terminal. The actions which require
  3837. confirmation include adding a file to the archive, extracting a file
  3838. from the archive, deleting a file from the archive, and deleting a file
  3839. from disk. To confirm the action, you must type a line of input
  3840. beginning with @samp{y}. If your input line begins with anything other
  3841. than @samp{y}, @command{tar} skips that file.
  3842. If @command{tar} is reading the archive from the standard input,
  3843. @command{tar} opens the file @file{/dev/tty} to support the interactive
  3844. communications.
  3845. Verbose output is normally sent to standard output, separate from
  3846. other error messages. However, if the archive is produced directly
  3847. on standard output, then verbose output is mixed with errors on
  3848. @code{stderr}. Producing the archive on standard output may be used
  3849. as a way to avoid using disk space, when the archive is soon to be
  3850. consumed by another process reading it, say. Some people felt the need
  3851. of producing an archive on stdout, still willing to segregate between
  3852. verbose output and error output. A possible approach would be using a
  3853. named pipe to receive the archive, and having the consumer process to
  3854. read from that named pipe. This has the advantage of letting standard
  3855. output free to receive verbose output, all separate from errors.
  3856. @node external
  3857. @section Running External Commands
  3858. Certain @GNUTAR{} operations imply running external commands that you
  3859. supply on the command line. One of such operations is checkpointing,
  3860. described above (@pxref{checkpoint exec}). Another example of this
  3861. feature is the @option{-I} option, which allows you to supply the
  3862. program to use for compressing or decompressing the archive
  3863. (@pxref{use-compress-program}).
  3864. Whenever such operation is requested, @command{tar} first splits the
  3865. supplied command into words much like the shell does. It then treats
  3866. the first word as the name of the program or the shell script to execute
  3867. and the rest of words as its command line arguments. The program,
  3868. unless given as an absolute file name, is searched in the shell's
  3869. @env{PATH}.
  3870. Any additional information is normally supplied to external commands
  3871. in environment variables, specific to each particular operation. For
  3872. example, the @option{--checkpoint-action=exec} option, defines the
  3873. @env{TAR_ARCHIVE} variable to the name of the archive being worked
  3874. upon. You can, should the need be, use these variables in the
  3875. command line of the external command. For example:
  3876. @smallexample
  3877. $ @kbd{tar -x -f archive.tar \
  3878. --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
  3879. @end smallexample
  3880. @noindent
  3881. This command prints for each checkpoint its number and the name of the
  3882. archive, using the same output line on the screen.
  3883. Notice the use of single quotes to prevent variable names from being
  3884. expanded by the shell when invoking @command{tar}.
  3885. @node operations
  3886. @chapter @GNUTAR{} Operations
  3887. @menu
  3888. * Basic tar::
  3889. * Advanced tar::
  3890. * create options::
  3891. * extract options::
  3892. * backup::
  3893. * looking ahead::
  3894. @end menu
  3895. @node Basic tar
  3896. @section Basic @GNUTAR{} Operations
  3897. The basic @command{tar} operations, @option{--create} (@option{-c}),
  3898. @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
  3899. @option{-x}), are currently presented and described in the tutorial
  3900. chapter of this manual. This section provides some complementary notes
  3901. for these operations.
  3902. @table @option
  3903. @xopindex{create, complementary notes}
  3904. @item --create
  3905. @itemx -c
  3906. Creating an empty archive would have some kind of elegance. One can
  3907. initialize an empty archive and later use @option{--append}
  3908. (@option{-r}) for adding all members. Some applications would not
  3909. welcome making an exception in the way of adding the first archive
  3910. member. On the other hand, many people reported that it is
  3911. dangerously too easy for @command{tar} to destroy a magnetic tape with
  3912. an empty archive@footnote{This is well described in @cite{Unix-haters
  3913. Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
  3914. Books, ISBN 1-56884-203-1.}. The two most common errors are:
  3915. @enumerate
  3916. @item
  3917. Mistakingly using @code{create} instead of @code{extract}, when the
  3918. intent was to extract the full contents of an archive. This error
  3919. is likely: keys @kbd{c} and @kbd{x} are right next to each other on
  3920. the QWERTY keyboard. Instead of being unpacked, the archive then
  3921. gets wholly destroyed. When users speak about @dfn{exploding} an
  3922. archive, they usually mean something else :-).
  3923. @item
  3924. Forgetting the argument to @code{file}, when the intent was to create
  3925. an archive with a single file in it. This error is likely because a
  3926. tired user can easily add the @kbd{f} key to the cluster of option
  3927. letters, by the mere force of habit, without realizing the full
  3928. consequence of doing so. The usual consequence is that the single
  3929. file, which was meant to be saved, is rather destroyed.
  3930. @end enumerate
  3931. So, recognizing the likelihood and the catastrophic nature of these
  3932. errors, @GNUTAR{} now takes some distance from elegance, and
  3933. cowardly refuses to create an archive when @option{--create} option is
  3934. given, there are no arguments besides options, and
  3935. @option{--files-from} (@option{-T}) option is @emph{not} used. To get
  3936. around the cautiousness of @GNUTAR{} and nevertheless create an
  3937. archive with nothing in it, one may still use, as the value for the
  3938. @option{--files-from} option, a file with no names in it, as shown in
  3939. the following commands:
  3940. @smallexample
  3941. @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
  3942. @kbd{tar -cf empty-archive.tar -T /dev/null}
  3943. @end smallexample
  3944. @xopindex{extract, complementary notes}
  3945. @item --extract
  3946. @itemx --get
  3947. @itemx -x
  3948. A socket is stored, within a @GNUTAR{} archive, as a pipe.
  3949. @item @option{--list} (@option{-t})
  3950. @GNUTAR{} now shows dates as @samp{1996-08-30},
  3951. while it used to show them as @samp{Aug 30 1996}. Preferably,
  3952. people should get used to ISO 8601 dates. Local American dates should
  3953. be made available again with full date localization support, once
  3954. ready. In the meantime, programs not being localizable for dates
  3955. should prefer international dates, that's really the way to go.
  3956. Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
  3957. are curious, it contains a detailed explanation of the ISO 8601 standard.
  3958. @end table
  3959. @node Advanced tar
  3960. @section Advanced @GNUTAR{} Operations
  3961. Now that you have learned the basics of using @GNUTAR{}, you may want
  3962. to learn about further ways in which @command{tar} can help you.
  3963. This chapter presents five, more advanced operations which you probably
  3964. won't use on a daily basis, but which serve more specialized functions.
  3965. We also explain the different styles of options and why you might want
  3966. to use one or another, or a combination of them in your @command{tar}
  3967. commands. Additionally, this chapter includes options which allow you to
  3968. define the output from @command{tar} more carefully, and provide help and
  3969. error correction in special circumstances.
  3970. @FIXME{check this after the chapter is actually revised to make sure
  3971. it still introduces the info in the chapter correctly : ).}
  3972. @menu
  3973. * Operations::
  3974. * append::
  3975. * update::
  3976. * concatenate::
  3977. * delete::
  3978. * compare::
  3979. @end menu
  3980. @node Operations
  3981. @subsection The Five Advanced @command{tar} Operations
  3982. @cindex basic operations
  3983. In the last chapter, you learned about the first three operations to
  3984. @command{tar}. This chapter presents the remaining five operations to
  3985. @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
  3986. @option{--delete}, and @option{--compare}.
  3987. You are not likely to use these operations as frequently as those
  3988. covered in the last chapter; however, since they perform specialized
  3989. functions, they are quite useful when you do need to use them. We
  3990. will give examples using the same directory and files that you created
  3991. in the last chapter. As you may recall, the directory is called
  3992. @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
  3993. and the two archive files you created are
  3994. @samp{collection.tar} and @samp{music.tar}.
  3995. We will also use the archive files @samp{afiles.tar} and
  3996. @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
  3997. @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
  3998. @samp{./birds}, @samp{baboon}, and @samp{./box}.
  3999. Unless we state otherwise, all practicing you do and examples you follow
  4000. in this chapter will take place in the @file{practice} directory that
  4001. you created in the previous chapter; see @ref{prepare for examples}.
  4002. (Below in this section, we will remind you of the state of the examples
  4003. where the last chapter left them.)
  4004. The five operations that we will cover in this chapter are:
  4005. @table @option
  4006. @item --append
  4007. @itemx -r
  4008. Add new entries to an archive that already exists.
  4009. @item --update
  4010. @itemx -u
  4011. Add more recent copies of archive members to the end of an archive, if
  4012. they exist.
  4013. @item --concatenate
  4014. @itemx --catenate
  4015. @itemx -A
  4016. Add one or more pre-existing archives to the end of another archive.
  4017. @item --delete
  4018. Delete items from an archive (does not work on tapes).
  4019. @item --compare
  4020. @itemx --diff
  4021. @itemx -d
  4022. Compare archive members to their counterparts in the file system.
  4023. @end table
  4024. @node append
  4025. @subsection How to Add Files to Existing Archives: @option{--append}
  4026. @cindex appending files to existing archive
  4027. @opindex append
  4028. If you want to add files to an existing archive, you don't need to
  4029. create a new archive; you can use @option{--append} (@option{-r}).
  4030. The archive must already exist in order to use @option{--append}. (A
  4031. related operation is the @option{--update} operation; you can use this
  4032. to add newer versions of archive members to an existing archive. To learn how to
  4033. do this with @option{--update}, @pxref{update}.)
  4034. If you use @option{--append} to add a file that has the same name as an
  4035. archive member to an archive containing that archive member, then the
  4036. old member is not deleted. What does happen, however, is somewhat
  4037. complex. @command{tar} @emph{allows} you to have infinite number of files
  4038. with the same name. Some operations treat these same-named members no
  4039. differently than any other set of archive members: for example, if you
  4040. view an archive with @option{--list} (@option{-t}), you will see all
  4041. of those members listed, with their data modification times, owners, etc.
  4042. Other operations don't deal with these members as perfectly as you might
  4043. prefer; if you were to use @option{--extract} to extract the archive,
  4044. only the most recently added copy of a member with the same name as
  4045. other members would end up in the working directory. This is because
  4046. @option{--extract} extracts an archive in the order the members appeared
  4047. in the archive; the most recently archived members will be extracted
  4048. last. Additionally, an extracted member will @emph{replace} a file of
  4049. the same name which existed in the directory already, and @command{tar}
  4050. will not prompt you about this@footnote{Unless you give it
  4051. @option{--keep-old-files} (or @option{--skip-old-files}) option, or
  4052. the disk copy is newer than the one in the archive and you invoke
  4053. @command{tar} with @option{--keep-newer-files} option.}. Thus, only
  4054. the most recently archived member will end up being extracted, as it
  4055. will replace the one extracted before it, and so on.
  4056. @cindex extracting @var{n}th copy of the file
  4057. @xopindex{occurrence, described}
  4058. There exists a special option that allows you to get around this
  4059. behavior and extract (or list) only a particular copy of the file.
  4060. This is @option{--occurrence} option. If you run @command{tar} with
  4061. this option, it will extract only the first copy of the file. You
  4062. may also give this option an argument specifying the number of
  4063. copy to be extracted. Thus, for example if the archive
  4064. @file{archive.tar} contained three copies of file @file{myfile}, then
  4065. the command
  4066. @smallexample
  4067. tar --extract --file archive.tar --occurrence=2 myfile
  4068. @end smallexample
  4069. @noindent
  4070. would extract only the second copy. @xref{Option
  4071. Summary,---occurrence}, for the description of @option{--occurrence}
  4072. option.
  4073. @FIXME{ hag -- you might want to incorporate some of the above into the
  4074. MMwtSN node; not sure. i didn't know how to make it simpler...
  4075. There are a few ways to get around this. Xref to Multiple Members
  4076. with the Same Name, maybe.}
  4077. @cindex Members, replacing with other members
  4078. @cindex Replacing members with other members
  4079. @xopindex{delete, using before --append}
  4080. If you want to replace an archive member, use @option{--delete} to
  4081. delete the member you want to remove from the archive, and then use
  4082. @option{--append} to add the member you want to be in the archive. Note
  4083. that you can not change the order of the archive; the most recently
  4084. added member will still appear last. In this sense, you cannot truly
  4085. ``replace'' one member with another. (Replacing one member with another
  4086. will not work on certain types of media, such as tapes; see @ref{delete}
  4087. and @ref{Media}, for more information.)
  4088. @menu
  4089. * appending files:: Appending Files to an Archive
  4090. * multiple::
  4091. @end menu
  4092. @node appending files
  4093. @subsubsection Appending Files to an Archive
  4094. @cindex Adding files to an Archive
  4095. @cindex Appending files to an Archive
  4096. @cindex Archives, Appending files to
  4097. @opindex append
  4098. The simplest way to add a file to an already existing archive is the
  4099. @option{--append} (@option{-r}) operation, which writes specified
  4100. files into the archive whether or not they are already among the
  4101. archived files.
  4102. When you use @option{--append}, you @emph{must} specify file name
  4103. arguments, as there is no default. If you specify a file that already
  4104. exists in the archive, another copy of the file will be added to the
  4105. end of the archive. As with other operations, the member names of the
  4106. newly added files will be exactly the same as their names given on the
  4107. command line. The @option{--verbose} (@option{-v}) option will print
  4108. out the names of the files as they are written into the archive.
  4109. @option{--append} cannot be performed on some tape drives, unfortunately,
  4110. due to deficiencies in the formats those tape drives use. The archive
  4111. must be a valid @command{tar} archive, or else the results of using this
  4112. operation will be unpredictable. @xref{Media}.
  4113. To demonstrate using @option{--append} to add a file to an archive,
  4114. create a file called @file{rock} in the @file{practice} directory.
  4115. Make sure you are in the @file{practice} directory. Then, run the
  4116. following @command{tar} command to add @file{rock} to
  4117. @file{collection.tar}:
  4118. @smallexample
  4119. $ @kbd{tar --append --file=collection.tar rock}
  4120. @end smallexample
  4121. @noindent
  4122. If you now use the @option{--list} (@option{-t}) operation, you will see that
  4123. @file{rock} has been added to the archive:
  4124. @smallexample
  4125. $ @kbd{tar --list --file=collection.tar}
  4126. -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
  4127. -rw-r--r-- me/user 21 1996-09-23 16:44 blues
  4128. -rw-r--r-- me/user 20 1996-09-23 16:44 folk
  4129. -rw-r--r-- me/user 20 1996-09-23 16:44 rock
  4130. @end smallexample
  4131. @node multiple
  4132. @subsubsection Multiple Members with the Same Name
  4133. @cindex members, multiple
  4134. @cindex multiple members
  4135. You can use @option{--append} (@option{-r}) to add copies of files
  4136. which have been updated since the archive was created. (However, we
  4137. do not recommend doing this since there is another @command{tar}
  4138. option called @option{--update}; @xref{update}, for more information.
  4139. We describe this use of @option{--append} here for the sake of
  4140. completeness.) When you extract the archive, the older version will
  4141. be effectively lost. This works because files are extracted from an
  4142. archive in the order in which they were archived. Thus, when the
  4143. archive is extracted, a file archived later in time will replace a
  4144. file of the same name which was archived earlier, even though the
  4145. older version of the file will remain in the archive unless you delete
  4146. all versions of the file.
  4147. Supposing you change the file @file{blues} and then append the changed
  4148. version to @file{collection.tar}. As you saw above, the original
  4149. @file{blues} is in the archive @file{collection.tar}. If you change the
  4150. file and append the new version of the file to the archive, there will
  4151. be two copies in the archive. When you extract the archive, the older
  4152. version of the file will be extracted first, and then replaced by the
  4153. newer version when it is extracted.
  4154. You can append the new, changed copy of the file @file{blues} to the
  4155. archive in this way:
  4156. @smallexample
  4157. $ @kbd{tar --append --verbose --file=collection.tar blues}
  4158. blues
  4159. @end smallexample
  4160. @noindent
  4161. Because you specified the @option{--verbose} option, @command{tar} has
  4162. printed the name of the file being appended as it was acted on. Now
  4163. list the contents of the archive:
  4164. @smallexample
  4165. $ @kbd{tar --list --verbose --file=collection.tar}
  4166. -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
  4167. -rw-r--r-- me/user 21 1996-09-23 16:44 blues
  4168. -rw-r--r-- me/user 20 1996-09-23 16:44 folk
  4169. -rw-r--r-- me/user 20 1996-09-23 16:44 rock
  4170. -rw-r--r-- me/user 58 1996-10-24 18:30 blues
  4171. @end smallexample
  4172. @noindent
  4173. The newest version of @file{blues} is now at the end of the archive
  4174. (note the different creation dates and file sizes). If you extract
  4175. the archive, the older version of the file @file{blues} will be
  4176. replaced by the newer version. You can confirm this by extracting
  4177. the archive and running @samp{ls} on the directory.
  4178. If you wish to extract the first occurrence of the file @file{blues}
  4179. from the archive, use @option{--occurrence} option, as shown in
  4180. the following example:
  4181. @smallexample
  4182. $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
  4183. -rw-r--r-- me/user 21 1996-09-23 16:44 blues
  4184. @end smallexample
  4185. @xref{Writing}, for more information on @option{--extract} and
  4186. see @ref{Option Summary, --occurrence}, for a description of
  4187. @option{--occurrence} option.
  4188. @node update
  4189. @subsection Updating an Archive
  4190. @cindex Updating an archive
  4191. @opindex update
  4192. In the previous section, you learned how to use @option{--append} to
  4193. add a file to an existing archive. A related operation is
  4194. @option{--update} (@option{-u}). The @option{--update} operation
  4195. updates a @command{tar} archive by comparing the date of the specified
  4196. archive members against the date of the file with the same name. If
  4197. the file has been modified more recently than the archive member, then
  4198. the newer version of the file is added to the archive (as with
  4199. @option{--append}).
  4200. Unfortunately, you cannot use @option{--update} with magnetic tape drives.
  4201. The operation will fail.
  4202. @FIXME{other examples of media on which --update will fail? need to ask
  4203. charles and/or mib/thomas/dave shevett..}
  4204. Both @option{--update} and @option{--append} work by adding to the end
  4205. of the archive. When you extract a file from the archive, only the
  4206. version stored last will wind up in the file system, unless you use
  4207. the @option{--backup} option. @xref{multiple}, for a detailed discussion.
  4208. @menu
  4209. * how to update::
  4210. @end menu
  4211. @node how to update
  4212. @subsubsection How to Update an Archive Using @option{--update}
  4213. @opindex update
  4214. You must use file name arguments with the @option{--update}
  4215. (@option{-u}) operation. If you don't specify any files,
  4216. @command{tar} won't act on any files and won't tell you that it didn't
  4217. do anything (which may end up confusing you).
  4218. @c note: the above parenthetical added because in fact, this
  4219. @c behavior just confused the author. :-)
  4220. To see the @option{--update} option at work, create a new file,
  4221. @file{classical}, in your practice directory, and some extra text to the
  4222. file @file{blues}, using any text editor. Then invoke @command{tar} with
  4223. the @samp{update} operation and the @option{--verbose} (@option{-v})
  4224. option specified, using the names of all the files in the @file{practice}
  4225. directory as file name arguments:
  4226. @smallexample
  4227. $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
  4228. blues
  4229. classical
  4230. $
  4231. @end smallexample
  4232. @noindent
  4233. Because we have specified verbose mode, @command{tar} prints out the names
  4234. of the files it is working on, which in this case are the names of the
  4235. files that needed to be updated. If you run @samp{tar --list} and look
  4236. at the archive, you will see @file{blues} and @file{classical} at its
  4237. end. There will be a total of two versions of the member @samp{blues};
  4238. the one at the end will be newer and larger, since you added text before
  4239. updating it.
  4240. The reason @command{tar} does not overwrite the older file when updating
  4241. it is that writing to the middle of a section of tape is a difficult
  4242. process. Tapes are not designed to go backward. @xref{Media}, for more
  4243. information about tapes.
  4244. @option{--update} (@option{-u}) is not suitable for performing backups for two
  4245. reasons: it does not change directory content entries, and it
  4246. lengthens the archive every time it is used. The @GNUTAR{}
  4247. options intended specifically for backups are more
  4248. efficient. If you need to run backups, please consult @ref{Backups}.
  4249. @node concatenate
  4250. @subsection Combining Archives with @option{--concatenate}
  4251. @cindex Adding archives to an archive
  4252. @cindex Concatenating Archives
  4253. @opindex concatenate
  4254. @opindex catenate
  4255. @c @cindex @option{-A} described
  4256. Sometimes it may be convenient to add a second archive onto the end of
  4257. an archive rather than adding individual files to the archive. To add
  4258. one or more archives to the end of another archive, you should use the
  4259. @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
  4260. To use @option{--concatenate}, give the first archive with
  4261. @option{--file} option and name the rest of archives to be
  4262. concatenated on the command line. The members, and their member
  4263. names, will be copied verbatim from those archives to the first
  4264. one@footnote{This can cause multiple members to have the same name. For
  4265. information on how this affects reading the archive, see @ref{multiple}.}.
  4266. The new, concatenated archive will be called by the same name as the
  4267. one given with the @option{--file} option. As usual, if you omit
  4268. @option{--file}, @command{tar} will use the value of the environment
  4269. variable @env{TAPE}, or, if this has not been set, the default archive name.
  4270. @FIXME{There is no way to specify a new name...}
  4271. To demonstrate how @option{--concatenate} works, create two small archives
  4272. called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
  4273. files from @file{practice}:
  4274. @smallexample
  4275. $ @kbd{tar -cvf bluesrock.tar blues rock}
  4276. blues
  4277. rock
  4278. $ @kbd{tar -cvf folkjazz.tar folk jazz}
  4279. folk
  4280. jazz
  4281. @end smallexample
  4282. @noindent
  4283. If you like, you can run @samp{tar --list} to make sure the archives
  4284. contain what they are supposed to:
  4285. @smallexample
  4286. $ @kbd{tar -tvf bluesrock.tar}
  4287. -rw-r--r-- melissa/user 105 1997-01-21 19:42 blues
  4288. -rw-r--r-- melissa/user 33 1997-01-20 15:34 rock
  4289. $ @kbd{tar -tvf jazzfolk.tar}
  4290. -rw-r--r-- melissa/user 20 1996-09-23 16:44 folk
  4291. -rw-r--r-- melissa/user 65 1997-01-30 14:15 jazz
  4292. @end smallexample
  4293. We can concatenate these two archives with @command{tar}:
  4294. @smallexample
  4295. $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
  4296. @end smallexample
  4297. If you now list the contents of the @file{bluesrock.tar}, you will see
  4298. that now it also contains the archive members of @file{jazzfolk.tar}:
  4299. @smallexample
  4300. $ @kbd{tar --list --file=bluesrock.tar}
  4301. blues
  4302. rock
  4303. folk
  4304. jazz
  4305. @end smallexample
  4306. When you use @option{--concatenate}, the source and target archives must
  4307. already exist and must have been created using compatible format
  4308. parameters. Notice, that @command{tar} does not check whether the
  4309. archives it concatenates have compatible formats, it does not
  4310. even check if the files are really tar archives.
  4311. Like @option{--append} (@option{-r}), this operation cannot be performed on some
  4312. tape drives, due to deficiencies in the formats those tape drives use.
  4313. @cindex @code{concatenate} vs @command{cat}
  4314. @cindex @command{cat} vs @code{concatenate}
  4315. It may seem more intuitive to you to want or try to use @command{cat} to
  4316. concatenate two archives instead of using the @option{--concatenate}
  4317. operation; after all, @command{cat} is the utility for combining files.
  4318. However, @command{tar} archives incorporate an end-of-file marker which
  4319. must be removed if the concatenated archives are to be read properly as
  4320. one archive. @option{--concatenate} removes the end-of-archive marker
  4321. from the target archive before each new archive is appended. If you use
  4322. @command{cat} to combine the archives, the result will not be a valid
  4323. @command{tar} format archive. If you need to retrieve files from an
  4324. archive that was added to using the @command{cat} utility, use the
  4325. @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
  4326. information on dealing with archives improperly combined using the
  4327. @command{cat} shell utility.
  4328. @node delete
  4329. @subsection Removing Archive Members Using @option{--delete}
  4330. @cindex Deleting files from an archive
  4331. @cindex Removing files from an archive
  4332. @opindex delete
  4333. You can remove members from an archive by using the @option{--delete}
  4334. option. Specify the name of the archive with @option{--file}
  4335. (@option{-f}) and then specify the names of the members to be deleted;
  4336. if you list no member names, nothing will be deleted. The
  4337. @option{--verbose} option will cause @command{tar} to print the names
  4338. of the members as they are deleted. As with @option{--extract}, you
  4339. must give the exact member names when using @samp{tar --delete}.
  4340. @option{--delete} will remove all versions of the named file from the
  4341. archive. The @option{--delete} operation can run very slowly.
  4342. Unlike other operations, @option{--delete} has no short form.
  4343. @cindex Tapes, using @option{--delete} and
  4344. @cindex Deleting from tape archives
  4345. This operation will rewrite the archive. You can only use
  4346. @option{--delete} on an archive if the archive device allows you to
  4347. write to any point on the media, such as a disk; because of this, it
  4348. does not work on magnetic tapes. Do not try to delete an archive member
  4349. from a magnetic tape; the action will not succeed, and you will be
  4350. likely to scramble the archive and damage your tape. There is no safe
  4351. way (except by completely re-writing the archive) to delete files from
  4352. most kinds of magnetic tape. @xref{Media}.
  4353. To delete all versions of the file @file{blues} from the archive
  4354. @file{collection.tar} in the @file{practice} directory, make sure you
  4355. are in that directory, and then,
  4356. @smallexample
  4357. $ @kbd{tar --list --file=collection.tar}
  4358. blues
  4359. folk
  4360. jazz
  4361. rock
  4362. $ @kbd{tar --delete --file=collection.tar blues}
  4363. $ @kbd{tar --list --file=collection.tar}
  4364. folk
  4365. jazz
  4366. rock
  4367. @end smallexample
  4368. @FIXME{Check if the above listing is actually produced after running
  4369. all the examples on collection.tar.}
  4370. The @option{--delete} option has been reported to work properly when
  4371. @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
  4372. @node compare
  4373. @subsection Comparing Archive Members with the File System
  4374. @cindex Verifying the currency of an archive
  4375. @opindex compare
  4376. The @option{--compare} (@option{-d}), or @option{--diff} operation compares
  4377. specified archive members against files with the same names, and then
  4378. reports differences in file size, mode, owner, modification date and
  4379. contents. You should @emph{only} specify archive member names, not file
  4380. names. If you do not name any members, then @command{tar} will compare the
  4381. entire archive. If a file is represented in the archive but does not
  4382. exist in the file system, @command{tar} reports a difference.
  4383. You have to specify the record size of the archive when modifying an
  4384. archive with a non-default record size.
  4385. @command{tar} ignores files in the file system that do not have
  4386. corresponding members in the archive.
  4387. The following example compares the archive members @file{rock},
  4388. @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
  4389. files of the same name in the file system. (Note that there is no file,
  4390. @file{funk}; @command{tar} will report an error message.)
  4391. @smallexample
  4392. $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
  4393. rock
  4394. blues
  4395. tar: funk not found in archive
  4396. @end smallexample
  4397. The spirit behind the @option{--compare} (@option{--diff},
  4398. @option{-d}) option is to check whether the archive represents the
  4399. current state of files on disk, more than validating the integrity of
  4400. the archive media. For this latter goal, see @ref{verify}.
  4401. @node create options
  4402. @section Options Used by @option{--create}
  4403. @xopindex{create, additional options}
  4404. The previous chapter described the basics of how to use
  4405. @option{--create} (@option{-c}) to create an archive from a set of files.
  4406. @xref{create}. This section described advanced options to be used with
  4407. @option{--create}.
  4408. @menu
  4409. * override:: Overriding File Metadata.
  4410. * Extended File Attributes::
  4411. * Ignore Failed Read::
  4412. @end menu
  4413. @node override
  4414. @subsection Overriding File Metadata
  4415. As described above, a @command{tar} archive keeps, for each member it contains,
  4416. its @dfn{metadata}, such as modification time, mode and ownership of
  4417. the file. @GNUTAR{} allows to replace these data with other values
  4418. when adding files to the archive. The options described in this
  4419. section affect creation of archives of any type. For POSIX archives,
  4420. see also @ref{PAX keywords}, for additional ways of controlling
  4421. metadata, stored in the archive.
  4422. @table @option
  4423. @opindex mode
  4424. @item --mode=@var{permissions}
  4425. When adding files to an archive, @command{tar} will use
  4426. @var{permissions} for the archive members, rather than the permissions
  4427. from the files. @var{permissions} can be specified either as an octal
  4428. number or as symbolic permissions, like with
  4429. @command{chmod} (@xref{File permissions, Permissions, File
  4430. permissions, coreutils, @acronym{GNU} core utilities}. This reference
  4431. also has useful information for those not being overly familiar with
  4432. the UNIX permission system). Using latter syntax allows for
  4433. more flexibility. For example, the value @samp{a+rw} adds read and write
  4434. permissions for everybody, while retaining executable bits on directories
  4435. or on any other file already marked as executable:
  4436. @smallexample
  4437. $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
  4438. @end smallexample
  4439. @item --mtime=@var{date}
  4440. @opindex mtime
  4441. When adding files to an archive, @command{tar} uses @var{date} as
  4442. the modification time of members when creating archives, instead of
  4443. their actual modification times. The argument @var{date} can be
  4444. either a textual date representation in almost arbitrary format
  4445. (@pxref{Date input formats}) or a name of an existing file, starting
  4446. with @samp{/} or @samp{.}. In the latter case, the modification time
  4447. of that file is used.
  4448. The following example sets the modification date to 00:00:00 @sc{utc} on
  4449. January 1, 1970:
  4450. @smallexample
  4451. $ @kbd{tar -c -f archive.tar --mtime='@@0' .}
  4452. @end smallexample
  4453. @noindent
  4454. When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
  4455. converts the specified date back to a textual form and compares it
  4456. with the one given with @option{--mtime}.
  4457. If the two forms differ, @command{tar} prints both forms in a message,
  4458. to help the user check that the right date is being used.
  4459. For example:
  4460. @smallexample
  4461. $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
  4462. tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
  4463. 13:06:29.152478
  4464. @dots{}
  4465. @end smallexample
  4466. @noindent
  4467. When used with @option{--clamp-mtime} @GNUTAR{} sets the
  4468. modification date to @var{date} only on files whose actual modification
  4469. date is later than @var{date}. This makes it easier to build
  4470. reproducible archives given a common timestamp for generated files
  4471. while still retaining the original timestamps of untouched files.
  4472. @xref{Reproducibility}.
  4473. @smallexample
  4474. $ @kbd{tar -c -f archive.tar --clamp-mtime --mtime="$SOURCE_EPOCH" .}
  4475. @end smallexample
  4476. @item --owner=@var{user}
  4477. @opindex owner
  4478. Specifies that @command{tar} should use @var{user} as the owner of members
  4479. when creating archives, instead of the user associated with the source
  4480. file.
  4481. If @var{user} contains a colon, it is taken to be of the form
  4482. @var{name}:@var{id} where a nonempty @var{name} specifies the user
  4483. name and a nonempty @var{id} specifies the decimal numeric user
  4484. @acronym{ID}. If @var{user} does not contain a colon, it is taken to
  4485. be a user number if it is one or more decimal digits; otherwise it is
  4486. taken to be a user name.
  4487. If a name is given but no number, the number is inferred from the
  4488. current host's user database if possible, and the file's user number
  4489. is used otherwise. If a number is given but no name, the name is
  4490. inferred from the number if possible, and an empty name is used
  4491. otherwise. If both name and number are given, the user database is
  4492. not consulted, and the name and number need not be valid on the
  4493. current host.
  4494. There is no value indicating a missing number, and @samp{0} usually means
  4495. @code{root}. Some people like to force @samp{0} as the value to offer in
  4496. their distributions for the owner of files, because the @code{root} user is
  4497. anonymous anyway, so that might as well be the owner of anonymous
  4498. archives. For example:
  4499. @smallexample
  4500. $ @kbd{tar -c -f archive.tar --owner=0 .}
  4501. @end smallexample
  4502. @noindent
  4503. or:
  4504. @smallexample
  4505. $ @kbd{tar -c -f archive.tar --owner=root .}
  4506. @end smallexample
  4507. @item --group=@var{group}
  4508. @opindex group
  4509. Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
  4510. rather than the group from the source file. As with @option{--owner},
  4511. the argument @var{group} can be an existing group symbolic name, or a
  4512. decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
  4513. @end table
  4514. The @option{--owner} and @option{--group} options affect all files
  4515. added to the archive. @GNUTAR{} provides also two options that allow
  4516. for more detailed control over owner translation:
  4517. @table @option
  4518. @item --owner-map=@var{file}
  4519. Read UID translation map from @var{file}.
  4520. When reading, empty lines are ignored. The @samp{#} sign, unless
  4521. quoted, introduces a comment, which extends to the end of the line.
  4522. Each nonempty line defines mapping for a single UID. It must consist
  4523. of two fields separated by any amount of whitespace. The first field
  4524. defines original username and UID. It can be a valid user name or
  4525. a valid UID prefixed with a plus sign. In both cases the
  4526. corresponding UID or user name is inferred from the current host's
  4527. user database.
  4528. The second field defines the UID and username to map the original one
  4529. to. Its format can be the same as described above. Otherwise, it can
  4530. have the form @var{newname}:@var{newuid}, in which case neither
  4531. @var{newname} nor @var{newuid} are required to be valid as per the
  4532. user database.
  4533. For example, consider the following file:
  4534. @example
  4535. +10 bin
  4536. smith root:0
  4537. @end example
  4538. @noindent
  4539. Given this file, each input file that is owner by UID 10 will be
  4540. stored in archive with owner name @samp{bin} and owner UID
  4541. corresponding to @samp{bin}. Each file owned by user @samp{smith}
  4542. will be stored with owner name @samp{root} and owner ID 0. Other
  4543. files will remain unchanged.
  4544. When used together with @option{--owner-map}, the @option{--owner}
  4545. option affects only files whose owner is not listed in the map file.
  4546. @item --group-map=@var{file}
  4547. Read GID translation map from @var{file}.
  4548. The format of @var{file} is the same as for @option{--owner-map}
  4549. option:
  4550. Each nonempty line defines mapping for a single GID. It must consist
  4551. of two fields separated by any amount of whitespace. The first field
  4552. defines original group name and GID. It can be a valid group name or
  4553. a valid GID prefixed with a plus sign. In both cases the
  4554. corresponding GID or user name is inferred from the current host's
  4555. group database.
  4556. The second field defines the GID and group name to map the original one
  4557. to. Its format can be the same as described above. Otherwise, it can
  4558. have the form @var{newname}:@var{newgid}, in which case neither
  4559. @var{newname} nor @var{newgid} are required to be valid as per the
  4560. group database.
  4561. When used together with @option{--group-map}, the @option{--group}
  4562. option affects only files whose owner group is not rewritten using the
  4563. map file.
  4564. @end table
  4565. @node Extended File Attributes
  4566. @subsection Extended File Attributes
  4567. Extended file attributes are name-value pairs that can be
  4568. associated with each node in a file system. Despite the fact that
  4569. POSIX.1e draft which proposed them has been withdrawn, the extended
  4570. file attributes are supported by many file systems. @GNUTAR{} can
  4571. store extended file attributes along with the files. This feature is
  4572. controlled by the following command line arguments:
  4573. @table @option
  4574. @item --xattrs
  4575. Enable extended attributes support. When used with @option{--create},
  4576. this option instructs @GNUTAR{} to store extended file attribute in the
  4577. created archive. This implies POSIX.1-2001 archive format
  4578. (@option{--format=pax}).
  4579. When used with @option{--extract}, this option tells @command{tar},
  4580. for each file extracted, to read stored attributes from the archive
  4581. and to apply them to the file.
  4582. @item --no-xattrs
  4583. Disable extended attributes support. This is the default.
  4584. @end table
  4585. Attribute names are strings prefixed by a @dfn{namespace} name and a dot.
  4586. Currently, four namespaces exist: @samp{user}, @samp{trusted},
  4587. @samp{security} and @samp{system}. By default, when @option{--xattrs}
  4588. is used, all names are stored in the archive (with @option{--create}),
  4589. but only @samp{user} namespace is extracted (if using @option{--extract}).
  4590. The reason for this behavior is that any other, system defined attributes
  4591. don't provide us sufficient compatibility promise. Storing all attributes
  4592. is safe operation for the archiving purposes. Though extracting those
  4593. (often security related) attributes on a different system than originally
  4594. archived can lead to extraction failures, or even misinterpretations.
  4595. This behavior can be controlled using the following options:
  4596. @table @option
  4597. @item --xattrs-exclude=@var{pattern}
  4598. Specify exclude pattern for extended attributes.
  4599. @item --xattrs-include=@var{pattern}
  4600. Specify include pattern for extended attributes.
  4601. @end table
  4602. Here, the @var{pattern} is a globbing pattern. For example, the
  4603. following command:
  4604. @example
  4605. $ @kbd{tar --xattrs --xattrs-exclude='user.*' -cf a.tar .}
  4606. @end example
  4607. will include in the archive @file{a.tar} all attributes, except those
  4608. from the @samp{user} namespace.
  4609. Users shall check the attributes are binary compatible with the target system
  4610. before any other namespace is extracted with an explicit
  4611. @option{--xattrs-include} option.
  4612. Any number of these options can be given, thereby creating lists of
  4613. include and exclude patterns.
  4614. When both options are used, first @option{--xattrs-include} is applied
  4615. to select the set of attribute names to keep, and then
  4616. @option{--xattrs-exclude} is applied to the resulting set. In other
  4617. words, only those attributes will be stored, whose names match one
  4618. of the regexps in @option{--xattrs-include} and don't match any of
  4619. the regexps from @option{--xattrs-exclude}.
  4620. When listing the archive, if both @option{--xattrs} and
  4621. @option{--verbose} options are given, files that have extended
  4622. attributes are marked with an asterisk following their permission
  4623. mask. For example:
  4624. @example
  4625. -rw-r--r--* smith/users 110 2016-03-16 16:07 file
  4626. @end example
  4627. When two or more @option{--verbose} options are given, a detailed
  4628. listing of extended attributes is printed after each file entry. Each
  4629. attribute is listed on a separate line, which begins with two spaces
  4630. and the letter @samp{x} indicating extended attribute. It is followed
  4631. by a colon, length of the attribute and its name, e.g.:
  4632. @example
  4633. -rw-r--r--* smith/users 110 2016-03-16 16:07 file
  4634. x: 7 user.mime_type
  4635. x: 32 trusted.md5sum
  4636. @end example
  4637. File access control lists (@dfn{ACL}) are another actively used feature
  4638. proposed by the POSIX.1e standard. Each ACL consists of a set of ACL
  4639. entries, each of which describes the access permissions on the file for
  4640. an individual user or a group of users as a combination of read, write
  4641. and search/execute permissions.
  4642. Whether or not to use ACLs is controlled by the following two options:
  4643. @table @option
  4644. @item --acls
  4645. Enable POSIX ACLs support. When used with @option{--create},
  4646. this option instructs @GNUTAR{} to store ACLs in the
  4647. created archive. This implies POSIX.1-2001 archive format
  4648. (@option{--format=pax}).
  4649. When used with @option{--extract}, this option tells @command{tar},
  4650. to restore ACLs for each file extracted (provided they are present
  4651. in the archive).
  4652. @item --no-acls
  4653. Disable POSIX ACLs support. This is the default.
  4654. @end table
  4655. When listing the archive, if both @option{--acls} and
  4656. @option{--verbose} options are given, files that have ACLs are marked
  4657. with a plus sign following their permission mask. For example:
  4658. @example
  4659. -rw-r--r--+ smith/users 110 2016-03-16 16:07 file
  4660. @end example
  4661. When two or more @option{--verbose} options are given, a detailed
  4662. listing of ACL is printed after each file entry:
  4663. @example
  4664. @group
  4665. -rw-r--r--+ smith/users 110 2016-03-16 16:07 file
  4666. a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r--
  4667. @end group
  4668. @end example
  4669. @dfn{Security-Enhanced Linux} (@dfn{SELinux} for short) is a Linux
  4670. kernel security module that provides a mechanism for supporting access
  4671. control security policies, including so-called mandatory access
  4672. controls (@dfn{MAC}). Support for SELinux attributes is controlled by
  4673. the following command line options:
  4674. @table @option
  4675. @item --selinux
  4676. Enable the SELinux context support.
  4677. @item --no-selinux
  4678. Disable SELinux context support.
  4679. @end table
  4680. @node Ignore Failed Read
  4681. @subsection Ignore Failed Read
  4682. @table @option
  4683. @item --ignore-failed-read
  4684. @opindex ignore-failed-read
  4685. Do not exit with nonzero if there are mild problems while reading.
  4686. @end table
  4687. This option has effect only during creation. It instructs tar to
  4688. treat as mild conditions any missing or unreadable files (directories),
  4689. or files that change while reading.
  4690. Such failures don't affect the program exit code, and the
  4691. corresponding diagnostic messages are marked as warnings, not errors.
  4692. These warnings can be suppressed using the
  4693. @option{--warning=failed-read} option (@pxref{warnings}).
  4694. @node extract options
  4695. @section Options Used by @option{--extract}
  4696. @cindex options for use with @option{--extract}
  4697. @xopindex{extract, additional options}
  4698. The previous chapter showed how to use @option{--extract} to extract
  4699. an archive into the file system. Various options cause @command{tar} to
  4700. extract more information than just file contents, such as the owner,
  4701. the permissions, the modification date, and so forth. This section
  4702. presents options to be used with @option{--extract} when certain special
  4703. considerations arise. You may review the information presented in
  4704. @ref{extract} for more basic information about the
  4705. @option{--extract} operation.
  4706. @menu
  4707. * Reading:: Options to Help Read Archives
  4708. * Writing:: Changing How @command{tar} Writes Files
  4709. * Scarce:: Coping with Scarce Resources
  4710. @end menu
  4711. @node Reading
  4712. @subsection Options to Help Read Archives
  4713. @cindex Options when reading archives
  4714. @cindex Reading incomplete records
  4715. @cindex Records, incomplete
  4716. @opindex read-full-records
  4717. Normally, @command{tar} will request data in full record increments from
  4718. an archive storage device. If the device cannot return a full record,
  4719. @command{tar} will report an error. However, some devices do not always
  4720. return full records, or do not require the last record of an archive to
  4721. be padded out to the next record boundary. To keep reading until you
  4722. obtain a full record, or to accept an incomplete record if it contains
  4723. an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
  4724. in conjunction with the @option{--extract} or @option{--list} operations.
  4725. @xref{Blocking}.
  4726. The @option{--read-full-records} (@option{-B}) option is turned on by default when
  4727. @command{tar} reads an archive from standard input, or from a remote
  4728. machine. This is because on @acronym{BSD} Unix systems, attempting to read a
  4729. pipe returns however much happens to be in the pipe, even if it is
  4730. less than was requested. If this option were not enabled, @command{tar}
  4731. would fail as soon as it read an incomplete record from the pipe.
  4732. If you're not sure of the blocking factor of an archive, you can
  4733. read the archive by specifying @option{--read-full-records} (@option{-B}) and
  4734. @option{--blocking-factor=@var{512-size}} (@option{-b
  4735. @var{512-size}}), using a blocking factor larger than what the archive
  4736. uses. This lets you avoid having to determine the blocking factor
  4737. of an archive. @xref{Blocking Factor}.
  4738. @menu
  4739. * read full records::
  4740. * Ignore Zeros::
  4741. @end menu
  4742. @node read full records
  4743. @unnumberedsubsubsec Reading Full Records
  4744. @FIXME{need sentence or so of intro here}
  4745. @table @option
  4746. @opindex read-full-records
  4747. @item --read-full-records
  4748. @item -B
  4749. Use in conjunction with @option{--extract} (@option{--get},
  4750. @option{-x}) to read an archive which contains incomplete records, or
  4751. one which has a blocking factor less than the one specified.
  4752. @end table
  4753. @node Ignore Zeros
  4754. @unnumberedsubsubsec Ignoring Blocks of Zeros
  4755. @cindex End-of-archive blocks, ignoring
  4756. @cindex Ignoring end-of-archive blocks
  4757. @opindex ignore-zeros
  4758. Normally, @command{tar} stops reading when it encounters a block of zeros
  4759. between file entries (which usually indicates the end of the archive).
  4760. @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
  4761. completely read an archive which contains a block of zeros before the
  4762. end (i.e., a damaged archive, or one that was created by concatenating
  4763. several archives together). This option also suppresses warnings
  4764. about missing or incomplete zero blocks at the end of the archive.
  4765. This can be turned on, if the need be, using the
  4766. @option{--warning=alone-zero-block --warning=missing-zero-blocks}
  4767. options (@pxref{warnings}).
  4768. The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
  4769. versions of @command{tar} write garbage after the end-of-archive entry,
  4770. since that part of the media is never supposed to be read. @GNUTAR{}
  4771. does not write after the end of an archive, but seeks to
  4772. maintain compatibility among archiving utilities.
  4773. @table @option
  4774. @item --ignore-zeros
  4775. @itemx -i
  4776. To ignore blocks of zeros (i.e., end-of-archive entries) which may be
  4777. encountered while reading an archive. Use in conjunction with
  4778. @option{--extract} or @option{--list}.
  4779. @end table
  4780. @node Writing
  4781. @subsection Changing How @command{tar} Writes Files
  4782. @UNREVISED{}
  4783. @FIXME{Introductory paragraph}
  4784. @menu
  4785. * Dealing with Old Files::
  4786. * Overwrite Old Files::
  4787. * Keep Old Files::
  4788. * Keep Newer Files::
  4789. * Unlink First::
  4790. * Recursive Unlink::
  4791. * Data Modification Times::
  4792. * Setting Access Permissions::
  4793. * Directory Modification Times and Permissions::
  4794. * Writing to Standard Output::
  4795. * Writing to an External Program::
  4796. * remove files::
  4797. @end menu
  4798. @node Dealing with Old Files
  4799. @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
  4800. @xopindex{overwrite-dir, introduced}
  4801. When extracting files, if @command{tar} discovers that the extracted
  4802. file already exists, it normally replaces the file by removing it before
  4803. extracting it, to prevent confusion in the presence of hard or symbolic
  4804. links. (If the existing file is a symbolic link, it is removed, not
  4805. followed.) However, if a directory cannot be removed because it is
  4806. nonempty, @command{tar} normally overwrites its metadata (ownership,
  4807. permission, etc.). The @option{--overwrite-dir} option enables this
  4808. default behavior. To be more cautious and preserve the metadata of
  4809. such a directory, use the @option{--no-overwrite-dir} option.
  4810. @cindex Overwriting old files, prevention
  4811. @xopindex{keep-old-files, introduced}
  4812. To be even more cautious and prevent existing files from being replaced, use
  4813. the @option{--keep-old-files} (@option{-k}) option. It causes
  4814. @command{tar} to refuse to replace or update a file that already
  4815. exists, i.e., a file with the same name as an archive member prevents
  4816. extraction of that archive member. Instead, it reports an error. For
  4817. example:
  4818. @example
  4819. $ @kbd{ls}
  4820. blues
  4821. $ @kbd{tar -x -k -f archive.tar}
  4822. tar: blues: Cannot open: File exists
  4823. tar: Exiting with failure status due to previous errors
  4824. @end example
  4825. @xopindex{skip-old-files, introduced}
  4826. If you wish to preserve old files untouched, but don't want
  4827. @command{tar} to treat them as errors, use the
  4828. @option{--skip-old-files} option. This option causes @command{tar} to
  4829. silently skip extracting over existing files.
  4830. @xopindex{overwrite, introduced}
  4831. To be more aggressive about altering existing files, use the
  4832. @option{--overwrite} option. It causes @command{tar} to overwrite
  4833. existing files and to follow existing symbolic links when extracting.
  4834. @cindex Protecting old files
  4835. Some people argue that @GNUTAR{} should not hesitate
  4836. to overwrite files with other files when extracting. When extracting
  4837. a @command{tar} archive, they expect to see a faithful copy of the
  4838. state of the file system when the archive was created. It is debatable
  4839. that this would always be a proper behavior. For example, suppose one
  4840. has an archive in which @file{usr/local} is a link to
  4841. @file{usr/local2}. Since then, maybe the site removed the link and
  4842. renamed the whole hierarchy from @file{/usr/local2} to
  4843. @file{/usr/local}. Such things happen all the time. I guess it would
  4844. not be welcome at all that @GNUTAR{} removes the
  4845. whole hierarchy just to make room for the link to be reinstated
  4846. (unless it @emph{also} simultaneously restores the full
  4847. @file{/usr/local2}, of course!) @GNUTAR{} is indeed
  4848. able to remove a whole hierarchy to reestablish a symbolic link, for
  4849. example, but @emph{only if} @option{--recursive-unlink} is specified
  4850. to allow this behavior. In any case, single files are silently
  4851. removed.
  4852. @xopindex{unlink-first, introduced}
  4853. Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
  4854. some cases by causing @command{tar} to remove files unconditionally
  4855. before extracting them.
  4856. @node Overwrite Old Files
  4857. @unnumberedsubsubsec Overwrite Old Files
  4858. @table @option
  4859. @opindex overwrite
  4860. @item --overwrite
  4861. Overwrite existing files and directory metadata when extracting files
  4862. from an archive.
  4863. This causes @command{tar} to write extracted files into the file system without
  4864. regard to the files already on the system; i.e., files with the same
  4865. names as archive members are overwritten when the archive is extracted.
  4866. It also causes @command{tar} to extract the ownership, permissions,
  4867. and time stamps onto any preexisting files or directories.
  4868. If the name of a corresponding file name is a symbolic link, the file
  4869. pointed to by the symbolic link will be overwritten instead of the
  4870. symbolic link itself (if this is possible). Moreover, special devices,
  4871. empty directories and even symbolic links are automatically removed if
  4872. they are in the way of extraction.
  4873. Be careful when using the @option{--overwrite} option, particularly when
  4874. combined with the @option{--absolute-names} (@option{-P}) option, as this combination
  4875. can change the contents, ownership or permissions of any file on your
  4876. system. Also, many systems do not take kindly to overwriting files that
  4877. are currently being executed.
  4878. @opindex overwrite-dir
  4879. @item --overwrite-dir
  4880. Overwrite the metadata of directories when extracting files from an
  4881. archive, but remove other files before extracting.
  4882. @end table
  4883. @node Keep Old Files
  4884. @unnumberedsubsubsec Keep Old Files
  4885. @GNUTAR{} provides two options to control its actions in a situation
  4886. when it is about to extract a file which already exists on disk.
  4887. @table @option
  4888. @opindex keep-old-files
  4889. @item --keep-old-files
  4890. @itemx -k
  4891. Do not replace existing files from archive. When such a file is
  4892. encountered, @command{tar} issues an error message. Upon end of
  4893. extraction, @command{tar} exits with code 2 (@pxref{exit status}).
  4894. @item --skip-old-files
  4895. Do not replace existing files from archive, but do not treat that
  4896. as error. Such files are silently skipped and do not affect
  4897. @command{tar} exit status.
  4898. Additional verbosity can be obtained using @option{--warning=existing-file}
  4899. together with that option (@pxref{warnings}).
  4900. @end table
  4901. @node Keep Newer Files
  4902. @unnumberedsubsubsec Keep Newer Files
  4903. @table @option
  4904. @opindex keep-newer-files
  4905. @item --keep-newer-files
  4906. Do not replace existing files that are newer than their archive
  4907. copies. This option is meaningless with @option{--list} (@option{-t}).
  4908. @end table
  4909. @node Unlink First
  4910. @unnumberedsubsubsec Unlink First
  4911. @table @option
  4912. @opindex unlink-first
  4913. @item --unlink-first
  4914. @itemx -U
  4915. Remove files before extracting over them.
  4916. This can make @command{tar} run a bit faster if you know in advance
  4917. that the extracted files all need to be removed. Normally this option
  4918. slows @command{tar} down slightly, so it is disabled by default.
  4919. @end table
  4920. @node Recursive Unlink
  4921. @unnumberedsubsubsec Recursive Unlink
  4922. @table @option
  4923. @opindex recursive-unlink
  4924. @item --recursive-unlink
  4925. When this option is specified, try removing files and directory hierarchies
  4926. before extracting over them. @emph{This is a dangerous option!}
  4927. @end table
  4928. If you specify the @option{--recursive-unlink} option,
  4929. @command{tar} removes @emph{anything} that keeps you from extracting a file
  4930. as far as current permissions will allow it. This could include removal
  4931. of the contents of a full directory hierarchy.
  4932. @node Data Modification Times
  4933. @unnumberedsubsubsec Setting Data Modification Times
  4934. @cindex Data modification times of extracted files
  4935. @cindex Modification times of extracted files
  4936. Normally, @command{tar} sets the data modification times of extracted
  4937. files to the corresponding times recorded for the files in the archive, but
  4938. limits the permissions of extracted files by the current @code{umask}
  4939. setting.
  4940. To set the data modification times of extracted files to the time when
  4941. the files were extracted, use the @option{--touch} (@option{-m}) option in
  4942. conjunction with @option{--extract} (@option{--get}, @option{-x}).
  4943. @table @option
  4944. @opindex touch
  4945. @item --touch
  4946. @itemx -m
  4947. Sets the data modification time of extracted archive members to the time
  4948. they were extracted, not the time recorded for them in the archive.
  4949. Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
  4950. @end table
  4951. @node Setting Access Permissions
  4952. @unnumberedsubsubsec Setting Access Permissions
  4953. @cindex Permissions of extracted files
  4954. @cindex Modes of extracted files
  4955. To set the modes (access permissions) of extracted files to those
  4956. recorded for those files in the archive, use @option{--same-permissions}
  4957. in conjunction with the @option{--extract} (@option{--get},
  4958. @option{-x}) operation.
  4959. @table @option
  4960. @opindex preserve-permissions
  4961. @opindex same-permissions
  4962. @item --preserve-permissions
  4963. @itemx --same-permissions
  4964. @c @itemx --ignore-umask
  4965. @itemx -p
  4966. Set modes of extracted archive members to those recorded in the
  4967. archive, instead of current umask settings. Use in conjunction with
  4968. @option{--extract} (@option{--get}, @option{-x}).
  4969. @end table
  4970. @node Directory Modification Times and Permissions
  4971. @unnumberedsubsubsec Directory Modification Times and Permissions
  4972. After successfully extracting a file member, @GNUTAR{} normally
  4973. restores its permissions and modification times, as described in the
  4974. previous sections. This cannot be done for directories, because
  4975. after extracting a directory @command{tar} will almost certainly
  4976. extract files into that directory and this will cause the directory
  4977. modification time to be updated. Moreover, restoring that directory
  4978. permissions may not permit file creation within it. Thus, restoring
  4979. directory permissions and modification times must be delayed at least
  4980. until all files have been extracted into that directory. @GNUTAR{}
  4981. restores directories using the following approach.
  4982. The extracted directories are created with the mode specified in the
  4983. archive, as modified by the umask of the user, which gives sufficient
  4984. permissions to allow file creation. The meta-information about the
  4985. directory is recorded in the temporary list of directories. When
  4986. preparing to extract next archive member, @GNUTAR{} checks if the
  4987. directory prefix of this file contains the remembered directory. If
  4988. it does not, the program assumes that all files have been extracted
  4989. into that directory, restores its modification time and permissions
  4990. and removes its entry from the internal list. This approach allows
  4991. to correctly restore directory meta-information in the majority of
  4992. cases, while keeping memory requirements sufficiently small. It is
  4993. based on the fact, that most @command{tar} archives use the predefined
  4994. order of members: first the directory, then all the files and
  4995. subdirectories in that directory.
  4996. However, this is not always true. The most important exception are
  4997. incremental archives (@pxref{Incremental Dumps}). The member order in
  4998. an incremental archive is reversed: first all directory members are
  4999. stored, followed by other (non-directory) members. So, when extracting
  5000. from incremental archives, @GNUTAR{} alters the above procedure. It
  5001. remembers all restored directories, and restores their meta-data
  5002. only after the entire archive has been processed. Notice, that you do
  5003. not need to specify any special options for that, as @GNUTAR{}
  5004. automatically detects archives in incremental format.
  5005. There may be cases, when such processing is required for normal archives
  5006. too. Consider the following example:
  5007. @smallexample
  5008. @group
  5009. $ @kbd{tar --no-recursion -cvf archive \
  5010. foo foo/file1 bar bar/file foo/file2}
  5011. foo/
  5012. foo/file1
  5013. bar/
  5014. bar/file
  5015. foo/file2
  5016. @end group
  5017. @end smallexample
  5018. During the normal operation, after encountering @file{bar}
  5019. @GNUTAR{} will assume that all files from the directory @file{foo}
  5020. were already extracted and will therefore restore its timestamp and
  5021. permission bits. However, after extracting @file{foo/file2} the
  5022. directory timestamp will be offset again.
  5023. To correctly restore directory meta-information in such cases, use
  5024. the @option{--delay-directory-restore} command line option:
  5025. @table @option
  5026. @opindex delay-directory-restore
  5027. @item --delay-directory-restore
  5028. Delays restoring of the modification times and permissions of extracted
  5029. directories until the end of extraction. This way, correct
  5030. meta-information is restored even if the archive has unusual member
  5031. ordering.
  5032. @opindex no-delay-directory-restore
  5033. @item --no-delay-directory-restore
  5034. Cancel the effect of the previous @option{--delay-directory-restore}.
  5035. Use this option if you have used @option{--delay-directory-restore} in
  5036. @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
  5037. temporarily disable it.
  5038. @end table
  5039. @node Writing to Standard Output
  5040. @unnumberedsubsubsec Writing to Standard Output
  5041. @cindex Writing extracted files to standard output
  5042. @cindex Standard output, writing extracted files to
  5043. To write the extracted files to the standard output, instead of
  5044. creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
  5045. conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
  5046. extracting files to send them through a pipe, and do not need to
  5047. preserve them in the file system. If you extract multiple members,
  5048. they appear on standard output concatenated, in the order they are
  5049. found in the archive.
  5050. @table @option
  5051. @opindex to-stdout
  5052. @item --to-stdout
  5053. @itemx -O
  5054. Writes files to the standard output. Use only in conjunction with
  5055. @option{--extract} (@option{--get}, @option{-x}). When this option is
  5056. used, instead of creating the files specified, @command{tar} writes
  5057. the contents of the files extracted to its standard output. This may
  5058. be useful if you are only extracting the files in order to send them
  5059. through a pipe. This option is meaningless with @option{--list}
  5060. (@option{-t}).
  5061. @end table
  5062. This can be useful, for example, if you have a tar archive containing
  5063. a big file and don't want to store the file on disk before processing
  5064. it. You can use a command like this:
  5065. @smallexample
  5066. tar -xOzf foo.tgz bigfile | process
  5067. @end smallexample
  5068. or even like this if you want to process the concatenation of the files:
  5069. @smallexample
  5070. tar -xOzf foo.tgz bigfile1 bigfile2 | process
  5071. @end smallexample
  5072. However, @option{--to-command} may be more convenient for use with
  5073. multiple files. See the next section.
  5074. @node Writing to an External Program
  5075. @unnumberedsubsubsec Writing to an External Program
  5076. You can instruct @command{tar} to send the contents of each extracted
  5077. file to the standard input of an external program:
  5078. @table @option
  5079. @opindex to-command
  5080. @item --to-command=@var{command}
  5081. Extract files and pipe their contents to the standard input of
  5082. @var{command}. When this option is used, instead of creating the
  5083. files specified, @command{tar} invokes @var{command} and pipes the
  5084. contents of the files to its standard output. The @var{command} may
  5085. contain command line arguments (see @ref{external, Running External Commands},
  5086. for more detail).
  5087. Notice, that @var{command} is executed once for each regular file
  5088. extracted. Non-regular files (directories, etc.)@: are ignored when this
  5089. option is used.
  5090. @end table
  5091. The command can obtain the information about the file it processes
  5092. from the following environment variables:
  5093. @table @env
  5094. @vrindex TAR_FILETYPE, to-command environment
  5095. @item TAR_FILETYPE
  5096. Type of the file. It is a single letter with the following meaning:
  5097. @multitable @columnfractions 0.10 0.90
  5098. @item f @tab Regular file
  5099. @item d @tab Directory
  5100. @item l @tab Symbolic link
  5101. @item h @tab Hard link
  5102. @item b @tab Block device
  5103. @item c @tab Character device
  5104. @end multitable
  5105. Currently only regular files are supported.
  5106. @vrindex TAR_MODE, to-command environment
  5107. @item TAR_MODE
  5108. File mode, an octal number.
  5109. @vrindex TAR_FILENAME, to-command environment
  5110. @item TAR_FILENAME
  5111. The name of the file.
  5112. @vrindex TAR_REALNAME, to-command environment
  5113. @item TAR_REALNAME
  5114. Name of the file as stored in the archive.
  5115. @vrindex TAR_UNAME, to-command environment
  5116. @item TAR_UNAME
  5117. Name of the file owner.
  5118. @vrindex TAR_GNAME, to-command environment
  5119. @item TAR_GNAME
  5120. Name of the file owner group.
  5121. @vrindex TAR_ATIME, to-command environment
  5122. @item TAR_ATIME
  5123. Time of last access. It is a decimal number, representing seconds
  5124. since the Epoch. If the archive provides times with nanosecond
  5125. precision, the nanoseconds are appended to the timestamp after a
  5126. decimal point.
  5127. @vrindex TAR_MTIME, to-command environment
  5128. @item TAR_MTIME
  5129. Time of last modification.
  5130. @vrindex TAR_CTIME, to-command environment
  5131. @item TAR_CTIME
  5132. Time of last status change.
  5133. @vrindex TAR_SIZE, to-command environment
  5134. @item TAR_SIZE
  5135. Size of the file.
  5136. @vrindex TAR_UID, to-command environment
  5137. @item TAR_UID
  5138. UID of the file owner.
  5139. @vrindex TAR_GID, to-command environment
  5140. @item TAR_GID
  5141. GID of the file owner.
  5142. @end table
  5143. Additionally, the following variables contain information about
  5144. tar mode and the archive being processed:
  5145. @table @env
  5146. @vrindex TAR_VERSION, to-command environment
  5147. @item TAR_VERSION
  5148. @GNUTAR{} version number.
  5149. @vrindex TAR_ARCHIVE, to-command environment
  5150. @item TAR_ARCHIVE
  5151. The name of the archive @command{tar} is processing.
  5152. @vrindex TAR_BLOCKING_FACTOR, to-command environment
  5153. @item TAR_BLOCKING_FACTOR
  5154. Current blocking factor (@pxref{Blocking}).
  5155. @vrindex TAR_VOLUME, to-command environment
  5156. @item TAR_VOLUME
  5157. Ordinal number of the volume @command{tar} is processing.
  5158. @vrindex TAR_FORMAT, to-command environment
  5159. @item TAR_FORMAT
  5160. Format of the archive being processed. @xref{Formats}, for a complete
  5161. list of archive format names.
  5162. @end table
  5163. These variables are defined prior to executing the command, so you can
  5164. pass them as arguments, if you prefer. For example, if the command
  5165. @var{proc} takes the member name and size as its arguments, then you
  5166. could do:
  5167. @smallexample
  5168. $ @kbd{tar -x -f archive.tar \
  5169. --to-command='proc $TAR_FILENAME $TAR_SIZE'}
  5170. @end smallexample
  5171. @noindent
  5172. Notice single quotes to prevent variable names from being expanded by
  5173. the shell when invoking @command{tar}.
  5174. If @var{command} exits with a non-0 status, @command{tar} will print
  5175. an error message similar to the following:
  5176. @smallexample
  5177. tar: 2345: Child returned status 1
  5178. @end smallexample
  5179. Here, @samp{2345} is the PID of the finished process.
  5180. If this behavior is not wanted, use @option{--ignore-command-error}:
  5181. @table @option
  5182. @opindex ignore-command-error
  5183. @item --ignore-command-error
  5184. Ignore exit codes of subprocesses. Notice that if the program
  5185. exits on signal or otherwise terminates abnormally, the error message
  5186. will be printed even if this option is used.
  5187. @opindex no-ignore-command-error
  5188. @item --no-ignore-command-error
  5189. Cancel the effect of any previous @option{--ignore-command-error}
  5190. option. This option is useful if you have set
  5191. @option{--ignore-command-error} in @env{TAR_OPTIONS}
  5192. (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
  5193. @end table
  5194. @node remove files
  5195. @unnumberedsubsubsec Removing Files
  5196. @FIXME{The section is too terse. Something more to add? An example,
  5197. maybe?}
  5198. @table @option
  5199. @opindex remove-files
  5200. @item --remove-files
  5201. Remove files after adding them to the archive.
  5202. @end table
  5203. @node Scarce
  5204. @subsection Coping with Scarce Resources
  5205. @UNREVISED{}
  5206. @cindex Small memory
  5207. @cindex Running out of space
  5208. @menu
  5209. * Starting File::
  5210. * Same Order::
  5211. @end menu
  5212. @node Starting File
  5213. @unnumberedsubsubsec Starting File
  5214. @table @option
  5215. @opindex starting-file
  5216. @item --starting-file=@var{name}
  5217. @itemx -K @var{name}
  5218. Starts an operation in the middle of an archive. Use in conjunction
  5219. with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
  5220. @end table
  5221. @cindex Middle of the archive, starting in the
  5222. If a previous attempt to extract files failed due to lack of disk
  5223. space, you can use @option{--starting-file=@var{name}} (@option{-K
  5224. @var{name}}) to start extracting only after member @var{name} of the
  5225. archive. This assumes, of course, that there is now free space, or
  5226. that you are now extracting into a different file system. (You could
  5227. also choose to suspend @command{tar}, remove unnecessary files from
  5228. the file system, and then resume the same @command{tar} operation.
  5229. In this case, @option{--starting-file} is not necessary.) See also
  5230. @ref{interactive}, and @ref{exclude}.
  5231. @node Same Order
  5232. @unnumberedsubsubsec Same Order
  5233. @table @option
  5234. @cindex Large lists of file names on small machines
  5235. @opindex same-order
  5236. @opindex preserve-order
  5237. @item --same-order
  5238. @itemx --preserve-order
  5239. @itemx -s
  5240. To process large lists of file names on machines with small amounts of
  5241. memory. Use in conjunction with @option{--compare} (@option{--diff},
  5242. @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
  5243. (@option{--get}, @option{-x}).
  5244. @end table
  5245. The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
  5246. names to be listed or extracted is sorted in the same order as the
  5247. files in the archive. This allows a large list of names to be used,
  5248. even on a small machine that would not otherwise be able to hold all
  5249. the names in memory at the same time. Such a sorted list can easily be
  5250. created by running @samp{tar -t} on the archive and editing its output.
  5251. This option is probably never needed on modern computer systems.
  5252. @node backup
  5253. @section Backup options
  5254. @cindex backup options
  5255. @GNUTAR{} offers options for making backups of files
  5256. before writing new versions. These options control the details of
  5257. these backups. They may apply to the archive itself before it is
  5258. created or rewritten, as well as individual extracted members. Other
  5259. @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
  5260. and @command{mv}, for example) offer similar options.
  5261. Backup options may prove unexpectedly useful when extracting archives
  5262. containing many members having identical name, or when extracting archives
  5263. on systems having file name limitations, making different members appear
  5264. as having similar names through the side-effect of name truncation.
  5265. @FIXME{This is true only if we have a good scheme for truncated backup names,
  5266. which I'm not sure at all: I suspect work is needed in this area.}
  5267. When any existing file is backed up before being overwritten by extraction,
  5268. then clashing files are automatically be renamed to be unique, and the
  5269. true name is kept for only the last file of a series of clashing files.
  5270. By using verbose mode, users may track exactly what happens.
  5271. At the detail level, some decisions are still experimental, and may
  5272. change in the future, we are waiting comments from our users. So, please
  5273. do not learn to depend blindly on the details of the backup features.
  5274. For example, currently, directories themselves are never renamed through
  5275. using these options, so, extracting a file over a directory still has
  5276. good chances to fail. Also, backup options apply to created archives,
  5277. not only to extracted members. For created archives, backups will not
  5278. be attempted when the archive is a block or character device, or when it
  5279. refers to a remote file.
  5280. For the sake of simplicity and efficiency, backups are made by renaming old
  5281. files prior to creation or extraction, and not by copying. The original
  5282. name is restored if the file creation fails. If a failure occurs after a
  5283. partial extraction of a file, both the backup and the partially extracted
  5284. file are kept.
  5285. @table @samp
  5286. @item --backup[=@var{method}]
  5287. @opindex backup
  5288. @vindex VERSION_CONTROL
  5289. @cindex backups
  5290. Back up files that are about to be overwritten or removed.
  5291. Without this option, the original versions are destroyed.
  5292. Use @var{method} to determine the type of backups made.
  5293. If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
  5294. environment variable. And if @env{VERSION_CONTROL} is not set,
  5295. use the @samp{existing} method.
  5296. @vindex version-control @r{Emacs variable}
  5297. This option corresponds to the Emacs variable @samp{version-control};
  5298. the same values for @var{method} are accepted as in Emacs. This option
  5299. also allows more descriptive names. The valid @var{method}s are:
  5300. @table @samp
  5301. @item t
  5302. @itemx numbered
  5303. @cindex numbered @r{backup method}
  5304. Always make numbered backups.
  5305. @item nil
  5306. @itemx existing
  5307. @cindex existing @r{backup method}
  5308. Make numbered backups of files that already have them, simple backups
  5309. of the others.
  5310. @item never
  5311. @itemx simple
  5312. @cindex simple @r{backup method}
  5313. Always make simple backups.
  5314. @end table
  5315. @item --suffix=@var{suffix}
  5316. @opindex suffix
  5317. @cindex backup suffix
  5318. @vindex SIMPLE_BACKUP_SUFFIX
  5319. Append @var{suffix} to each backup file made with @option{--backup}. If this
  5320. option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
  5321. environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
  5322. set, the default is @samp{~}, just as in Emacs.
  5323. @end table
  5324. @node looking ahead
  5325. @section Looking Ahead: The Rest of this Manual
  5326. You have now seen how to use all eight of the operations available to
  5327. @command{tar}, and a number of the possible options. The next chapter
  5328. explains how to choose and change file and archive names, how to use
  5329. files to store names of other files which you can then call as
  5330. arguments to @command{tar} (this can help you save time if you expect to
  5331. archive the same list of files a number of times), and so forth.
  5332. @FIXME{in case it's not obvious, i'm making this up in some sense
  5333. based on my limited memory of what the next chapter *really* does. i
  5334. just wanted to flesh out this final section a little bit so i'd
  5335. remember to stick it in here. :-)}
  5336. If there are too many files to conveniently list on the command line,
  5337. you can list the names in a file, and @command{tar} will read that file.
  5338. @xref{files}.
  5339. There are various ways of causing @command{tar} to skip over some files,
  5340. and not archive them. @xref{Choosing}.
  5341. @node Backups
  5342. @chapter Performing Backups and Restoring Files
  5343. @cindex backups
  5344. @GNUTAR{} is distributed along with the scripts for performing backups
  5345. and restores. Even if there is a good chance those scripts may be
  5346. satisfying to you, they are not the only scripts or methods available for doing
  5347. backups and restore. You may well create your own, or use more
  5348. sophisticated packages dedicated to that purpose.
  5349. Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
  5350. Automatic Network Disk Archiver), a backup system developed by James
  5351. da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
  5352. This is free software, and it is available from @uref{http://www.amanda.org}.
  5353. @FIXME{
  5354. Here is a possible plan for a future documentation about the backuping
  5355. scripts which are provided within the @GNUTAR{}
  5356. distribution.
  5357. @itemize @bullet
  5358. @item dumps
  5359. @itemize @minus
  5360. @item what are dumps
  5361. @item different levels of dumps
  5362. @itemize +
  5363. @item full dump = dump everything
  5364. @item level 1, level 2 dumps etc
  5365. A level @var{n} dump dumps everything changed since the last level
  5366. @var{n}-1 dump (?)
  5367. @end itemize
  5368. @item how to use scripts for dumps (ie, the concept)
  5369. @itemize +
  5370. @item scripts to run after editing backup specs (details)
  5371. @end itemize
  5372. @item Backup Specs, what is it.
  5373. @itemize +
  5374. @item how to customize
  5375. @item actual text of script [/sp/dump/backup-specs]
  5376. @end itemize
  5377. @item Problems
  5378. @itemize +
  5379. @item rsh doesn't work
  5380. @item rtape isn't installed
  5381. @item (others?)
  5382. @end itemize
  5383. @item the @option{--incremental} option of tar
  5384. @item tapes
  5385. @itemize +
  5386. @item write protection
  5387. @item types of media, different sizes and types, useful for different things
  5388. @item files and tape marks
  5389. one tape mark between files, two at end.
  5390. @item positioning the tape
  5391. MT writes two at end of write,
  5392. backspaces over one when writing again.
  5393. @end itemize
  5394. @end itemize
  5395. @end itemize
  5396. }
  5397. This chapter documents both the provided shell scripts and @command{tar}
  5398. options which are more specific to usage as a backup tool.
  5399. To @dfn{back up} a file system means to create archives that contain
  5400. all the files in that file system. Those archives can then be used to
  5401. restore any or all of those files (for instance if a disk crashes or a
  5402. file is accidentally deleted). File system @dfn{backups} are also
  5403. called @dfn{dumps}.
  5404. @menu
  5405. * Full Dumps:: Using @command{tar} to Perform Full Dumps
  5406. * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
  5407. * Backup Levels:: Levels of Backups
  5408. * Backup Parameters:: Setting Parameters for Backups and Restoration
  5409. * Scripted Backups:: Using the Backup Scripts
  5410. * Scripted Restoration:: Using the Restore Script
  5411. @end menu
  5412. @node Full Dumps
  5413. @section Using @command{tar} to Perform Full Dumps
  5414. @UNREVISED{}
  5415. @cindex full dumps
  5416. @cindex dumps, full
  5417. @cindex corrupted archives
  5418. Full dumps should only be made when no other people or programs
  5419. are modifying files in the file system. If files are modified while
  5420. @command{tar} is making the backup, they may not be stored properly in
  5421. the archive, in which case you won't be able to restore them if you
  5422. have to. (Files not being modified are written with no trouble, and do
  5423. not corrupt the entire archive.)
  5424. You will want to use the @option{--label=@var{archive-label}}
  5425. (@option{-V @var{archive-label}}) option to give the archive a
  5426. volume label, so you can tell what this archive is even if the label
  5427. falls off the tape, or anything like that.
  5428. Unless the file system you are dumping is guaranteed to fit on
  5429. one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
  5430. Make sure you have enough tapes on hand to complete the backup.
  5431. If you want to dump each file system separately you will need to use
  5432. the @option{--one-file-system} option to prevent
  5433. @command{tar} from crossing file system boundaries when storing
  5434. (sub)directories.
  5435. The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
  5436. option is not needed, since this is a complete copy of everything in
  5437. the file system, and a full restore from this backup would only be
  5438. done onto a completely
  5439. empty disk.
  5440. Unless you are in a hurry, and trust the @command{tar} program (and your
  5441. tapes), it is a good idea to use the @option{--verify} (@option{-W})
  5442. option, to make sure your files really made it onto the dump properly.
  5443. This will also detect cases where the file was modified while (or just
  5444. after) it was being archived. Not all media (notably cartridge tapes)
  5445. are capable of being verified, unfortunately.
  5446. @node Incremental Dumps
  5447. @section Using @command{tar} to Perform Incremental Dumps
  5448. @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
  5449. stores additional metadata so that exact state of the file system
  5450. can be restored when extracting the archive.
  5451. @GNUTAR{} currently offers two options for handling incremental
  5452. backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
  5453. @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
  5454. @xopindex{listed-incremental, described}
  5455. The option @option{--listed-incremental} instructs tar to operate on
  5456. an incremental archive with additional metadata stored in a standalone
  5457. file, called a @dfn{snapshot file}. The purpose of this file is to help
  5458. determine which files have been changed, added or deleted since the
  5459. last backup, so that the next incremental backup will contain only
  5460. modified files. The name of the snapshot file is given as an argument
  5461. to the option:
  5462. @table @option
  5463. @item --listed-incremental=@var{file}
  5464. @itemx -g @var{file}
  5465. Handle incremental backups with snapshot data in @var{file}.
  5466. @end table
  5467. To create an incremental backup, you would use
  5468. @option{--listed-incremental} together with @option{--create}
  5469. (@pxref{create}). For example:
  5470. @smallexample
  5471. $ @kbd{tar --create \
  5472. --file=archive.1.tar \
  5473. --listed-incremental=/var/log/usr.snar \
  5474. /usr}
  5475. @end smallexample
  5476. This will create in @file{archive.1.tar} an incremental backup of
  5477. the @file{/usr} file system, storing additional metadata in the file
  5478. @file{/var/log/usr.snar}. If this file does not exist, it will be
  5479. created. The created archive will then be a @dfn{level 0 backup};
  5480. please see the next section for more on backup levels.
  5481. Otherwise, if the file @file{/var/log/usr.snar} exists, it
  5482. determines which files are modified. In this case only these files will be
  5483. stored in the archive. Suppose, for example, that after running the
  5484. above command, you delete file @file{/usr/doc/old} and create
  5485. directory @file{/usr/local/db} with the following contents:
  5486. @smallexample
  5487. $ @kbd{ls /usr/local/db}
  5488. /usr/local/db/data
  5489. /usr/local/db/index
  5490. @end smallexample
  5491. Some time later you create another incremental backup. You will
  5492. then see:
  5493. @smallexample
  5494. $ @kbd{tar --create \
  5495. --file=archive.2.tar \
  5496. --listed-incremental=/var/log/usr.snar \
  5497. /usr}
  5498. tar: usr/local/db: Directory is new
  5499. usr/local/db/
  5500. usr/local/db/data
  5501. usr/local/db/index
  5502. @end smallexample
  5503. @noindent
  5504. The created archive @file{archive.2.tar} will contain only these
  5505. three members. This archive is called a @dfn{level 1 backup}. Notice
  5506. that @file{/var/log/usr.snar} will be updated with the new data, so if
  5507. you plan to create more @samp{level 1} backups, it is necessary to
  5508. create a working copy of the snapshot file before running
  5509. @command{tar}. The above example will then be modified as follows:
  5510. @smallexample
  5511. $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
  5512. $ @kbd{tar --create \
  5513. --file=archive.2.tar \
  5514. --listed-incremental=/var/log/usr.snar-1 \
  5515. /usr}
  5516. @end smallexample
  5517. @anchor{--level=0}
  5518. @xopindex{level, described}
  5519. You can force @samp{level 0} backups either by removing the snapshot
  5520. file before running @command{tar}, or by supplying the
  5521. @option{--level=0} option, e.g.:
  5522. @smallexample
  5523. $ @kbd{tar --create \
  5524. --file=archive.2.tar \
  5525. --listed-incremental=/var/log/usr.snar-0 \
  5526. --level=0 \
  5527. /usr}
  5528. @end smallexample
  5529. Incremental dumps depend crucially on time stamps, so the results are
  5530. unreliable if you modify a file's time stamps during dumping (e.g.,
  5531. with the @option{--atime-preserve=replace} option), or if you set the clock
  5532. backwards.
  5533. @anchor{device numbers}
  5534. @cindex Device numbers, using in incremental backups
  5535. Metadata stored in snapshot files include device numbers, which,
  5536. obviously are supposed to be non-volatile values. However, it turns
  5537. out that @acronym{NFS} devices have undependable values when an automounter
  5538. gets in the picture. This can lead to a great deal of spurious
  5539. redumping in incremental dumps, so it is somewhat useless to compare
  5540. two @acronym{NFS} devices numbers over time. The solution implemented
  5541. currently is to consider all @acronym{NFS} devices as being equal
  5542. when it comes to comparing directories; this is fairly gross, but
  5543. there does not seem to be a better way to go.
  5544. Apart from using @acronym{NFS}, there are a number of cases where
  5545. relying on device numbers can cause spurious redumping of unmodified
  5546. files. For example, this occurs when archiving @acronym{LVM} snapshot
  5547. volumes. To avoid this, use @option{--no-check-device} option:
  5548. @table @option
  5549. @xopindex{no-check-device, described}
  5550. @item --no-check-device
  5551. Do not rely on device numbers when preparing a list of changed files
  5552. for an incremental dump.
  5553. @xopindex{check-device, described}
  5554. @item --check-device
  5555. Use device numbers when preparing a list of changed files
  5556. for an incremental dump. This is the default behavior. The purpose
  5557. of this option is to undo the effect of the @option{--no-check-device}
  5558. if it was given in @env{TAR_OPTIONS} environment variable
  5559. (@pxref{TAR_OPTIONS}).
  5560. @end table
  5561. There is also another way to cope with changing device numbers. It is
  5562. described in detail in @ref{Fixing Snapshot Files}.
  5563. Note that incremental archives use @command{tar} extensions and may
  5564. not be readable by non-@acronym{GNU} versions of the @command{tar} program.
  5565. @xopindex{listed-incremental, using with @option{--extract}}
  5566. @xopindex{extract, using with @option{--listed-incremental}}
  5567. To extract from the incremental dumps, use
  5568. @option{--listed-incremental} together with @option{--extract}
  5569. option (@pxref{extracting files}). In this case, @command{tar} does
  5570. not need to access snapshot file, since all the data necessary for
  5571. extraction are stored in the archive itself. So, when extracting, you
  5572. can give whatever argument to @option{--listed-incremental}, the usual
  5573. practice is to use @option{--listed-incremental=/dev/null}.
  5574. Alternatively, you can use @option{--incremental}, which needs no
  5575. arguments. In general, @option{--incremental} (@option{-G}) can be
  5576. used as a shortcut for @option{--listed-incremental} when listing or
  5577. extracting incremental backups (for more information regarding this
  5578. option, @pxref{incremental-op}).
  5579. When extracting from the incremental backup @GNUTAR{} attempts to
  5580. restore the exact state the file system had when the archive was
  5581. created. In particular, it will @emph{delete} those files in the file
  5582. system that did not exist in their directories when the archive was
  5583. created. If you have created several levels of incremental files,
  5584. then in order to restore the exact contents the file system had when
  5585. the last level was created, you will need to restore from all backups
  5586. in turn. Continuing our example, to restore the state of @file{/usr}
  5587. file system, one would do@footnote{Notice, that since both archives
  5588. were created without @option{-P} option (@pxref{absolute}), these
  5589. commands should be run from the root file system.}:
  5590. @smallexample
  5591. $ @kbd{tar --extract \
  5592. --listed-incremental=/dev/null \
  5593. --file archive.1.tar}
  5594. $ @kbd{tar --extract \
  5595. --listed-incremental=/dev/null \
  5596. --file archive.2.tar}
  5597. @end smallexample
  5598. To list the contents of an incremental archive, use @option{--list}
  5599. (@pxref{list}), as usual. To obtain more information about the
  5600. archive, use @option{--listed-incremental} or @option{--incremental}
  5601. combined with two @option{--verbose} options@footnote{Two
  5602. @option{--verbose} options were selected to avoid breaking usual
  5603. verbose listing output (@option{--list --verbose}) when using in
  5604. scripts.
  5605. @xopindex{incremental, using with @option{--list}}
  5606. @xopindex{listed-incremental, using with @option{--list}}
  5607. @xopindex{list, using with @option{--incremental}}
  5608. @xopindex{list, using with @option{--listed-incremental}}
  5609. Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
  5610. contents of the DUMPDIR header (with terminating nulls) when
  5611. @option{--incremental} or @option{--listed-incremental} option was
  5612. given, no matter what the verbosity level. This behavior, and,
  5613. especially, the binary output it produced were considered inconvenient
  5614. and were changed in version 1.16.}:
  5615. @smallexample
  5616. @kbd{tar --list --incremental --verbose --verbose --file archive.tar}
  5617. @end smallexample
  5618. This command will print, for each directory in the archive, the list
  5619. of files in that directory at the time the archive was created. This
  5620. information is put out in a format which is both human-readable and
  5621. unambiguous for a program: each file name is printed as
  5622. @smallexample
  5623. @var{x} @var{file}
  5624. @end smallexample
  5625. @noindent
  5626. where @var{x} is a letter describing the status of the file: @samp{Y}
  5627. if the file is present in the archive, @samp{N} if the file is not
  5628. included in the archive, or a @samp{D} if the file is a directory (and
  5629. is included in the archive). @xref{Dumpdir}, for the detailed
  5630. description of dumpdirs and status codes. Each such
  5631. line is terminated by a newline character. The last line is followed
  5632. by an additional newline to indicate the end of the data.
  5633. @anchor{incremental-op}The option @option{--incremental} (@option{-G})
  5634. gives the same behavior as @option{--listed-incremental} when used
  5635. with @option{--list} and @option{--extract} options. When used with
  5636. @option{--create} option, it creates an incremental archive without
  5637. creating snapshot file. Thus, it is impossible to create several
  5638. levels of incremental backups with @option{--incremental} option.
  5639. @node Backup Levels
  5640. @section Levels of Backups
  5641. An archive containing all the files in the file system is called a
  5642. @dfn{full backup} or @dfn{full dump}. You could insure your data by
  5643. creating a full dump every day. This strategy, however, would waste a
  5644. substantial amount of archive media and user time, as unchanged files
  5645. are daily re-archived.
  5646. It is more efficient to do a full dump only occasionally. To back up
  5647. files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
  5648. one} dump archives all the files that have changed since the last full
  5649. dump.
  5650. A typical dump strategy would be to perform a full dump once a week,
  5651. and a level one dump once a day. This means some versions of files
  5652. will in fact be archived more than once, but this dump strategy makes
  5653. it possible to restore a file system to within one day of accuracy by
  5654. only extracting two archives---the last weekly (full) dump and the
  5655. last daily (level one) dump. The only information lost would be in
  5656. files changed or created since the last daily backup. (Doing dumps
  5657. more than once a day is usually not worth the trouble.)
  5658. @GNUTAR{} comes with scripts you can use to do full
  5659. and level-one (actually, even level-two and so on) dumps. Using
  5660. scripts (shell programs) to perform backups and restoration is a
  5661. convenient and reliable alternative to typing out file name lists
  5662. and @command{tar} commands by hand.
  5663. Before you use these scripts, you need to edit the file
  5664. @file{backup-specs}, which specifies parameters used by the backup
  5665. scripts and by the restore script. This file is usually located
  5666. in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
  5667. detailed description. Once the backup parameters are set, you can
  5668. perform backups or restoration by running the appropriate script.
  5669. The name of the backup script is @code{backup}. The name of the
  5670. restore script is @code{restore}. The following sections describe
  5671. their use in detail.
  5672. @emph{Please Note:} The backup and restoration scripts are
  5673. designed to be used together. While it is possible to restore files by
  5674. hand from an archive which was created using a backup script, and to create
  5675. an archive by hand which could then be extracted using the restore script,
  5676. it is easier to use the scripts. @xref{Incremental Dumps}, before
  5677. making such an attempt.
  5678. @node Backup Parameters
  5679. @section Setting Parameters for Backups and Restoration
  5680. The file @file{backup-specs} specifies backup parameters for the
  5681. backup and restoration scripts provided with @command{tar}. You must
  5682. edit @file{backup-specs} to fit your system configuration and schedule
  5683. before using these scripts.
  5684. Syntactically, @file{backup-specs} is a shell script, containing
  5685. mainly variable assignments. However, any valid shell construct
  5686. is allowed in this file. Particularly, you may wish to define
  5687. functions within that script (e.g., see @code{RESTORE_BEGIN} below).
  5688. For more information about shell script syntax, please refer to
  5689. @url{https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html,
  5690. the definition of the Shell Command Language}. See also
  5691. @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
  5692. The shell variables controlling behavior of @code{backup} and
  5693. @code{restore} are described in the following subsections.
  5694. @menu
  5695. * General-Purpose Variables::
  5696. * Magnetic Tape Control::
  5697. * User Hooks::
  5698. * backup-specs example:: An Example Text of @file{Backup-specs}
  5699. @end menu
  5700. @node General-Purpose Variables
  5701. @subsection General-Purpose Variables
  5702. @defvr {Backup variable} ADMINISTRATOR
  5703. The user name of the backup administrator. @code{Backup} scripts
  5704. sends a backup report to this address.
  5705. @end defvr
  5706. @defvr {Backup variable} BACKUP_HOUR
  5707. The hour at which the backups are done. This can be a number from 0
  5708. to 23, or the time specification in form @var{hours}:@var{minutes},
  5709. or the string @samp{now}.
  5710. This variable is used by @code{backup}. Its value may be overridden
  5711. using @option{--time} option (@pxref{Scripted Backups}).
  5712. @end defvr
  5713. @defvr {Backup variable} TAPE_FILE
  5714. The device @command{tar} writes the archive to. If @var{TAPE_FILE}
  5715. is a remote archive (@pxref{remote-dev}), backup script will suppose
  5716. that your @command{mt} is able to access remote devices. If @var{RSH}
  5717. (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
  5718. invocations of @command{mt}.
  5719. @end defvr
  5720. @defvr {Backup variable} BLOCKING
  5721. The blocking factor @command{tar} will use when writing the dump archive.
  5722. @xref{Blocking Factor}.
  5723. @end defvr
  5724. @defvr {Backup variable} BACKUP_DIRS
  5725. A list of file systems to be dumped (for @code{backup}), or restored
  5726. (for @code{restore}). You can include any directory
  5727. name in the list --- subdirectories on that file system will be
  5728. included, regardless of how they may look to other networked machines.
  5729. Subdirectories on other file systems will be ignored.
  5730. The host name specifies which host to run @command{tar} on, and should
  5731. normally be the host that actually contains the file system. However,
  5732. the host machine must have @GNUTAR{} installed, and
  5733. must be able to access the directory containing the backup scripts and
  5734. their support files using the same file name that is used on the
  5735. machine where the scripts are run (i.e., what @command{pwd} will print
  5736. when in that directory on that machine). If the host that contains
  5737. the file system does not have this capability, you can specify another
  5738. host as long as it can access the file system through @acronym{NFS}.
  5739. If the list of file systems is very long you may wish to put it
  5740. in a separate file. This file is usually named
  5741. @file{/etc/backup/dirs}, but this name may be overridden in
  5742. @file{backup-specs} using @code{DIRLIST} variable.
  5743. @end defvr
  5744. @defvr {Backup variable} DIRLIST
  5745. The name of the file that contains a list of file systems to backup
  5746. or restore. By default it is @file{/etc/backup/dirs}.
  5747. @end defvr
  5748. @defvr {Backup variable} BACKUP_FILES
  5749. A list of individual files to be dumped (for @code{backup}), or restored
  5750. (for @code{restore}). These should be accessible from the machine on
  5751. which the backup script is run.
  5752. If the list of individual files is very long you may wish to store it
  5753. in a separate file. This file is usually named
  5754. @file{/etc/backup/files}, but this name may be overridden in
  5755. @file{backup-specs} using @code{FILELIST} variable.
  5756. @end defvr
  5757. @defvr {Backup variable} FILELIST
  5758. The name of the file that contains a list of individual files to backup
  5759. or restore. By default it is @file{/etc/backup/files}.
  5760. @end defvr
  5761. @defvr {Backup variable} MT
  5762. Full file name of @command{mt} binary.
  5763. @end defvr
  5764. @defvr {Backup variable} RSH
  5765. @anchor{RSH}
  5766. Full file name of @command{rsh} binary or its equivalent. You may wish to
  5767. set it to @code{ssh}, to improve security. In this case you will have
  5768. to use public key authentication.
  5769. @end defvr
  5770. @defvr {Backup variable} RSH_COMMAND
  5771. Full file name of @command{rsh} binary on remote machines. This will
  5772. be passed via @option{--rsh-command} option to the remote invocation
  5773. of @GNUTAR{}.
  5774. @end defvr
  5775. @defvr {Backup variable} VOLNO_FILE
  5776. Name of temporary file to hold volume numbers. This needs to be accessible
  5777. by all the machines which have file systems to be dumped.
  5778. @end defvr
  5779. @defvr {Backup variable} XLIST
  5780. Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
  5781. located on the remote machine and containing the list of files to
  5782. be excluded from the backup. Exclude file lists are searched in
  5783. /etc/tar-backup directory. A common use for exclude file lists
  5784. is to exclude files containing security-sensitive information
  5785. (e.g., @file{/etc/shadow} from backups).
  5786. This variable affects only @code{backup}.
  5787. @end defvr
  5788. @defvr {Backup variable} SLEEP_TIME
  5789. Time to sleep between dumps of any two successive file systems
  5790. This variable affects only @code{backup}.
  5791. @end defvr
  5792. @defvr {Backup variable} DUMP_REMIND_SCRIPT
  5793. Script to be run when it's time to insert a new tape in for the next
  5794. volume. Administrators may want to tailor this script for their site.
  5795. If this variable isn't set, @GNUTAR{} will display its built-in
  5796. prompt, and will expect confirmation from the console. For the
  5797. description of the default prompt, see @ref{change volume prompt}.
  5798. @end defvr
  5799. @defvr {Backup variable} SLEEP_MESSAGE
  5800. Message to display on the terminal while waiting for dump time. Usually
  5801. this will just be some literal text.
  5802. @end defvr
  5803. @defvr {Backup variable} TAR
  5804. Full file name of the @GNUTAR{} executable. If this is not set, backup
  5805. scripts will search @command{tar} in the current shell path.
  5806. @end defvr
  5807. @node Magnetic Tape Control
  5808. @subsection Magnetic Tape Control
  5809. Backup scripts access tape device using special @dfn{hook functions}.
  5810. These functions take a single argument --- the name of the tape
  5811. device. Their names are kept in the following variables:
  5812. @defvr {Backup variable} MT_BEGIN
  5813. The name of @dfn{begin} function. This function is called before
  5814. accessing the drive. By default it retensions the tape:
  5815. @smallexample
  5816. MT_BEGIN=mt_begin
  5817. mt_begin() @{
  5818. mt -f "$1" retension
  5819. @}
  5820. @end smallexample
  5821. @end defvr
  5822. @defvr {Backup variable} MT_REWIND
  5823. The name of @dfn{rewind} function. The default definition is as
  5824. follows:
  5825. @smallexample
  5826. MT_REWIND=mt_rewind
  5827. mt_rewind() @{
  5828. mt -f "$1" rewind
  5829. @}
  5830. @end smallexample
  5831. @end defvr
  5832. @defvr {Backup variable} MT_OFFLINE
  5833. The name of the function switching the tape off line. By default
  5834. it is defined as follows:
  5835. @smallexample
  5836. MT_OFFLINE=mt_offline
  5837. mt_offline() @{
  5838. mt -f "$1" offl
  5839. @}
  5840. @end smallexample
  5841. @end defvr
  5842. @defvr {Backup variable} MT_STATUS
  5843. The name of the function used to obtain the status of the archive device,
  5844. including error count. Default definition:
  5845. @smallexample
  5846. MT_STATUS=mt_status
  5847. mt_status() @{
  5848. mt -f "$1" status
  5849. @}
  5850. @end smallexample
  5851. @end defvr
  5852. @node User Hooks
  5853. @subsection User Hooks
  5854. @dfn{User hooks} are shell functions executed before and after
  5855. each @command{tar} invocation. Thus, there are @dfn{backup
  5856. hooks}, which are executed before and after dumping each file
  5857. system, and @dfn{restore hooks}, executed before and
  5858. after restoring a file system. Each user hook is a shell function
  5859. taking four arguments:
  5860. @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
  5861. Its arguments are:
  5862. @table @var
  5863. @item level
  5864. Current backup or restore level.
  5865. @item host
  5866. Name or IP address of the host machine being dumped or restored.
  5867. @item fs
  5868. Full file name of the file system being dumped or restored.
  5869. @item fsname
  5870. File system name with directory separators replaced with colons. This
  5871. is useful, e.g., for creating unique files.
  5872. @end table
  5873. @end deffn
  5874. Following variables keep the names of user hook functions:
  5875. @defvr {Backup variable} DUMP_BEGIN
  5876. Dump begin function. It is executed before dumping the file system.
  5877. @end defvr
  5878. @defvr {Backup variable} DUMP_END
  5879. Executed after dumping the file system.
  5880. @end defvr
  5881. @defvr {Backup variable} RESTORE_BEGIN
  5882. Executed before restoring the file system.
  5883. @end defvr
  5884. @defvr {Backup variable} RESTORE_END
  5885. Executed after restoring the file system.
  5886. @end defvr
  5887. @node backup-specs example
  5888. @subsection An Example Text of @file{Backup-specs}
  5889. The following is an example of @file{backup-specs}:
  5890. @smallexample
  5891. # site-specific parameters for file system backup.
  5892. ADMINISTRATOR=friedman
  5893. BACKUP_HOUR=1
  5894. TAPE_FILE=/dev/nrsmt0
  5895. # Use @code{ssh} instead of the less secure @code{rsh}
  5896. RSH=/usr/bin/ssh
  5897. RSH_COMMAND=/usr/bin/ssh
  5898. # Override MT_STATUS function:
  5899. my_status() @{
  5900. mts -t $TAPE_FILE
  5901. @}
  5902. MT_STATUS=my_status
  5903. # Disable MT_OFFLINE function
  5904. MT_OFFLINE=:
  5905. BLOCKING=124
  5906. BACKUP_DIRS="
  5907. albert:/fs/fsf
  5908. apple-gunkies:/gd
  5909. albert:/fs/gd2
  5910. albert:/fs/gp
  5911. geech:/usr/jla
  5912. churchy:/usr/roland
  5913. albert:/
  5914. albert:/usr
  5915. apple-gunkies:/
  5916. apple-gunkies:/usr
  5917. gnu:/hack
  5918. gnu:/u
  5919. apple-gunkies:/com/mailer/gnu
  5920. apple-gunkies:/com/archive/gnu"
  5921. BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
  5922. @end smallexample
  5923. @node Scripted Backups
  5924. @section Using the Backup Scripts
  5925. The syntax for running a backup script is:
  5926. @smallexample
  5927. backup --level=@var{level} --time=@var{time}
  5928. @end smallexample
  5929. The @option{--level} option requests the dump level. Thus, to produce
  5930. a full dump, specify @code{--level=0} (this is the default, so
  5931. @option{--level} may be omitted if its value is
  5932. @code{0})@footnote{For backward compatibility, the @code{backup} will also
  5933. try to deduce the requested dump level from the name of the
  5934. script itself. If the name consists of a string @samp{level-}
  5935. followed by a single decimal digit, that digit is taken as
  5936. the dump level number. Thus, you may create a link from @code{backup}
  5937. to @code{level-1} and then run @code{level-1} whenever you need to
  5938. create a level one dump.}.
  5939. The @option{--time} option determines when should the backup be
  5940. run. @var{Time} may take three forms:
  5941. @table @asis
  5942. @item @var{hh}:@var{mm}
  5943. The dump must be run at @var{hh} hours @var{mm} minutes.
  5944. @item @var{hh}
  5945. The dump must be run at @var{hh} hours.
  5946. @item now
  5947. The dump must be run immediately.
  5948. @end table
  5949. You should start a script with a tape or disk mounted. Once you
  5950. start a script, it prompts you for new tapes or disks as it
  5951. needs them. Media volumes don't have to correspond to archive
  5952. files --- a multi-volume archive can be started in the middle of a
  5953. tape that already contains the end of another multi-volume archive.
  5954. The @code{restore} script prompts for media by its archive volume,
  5955. so to avoid an error message you should keep track of which tape
  5956. (or disk) contains which volume of the archive (@pxref{Scripted
  5957. Restoration}).
  5958. The backup scripts write two files on the file system. The first is a
  5959. record file in @file{/etc/tar-backup/}, which is used by the scripts
  5960. to store and retrieve information about which files were dumped. This
  5961. file is not meant to be read by humans, and should not be deleted by
  5962. them. @xref{Snapshot Files}, for a more detailed explanation of this
  5963. file.
  5964. The second file is a log file containing the names of the file systems
  5965. and files dumped, what time the backup was made, and any error
  5966. messages that were generated, as well as how much space was left in
  5967. the media volume after the last volume of the archive was written.
  5968. You should check this log file after every backup. The file name is
  5969. @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
  5970. represents current date, and @var{n} represents current dump level number.
  5971. The script also prints the name of each system being dumped to the
  5972. standard output.
  5973. Following is the full list of options accepted by @code{backup}
  5974. script:
  5975. @table @option
  5976. @item -l @var{level}
  5977. @itemx --level=@var{level}
  5978. Do backup level @var{level} (default 0).
  5979. @item -f
  5980. @itemx --force
  5981. Force backup even if today's log file already exists.
  5982. @item -v[@var{level}]
  5983. @itemx --verbose[=@var{level}]
  5984. Set verbosity level. The higher the level is, the more debugging
  5985. information will be output during execution. Default @var{level}
  5986. is 100, which means the highest debugging level.
  5987. @item -t @var{start-time}
  5988. @itemx --time=@var{start-time}
  5989. Wait till @var{time}, then do backup.
  5990. @item -h
  5991. @itemx --help
  5992. Display short help message and exit.
  5993. @item -V
  5994. @itemx --version
  5995. Display information about the program's name, version, origin and legal
  5996. status, all on standard output, and then exit successfully.
  5997. @end table
  5998. @node Scripted Restoration
  5999. @section Using the Restore Script
  6000. To restore files that were archived using a scripted backup, use the
  6001. @code{restore} script. Its usage is quite straightforward. In the
  6002. simplest form, invoke @code{restore --all}, it will
  6003. then restore all the file systems and files specified in
  6004. @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
  6005. You may select the file systems (and/or files) to restore by
  6006. giving @code{restore} a list of @dfn{patterns} in its command
  6007. line. For example, running
  6008. @smallexample
  6009. restore 'albert:*'
  6010. @end smallexample
  6011. @noindent
  6012. will restore all file systems on the machine @samp{albert}. A more
  6013. complicated example:
  6014. @smallexample
  6015. restore 'albert:*' '*:/var'
  6016. @end smallexample
  6017. @noindent
  6018. This command will restore all file systems on the machine @samp{albert}
  6019. as well as @file{/var} file system on all machines.
  6020. By default @code{restore} will start restoring files from the lowest
  6021. available dump level (usually zero) and will continue through
  6022. all available dump levels. There may be situations where such a
  6023. thorough restore is not necessary. For example, you may wish to
  6024. restore only files from the recent level one backup. To do so,
  6025. use @option{--level} option, as shown in the example below:
  6026. @smallexample
  6027. restore --level=1
  6028. @end smallexample
  6029. The full list of options accepted by @code{restore} follows:
  6030. @table @option
  6031. @item -a
  6032. @itemx --all
  6033. Restore all file systems and files specified in @file{backup-specs}.
  6034. @item -l @var{level}
  6035. @itemx --level=@var{level}
  6036. Start restoring from the given backup level, instead of the default 0.
  6037. @item -v[@var{level}]
  6038. @itemx --verbose[=@var{level}]
  6039. Set verbosity level. The higher the level is, the more debugging
  6040. information will be output during execution. Default @var{level}
  6041. is 100, which means the highest debugging level.
  6042. @item -h
  6043. @itemx --help
  6044. Display short help message and exit.
  6045. @item -V
  6046. @itemx --version
  6047. Display information about the program's name, version, origin and legal
  6048. status, all on standard output, and then exit successfully.
  6049. @end table
  6050. You should start the restore script with the media containing the
  6051. first volume of the archive mounted. The script will prompt for other
  6052. volumes as they are needed. If the archive is on tape, you don't need
  6053. to rewind the tape to to its beginning---if the tape head is
  6054. positioned past the beginning of the archive, the script will rewind
  6055. the tape as needed. @xref{Tape Positioning}, for a discussion of tape
  6056. positioning.
  6057. @quotation
  6058. @strong{Warning:} The script will delete files from the active file
  6059. system if they were not in the file system when the archive was made.
  6060. @end quotation
  6061. @xref{Incremental Dumps}, for an explanation of how the script makes
  6062. that determination.
  6063. @node Choosing
  6064. @chapter Choosing Files and Names for @command{tar}
  6065. Certain options to @command{tar} enable you to specify a name for your
  6066. archive. Other options let you decide which files to include or exclude
  6067. from the archive, based on when or whether files were modified, whether
  6068. the file names do or don't match specified patterns, or whether files
  6069. are in specified directories.
  6070. This chapter discusses these options in detail.
  6071. @menu
  6072. * file:: Choosing the Archive's Name
  6073. * Selecting Archive Members::
  6074. * files:: Reading Names from a File
  6075. * exclude:: Excluding Some Files
  6076. * wildcards:: Wildcards Patterns and Matching
  6077. * quoting styles:: Ways of Quoting Special Characters in Names
  6078. * transform:: Modifying File and Member Names
  6079. * after:: Operating Only on New Files
  6080. * recurse:: Descending into Directories
  6081. * one:: Crossing File System Boundaries
  6082. @end menu
  6083. @node file
  6084. @section Choosing and Naming Archive Files
  6085. @cindex Naming an archive
  6086. @cindex Archive Name
  6087. @cindex Choosing an archive file
  6088. @cindex Where is the archive?
  6089. @opindex file
  6090. By default, @command{tar} uses an archive file name that was compiled when
  6091. it was built on the system; usually this name refers to some physical
  6092. tape drive on the machine. However, the person who installed @command{tar}
  6093. on the system may not have set the default to a meaningful value as far as
  6094. most users are concerned. As a result, you will usually want to tell
  6095. @command{tar} where to find (or create) the archive. The
  6096. @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
  6097. option allows you to either specify or name a file to use as the archive
  6098. instead of the default archive file location.
  6099. @table @option
  6100. @xopindex{file, short description}
  6101. @item --file=@var{archive-name}
  6102. @itemx -f @var{archive-name}
  6103. Name the archive to create or operate on. Use in conjunction with
  6104. any operation.
  6105. @end table
  6106. For example, in this @command{tar} command,
  6107. @smallexample
  6108. $ @kbd{tar -cvf collection.tar blues folk jazz}
  6109. @end smallexample
  6110. @noindent
  6111. @file{collection.tar} is the name of the archive. It must directly
  6112. follow the @option{-f} option, since whatever directly follows @option{-f}
  6113. @emph{will} end up naming the archive. If you neglect to specify an
  6114. archive name, you may end up overwriting a file in the working directory
  6115. with the archive you create since @command{tar} will use this file's name
  6116. for the archive name.
  6117. An archive can be saved as a file in the file system, sent through a
  6118. pipe or over a network, or written to an I/O device such as a tape,
  6119. floppy disk, or CD write drive.
  6120. @cindex Writing new archives
  6121. @cindex Archive creation
  6122. If you do not name the archive, @command{tar} uses the value of the
  6123. environment variable @env{TAPE} as the file name for the archive. If
  6124. that is not available, @command{tar} uses a default, compiled-in archive
  6125. name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
  6126. @cindex Standard input and output
  6127. @cindex tar to standard input and output
  6128. If you use @file{-} as an @var{archive-name}, @command{tar} reads the
  6129. archive from standard input (when listing or extracting files), or
  6130. writes it to standard output (when creating an archive). If you use
  6131. @file{-} as an @var{archive-name} when modifying an archive,
  6132. @command{tar} reads the original archive from its standard input and
  6133. writes the entire new archive to its standard output.
  6134. The following example is a convenient way of copying directory
  6135. hierarchy from @file{sourcedir} to @file{targetdir}.
  6136. @smallexample
  6137. $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
  6138. @end smallexample
  6139. The @option{-C} option allows to avoid using subshells:
  6140. @smallexample
  6141. $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
  6142. @end smallexample
  6143. In both examples above, the leftmost @command{tar} invocation archives
  6144. the contents of @file{sourcedir} to the standard output, while the
  6145. rightmost one reads this archive from its standard input and
  6146. extracts it. The @option{-p} option tells it to restore permissions
  6147. of the extracted files.
  6148. @cindex Remote devices
  6149. @cindex tar to a remote device
  6150. @anchor{remote-dev}
  6151. To specify an archive file on a device attached to a remote machine,
  6152. use the following:
  6153. @smallexample
  6154. @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
  6155. @end smallexample
  6156. @noindent
  6157. @command{tar} will set up the remote connection, if possible, and
  6158. prompt you for a username and password. If you use
  6159. @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
  6160. will attempt to set up the remote connection using your username
  6161. as the username on the remote machine.
  6162. @cindex Local and remote archives
  6163. @anchor{local and remote archives}
  6164. If the archive file name includes a colon (@samp{:}), then it is assumed
  6165. to be a file on another machine. If the archive file is
  6166. @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
  6167. host @var{host}. The remote host is accessed using the @command{rsh}
  6168. program, with a username of @var{user}. If the username is omitted
  6169. (along with the @samp{@@} sign), then your user name will be used.
  6170. (This is the normal @command{rsh} behavior.) It is necessary for the
  6171. remote machine, in addition to permitting your @command{rsh} access, to
  6172. have the @file{rmt} program installed (this command is included in
  6173. the @GNUTAR{} distribution and by default is installed under
  6174. @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
  6175. installation prefix). If you need to use a file whose name includes a
  6176. colon, then the remote tape drive behavior
  6177. can be inhibited by using the @option{--force-local} option.
  6178. When the archive is being created to @file{/dev/null}, @GNUTAR{}
  6179. tries to minimize input and output operations. The Amanda backup
  6180. system, when used with @GNUTAR{}, has an initial sizing pass which
  6181. uses this feature.
  6182. @node Selecting Archive Members
  6183. @section Selecting Archive Members
  6184. @cindex Specifying files to act on
  6185. @cindex Specifying archive members
  6186. @dfn{File Name arguments} specify which files in the file system
  6187. @command{tar} operates on, when creating or adding to an archive, or which
  6188. archive members @command{tar} operates on, when reading or deleting from
  6189. an archive. @xref{Operations}.
  6190. To specify file names, you can include them as the last arguments on
  6191. the command line, as follows:
  6192. @smallexample
  6193. @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
  6194. @end smallexample
  6195. If a file name begins with dash (@samp{-}), precede it with
  6196. @option{--add-file} option to prevent it from being treated as an
  6197. option.
  6198. @anchor{input name quoting}
  6199. By default @GNUTAR{} attempts to @dfn{unquote} each file or member
  6200. name, replacing @dfn{escape sequences} according to the following
  6201. table:
  6202. @multitable @columnfractions 0.20 0.60
  6203. @headitem Escape @tab Replaced with
  6204. @item \a @tab Audible bell (@acronym{ASCII} 7)
  6205. @item \b @tab Backspace (@acronym{ASCII} 8)
  6206. @item \f @tab Form feed (@acronym{ASCII} 12)
  6207. @item \n @tab New line (@acronym{ASCII} 10)
  6208. @item \r @tab Carriage return (@acronym{ASCII} 13)
  6209. @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
  6210. @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
  6211. @item \? @tab @acronym{ASCII} 127
  6212. @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
  6213. of up to 3 digits)
  6214. @end multitable
  6215. A backslash followed by any other symbol is retained.
  6216. This default behavior is controlled by the following command line
  6217. option:
  6218. @table @option
  6219. @opindex unquote
  6220. @item --unquote
  6221. Enable unquoting input file or member names (default).
  6222. @opindex no-unquote
  6223. @item --no-unquote
  6224. Disable unquoting input file or member names.
  6225. @end table
  6226. If you specify a directory name as a file name argument, all the files
  6227. in that directory are operated on by @command{tar}.
  6228. If you do not specify files, @command{tar} behavior differs depending
  6229. on the operation mode as described below:
  6230. When @command{tar} is invoked with @option{--create} (@option{-c}),
  6231. @command{tar} will stop immediately, reporting the following:
  6232. @smallexample
  6233. @group
  6234. $ @kbd{tar cf a.tar}
  6235. tar: Cowardly refusing to create an empty archive
  6236. Try 'tar --help' or 'tar --usage' for more information.
  6237. @end group
  6238. @end smallexample
  6239. If you specify either @option{--list} (@option{-t}) or
  6240. @option{--extract} (@option{--get}, @option{-x}), @command{tar}
  6241. operates on all the archive members in the archive.
  6242. If run with @option{--diff} option, tar will compare the archive with
  6243. the contents of the current working directory.
  6244. If you specify any other operation, @command{tar} does nothing.
  6245. By default, @command{tar} takes file names from the command line. However,
  6246. there are other ways to specify file or member names, or to modify the
  6247. manner in which @command{tar} selects the files or members upon which to
  6248. operate. In general, these methods work both for specifying the names
  6249. of files and archive members.
  6250. @node files
  6251. @section Reading Names from a File
  6252. @cindex Reading file names from a file
  6253. @cindex Lists of file names
  6254. @cindex File Name arguments, alternatives
  6255. @cindex @command{find}, using with @command{tar}
  6256. Instead of giving the names of files or archive members on the command
  6257. line, you can put the names into a file, and then use the
  6258. @option{--files-from=@var{file-of-names}} (@option{-T
  6259. @var{file-of-names}}) option to @command{tar}. Give the name of the
  6260. file which contains the list of files to include as the argument to
  6261. @option{--files-from}. In the list, the file names should be separated by
  6262. newlines. You will frequently use this option when you have generated
  6263. the list of files to archive with the @command{find} utility.
  6264. @table @option
  6265. @opindex files-from
  6266. @item --files-from=@var{file-name}
  6267. @itemx -T @var{file-name}
  6268. Get names to extract or create from file @var{file-name}.
  6269. @end table
  6270. If you give a single dash as a file name for @option{--files-from}, (i.e.,
  6271. you specify either @code{--files-from=-} or @code{-T -}), then the file
  6272. names are read from standard input.
  6273. Unless you are running @command{tar} with @option{--create}, you cannot use
  6274. both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
  6275. command.
  6276. Any number of @option{-T} options can be given in the command line.
  6277. The following example shows how to use @command{find} to generate a list of
  6278. files smaller than 400 blocks in length@footnote{A file system block
  6279. is usually 512 bytes, so this amounts to 200K. Use the @samp{c}
  6280. suffix to specify size in @emph{bytes}. Also, when using
  6281. GNU find, you can specify other size units, such as @samp{k},
  6282. @samp{m}, etc. @xref{Size,,,find.info,GNU Findutils}, for details.} and put that list into a file
  6283. called @file{small-files}. You can then use the @option{-T} option to
  6284. @command{tar} to specify the files from that file, @file{small-files}, to
  6285. create the archive @file{little.tgz}. (The @option{-z} option to
  6286. @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
  6287. more information.)
  6288. @smallexample
  6289. $ @kbd{find . -size -400 -print > small-files}
  6290. $ @kbd{tar -c -v -z -T small-files -f little.tgz}
  6291. @end smallexample
  6292. @noindent
  6293. By default, each line read from the file list is first stripped off
  6294. any leading and trailing whitespace. If the resulting string begins
  6295. with @samp{-} character, it is considered a @command{tar} option and is
  6296. processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
  6297. recognized only @option{-C} option in file lists, and only if the
  6298. option and its argument occupied two consecutive lines.}. Only a
  6299. subset of @GNUTAR{} options is allowed for use in file lists. For
  6300. a list of such options, @ref{Position-Sensitive Options}.
  6301. For example, the common use of this feature is to change to another
  6302. directory by specifying @option{-C} option:
  6303. @smallexample
  6304. @group
  6305. $ @kbd{cat list}
  6306. -C/etc
  6307. passwd
  6308. hosts
  6309. -C/lib
  6310. libc.a
  6311. $ @kbd{tar -c -f foo.tar --files-from list}
  6312. @end group
  6313. @end smallexample
  6314. @noindent
  6315. In this example, @command{tar} will first switch to @file{/etc}
  6316. directory and add files @file{passwd} and @file{hosts} to the
  6317. archive. Then it will change to @file{/lib} directory and will archive
  6318. the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
  6319. contain:
  6320. @smallexample
  6321. @group
  6322. $ @kbd{tar tf foo.tar}
  6323. passwd
  6324. hosts
  6325. libc.a
  6326. @end group
  6327. @end smallexample
  6328. Note, that any options used in the file list remain in effect for the
  6329. rest of the command line. For example, using the same @file{list}
  6330. file as above, the following command
  6331. @smallexample
  6332. $ @kbd{tar -c -f foo.tar --files-from list libcurses.a}
  6333. @end smallexample
  6334. @noindent
  6335. will look for file @file{libcurses.a} in the directory @file{/lib},
  6336. because it was used with the last @option{-C} option
  6337. (@pxref{Position-Sensitive Options}).
  6338. @anchor{verbatim-files-from}
  6339. @opindex verbatim-files-from
  6340. If such option handling is undesirable, use the
  6341. @option{--verbatim-files-from} option. When this option is in effect,
  6342. each line read from the file list is treated as a file name. Notice,
  6343. that this means, in particular, that no whitespace trimming is
  6344. performed.
  6345. @anchor{no-verbatim-files-from}
  6346. @opindex no-verbatim-files-from
  6347. The @option{--verbatim-files-from} affects all @option{-T} options
  6348. that follow it in the command line. The default behavior can be
  6349. restored using @option{--no-verbatim-files-from} option.
  6350. @opindex add-file
  6351. To disable option handling for a single file name, use the
  6352. @option{--add-file} option, e.g.: @code{--add-file=--my-file}.
  6353. You can use any @GNUTAR{} command line options in the file list file,
  6354. including @option{--files-from} option itself. This allows for
  6355. including contents of a file list into another file list file.
  6356. Note however, that options that control file list processing, such as
  6357. @option{--verbatim-files-from} or @option{--null} won't affect the
  6358. file they appear in. They will affect next @option{--files-from}
  6359. option, if there is any.
  6360. @menu
  6361. * nul::
  6362. @end menu
  6363. @node nul
  6364. @subsection @code{NUL}-Terminated File Names
  6365. @cindex File names, terminated by @code{NUL}
  6366. @cindex @code{NUL}-terminated file names
  6367. The @option{--null} option causes
  6368. @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
  6369. to read file names terminated by a @code{NUL} instead of a newline, so
  6370. files whose names contain newlines can be archived using
  6371. @option{--files-from}.
  6372. @table @option
  6373. @xopindex{null, described}
  6374. @item --null
  6375. Only consider @code{NUL}-terminated file names, instead of files that
  6376. terminate in a newline.
  6377. @xopindex{no-null, described}
  6378. @item --no-null
  6379. Undo the effect of any previous @option{--null} option.
  6380. @end table
  6381. The @option{--null} option is just like the one in @acronym{GNU}
  6382. @command{xargs} and @command{cpio}, and is useful with the
  6383. @option{-print0} predicate of @acronym{GNU} @command{find}. In
  6384. @command{tar}, @option{--null} also disables special handling for
  6385. file names that begin with dash (similar to
  6386. @option{--verbatim-files-from} option).
  6387. This example shows how to use @command{find} to generate a list of files
  6388. larger than 800 blocks in length and put that list into a file called
  6389. @file{long-files}. The @option{-print0} option to @command{find} is just
  6390. like @option{-print}, except that it separates files with a @code{NUL}
  6391. rather than with a newline. You can then run @command{tar} with both the
  6392. @option{--null} and @option{-T} options to specify that @command{tar} gets the
  6393. files from that file, @file{long-files}, to create the archive
  6394. @file{big.tgz}. The @option{--null} option to @command{tar} will cause
  6395. @command{tar} to recognize the @code{NUL} separator between files.
  6396. @smallexample
  6397. $ @kbd{find . -size +800 -print0 > long-files}
  6398. $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
  6399. @end smallexample
  6400. The @option{--no-null} option can be used if you need to read both
  6401. @code{NUL}-terminated and newline-terminated files on the same command line.
  6402. For example, if @file{flist} is a newline-terminated file, then the
  6403. following command can be used to combine it with the above command:
  6404. @smallexample
  6405. @group
  6406. $ @kbd{find . -size +800 -print0 |
  6407. tar -c -f big.tar --null -T - --no-null -T flist}
  6408. @end group
  6409. @end smallexample
  6410. This example uses short options for typographic reasons, to avoid
  6411. very long lines.
  6412. @GNUTAR{} is tries to automatically detect @code{NUL}-terminated file
  6413. lists, so in many cases it is safe to use them even without the
  6414. @option{--null} option. In this case @command{tar} will print a
  6415. warning and continue reading such a file as if @option{--null} were
  6416. actually given:
  6417. @smallexample
  6418. @group
  6419. $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
  6420. tar: -: file name read contains nul character
  6421. @end group
  6422. @end smallexample
  6423. The null terminator, however, remains in effect only for this
  6424. particular file, any following @option{-T} options will assume
  6425. newline termination. Of course, the null autodetection applies
  6426. to these eventual surplus @option{-T} options as well.
  6427. @node exclude
  6428. @section Excluding Some Files
  6429. @cindex File names, excluding files by
  6430. @cindex Excluding files by name and pattern
  6431. @cindex Excluding files by file system
  6432. @opindex exclude
  6433. @opindex exclude-from
  6434. To avoid operating on files whose names match a particular pattern,
  6435. use the @option{--exclude} or @option{--exclude-from} options.
  6436. @table @option
  6437. @opindex exclude
  6438. @item --exclude=@var{pattern}
  6439. Causes @command{tar} to ignore files that match the @var{pattern}.
  6440. @end table
  6441. @findex exclude
  6442. The @option{--exclude=@var{pattern}} option prevents any file or
  6443. member whose name matches the shell wildcard (@var{pattern}) from
  6444. being operated on.
  6445. For example, to create an archive with all the contents of the directory
  6446. @file{src} except for files whose names end in @file{.o}, use the
  6447. command @samp{tar -cf src.tar --exclude='*.o' src}.
  6448. You may give multiple @option{--exclude} options.
  6449. @table @option
  6450. @opindex exclude-from
  6451. @item --exclude-from=@var{file}
  6452. @itemx -X @var{file}
  6453. Causes @command{tar} to ignore files that match the patterns listed in
  6454. @var{file}.
  6455. @end table
  6456. @findex exclude-from
  6457. Use the @option{--exclude-from} option to read a
  6458. list of patterns, one per line, from @var{file}; @command{tar} will
  6459. ignore files matching those patterns. Thus if @command{tar} is
  6460. called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
  6461. single line @file{*.o}, no files whose names end in @file{.o} will be
  6462. added to the archive.
  6463. Notice, that lines from @var{file} are read verbatim. One of the
  6464. frequent errors is leaving some extra whitespace after a file name,
  6465. which is difficult to catch using text editors.
  6466. However, empty lines are OK.
  6467. @cindex VCS, excluding patterns from ignore files
  6468. @cindex VCS, ignore files
  6469. @cindex CVS, ignore files
  6470. @cindex Git, ignore files
  6471. @cindex Bazaar, ignore files
  6472. @cindex Mercurial, ignore files
  6473. When archiving directories that are under some version control system (VCS),
  6474. it is often convenient to read exclusion patterns from this VCS'
  6475. ignore files (e.g. @file{.cvsignore}, @file{.gitignore}, etc.) The
  6476. following options provide such possibility:
  6477. @table @option
  6478. @anchor{exclude-vcs-ignores}
  6479. @opindex exclude-vcs-ignores
  6480. @item --exclude-vcs-ignores
  6481. Before archiving a directory, see if it contains any of the following
  6482. files: @file{cvsignore}, @file{.gitignore}, @file{.bzrignore}, or
  6483. @file{.hgignore}. If so, read ignore patterns from these files.
  6484. The patterns are treated much as the corresponding VCS would treat
  6485. them, i.e.:
  6486. @table @file
  6487. @findex .cvsignore
  6488. @item .cvsignore
  6489. Contains shell-style globbing patterns that apply only to the
  6490. directory where this file resides. No comments are allowed in the
  6491. file. Empty lines are ignored.
  6492. @findex .gitignore
  6493. @item .gitignore
  6494. Contains shell-style globbing patterns. Applies to the directory
  6495. where @file{.gitfile} is located and all its subdirectories.
  6496. Any line beginning with a @samp{#} is a comment. Backslash escapes
  6497. the comment character.
  6498. @findex .bzrignore
  6499. @item .bzrignore
  6500. Contains shell globbing-patterns and regular expressions (if prefixed
  6501. with @samp{RE:}@footnote{According to the Bazaar docs,
  6502. globbing-patterns are Korn-shell style and regular expressions are
  6503. perl-style. As of @GNUTAR{} version @value{VERSION}, these are
  6504. treated as shell-style globs and POSIX extended regexps. This will be
  6505. fixed in future releases.}. Patterns affect the directory and all its
  6506. subdirectories.
  6507. Any line beginning with a @samp{#} is a comment.
  6508. @findex .hgignore
  6509. @item .hgignore
  6510. Contains POSIX regular expressions@footnote{Support for perl-style
  6511. regexps will appear in future releases.}. The line @samp{syntax:
  6512. glob} switches to shell globbing patterns. The line @samp{syntax:
  6513. regexp} switches back. Comments begin with a @samp{#}. Patterns
  6514. affect the directory and all its subdirectories.
  6515. @end table
  6516. @opindex exclude-ignore
  6517. @item --exclude-ignore=@var{file}
  6518. Before dumping a directory, @command{tar} checks if it contains
  6519. @var{file}. If so, exclusion patterns are read from this file.
  6520. The patterns affect only the directory itself.
  6521. @opindex exclude-ignore-recursive
  6522. @item --exclude-ignore-recursive=@var{file}
  6523. Same as @option{--exclude-ignore}, except that the patterns read
  6524. affect both the directory where @var{file} resides and all its
  6525. subdirectories.
  6526. @end table
  6527. @table @option
  6528. @cindex version control system, excluding files
  6529. @cindex VCS, excluding files
  6530. @cindex SCCS, excluding files
  6531. @cindex RCS, excluding files
  6532. @cindex CVS, excluding files
  6533. @cindex SVN, excluding files
  6534. @cindex git, excluding files
  6535. @cindex Bazaar, excluding files
  6536. @cindex Arch, excluding files
  6537. @cindex Mercurial, excluding files
  6538. @cindex Darcs, excluding files
  6539. @anchor{exclude-vcs}
  6540. @opindex exclude-vcs
  6541. @item --exclude-vcs
  6542. Exclude files and directories used by following version control
  6543. systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
  6544. @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
  6545. As of version @value{VERSION}, the following files are excluded:
  6546. @itemize @bullet
  6547. @item @file{CVS/}, and everything under it
  6548. @item @file{RCS/}, and everything under it
  6549. @item @file{SCCS/}, and everything under it
  6550. @item @file{.git/}, and everything under it
  6551. @item @file{.gitignore}
  6552. @item @file{.gitmodules}
  6553. @item @file{.gitattributes}
  6554. @item @file{.cvsignore}
  6555. @item @file{.svn/}, and everything under it
  6556. @item @file{.arch-ids/}, and everything under it
  6557. @item @file{@{arch@}/}, and everything under it
  6558. @item @file{=RELEASE-ID}
  6559. @item @file{=meta-update}
  6560. @item @file{=update}
  6561. @item @file{.bzr}
  6562. @item @file{.bzrignore}
  6563. @item @file{.bzrtags}
  6564. @item @file{.hg}
  6565. @item @file{.hgignore}
  6566. @item @file{.hgrags}
  6567. @item @file{_darcs}
  6568. @end itemize
  6569. @opindex exclude-backups
  6570. @item --exclude-backups
  6571. Exclude backup and lock files. This option causes exclusion of files
  6572. that match the following shell globbing patterns:
  6573. @table @asis
  6574. @item .#*
  6575. @item *~
  6576. @item #*#
  6577. @end table
  6578. @end table
  6579. @findex exclude-caches
  6580. When creating an archive, the @option{--exclude-caches} option family
  6581. causes @command{tar} to exclude all directories that contain a @dfn{cache
  6582. directory tag}. A cache directory tag is a short file with the
  6583. well-known name @file{CACHEDIR.TAG} and having a standard header
  6584. specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
  6585. Various applications write cache directory tags into directories they
  6586. use to hold regenerable, non-precious data, so that such data can be
  6587. more easily excluded from backups.
  6588. There are three @samp{exclude-caches} options, each providing a different
  6589. exclusion semantics:
  6590. @table @option
  6591. @opindex exclude-caches
  6592. @item --exclude-caches
  6593. Do not archive the contents of the directory, but archive the
  6594. directory itself and the @file{CACHEDIR.TAG} file.
  6595. @opindex exclude-caches-under
  6596. @item --exclude-caches-under
  6597. Do not archive the contents of the directory, nor the
  6598. @file{CACHEDIR.TAG} file, archive only the directory itself.
  6599. @opindex exclude-caches-all
  6600. @item --exclude-caches-all
  6601. Omit directories containing @file{CACHEDIR.TAG} file entirely.
  6602. @end table
  6603. @findex exclude-tag
  6604. Another option family, @option{--exclude-tag}, provides a generalization of
  6605. this concept. It takes a single argument, a file name to look for.
  6606. Any directory that contains this file will be excluded from the dump.
  6607. Similarly to @samp{exclude-caches}, there are three options in this
  6608. option family:
  6609. @table @option
  6610. @opindex exclude-tag
  6611. @item --exclude-tag=@var{file}
  6612. Do not dump the contents of the directory, but dump the
  6613. directory itself and the @var{file}.
  6614. @opindex exclude-tag-under
  6615. @item --exclude-tag-under=@var{file}
  6616. Do not dump the contents of the directory, nor the
  6617. @var{file}, archive only the directory itself.
  6618. @opindex exclude-tag-all
  6619. @item --exclude-tag-all=@var{file}
  6620. Omit directories containing @var{file} file entirely.
  6621. @end table
  6622. Multiple @option{--exclude-tag*} options can be given.
  6623. For example, given this directory:
  6624. @smallexample
  6625. @group
  6626. $ @kbd{find dir}
  6627. dir
  6628. dir/blues
  6629. dir/jazz
  6630. dir/folk
  6631. dir/folk/tagfile
  6632. dir/folk/sanjuan
  6633. dir/folk/trote
  6634. @end group
  6635. @end smallexample
  6636. The @option{--exclude-tag} will produce the following:
  6637. @smallexample
  6638. $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
  6639. dir/
  6640. dir/blues
  6641. dir/jazz
  6642. dir/folk/
  6643. tar: dir/folk/: contains a cache directory tag tagfile;
  6644. contents not dumped
  6645. dir/folk/tagfile
  6646. @end smallexample
  6647. Both the @file{dir/folk} directory and its tagfile are preserved in
  6648. the archive, however the rest of files in this directory are not.
  6649. Now, using the @option{--exclude-tag-under} option will exclude
  6650. @file{tagfile} from the dump, while still preserving the directory
  6651. itself, as shown in this example:
  6652. @smallexample
  6653. $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
  6654. dir/
  6655. dir/blues
  6656. dir/jazz
  6657. dir/folk/
  6658. ./tar: dir/folk/: contains a cache directory tag tagfile;
  6659. contents not dumped
  6660. @end smallexample
  6661. Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
  6662. directory entirely:
  6663. @smallexample
  6664. $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
  6665. dir/
  6666. dir/blues
  6667. dir/jazz
  6668. ./tar: dir/folk/: contains a cache directory tag tagfile;
  6669. directory not dumped
  6670. @end smallexample
  6671. @menu
  6672. * problems with exclude::
  6673. @end menu
  6674. @node problems with exclude
  6675. @unnumberedsubsec Problems with Using the @code{exclude} Options
  6676. @xopindex{exclude, potential problems with}
  6677. Some users find @samp{exclude} options confusing. Here are some common
  6678. pitfalls:
  6679. @itemize @bullet
  6680. @item
  6681. The main operating mode of @command{tar} does not act on a file name
  6682. explicitly listed on the command line, if one of its file name
  6683. components is excluded. In the example above, if
  6684. you create an archive and exclude files that end with @samp{*.o}, but
  6685. explicitly name the file @samp{dir.o/foo} after all the options have been
  6686. listed, @samp{dir.o/foo} will be excluded from the archive.
  6687. @item
  6688. You can sometimes confuse the meanings of @option{--exclude} and
  6689. @option{--exclude-from}. Be careful: use @option{--exclude} when files
  6690. to be excluded are given as a pattern on the command line. Use
  6691. @option{--exclude-from} to introduce the name of a file which contains
  6692. a list of patterns, one per line; each of these patterns can exclude
  6693. zero, one, or many files.
  6694. @item
  6695. When you use @option{--exclude=@var{pattern}}, be sure to quote the
  6696. @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
  6697. like @samp{*}. If you do not do this, the shell might expand the
  6698. @samp{*} itself using files at hand, so @command{tar} might receive a
  6699. list of files instead of one pattern, or none at all, making the
  6700. command somewhat illegal. This might not correspond to what you want.
  6701. For example, write:
  6702. @smallexample
  6703. $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
  6704. @end smallexample
  6705. @noindent
  6706. rather than:
  6707. @smallexample
  6708. # @emph{Wrong!}
  6709. $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
  6710. @end smallexample
  6711. @item
  6712. You must use use shell syntax, or globbing, rather than @code{regexp}
  6713. syntax, when using exclude options in @command{tar}. If you try to use
  6714. @code{regexp} syntax to describe files to be excluded, your command
  6715. might fail.
  6716. @item
  6717. @FIXME{The change in semantics must have occurred before 1.11,
  6718. so I doubt if it is worth mentioning at all. Anyway, should at
  6719. least specify in which version the semantics changed.}
  6720. In earlier versions of @command{tar}, what is now the
  6721. @option{--exclude-from} option was called @option{--exclude} instead.
  6722. Now, @option{--exclude} applies to patterns listed on the command
  6723. line and @option{--exclude-from} applies to patterns listed in a
  6724. file.
  6725. @end itemize
  6726. @node wildcards
  6727. @section Wildcards Patterns and Matching
  6728. @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
  6729. @samp{*} or @samp{?} for example, are replaced and expanded into all
  6730. existing files matching the given pattern. @GNUTAR{} can use wildcard
  6731. patterns for matching (or globbing) archive members when extracting
  6732. from or listing an archive. Wildcard patterns are also used for
  6733. verifying volume labels of @command{tar} archives. This section has the
  6734. purpose of explaining wildcard syntax for @command{tar}.
  6735. @FIXME{the next few paragraphs need work.}
  6736. A @var{pattern} should be written according to shell syntax, using wildcard
  6737. characters to effect globbing. Most characters in the pattern stand
  6738. for themselves in the matched string, and case is significant: @samp{a}
  6739. will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
  6740. pattern matches any single character in the matched string. The character
  6741. @samp{*} in the pattern matches zero, one, or more single characters in
  6742. the matched string. The character @samp{\} says to take the following
  6743. character of the pattern @emph{literally}; it is useful when one needs to
  6744. match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
  6745. The character @samp{[}, up to the matching @samp{]}, introduces a character
  6746. class. A @dfn{character class} is a list of acceptable characters
  6747. for the next single character of the matched string. For example,
  6748. @samp{[abcde]} would match any of the first five letters of the alphabet.
  6749. Note that within a character class, all of the ``special characters''
  6750. listed above other than @samp{\} lose their special meaning; for example,
  6751. @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
  6752. @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
  6753. the characters @samp{-} and @samp{]} must either come @emph{first} or
  6754. @emph{last} in a character class.)
  6755. @cindex Excluding characters from a character class
  6756. @cindex Character class, excluding characters from
  6757. If the first character of the class after the opening @samp{[}
  6758. is @samp{!} or @samp{^}, then the meaning of the class is reversed.
  6759. Rather than listing character to match, it lists those characters which
  6760. are @emph{forbidden} as the next single character of the matched string.
  6761. Other characters of the class stand for themselves. The special
  6762. construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
  6763. letters, is meant to represent all characters between @var{a} and
  6764. @var{e}, inclusive.
  6765. @FIXME{need to add a sentence or so here to make this clear for those
  6766. who don't have dan around.}
  6767. Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
  6768. special for wildcard matches. However, if a pattern completely matches
  6769. a directory prefix of a matched string, then it matches the full matched
  6770. string: thus, excluding a directory also excludes all the files beneath it.
  6771. @menu
  6772. * controlling pattern-matching::
  6773. @end menu
  6774. @node controlling pattern-matching
  6775. @unnumberedsubsec Controlling Pattern-Matching
  6776. For the purposes of this section, we call @dfn{exclusion members} all
  6777. member names obtained while processing @option{--exclude} and
  6778. @option{--exclude-from} options, and @dfn{inclusion members} those
  6779. member names that were given in the command line or read from the file
  6780. specified with @option{--files-from} option.
  6781. These two pairs of member lists are used in the following operations:
  6782. @option{--diff}, @option{--extract}, @option{--list},
  6783. @option{--update}.
  6784. There are no inclusion members in create mode (@option{--create} and
  6785. @option{--append}), since in this mode the names obtained from the
  6786. command line refer to @emph{files}, not archive members.
  6787. By default, inclusion members are compared with archive members
  6788. literally @footnote{Notice that earlier @GNUTAR{} versions used
  6789. globbing for inclusion members, which contradicted to UNIX98
  6790. specification and was not documented. @xref{Changes}, for more
  6791. information on this and other changes.} and exclusion members are
  6792. treated as globbing patterns. For example:
  6793. @smallexample
  6794. @group
  6795. $ @kbd{tar tf foo.tar}
  6796. a.c
  6797. b.c
  6798. a.txt
  6799. [remarks]
  6800. # @i{Member names are used verbatim:}
  6801. $ @kbd{tar -xf foo.tar -v '[remarks]'}
  6802. [remarks]
  6803. # @i{Exclude member names are globbed:}
  6804. $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
  6805. a.txt
  6806. [remarks]
  6807. @end group
  6808. @end smallexample
  6809. This behavior can be altered by using the following options:
  6810. @table @option
  6811. @opindex wildcards
  6812. @item --wildcards
  6813. Treat all member names as wildcards.
  6814. @opindex no-wildcards
  6815. @item --no-wildcards
  6816. Treat all member names as literal strings.
  6817. @end table
  6818. Thus, to extract files whose names end in @samp{.c}, you can use:
  6819. @smallexample
  6820. $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
  6821. a.c
  6822. b.c
  6823. @end smallexample
  6824. @noindent
  6825. Notice quoting of the pattern to prevent the shell from interpreting
  6826. it.
  6827. The effect of @option{--wildcards} option is canceled by
  6828. @option{--no-wildcards}. This can be used to pass part of
  6829. the command line arguments verbatim and other part as globbing
  6830. patterns. For example, the following invocation:
  6831. @smallexample
  6832. $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
  6833. @end smallexample
  6834. @noindent
  6835. instructs @command{tar} to extract from @file{foo.tar} all files whose
  6836. names end in @samp{.txt} and the file named @file{[remarks]}.
  6837. Normally, a pattern matches a name if an initial subsequence of the
  6838. name's components matches the pattern, where @samp{*}, @samp{?}, and
  6839. @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
  6840. and wildcards can match @samp{/}.
  6841. Other than optionally stripping leading @samp{/} from names
  6842. (@pxref{absolute}), patterns and names are used as-is. For
  6843. example, trailing @samp{/} is not trimmed from a user-specified name
  6844. before deciding whether to exclude it.
  6845. However, this matching procedure can be altered by the options listed
  6846. below. These options accumulate. For example:
  6847. @smallexample
  6848. --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
  6849. @end smallexample
  6850. @noindent
  6851. ignores case when excluding @samp{makefile}, but not when excluding
  6852. @samp{readme}.
  6853. @table @option
  6854. @anchor{anchored patterns}
  6855. @opindex anchored
  6856. @opindex no-anchored
  6857. @item --anchored
  6858. @itemx --no-anchored
  6859. If anchored, a pattern must match an initial subsequence
  6860. of the name's components. Otherwise, the pattern can match any
  6861. subsequence. Default is @option{--no-anchored} for exclusion members
  6862. and @option{--anchored} inclusion members.
  6863. @anchor{case-insensitive matches}
  6864. @opindex ignore-case
  6865. @opindex no-ignore-case
  6866. @item --ignore-case
  6867. @itemx --no-ignore-case
  6868. When ignoring case, upper-case patterns match lower-case names and vice versa.
  6869. When not ignoring case (the default), matching is case-sensitive.
  6870. @opindex wildcards-match-slash
  6871. @opindex no-wildcards-match-slash
  6872. @item --wildcards-match-slash
  6873. @itemx --no-wildcards-match-slash
  6874. When wildcards match slash (the default for exclusion members), a
  6875. wildcard like @samp{*} in the pattern can match a @samp{/} in the
  6876. name. Otherwise, @samp{/} is matched only by @samp{/}.
  6877. @end table
  6878. The @option{--recursion} and @option{--no-recursion} options
  6879. (@pxref{recurse}) also affect how member patterns are interpreted. If
  6880. recursion is in effect, a pattern matches a name if it matches any of
  6881. the name's parent directories.
  6882. The following table summarizes pattern-matching default values:
  6883. @multitable @columnfractions .3 .7
  6884. @headitem Members @tab Default settings
  6885. @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
  6886. @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
  6887. @end multitable
  6888. @node quoting styles
  6889. @section Quoting Member Names
  6890. When displaying member names, @command{tar} takes care to avoid
  6891. ambiguities caused by certain characters. This is called @dfn{name
  6892. quoting}. The characters in question are:
  6893. @itemize @bullet
  6894. @item Non-printable control characters:
  6895. @anchor{escape sequences}
  6896. @multitable @columnfractions 0.20 0.10 0.60
  6897. @headitem Character @tab @acronym{ASCII} @tab Character name
  6898. @item \a @tab 7 @tab Audible bell
  6899. @item \b @tab 8 @tab Backspace
  6900. @item \f @tab 12 @tab Form feed
  6901. @item \n @tab 10 @tab New line
  6902. @item \r @tab 13 @tab Carriage return
  6903. @item \t @tab 9 @tab Horizontal tabulation
  6904. @item \v @tab 11 @tab Vertical tabulation
  6905. @end multitable
  6906. @item Space (@acronym{ASCII} 32)
  6907. @item Single and double quotes (@samp{'} and @samp{"})
  6908. @item Backslash (@samp{\})
  6909. @end itemize
  6910. The exact way @command{tar} uses to quote these characters depends on
  6911. the @dfn{quoting style}. The default quoting style, called
  6912. @dfn{escape} (see below), uses backslash notation to represent control
  6913. characters and backslash.
  6914. @GNUTAR{} offers seven distinct quoting styles, which can be selected
  6915. using @option{--quoting-style} option:
  6916. @table @option
  6917. @item --quoting-style=@var{style}
  6918. @opindex quoting-style
  6919. Sets quoting style. Valid values for @var{style} argument are:
  6920. literal, shell, shell-always, c, escape, locale, clocale.
  6921. @end table
  6922. These styles are described in detail below. To illustrate their
  6923. effect, we will use an imaginary tar archive @file{arch.tar}
  6924. containing the following members:
  6925. @smallexample
  6926. @group
  6927. # 1. Contains horizontal tabulation character.
  6928. a tab
  6929. # 2. Contains newline character
  6930. a
  6931. newline
  6932. # 3. Contains a space
  6933. a space
  6934. # 4. Contains double quotes
  6935. a"double"quote
  6936. # 5. Contains single quotes
  6937. a'single'quote
  6938. # 6. Contains a backslash character:
  6939. a\backslash
  6940. @end group
  6941. @end smallexample
  6942. Here is how usual @command{ls} command would have listed them, if they
  6943. had existed in the current working directory:
  6944. @smallexample
  6945. @group
  6946. $ @kbd{ls}
  6947. a\ttab
  6948. a\nnewline
  6949. a\ space
  6950. a"double"quote
  6951. a'single'quote
  6952. a\\backslash
  6953. @end group
  6954. @end smallexample
  6955. Quoting styles:
  6956. @table @samp
  6957. @item literal
  6958. No quoting, display each character as is:
  6959. @smallexample
  6960. @group
  6961. $ @kbd{tar tf arch.tar --quoting-style=literal}
  6962. ./
  6963. ./a space
  6964. ./a'single'quote
  6965. ./a"double"quote
  6966. ./a\backslash
  6967. ./a tab
  6968. ./a
  6969. newline
  6970. @end group
  6971. @end smallexample
  6972. @item shell
  6973. Display characters the same way Bourne shell does:
  6974. control characters, except @samp{\t} and @samp{\n}, are printed using
  6975. backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
  6976. single quote is printed as @samp{\'}. If a name contains any quoted
  6977. characters, it is enclosed in single quotes. In particular, if a name
  6978. contains single quotes, it is printed as several single-quoted strings:
  6979. @smallexample
  6980. @group
  6981. $ @kbd{tar tf arch.tar --quoting-style=shell}
  6982. ./
  6983. './a space'
  6984. './a'\''single'\''quote'
  6985. './a"double"quote'
  6986. './a\backslash'
  6987. './a tab'
  6988. './a
  6989. newline'
  6990. @end group
  6991. @end smallexample
  6992. @item shell-always
  6993. Same as @samp{shell}, but the names are always enclosed in single
  6994. quotes:
  6995. @smallexample
  6996. @group
  6997. $ @kbd{tar tf arch.tar --quoting-style=shell-always}
  6998. './'
  6999. './a space'
  7000. './a'\''single'\''quote'
  7001. './a"double"quote'
  7002. './a\backslash'
  7003. './a tab'
  7004. './a
  7005. newline'
  7006. @end group
  7007. @end smallexample
  7008. @item c
  7009. Use the notation of the C programming language. All names are
  7010. enclosed in double quotes. Control characters are quoted using
  7011. backslash notations, double quotes are represented as @samp{\"},
  7012. backslash characters are represented as @samp{\\}. Single quotes and
  7013. spaces are not quoted:
  7014. @smallexample
  7015. @group
  7016. $ @kbd{tar tf arch.tar --quoting-style=c}
  7017. "./"
  7018. "./a space"
  7019. "./a'single'quote"
  7020. "./a\"double\"quote"
  7021. "./a\\backslash"
  7022. "./a\ttab"
  7023. "./a\nnewline"
  7024. @end group
  7025. @end smallexample
  7026. @item escape
  7027. Control characters are printed using backslash notation, and a
  7028. backslash as @samp{\\}. This is the default quoting style, unless it
  7029. was changed when configured the package.
  7030. @smallexample
  7031. @group
  7032. $ @kbd{tar tf arch.tar --quoting-style=escape}
  7033. ./
  7034. ./a space
  7035. ./a'single'quote
  7036. ./a"double"quote
  7037. ./a\\backslash
  7038. ./a\ttab
  7039. ./a\nnewline
  7040. @end group
  7041. @end smallexample
  7042. @item locale
  7043. Control characters, single quote and backslash are printed using
  7044. backslash notation. All names are quoted using left and right
  7045. quotation marks, appropriate to the current locale. If it does not
  7046. define quotation marks, use @samp{'} as left and as right
  7047. quotation marks. Any occurrences of the right quotation mark in a
  7048. name are escaped with @samp{\}, for example:
  7049. For example:
  7050. @smallexample
  7051. @group
  7052. $ @kbd{tar tf arch.tar --quoting-style=locale}
  7053. './'
  7054. './a space'
  7055. './a\'single\'quote'
  7056. './a"double"quote'
  7057. './a\\backslash'
  7058. './a\ttab'
  7059. './a\nnewline'
  7060. @end group
  7061. @end smallexample
  7062. @item clocale
  7063. Same as @samp{locale}, but @samp{"} is used for both left and right
  7064. quotation marks, if not provided by the currently selected locale:
  7065. @smallexample
  7066. @group
  7067. $ @kbd{tar tf arch.tar --quoting-style=clocale}
  7068. "./"
  7069. "./a space"
  7070. "./a'single'quote"
  7071. "./a\"double\"quote"
  7072. "./a\\backslash"
  7073. "./a\ttab"
  7074. "./a\nnewline"
  7075. @end group
  7076. @end smallexample
  7077. @end table
  7078. You can specify which characters should be quoted in addition to those
  7079. implied by the current quoting style:
  7080. @table @option
  7081. @item --quote-chars=@var{string}
  7082. Always quote characters from @var{string}, even if the selected
  7083. quoting style would not quote them.
  7084. @end table
  7085. For example, using @samp{escape} quoting (compare with the usual
  7086. escape listing above):
  7087. @smallexample
  7088. @group
  7089. $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
  7090. ./
  7091. ./a\ space
  7092. ./a'single'quote
  7093. ./a\"double\"quote
  7094. ./a\\backslash
  7095. ./a\ttab
  7096. ./a\nnewline
  7097. @end group
  7098. @end smallexample
  7099. To disable quoting of such additional characters, use the following
  7100. option:
  7101. @table @option
  7102. @item --no-quote-chars=@var{string}
  7103. Remove characters listed in @var{string} from the list of quoted
  7104. characters set by the previous @option{--quote-chars} option.
  7105. @end table
  7106. This option is particularly useful if you have added
  7107. @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
  7108. and wish to disable it for the current invocation.
  7109. Note, that @option{--no-quote-chars} does @emph{not} disable those
  7110. characters that are quoted by default in the selected quoting style.
  7111. @node transform
  7112. @section Modifying File and Member Names
  7113. @command{Tar} archives contain detailed information about files stored
  7114. in them and full file names are part of that information. When
  7115. storing a file to an archive, its file name is recorded in it,
  7116. along with the actual file contents. When restoring from an archive,
  7117. a file is created on disk with exactly the same name as that stored
  7118. in the archive. In the majority of cases this is the desired behavior
  7119. of a file archiver. However, there are some cases when it is not.
  7120. First of all, it is often unsafe to extract archive members with
  7121. absolute file names or those that begin with a @file{../}. @GNUTAR{}
  7122. takes special precautions when extracting such names and provides a
  7123. special option for handling them, which is described in
  7124. @ref{absolute}.
  7125. Secondly, you may wish to extract file names without some leading
  7126. directory components, or with otherwise modified names. In other
  7127. cases it is desirable to store files under differing names in the
  7128. archive.
  7129. @GNUTAR{} provides several options for these needs.
  7130. @table @option
  7131. @opindex strip-components
  7132. @item --strip-components=@var{number}
  7133. Strip given @var{number} of leading components from file names before
  7134. extraction.
  7135. @end table
  7136. For example, suppose you have archived whole @file{/usr} hierarchy to
  7137. a tar archive named @file{usr.tar}. Among other files, this archive
  7138. contains @file{usr/include/stdlib.h}, which you wish to extract to
  7139. the current working directory. To do so, you type:
  7140. @smallexample
  7141. $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
  7142. @end smallexample
  7143. The option @option{--strip=2} instructs @command{tar} to strip the
  7144. two leading components (@file{usr/} and @file{include/}) off the file
  7145. name.
  7146. If you add the @option{--verbose} (@option{-v}) option to the invocation
  7147. above, you will note that the verbose listing still contains the
  7148. full file name, with the two removed components still in place. This
  7149. can be inconvenient, so @command{tar} provides a special option for
  7150. altering this behavior:
  7151. @anchor{show-transformed-names}
  7152. @table @option
  7153. @opindex show-transformed-names
  7154. @item --show-transformed-names
  7155. Display file or member names with all requested transformations
  7156. applied.
  7157. @end table
  7158. @noindent
  7159. For example:
  7160. @smallexample
  7161. @group
  7162. $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
  7163. usr/include/stdlib.h
  7164. $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
  7165. stdlib.h
  7166. @end group
  7167. @end smallexample
  7168. Notice that in both cases the file @file{stdlib.h} is extracted to the
  7169. current working directory, @option{--show-transformed-names} affects
  7170. only the way its name is displayed.
  7171. This option is especially useful for verifying whether the invocation
  7172. will have the desired effect. Thus, before running
  7173. @smallexample
  7174. $ @kbd{tar -x --strip=@var{n}}
  7175. @end smallexample
  7176. @noindent
  7177. it is often advisable to run
  7178. @smallexample
  7179. $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
  7180. @end smallexample
  7181. @noindent
  7182. to make sure the command will produce the intended results.
  7183. In case you need to apply more complex modifications to the file name,
  7184. @GNUTAR{} provides a general-purpose transformation option:
  7185. @table @option
  7186. @opindex transform
  7187. @opindex xform
  7188. @item --transform=@var{expression}
  7189. @itemx --xform=@var{expression}
  7190. Modify file names using supplied @var{expression}.
  7191. @end table
  7192. @noindent
  7193. The @var{expression} is a @command{sed}-like replace expression of the
  7194. form:
  7195. @smallexample
  7196. s/@var{regexp}/@var{replace}/[@var{flags}]
  7197. @end smallexample
  7198. @noindent
  7199. where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
  7200. replacement for each file name part that matches @var{regexp}. Both
  7201. @var{regexp} and @var{replace} are described in detail in
  7202. @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
  7203. Any delimiter can be used in lieu of @samp{/}, the only requirement being
  7204. that it be used consistently throughout the expression. For example,
  7205. the following two expressions are equivalent:
  7206. @smallexample
  7207. @group
  7208. s/one/two/
  7209. s,one,two,
  7210. @end group
  7211. @end smallexample
  7212. Changing delimiters is often useful when the @var{regex} contains
  7213. slashes. For example, it is more convenient to write @code{s,/,-,} than
  7214. @code{s/\//-/}.
  7215. As in @command{sed}, you can give several replace expressions,
  7216. separated by a semicolon.
  7217. Supported @var{flags} are:
  7218. @table @samp
  7219. @item g
  7220. Apply the replacement to @emph{all} matches to the @var{regexp}, not
  7221. just the first.
  7222. @item i
  7223. Use case-insensitive matching.
  7224. @item x
  7225. @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
  7226. regexps, Extended regular expressions, Extended regular expressions,
  7227. sed, GNU sed}).
  7228. @item @var{number}
  7229. Only replace the @var{number}th match of the @var{regexp}.
  7230. Note: the @acronym{POSIX} standard does not specify what should happen
  7231. when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
  7232. follows the GNU @command{sed} implementation in this regard, so
  7233. the interaction is defined to be: ignore matches before the
  7234. @var{number}th, and then match and replace all matches from the
  7235. @var{number}th on.
  7236. @end table
  7237. In addition, several @dfn{transformation scope} flags are supported,
  7238. that control to what files transformations apply. These are:
  7239. @table @samp
  7240. @item r
  7241. Apply transformation to regular archive members.
  7242. @item R
  7243. Do not apply transformation to regular archive members.
  7244. @item s
  7245. Apply transformation to symbolic link targets.
  7246. @item S
  7247. Do not apply transformation to symbolic link targets.
  7248. @item h
  7249. Apply transformation to hard link targets.
  7250. @item H
  7251. Do not apply transformation to hard link targets.
  7252. @end table
  7253. Default is @samp{rsh}, which means to apply transformations to both archive
  7254. members and targets of symbolic and hard links.
  7255. Default scope flags can also be changed using @samp{flags=} statement
  7256. in the transform expression. The flags set this way remain in force
  7257. until next @samp{flags=} statement or end of expression, whichever
  7258. occurs first. For example:
  7259. @smallexample
  7260. --transform 'flags=S;s|^|/usr/local/|'
  7261. @end smallexample
  7262. Here are several examples of @option{--transform} usage:
  7263. @enumerate
  7264. @item Extract @file{usr/} hierarchy into @file{usr/local/}:
  7265. @smallexample
  7266. $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
  7267. @end smallexample
  7268. @item Strip two leading directory components (equivalent to
  7269. @option{--strip-components=2}):
  7270. @smallexample
  7271. $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
  7272. @end smallexample
  7273. @item Convert each file name to lower case:
  7274. @smallexample
  7275. $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
  7276. @end smallexample
  7277. @item Prepend @file{/prefix/} to each file name:
  7278. @smallexample
  7279. $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
  7280. @end smallexample
  7281. @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
  7282. to each archive member:
  7283. @smallexample
  7284. $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
  7285. @end smallexample
  7286. @end enumerate
  7287. Notice the use of flags in the last example. The @file{/lib}
  7288. directory often contains many symbolic links to files within it.
  7289. It may look, for example, like this:
  7290. @smallexample
  7291. $ @kbd{ls -l}
  7292. drwxr-xr-x root/root 0 2008-07-08 16:20 /lib/
  7293. -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
  7294. lrwxrwxrwx root/root 0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
  7295. ...
  7296. @end smallexample
  7297. Using the expression @samp{s,^,/usr/local/,} would mean adding
  7298. @samp{/usr/local} to both regular archive members and to link
  7299. targets. In this case, @file{/lib/libc.so.6} would become:
  7300. @smallexample
  7301. /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
  7302. @end smallexample
  7303. This is definitely not desired. To avoid this, the @samp{S} flag
  7304. is used, which excludes symbolic link targets from filename
  7305. transformations. The result is:
  7306. @smallexample
  7307. $ @kbd{tar --transform 's,^,/usr/local/,S' -c -v -f arch.tar \
  7308. --show-transformed /lib}
  7309. drwxr-xr-x root/root 0 2008-07-08 16:20 /usr/local/lib/
  7310. -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
  7311. lrwxrwxrwx root/root 0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
  7312. -> libc-2.3.2.so
  7313. @end smallexample
  7314. Unlike @option{--strip-components}, @option{--transform} can be used
  7315. in any @GNUTAR{} operation mode. For example, the following command
  7316. adds files to the archive while replacing the leading @file{usr/}
  7317. component with @file{var/}:
  7318. @smallexample
  7319. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
  7320. @end smallexample
  7321. To test @option{--transform} effect we suggest using
  7322. @option{--show-transformed-names} option:
  7323. @smallexample
  7324. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
  7325. --verbose --show-transformed-names /}
  7326. @end smallexample
  7327. If both @option{--strip-components} and @option{--transform} are used
  7328. together, then @option{--transform} is applied first, and the required
  7329. number of components is then stripped from its result.
  7330. You can use as many @option{--transform} options in a single command
  7331. line as you want. The specified expressions will then be applied in
  7332. order of their appearance. For example, the following two invocations
  7333. are equivalent:
  7334. @smallexample
  7335. $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
  7336. --transform='s,/usr/local,/usr/,'}
  7337. $ @kbd{tar -cf arch.tar \
  7338. --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
  7339. @end smallexample
  7340. @node after
  7341. @section Operating Only on New Files
  7342. @cindex Excluding file by age
  7343. @cindex Data Modification time, excluding files by
  7344. @cindex Modification time, excluding files by
  7345. @cindex Age, excluding files by
  7346. The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
  7347. @option{-N @var{date}}) option causes @command{tar} to only work on
  7348. files whose data modification or status change times are newer than
  7349. the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
  7350. it is taken to be a file name; the data modification time of that file
  7351. is used as the date. If you use this option when creating or appending
  7352. to an archive, the archive will only include new files. If you use
  7353. @option{--after-date} when extracting an archive, @command{tar} will
  7354. only extract files newer than the @var{date} you specify.
  7355. If you want @command{tar} to make the date comparison based only on
  7356. modification of the file's data (rather than status
  7357. changes), then use the @option{--newer-mtime=@var{date}} option.
  7358. @cindex --after-date and --update compared
  7359. @cindex --newer-mtime and --update compared
  7360. You may use these options with any operation. Note that these options
  7361. differ from the @option{--update} (@option{-u}) operation in that they
  7362. allow you to specify a particular date against which @command{tar} can
  7363. compare when deciding whether or not to archive the files.
  7364. @table @option
  7365. @opindex after-date
  7366. @opindex newer
  7367. @item --after-date=@var{date}
  7368. @itemx --newer=@var{date}
  7369. @itemx -N @var{date}
  7370. Only store files newer than @var{date}.
  7371. Acts on files only if their data modification or status change times are
  7372. later than @var{date}. Use in conjunction with any operation.
  7373. If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
  7374. name; the data modification time of that file is used as the date.
  7375. @opindex newer-mtime
  7376. @item --newer-mtime=@var{date}
  7377. Act like @option{--after-date}, but look only at data modification times.
  7378. @end table
  7379. These options limit @command{tar} to operate only on files which have
  7380. been modified after the date specified. A file's status is considered to have
  7381. changed if its contents have been modified, or if its owner,
  7382. permissions, and so forth, have been changed. (For more information on
  7383. how to specify a date, see @ref{Date input formats}; remember that the
  7384. entire date argument must be quoted if it contains any spaces.)
  7385. Gurus would say that @option{--after-date} tests both the data
  7386. modification time (@code{mtime}, the time the contents of the file
  7387. were last modified) and the status change time (@code{ctime}, the time
  7388. the file's status was last changed: owner, permissions, etc.@:)
  7389. fields, while @option{--newer-mtime} tests only the @code{mtime}
  7390. field.
  7391. To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
  7392. @code{ctime} and processes the file if either one is more recent than
  7393. @var{date}, while @option{--newer-mtime} checks only @code{mtime} and
  7394. disregards @code{ctime}. Neither option uses @code{atime} (the last time the
  7395. contents of the file were looked at).
  7396. Date specifiers can have embedded spaces. Because of this, you may need
  7397. to quote date arguments to keep the shell from parsing them as separate
  7398. arguments. For example, the following command will add to the archive
  7399. all the files modified less than two days ago:
  7400. @smallexample
  7401. $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
  7402. @end smallexample
  7403. When any of these options is used with the option @option{--verbose}
  7404. (@pxref{verbose tutorial}) @GNUTAR{} converts the specified
  7405. date back to a textual form and compares that with the
  7406. one given with the option. If the two forms differ, @command{tar}
  7407. prints both forms in a message, to help the user check that the right
  7408. date is being used. For example:
  7409. @smallexample
  7410. @group
  7411. $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
  7412. tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
  7413. 13:19:37.232434
  7414. @end group
  7415. @end smallexample
  7416. @quotation
  7417. @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
  7418. should not be used for incremental backups. @xref{Incremental Dumps},
  7419. for proper way of creating incremental backups.
  7420. @end quotation
  7421. @node recurse
  7422. @section Descending into Directories
  7423. @cindex Avoiding recursion in directories
  7424. @cindex Descending directories, avoiding
  7425. @cindex Directories, avoiding recursion
  7426. @cindex Recursion in directories, avoiding
  7427. Usually, @command{tar} will recursively explore all directories (either
  7428. those given on the command line or through the @option{--files-from}
  7429. option) for the various files they contain. However, you may not always
  7430. want @command{tar} to act this way.
  7431. @opindex no-recursion
  7432. @cindex @command{find}, using with @command{tar}
  7433. The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
  7434. into specified directories. If you specify @option{--no-recursion}, you can
  7435. use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
  7436. utility for hunting through levels of directories to
  7437. construct a list of file names which you could then pass to @command{tar}.
  7438. @command{find} allows you to be more selective when choosing which files to
  7439. archive; see @ref{files}, for more information on using @command{find} with
  7440. @command{tar}.
  7441. @table @option
  7442. @item --no-recursion
  7443. Prevents @command{tar} from recursively descending directories.
  7444. @opindex recursion
  7445. @item --recursion
  7446. Requires @command{tar} to recursively descend directories.
  7447. This is the default.
  7448. @end table
  7449. When you use @option{--no-recursion}, @GNUTAR{} grabs
  7450. directory entries themselves, but does not descend on them
  7451. recursively. Many people use @command{find} for locating files they
  7452. want to back up, and since @command{tar} @emph{usually} recursively
  7453. descends on directories, they have to use the @samp{@w{-not -type d}}
  7454. test in their @command{find} invocation (@pxref{Type, Type, Type test,
  7455. find, Finding Files}), as they usually do not want all the files in a
  7456. directory. They then use the @option{--files-from} option to archive
  7457. the files located via @command{find}.
  7458. The problem when restoring files archived in this manner is that the
  7459. directories themselves are not in the archive; so the
  7460. @option{--same-permissions} (@option{--preserve-permissions},
  7461. @option{-p}) option does not affect them---while users might really
  7462. like it to. Specifying @option{--no-recursion} is a way to tell
  7463. @command{tar} to grab only the directory entries given to it, adding
  7464. no new files on its own. To summarize, if you use @command{find} to
  7465. create a list of files to be stored in an archive, use it as follows:
  7466. @smallexample
  7467. @group
  7468. $ @kbd{find @var{dir} @var{tests} | \
  7469. tar -cf @var{archive} --no-recursion -T -}
  7470. @end group
  7471. @end smallexample
  7472. The @option{--no-recursion} option also applies when extracting: it
  7473. causes @command{tar} to extract only the matched directory entries, not
  7474. the files under those directories.
  7475. The @option{--no-recursion} option also affects how globbing patterns
  7476. are interpreted (@pxref{controlling pattern-matching}).
  7477. The @option{--no-recursion} and @option{--recursion} options apply to
  7478. later options and operands, and can be overridden by later occurrences
  7479. of @option{--no-recursion} and @option{--recursion}. For example:
  7480. @smallexample
  7481. $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
  7482. @end smallexample
  7483. @noindent
  7484. creates an archive with one entry for @file{grape}, and the recursive
  7485. contents of @file{grape/concord}, but no entries under @file{grape}
  7486. other than @file{grape/concord}.
  7487. @node one
  7488. @section Crossing File System Boundaries
  7489. @cindex File system boundaries, not crossing
  7490. @command{tar} will normally automatically cross file system boundaries in
  7491. order to archive files which are part of a directory tree. You can
  7492. change this behavior by running @command{tar} and specifying
  7493. @option{--one-file-system}. This option only affects files that are
  7494. archived because they are in a directory that is being archived;
  7495. @command{tar} will still archive files explicitly named on the command line
  7496. or through @option{--files-from}, regardless of where they reside.
  7497. @table @option
  7498. @opindex one-file-system
  7499. @item --one-file-system
  7500. Prevents @command{tar} from crossing file system boundaries when
  7501. archiving. Use in conjunction with any write operation.
  7502. @end table
  7503. The @option{--one-file-system} option causes @command{tar} to modify its
  7504. normal behavior in archiving the contents of directories. If a file in
  7505. a directory is not on the same file system as the directory itself, then
  7506. @command{tar} will not archive that file. If the file is a directory
  7507. itself, @command{tar} will not archive anything beneath it; in other words,
  7508. @command{tar} will not cross mount points.
  7509. This option is useful for making full or incremental archival backups of
  7510. a file system. If this option is used in conjunction with
  7511. @option{--verbose} (@option{-v}), files that are excluded are
  7512. mentioned by name on the standard error.
  7513. @menu
  7514. * directory:: Changing Directory
  7515. * absolute:: Absolute File Names
  7516. @end menu
  7517. @node directory
  7518. @subsection Changing the Working Directory
  7519. @FIXME{need to read over this node now for continuity; i've switched
  7520. things around some.}
  7521. @cindex Changing directory mid-stream
  7522. @cindex Directory, changing mid-stream
  7523. @cindex Working directory, specifying
  7524. To change the working directory in the middle of a list of file names,
  7525. either on the command line or in a file specified using
  7526. @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
  7527. This will change the working directory to the specified directory
  7528. after that point in the list.
  7529. @table @option
  7530. @opindex directory
  7531. @item --directory=@var{directory}
  7532. @itemx -C @var{directory}
  7533. Changes the working directory in the middle of a command line.
  7534. @end table
  7535. For example,
  7536. @smallexample
  7537. $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
  7538. @end smallexample
  7539. @noindent
  7540. will place the files @file{grape} and @file{prune} from the current
  7541. directory into the archive @file{jams.tar}, followed by the file
  7542. @file{cherry} from the directory @file{food}. This option is especially
  7543. useful when you have several widely separated files that you want to
  7544. store in the same archive.
  7545. Note that the file @file{cherry} is recorded in the archive under the
  7546. precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
  7547. archive will contain three files that all appear to have come from the
  7548. same directory; if the archive is extracted with plain @samp{tar
  7549. --extract}, all three files will be written in the current directory.
  7550. Contrast this with the command,
  7551. @smallexample
  7552. $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
  7553. @end smallexample
  7554. @noindent
  7555. which records the third file in the archive under the name
  7556. @file{red/cherry} so that, if the archive is extracted using
  7557. @samp{tar --extract}, the third file will be written in a subdirectory
  7558. named @file{red}.
  7559. You can use the @option{--directory} option to make the archive
  7560. independent of the original name of the directory holding the files.
  7561. The following command places the files @file{/etc/passwd},
  7562. @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
  7563. @file{foo.tar}:
  7564. @smallexample
  7565. $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
  7566. @end smallexample
  7567. @noindent
  7568. However, the names of the archive members will be exactly what they were
  7569. on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
  7570. They will not appear to be related by file name to the original
  7571. directories where those files were located.
  7572. Note that @option{--directory} options are interpreted consecutively. If
  7573. @option{--directory} specifies a relative file name, it is interpreted
  7574. relative to the then current directory, which might not be the same as
  7575. the original current working directory of @command{tar}, due to a previous
  7576. @option{--directory} option.
  7577. When using @option{--files-from} (@pxref{files}), you can put various
  7578. @command{tar} options (including @option{-C}) in the file list. Notice,
  7579. however, that in this case the option and its argument may not be
  7580. separated by whitespace. If you use short option, its argument must
  7581. either follow the option letter immediately, without any intervening
  7582. whitespace, or occupy the next line. Otherwise, if you use long
  7583. option, separate its argument by an equal sign.
  7584. For instance, the file list for the above example will be:
  7585. @smallexample
  7586. @group
  7587. -C/etc
  7588. passwd
  7589. hosts
  7590. --directory=/lib
  7591. libc.a
  7592. @end group
  7593. @end smallexample
  7594. @noindent
  7595. To use it, you would invoke @command{tar} as follows:
  7596. @smallexample
  7597. $ @kbd{tar -c -f foo.tar --files-from list}
  7598. @end smallexample
  7599. The interpretation of options in file lists is disabled by
  7600. @option{--verbatim-files-from} and @option{--null} options.
  7601. @node absolute
  7602. @subsection Absolute File Names
  7603. @cindex absolute file names
  7604. @cindex file names, absolute
  7605. By default, @GNUTAR{} drops a leading @samp{/} on
  7606. input or output, and complains about file names containing a @file{..}
  7607. component. There is an option that turns off this behavior:
  7608. @table @option
  7609. @opindex absolute-names
  7610. @item --absolute-names
  7611. @itemx -P
  7612. Do not strip leading slashes from file names, and permit file names
  7613. containing a @file{..} file name component.
  7614. @end table
  7615. When @command{tar} extracts archive members from an archive, it strips any
  7616. leading slashes (@samp{/}) from the member name. This causes absolute
  7617. member names in the archive to be treated as relative file names. This
  7618. allows you to have such members extracted wherever you want, instead of
  7619. being restricted to extracting the member in the exact directory named
  7620. in the archive. For example, if the archive member has the name
  7621. @file{/etc/passwd}, @command{tar} will extract it as if the name were
  7622. really @file{etc/passwd}.
  7623. File names containing @file{..} can cause problems when extracting, so
  7624. @command{tar} normally warns you about such files when creating an
  7625. archive, and rejects attempts to extracts such files.
  7626. Other @command{tar} programs do not do this. As a result, if you
  7627. create an archive whose member names start with a slash, they will be
  7628. difficult for other people with a non-@GNUTAR{}
  7629. program to use. Therefore, @GNUTAR{} also strips
  7630. leading slashes from member names when putting members into the
  7631. archive. For example, if you ask @command{tar} to add the file
  7632. @file{/bin/ls} to an archive, it will do so, but the member name will
  7633. be @file{bin/ls}@footnote{A side effect of this is that when
  7634. @option{--create} is used with @option{--verbose} the resulting output
  7635. is not, generally speaking, the same as the one you'd get running
  7636. @kbd{tar --list} command. This may be important if you use some
  7637. scripts for comparing both outputs. @xref{listing member and file names},
  7638. for the information on how to handle this case.}.
  7639. Symbolic links containing @file{..} or leading @samp{/} can also cause
  7640. problems when extracting, so @command{tar} normally extracts them last;
  7641. it may create empty files as placeholders during extraction.
  7642. If you use the @option{--absolute-names} (@option{-P}) option,
  7643. @command{tar} will do none of these transformations.
  7644. To archive or extract files relative to the root directory, specify
  7645. the @option{--absolute-names} (@option{-P}) option.
  7646. Normally, @command{tar} acts on files relative to the working
  7647. directory---ignoring superior directory names when archiving, and
  7648. ignoring leading slashes when extracting.
  7649. When you specify @option{--absolute-names} (@option{-P}),
  7650. @command{tar} stores file names including all superior directory
  7651. names, and preserves leading slashes. If you only invoked
  7652. @command{tar} from the root directory you would never need the
  7653. @option{--absolute-names} option, but using this option
  7654. may be more convenient than switching to root.
  7655. @FIXME{Should be an example in the tutorial/wizardry section using this
  7656. to transfer files between systems.}
  7657. @table @option
  7658. @item --absolute-names
  7659. Preserves full file names (including superior directory names) when
  7660. archiving and extracting files.
  7661. @end table
  7662. @command{tar} prints out a message about removing the @samp{/} from
  7663. file names. This message appears once per @GNUTAR{}
  7664. invocation. It represents something which ought to be told; ignoring
  7665. what it means can cause very serious surprises, later.
  7666. Some people, nevertheless, do not want to see this message. Wanting to
  7667. play really dangerously, one may of course redirect @command{tar} standard
  7668. error to the sink. For example, under @command{sh}:
  7669. @smallexample
  7670. $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
  7671. @end smallexample
  7672. @noindent
  7673. Another solution, both nicer and simpler, would be to change to
  7674. the @file{/} directory first, and then avoid absolute notation.
  7675. For example:
  7676. @smallexample
  7677. $ @kbd{tar -c -f archive.tar -C / home}
  7678. @end smallexample
  7679. @xref{Integrity}, for some of the security-related implications
  7680. of using this option.
  7681. @include parse-datetime.texi
  7682. @node Formats
  7683. @chapter Controlling the Archive Format
  7684. @cindex Tar archive formats
  7685. Due to historical reasons, there are several formats of tar archives.
  7686. All of them are based on the same principles, but have some subtle
  7687. differences that often make them incompatible with each other.
  7688. GNU tar is able to create and handle archives in a variety of formats.
  7689. The most frequently used formats are (in alphabetical order):
  7690. @table @asis
  7691. @item gnu
  7692. Format used by @GNUTAR{} versions up to 1.13.25. This format derived
  7693. from an early @acronym{POSIX} standard, adding some improvements such as
  7694. sparse file handling and incremental archives. Unfortunately these
  7695. features were implemented in a way incompatible with other archive
  7696. formats.
  7697. Archives in @samp{gnu} format are able to hold file names of unlimited
  7698. length.
  7699. @item oldgnu
  7700. Format used by @GNUTAR{} of versions prior to 1.12.
  7701. @item v7
  7702. Archive format, compatible with the V7 implementation of tar. This
  7703. format imposes a number of limitations. The most important of them
  7704. are:
  7705. @enumerate
  7706. @item
  7707. File names and symbolic links can contain at most 100 bytes.
  7708. @item
  7709. File sizes must be less than 8 GiB (@math{2^33} bytes = 8,589,934,592 bytes).
  7710. @item
  7711. It is impossible to store special files (block and character
  7712. devices, fifos etc.)
  7713. @item
  7714. UIDs and GIDs must be less than @math{2^21} (2,097,152).
  7715. @item
  7716. V7 archives do not contain symbolic ownership information (user
  7717. and group name of the file owner).
  7718. @end enumerate
  7719. This format has traditionally been used by Automake when producing
  7720. Makefiles. This practice will change in the future, in the meantime,
  7721. however this means that projects containing file names more than 100
  7722. bytes long will not be able to use @GNUTAR{} @value{VERSION} and
  7723. Automake prior to 1.9.
  7724. @item ustar
  7725. Archive format defined by @acronym{POSIX.1-1988} and later. It stores
  7726. symbolic ownership information. It is also able to store
  7727. special files. However, it imposes several restrictions as well:
  7728. @enumerate
  7729. @item
  7730. File names can contain at most 255 bytes.
  7731. @item
  7732. File names longer than 100 bytes must be split at a directory separator in
  7733. two parts, the first being at most 155 bytes long.
  7734. So, in most cases file names must be a bit shorter than 255 bytes.
  7735. @item
  7736. Symbolic links can contain at most 100 bytes.
  7737. @item
  7738. Files can contain at most 8 GiB (@math{2^33} bytes = 8,589,934,592 bytes).
  7739. @item
  7740. UIDs, GIDs, device major numbers, and device minor numbers
  7741. must be less than @math{2^21} (2,097,152).
  7742. @end enumerate
  7743. @item star
  7744. The format used by the late J@"org Schilling's @command{star}
  7745. implementation. @GNUTAR{} is able to read @samp{star} archives but
  7746. currently does not produce them.
  7747. @item posix
  7748. The format defined by @acronym{POSIX.1-2001} and later. This is the
  7749. most flexible and feature-rich format. It does not impose arbitrary
  7750. restrictions on file sizes or file name lengths. This format is more
  7751. recent, so some @command{tar} implementations cannot handle it properly.
  7752. However, any @command{tar} implementation able to read @samp{ustar}
  7753. archives should be able to read most @samp{posix} archives as well,
  7754. except that it will extract any additional information (such as long
  7755. file names) as extra plain text files.
  7756. This archive format will be the default format for future versions
  7757. of @GNUTAR{}.
  7758. @end table
  7759. The following table summarizes the limitations of each of these
  7760. formats:
  7761. @multitable @columnfractions .10 .20 .20 .20 .20
  7762. @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
  7763. @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  7764. @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  7765. @item v7 @tab 2097151 @tab 8 GiB @minus{} 1 @tab 99 @tab n/a
  7766. @item ustar @tab 2097151 @tab 8 GiB @minus{} 1 @tab 255 @tab 21
  7767. @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
  7768. @end multitable
  7769. The default format for @GNUTAR{} is defined at compilation
  7770. time. You may check it by running @command{tar --help}, and examining
  7771. the last lines of its output. Usually, @GNUTAR{} is configured
  7772. to create archives in @samp{gnu} format, however, a future version will
  7773. switch to @samp{posix}.
  7774. @menu
  7775. * Compression:: Using Less Space through Compression
  7776. * Attributes:: Handling File Attributes
  7777. * Portability:: Making @command{tar} Archives More Portable
  7778. * Reproducibility:: Making @command{tar} Archives More Reproducible
  7779. * cpio:: Comparison of @command{tar} and @command{cpio}
  7780. @end menu
  7781. @node Compression
  7782. @section Using Less Space through Compression
  7783. @menu
  7784. * gzip:: Creating and Reading Compressed Archives
  7785. * sparse:: Archiving Sparse Files
  7786. @end menu
  7787. @node gzip
  7788. @subsection Creating and Reading Compressed Archives
  7789. @cindex Compressed archives
  7790. @cindex Storing archives in compressed format
  7791. @cindex gzip
  7792. @cindex bzip2
  7793. @cindex lzip
  7794. @cindex lzma
  7795. @cindex lzop
  7796. @cindex compress
  7797. @cindex zstd
  7798. @GNUTAR{} is able to create and read compressed archives. It supports
  7799. a wide variety of compression programs, namely: @command{gzip},
  7800. @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
  7801. @command{zstd}, @command{xz} and traditional @command{compress}. The
  7802. latter is supported mostly for backward compatibility, and we recommend
  7803. against using it, because it is by far less effective than the other
  7804. compression programs@footnote{It also had patent problems in the past.}.
  7805. Creating a compressed archive is simple: you just specify a
  7806. @dfn{compression option} along with the usual archive creation
  7807. commands. Available compression options are summarized in the
  7808. table below:
  7809. @multitable @columnfractions 0.4 0.2 0.4
  7810. @headitem Long @tab Short @tab Archive format
  7811. @item @option{--gzip} @tab @option{-z} @tab @command{gzip}
  7812. @item @option{--bzip2} @tab @option{-j} @tab @command{bzip2}
  7813. @item @option{--xz} @tab @option{-J} @tab @command{xz}
  7814. @item @option{--lzip} @tab @tab @command{lzip}
  7815. @item @option{--lzma} @tab @tab @command{lzma}
  7816. @item @option{--lzop} @tab @tab @command{lzop}
  7817. @item @option{--zstd} @tab @tab @command{zstd}
  7818. @item @option{--compress} @tab @option{-Z} @tab @command{compress}
  7819. @end multitable
  7820. For example:
  7821. @smallexample
  7822. $ @kbd{tar czf archive.tar.gz .}
  7823. @end smallexample
  7824. You can also let @GNUTAR{} select the compression program based on
  7825. the suffix of the archive file name. This is done using
  7826. @option{--auto-compress} (@option{-a}) command line option. For
  7827. example, the following invocation will use @command{bzip2} for
  7828. compression:
  7829. @smallexample
  7830. $ @kbd{tar caf archive.tar.bz2 .}
  7831. @end smallexample
  7832. @noindent
  7833. whereas the following one will use @command{lzma}:
  7834. @smallexample
  7835. $ @kbd{tar caf archive.tar.lzma .}
  7836. @end smallexample
  7837. For a complete list of file name suffixes recognized by @GNUTAR{},
  7838. see @ref{auto-compress}.
  7839. Reading compressed archive is even simpler: you don't need to specify
  7840. any additional options as @GNUTAR{} recognizes its format
  7841. automatically. Thus, the following commands will list and extract the
  7842. archive created in previous example:
  7843. @smallexample
  7844. # List the compressed archive
  7845. $ @kbd{tar tf archive.tar.gz}
  7846. # Extract the compressed archive
  7847. $ @kbd{tar xf archive.tar.gz}
  7848. @end smallexample
  7849. The format recognition algorithm is based on @dfn{signatures}, a
  7850. special byte sequences in the beginning of file, that are specific for
  7851. certain compression formats. If this approach fails, @command{tar}
  7852. falls back to using archive name suffix to determine its format
  7853. (@pxref{auto-compress}, for a list of recognized suffixes).
  7854. @anchor{alternative decompression programs}
  7855. @cindex alternative decompression programs
  7856. Some compression programs are able to handle different compression
  7857. formats. @GNUTAR{} uses this, if the principal decompressor for the
  7858. given format is not available. For example, if @command{compress} is
  7859. not installed, @command{tar} will try to use @command{gzip}. As of
  7860. version @value{VERSION} the following alternatives are
  7861. tried@footnote{To verbosely trace the decompressor selection, use the
  7862. @option{--warning=decompress-program} option
  7863. (@pxref{warnings,decompress-program}).}:
  7864. @multitable @columnfractions 0.3 0.3 0.3
  7865. @headitem Format @tab Main decompressor @tab Alternatives
  7866. @item compress @tab compress @tab gzip
  7867. @item lzma @tab lzma @tab xz
  7868. @item bzip2 @tab bzip2 @tab lbzip2
  7869. @end multitable
  7870. The only case when you have to specify a decompression option while
  7871. reading the archive is when reading from a pipe or from a tape drive
  7872. that does not support random access. However, in this case @GNUTAR{}
  7873. will indicate which option you should use. For example:
  7874. @smallexample
  7875. $ @kbd{cat archive.tar.gz | tar tf -}
  7876. tar: Archive is compressed. Use -z option
  7877. tar: Error is not recoverable: exiting now
  7878. @end smallexample
  7879. If you see such diagnostics, just add the suggested option to the
  7880. invocation of @GNUTAR{}:
  7881. @smallexample
  7882. $ @kbd{cat archive.tar.gz | tar tzf -}
  7883. @end smallexample
  7884. Notice also, that there are several restrictions on operations on
  7885. compressed archives. First of all, compressed archives cannot be
  7886. modified, i.e., you cannot update (@option{--update}, alias @option{-u})
  7887. them or delete (@option{--delete}) members from them or
  7888. add (@option{--append}, alias @option{-r}) members to them. Likewise, you
  7889. cannot append another @command{tar} archive to a compressed archive using
  7890. @option{--concatenate} (@option{-A}). Secondly, multi-volume
  7891. archives cannot be compressed.
  7892. The following options allow to select a particular compressor program:
  7893. @table @option
  7894. @opindex gzip
  7895. @opindex ungzip
  7896. @item -z
  7897. @itemx --gzip
  7898. @itemx --ungzip
  7899. Filter the archive through @command{gzip}.
  7900. @opindex xz
  7901. @item -J
  7902. @itemx --xz
  7903. Filter the archive through @code{xz}.
  7904. @item -j
  7905. @itemx --bzip2
  7906. Filter the archive through @code{bzip2}.
  7907. @opindex lzip
  7908. @item --lzip
  7909. Filter the archive through @command{lzip}.
  7910. @opindex lzma
  7911. @item --lzma
  7912. Filter the archive through @command{lzma}.
  7913. @opindex lzop
  7914. @item --lzop
  7915. Filter the archive through @command{lzop}.
  7916. @opindex zstd
  7917. @item --zstd
  7918. Filter the archive through @command{zstd}.
  7919. @opindex compress
  7920. @opindex uncompress
  7921. @item -Z
  7922. @itemx --compress
  7923. @itemx --uncompress
  7924. Filter the archive through @command{compress}.
  7925. @end table
  7926. When any of these options is given, @GNUTAR{} searches the compressor
  7927. binary in the current path and invokes it. The name of the compressor
  7928. program is specified at compilation time using a corresponding
  7929. @option{--with-@var{compname}} option to @command{configure}, e.g.
  7930. @option{--with-bzip2} to select a specific @command{bzip2} binary.
  7931. @xref{lbzip2}, for a detailed discussion.
  7932. The output produced by @command{tar --help} shows the actual
  7933. compressor names along with each of these options.
  7934. You can use any of these options on physical devices (tape drives,
  7935. etc.)@: and remote files as well as on normal files; data to or from
  7936. such devices or remote files is reblocked by another copy of the
  7937. @command{tar} program to enforce the specified (or default) record
  7938. size. The default compression parameters are used.
  7939. You can override them by using the @option{-I} option (see
  7940. below), e.g.:
  7941. @smallexample
  7942. $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
  7943. @end smallexample
  7944. @noindent
  7945. A more traditional way to do this is to use a pipe:
  7946. @smallexample
  7947. $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
  7948. @end smallexample
  7949. @cindex corrupted archives
  7950. Compressed archives are easily corrupted, because compressed files
  7951. have little redundancy. The adaptive nature of the
  7952. compression scheme means that the compression tables are implicitly
  7953. spread all over the archive. If you lose a few blocks, the dynamic
  7954. construction of the compression tables becomes unsynchronized, and there
  7955. is little chance that you could recover later in the archive.
  7956. Other compression options provide better control over creating
  7957. compressed archives. These are:
  7958. @table @option
  7959. @anchor{auto-compress}
  7960. @opindex auto-compress
  7961. @item --auto-compress
  7962. @itemx -a
  7963. Select a compression program to use by the archive file name
  7964. suffix. The following suffixes are recognized:
  7965. @multitable @columnfractions 0.3 0.6
  7966. @headitem Suffix @tab Compression program
  7967. @item @samp{.gz} @tab @command{gzip}
  7968. @item @samp{.tgz} @tab @command{gzip}
  7969. @item @samp{.taz} @tab @command{gzip}
  7970. @item @samp{.Z} @tab @command{compress}
  7971. @item @samp{.taZ} @tab @command{compress}
  7972. @item @samp{.bz2} @tab @command{bzip2}
  7973. @item @samp{.tz2} @tab @command{bzip2}
  7974. @item @samp{.tbz2} @tab @command{bzip2}
  7975. @item @samp{.tbz} @tab @command{bzip2}
  7976. @item @samp{.lz} @tab @command{lzip}
  7977. @item @samp{.lzma} @tab @command{lzma}
  7978. @item @samp{.tlz} @tab @command{lzma}
  7979. @item @samp{.lzo} @tab @command{lzop}
  7980. @item @samp{.xz} @tab @command{xz}
  7981. @item @samp{.zst} @tab @command{zstd}
  7982. @item @samp{.tzst} @tab @command{zstd}
  7983. @end multitable
  7984. @anchor{use-compress-program}
  7985. @opindex use-compress-program
  7986. @item --use-compress-program=@var{command}
  7987. @itemx -I=@var{command}
  7988. Use external compression program @var{command}. Use this option if you
  7989. want to specify options for the compression program, or if you
  7990. are not happy with the compression program associated with the suffix
  7991. at compile time, or if you have a compression program that @GNUTAR{}
  7992. does not support. The @var{command} argument is a valid command
  7993. invocation, as you would type it at the command line prompt, with any
  7994. additional options as needed. Enclose it in quotes if it contains
  7995. white space (@pxref{external, Running External Commands}).
  7996. The @var{command} should follow two conventions:
  7997. First, when invoked without additional options, it should read data
  7998. from standard input, compress it and output it on standard output.
  7999. Secondly, if invoked with the additional @option{-d} option, it should
  8000. do exactly the opposite, i.e., read the compressed data from the
  8001. standard input and produce uncompressed data on the standard output.
  8002. The latter requirement means that you must not use the @option{-d}
  8003. option as a part of the @var{command} itself.
  8004. @end table
  8005. @cindex gpg, using with tar
  8006. @cindex gnupg, using with tar
  8007. @cindex Using encrypted archives
  8008. The @option{--use-compress-program} option, in particular, lets you
  8009. implement your own filters, not necessarily dealing with
  8010. compression/decompression. For example, suppose you wish to implement
  8011. PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
  8012. gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
  8013. Manual}). The following script does that:
  8014. @smallexample
  8015. @group
  8016. #! /bin/sh
  8017. case $1 in
  8018. -d) gpg --decrypt - | gzip -d -c;;
  8019. '') gzip -c | gpg -s;;
  8020. *) echo "Unknown option $1">&2; exit 1;;
  8021. esac
  8022. @end group
  8023. @end smallexample
  8024. Suppose you name it @file{gpgz} and save it somewhere in your
  8025. @env{PATH}. Then the following command will create a compressed
  8026. archive signed with your private key:
  8027. @smallexample
  8028. $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
  8029. @end smallexample
  8030. @noindent
  8031. Likewise, the command below will list its contents:
  8032. @smallexample
  8033. $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
  8034. @end smallexample
  8035. @ignore
  8036. The above is based on the following discussion:
  8037. I have one question, or maybe it's a suggestion if there isn't a way
  8038. to do it now. I would like to use @option{--gzip}, but I'd also like
  8039. the output to be fed through a program like @acronym{GNU}
  8040. @command{ecc} (actually, right now that's @samp{exactly} what I'd like
  8041. to use :-)), basically adding ECC protection on top of compression.
  8042. It seems as if this should be quite easy to do, but I can't work out
  8043. exactly how to go about it. Of course, I can pipe the standard output
  8044. of @command{tar} through @command{ecc}, but then I lose (though I
  8045. haven't started using it yet, I confess) the ability to have
  8046. @command{tar} use @command{rmt} for it's I/O (I think).
  8047. I think the most straightforward thing would be to let me specify a
  8048. general set of filters outboard of compression (preferably ordered,
  8049. so the order can be automatically reversed on input operations, and
  8050. with the options they require specifiable), but beggars shouldn't be
  8051. choosers and anything you decide on would be fine with me.
  8052. By the way, I like @command{ecc} but if (as the comments say) it can't
  8053. deal with loss of block sync, I'm tempted to throw some time at adding
  8054. that capability. Supposing I were to actually do such a thing and
  8055. get it (apparently) working, do you accept contributed changes to
  8056. utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
  8057. Isn't that exactly the role of the
  8058. @option{--use-compress-prog=@var{program}} option?
  8059. I never tried it myself, but I suspect you may want to write a
  8060. @var{prog} script or program able to filter stdin to stdout to
  8061. way you want. It should recognize the @option{-d} option, for when
  8062. extraction is needed rather than creation.
  8063. It has been reported that if one writes compressed data (through the
  8064. @option{--gzip} or @option{--compress} options) to a DLT and tries to use
  8065. the DLT compression mode, the data will actually get bigger and one will
  8066. end up with less space on the tape.
  8067. @end ignore
  8068. @menu
  8069. * lbzip2:: Using lbzip2 with @GNUTAR{}.
  8070. @end menu
  8071. @node lbzip2
  8072. @subsubsection Using lbzip2 with @GNUTAR{}.
  8073. @cindex lbzip2
  8074. @cindex Laszlo Ersek
  8075. @command{Lbzip2} is a multithreaded utility for handling
  8076. @samp{bzip2} compression, written by Laszlo Ersek. It makes use of
  8077. multiple processors to speed up its operation and in general works
  8078. considerably faster than @command{bzip2}. For a detailed description
  8079. of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
  8080. @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
  8081. lbzip2: parallel bzip2 utility}.
  8082. Recent versions of @command{lbzip2} are mostly command line compatible
  8083. with @command{bzip2}, which makes it possible to automatically invoke
  8084. it via the @option{--bzip2} @GNUTAR{} command line option. To do so,
  8085. @GNUTAR{} must be configured with the @option{--with-bzip2} command
  8086. line option, like this:
  8087. @smallexample
  8088. $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
  8089. @end smallexample
  8090. Once configured and compiled this way, @command{tar --help} will show the
  8091. following:
  8092. @smallexample
  8093. @group
  8094. $ @kbd{tar --help | grep -- --bzip2}
  8095. -j, --bzip2 filter the archive through lbzip2
  8096. @end group
  8097. @end smallexample
  8098. @noindent
  8099. which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
  8100. @node sparse
  8101. @subsection Archiving Sparse Files
  8102. @cindex Sparse Files
  8103. Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
  8104. in a file is a section of the file's contents which was never written.
  8105. The contents of a hole reads as all zeros. On many operating systems,
  8106. actual disk storage is not allocated for holes, but they are counted
  8107. in the length of the file. If you archive such a file, @command{tar}
  8108. could create an archive longer than the original. To have @command{tar}
  8109. attempt to recognize the holes in a file, use @option{--sparse}
  8110. (@option{-S}). When you use this option, then, for any file using
  8111. less disk space than would be expected from its length, @command{tar}
  8112. searches the file for holes. It then records in the archive for the file where
  8113. the holes (consecutive stretches of zeros) are, and only archives the
  8114. ``real contents'' of the file. On extraction (using @option{--sparse} is not
  8115. needed on extraction) any such files have also holes created wherever the holes
  8116. were found. Thus, if you use @option{--sparse}, @command{tar} archives won't
  8117. take more space than the original.
  8118. @GNUTAR{} uses two methods for detecting holes in sparse files. These
  8119. methods are described later in this subsection.
  8120. @table @option
  8121. @opindex sparse
  8122. @item -S
  8123. @itemx --sparse
  8124. This option instructs @command{tar} to test each file for sparseness
  8125. before attempting to archive it. If the file is found to be sparse it
  8126. is treated specially, thus allowing to decrease the amount of space
  8127. used by its image in the archive.
  8128. This option is meaningful only when creating or updating archives. It
  8129. has no effect on extraction.
  8130. @end table
  8131. Consider using @option{--sparse} when performing file system backups,
  8132. to avoid archiving the expanded forms of files stored sparsely in the
  8133. system.
  8134. Even if your system has no sparse files currently, some may be
  8135. created in the future. If you use @option{--sparse} while making file
  8136. system backups as a matter of course, you can be assured the archive
  8137. will never take more space on the media than the files take on disk
  8138. (otherwise, archiving a disk filled with sparse files might take
  8139. hundreds of tapes). @xref{Incremental Dumps}.
  8140. However, be aware that @option{--sparse} option may present a serious
  8141. drawback. Namely, in order to determine the positions of holes in a file
  8142. @command{tar} may have to read it before trying to archive it, so in total
  8143. the file may be read @strong{twice}. This may happen when your OS or your FS
  8144. does not support @dfn{SEEK_HOLE/SEEK_DATA} feature in @dfn{lseek} (See
  8145. @option{--hole-detection}, below).
  8146. @cindex sparse formats, defined
  8147. When using @samp{POSIX} archive format, @GNUTAR{} is able to store
  8148. sparse files using in three distinct ways, called @dfn{sparse
  8149. formats}. A sparse format is identified by its @dfn{number},
  8150. consisting, as usual of two decimal numbers, delimited by a dot. By
  8151. default, format @samp{1.0} is used. If, for some reason, you wish to
  8152. use an earlier format, you can select it using
  8153. @option{--sparse-version} option.
  8154. @table @option
  8155. @opindex sparse-version
  8156. @item --sparse-version=@var{version}
  8157. Select the format to store sparse files in. Valid @var{version} values
  8158. are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
  8159. for a detailed description of each format.
  8160. @end table
  8161. Using @option{--sparse-format} option implies @option{--sparse}.
  8162. @table @option
  8163. @opindex hole-detection
  8164. @cindex hole detection
  8165. @item --hole-detection=@var{method}
  8166. Enforce concrete hole detection method. Before the real contents of sparse
  8167. file are stored, @command{tar} needs to gather knowledge about file
  8168. sparseness. This is because it needs to have the file's map of holes
  8169. stored into tar header before it starts archiving the file contents.
  8170. Currently, two methods of hole detection are implemented:
  8171. @itemize @bullet
  8172. @item @option{--hole-detection=seek}
  8173. Seeking the file for data and holes. It uses enhancement of the @code{lseek}
  8174. system call (@code{SEEK_HOLE} and @code{SEEK_DATA}) which is able to
  8175. reuse file system knowledge about sparse file contents - so the
  8176. detection is usually very fast. To use this feature, your file system
  8177. and operating system must support it. At the time of this writing
  8178. (2015) this feature, in spite of not being accepted by POSIX, is
  8179. fairly widely supported by different operating systems.
  8180. @item @option{--hole-detection=raw}
  8181. Reading byte-by-byte the whole sparse file before the archiving. This
  8182. method detects holes like consecutive stretches of zeroes. Comparing to
  8183. the previous method, it is usually much slower, although more
  8184. portable.
  8185. @end itemize
  8186. @end table
  8187. When no @option{--hole-detection} option is given, @command{tar} uses
  8188. the @samp{seek}, if supported by the operating system.
  8189. Using @option{--hole-detection} option implies @option{--sparse}.
  8190. @node Attributes
  8191. @section Handling File Attributes
  8192. @cindex attributes, files
  8193. @cindex file attributes
  8194. When @command{tar} reads files, it updates their access times. To
  8195. avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
  8196. reset the access time retroactively or avoid changing it in the first
  8197. place.
  8198. @table @option
  8199. @opindex atime-preserve
  8200. @item --atime-preserve
  8201. @itemx --atime-preserve=replace
  8202. @itemx --atime-preserve=system
  8203. Preserve the access times of files that are read. This works only for
  8204. files that you own, unless you have superuser privileges.
  8205. @option{--atime-preserve=replace} works on most systems, but it also
  8206. restores the data modification time and updates the status change
  8207. time. Hence it doesn't interact with incremental dumps nicely
  8208. (@pxref{Incremental Dumps}), and it can set access or data modification times
  8209. incorrectly if other programs access the file while @command{tar} is
  8210. running.
  8211. @option{--atime-preserve=system} avoids changing the access time in
  8212. the first place, if the operating system supports this.
  8213. Unfortunately, this may or may not work on any given operating system
  8214. or file system. If @command{tar} knows for sure it won't work, it
  8215. complains right away.
  8216. Currently @option{--atime-preserve} with no operand defaults to
  8217. @option{--atime-preserve=replace}, but this is intended to change to
  8218. @option{--atime-preserve=system} when the latter is better-supported.
  8219. @opindex touch
  8220. @item -m
  8221. @itemx --touch
  8222. Do not extract data modification time.
  8223. When this option is used, @command{tar} leaves the data modification times
  8224. of the files it extracts as the times when the files were extracted,
  8225. instead of setting it to the times recorded in the archive.
  8226. This option is meaningless with @option{--list} (@option{-t}).
  8227. @opindex same-owner
  8228. @item --same-owner
  8229. Create extracted files with the same ownership they have in the
  8230. archive.
  8231. This is the default behavior for the superuser,
  8232. so this option is meaningful only for non-root users, when @command{tar}
  8233. is executed on those systems able to give files away. This is
  8234. considered as a security flaw by many people, at least because it
  8235. makes quite difficult to correctly account users for the disk space
  8236. they occupy. Also, the @code{suid} or @code{sgid} attributes of
  8237. files are easily and silently lost when files are given away.
  8238. When writing an archive, @command{tar} writes the user @acronym{ID} and user name
  8239. separately. If it can't find a user name (because the user @acronym{ID} is not
  8240. in @file{/etc/passwd}), then it does not write one. When restoring,
  8241. it tries to look the name (if one was written) up in
  8242. @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
  8243. the archive instead.
  8244. @opindex no-same-owner
  8245. @item --no-same-owner
  8246. @itemx -o
  8247. Do not attempt to restore ownership when extracting. This is the
  8248. default behavior for ordinary users, so this option has an effect
  8249. only for the superuser.
  8250. @opindex numeric-owner
  8251. @item --numeric-owner
  8252. The @option{--numeric-owner} option allows (ANSI) archives to be written
  8253. without user/group name information or such information to be ignored
  8254. when extracting. It effectively disables the generation and/or use
  8255. of user/group name information. This option forces extraction using
  8256. the numeric ids from the archive, ignoring the names.
  8257. This is useful in certain circumstances, when restoring a backup from
  8258. an emergency floppy with different passwd/group files for example.
  8259. It is otherwise impossible to extract files with the right ownerships
  8260. if the password file in use during the extraction does not match the
  8261. one belonging to the file system(s) being extracted. This occurs,
  8262. for example, if you are restoring your files after a major crash and
  8263. had booted from an emergency floppy with no password file or put your
  8264. disk into another machine to do the restore.
  8265. The numeric ids are @emph{always} saved into @command{tar} archives.
  8266. The identifying names are added at create time when provided by the
  8267. system, unless @option{--format=oldgnu} is used. Numeric ids could be
  8268. used when moving archives between a collection of machines using
  8269. a centralized management for attribution of numeric ids to users
  8270. and groups. This is often made through using the NIS capabilities.
  8271. When making a @command{tar} file for distribution to other sites, it
  8272. is sometimes cleaner to use a single owner for all files in the
  8273. distribution, and nicer to specify the write permission bits of the
  8274. files as stored in the archive independently of their actual value on
  8275. the file system. The way to prepare a clean distribution is usually
  8276. to have some Makefile rule creating a directory, copying all needed
  8277. files in that directory, then setting ownership and permissions as
  8278. wanted (there are a lot of possible schemes), and only then making a
  8279. @command{tar} archive out of this directory, before cleaning
  8280. everything out. Of course, we could add a lot of options to
  8281. @GNUTAR{} for fine tuning permissions and ownership.
  8282. This is not the good way, I think. @GNUTAR{} is
  8283. already crowded with options and moreover, the approach just explained
  8284. gives you a great deal of control already.
  8285. @xopindex{same-permissions, short description}
  8286. @xopindex{preserve-permissions, short description}
  8287. @item -p
  8288. @itemx --same-permissions
  8289. @itemx --preserve-permissions
  8290. Extract all protection information.
  8291. This option causes @command{tar} to set the modes (access permissions) of
  8292. extracted files exactly as recorded in the archive. If this option
  8293. is not used, the current @code{umask} setting limits the permissions
  8294. on extracted files. This option is by default enabled when
  8295. @command{tar} is executed by a superuser.
  8296. This option is meaningless with @option{--list} (@option{-t}).
  8297. @end table
  8298. @node Portability
  8299. @section Making @command{tar} Archives More Portable
  8300. @cindex portable archives
  8301. Creating a @command{tar} archive on a particular system that is meant to be
  8302. useful later on many other machines and with other versions of @command{tar}
  8303. is more challenging than you might think. @command{tar} archive formats
  8304. have been evolving since the first versions of Unix. Many such formats
  8305. are around, and are not always compatible with each other. This section
  8306. discusses a few problems, and gives some advice about making @command{tar}
  8307. archives more portable.
  8308. One golden rule is simplicity. For example, limit your @command{tar}
  8309. archives to contain only regular files and directories, avoiding
  8310. other kind of special files. Do not attempt to save sparse files or
  8311. contiguous files as such. Let's discuss a few more problems, in turn.
  8312. @FIXME{Discuss GNU extensions (incremental backups, multi-volume
  8313. archives and archive labels) in GNU and PAX formats.}
  8314. @menu
  8315. * Portable Names:: Portable Names
  8316. * dereference:: Symbolic Links
  8317. * hard links:: Hard Links
  8318. * old:: Old V7 Archives
  8319. * ustar:: Ustar Archives
  8320. * gnu:: GNU and old GNU format archives.
  8321. * posix:: @acronym{POSIX} archives
  8322. * Checksumming:: Checksumming Problems
  8323. * Large or Negative Values:: Large files, negative time stamps, etc.
  8324. * Other Tars:: How to Extract GNU-Specific Data Using
  8325. Other @command{tar} Implementations
  8326. @end menu
  8327. @node Portable Names
  8328. @subsection Portable Names
  8329. Use portable file and member names. A name is portable if it contains
  8330. only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
  8331. @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
  8332. contain @samp{/-}. Avoid deep directory nesting. For portability to
  8333. old Unix hosts, limit your file name components to 14 characters or
  8334. less.
  8335. If you intend to have your @command{tar} archives to be read on
  8336. case-insensitive file systems like FAT32,
  8337. you should not rely on case distinction for file names.
  8338. @node dereference
  8339. @subsection Symbolic Links
  8340. @cindex File names, using symbolic links
  8341. @cindex Symbolic link as file name
  8342. @opindex dereference
  8343. Normally, when @command{tar} archives a symbolic link, it writes a
  8344. block to the archive naming the target of the link. In that way, the
  8345. @command{tar} archive is a faithful record of the file system contents.
  8346. When @option{--dereference} (@option{-h}) is used with
  8347. @option{--create} (@option{-c}), @command{tar} archives the files
  8348. symbolic links point to, instead of
  8349. the links themselves.
  8350. When creating portable archives, use @option{--dereference}
  8351. (@option{-h}): some systems do not support
  8352. symbolic links, and moreover, your distribution might be unusable if
  8353. it contains unresolved symbolic links.
  8354. When reading from an archive, the @option{--dereference} (@option{-h})
  8355. option causes @command{tar} to follow an already-existing symbolic
  8356. link when @command{tar} writes or reads a file named in the archive.
  8357. Ordinarily, @command{tar} does not follow such a link, though it may
  8358. remove the link before writing a new file. @xref{Dealing with Old
  8359. Files}.
  8360. The @option{--dereference} option is unsafe if an untrusted user can
  8361. modify directories while @command{tar} is running. @xref{Security}.
  8362. @node hard links
  8363. @subsection Hard Links
  8364. @cindex File names, using hard links
  8365. @cindex hard links, dereferencing
  8366. @cindex dereferencing hard links
  8367. Normally, when @command{tar} archives a hard link, it writes a
  8368. block to the archive naming the target of the link (a @samp{1} type
  8369. block). In that way, the actual file contents is stored in file only
  8370. once. For example, consider the following two files:
  8371. @smallexample
  8372. @group
  8373. $ ls -l
  8374. -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
  8375. -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
  8376. @end group
  8377. @end smallexample
  8378. Here, @file{jeden} is a link to @file{one}. When archiving this
  8379. directory with a verbose level 2, you will get an output similar to
  8380. the following:
  8381. @smallexample
  8382. $ tar cvvf ../archive.tar .
  8383. drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
  8384. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
  8385. hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
  8386. @end smallexample
  8387. The last line shows that, instead of storing two copies of the file,
  8388. @command{tar} stored it only once, under the name @file{jeden}, and
  8389. stored file @file{one} as a hard link to this file.
  8390. It may be important to know that all hard links to the given file are
  8391. stored in the archive. For example, this may be necessary for exact
  8392. reproduction of the file system. The following option does that:
  8393. @table @option
  8394. @xopindex{check-links, described}
  8395. @item --check-links
  8396. @itemx -l
  8397. Check the number of links dumped for each processed file. If this
  8398. number does not match the total number of hard links for the file, print
  8399. a warning message.
  8400. @end table
  8401. For example, trying to archive only file @file{jeden} with this option
  8402. produces the following diagnostics:
  8403. @smallexample
  8404. $ tar -c -f ../archive.tar -l jeden
  8405. tar: Missing links to 'jeden'.
  8406. @end smallexample
  8407. Although creating special records for hard links helps keep a faithful
  8408. record of the file system contents and makes archives more compact, it
  8409. may present some difficulties when extracting individual members from
  8410. the archive. For example, trying to extract file @file{one} from the
  8411. archive created in previous examples produces, in the absence of file
  8412. @file{jeden}:
  8413. @smallexample
  8414. $ tar xf archive.tar ./one
  8415. tar: ./one: Cannot hard link to './jeden': No such file or directory
  8416. tar: Error exit delayed from previous errors
  8417. @end smallexample
  8418. The reason for this behavior is that @command{tar} cannot seek back in
  8419. the archive to the previous member (in this case, @file{one}), to
  8420. extract it@footnote{There are plans to fix this in future releases.}.
  8421. If you wish to avoid such problems at the cost of a bigger archive,
  8422. use the following option:
  8423. @table @option
  8424. @xopindex{hard-dereference, described}
  8425. @item --hard-dereference
  8426. Dereference hard links and store the files they refer to.
  8427. @end table
  8428. For example, trying this option on our two sample files, we get two
  8429. copies in the archive, each of which can then be extracted
  8430. independently of the other:
  8431. @smallexample
  8432. @group
  8433. $ tar -c -vv -f ../archive.tar --hard-dereference .
  8434. drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
  8435. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
  8436. -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
  8437. @end group
  8438. @end smallexample
  8439. @node old
  8440. @subsection Old V7 Archives
  8441. @cindex Format, old style
  8442. @cindex Old style format
  8443. @cindex Old style archives
  8444. @cindex v7 archive format
  8445. Certain old versions of @command{tar} cannot handle additional
  8446. information recorded by newer @command{tar} programs. To create an
  8447. archive in V7 format (not ANSI), which can be read by these old
  8448. versions, specify the @option{--format=v7} option in
  8449. conjunction with the @option{--create} (@option{-c}) (@command{tar} also
  8450. accepts @option{--portability} or @option{--old-archive} for this
  8451. option). When you specify it,
  8452. @command{tar} leaves out information about directories, pipes, fifos,
  8453. contiguous files, and device files, and specifies file ownership by
  8454. group and user IDs instead of group and user names.
  8455. When updating an archive, do not use @option{--format=v7}
  8456. unless the archive was created using this option.
  8457. In most cases, a @emph{new} format archive can be read by an @emph{old}
  8458. @command{tar} program without serious trouble, so this option should
  8459. seldom be needed. On the other hand, most modern @command{tar}s are
  8460. able to read old format archives, so it might be safer for you to
  8461. always use @option{--format=v7} for your distributions. Notice,
  8462. however, that @samp{ustar} format is a better alternative, as it is
  8463. free from many of @samp{v7}'s drawbacks.
  8464. @node ustar
  8465. @subsection Ustar Archive Format
  8466. @cindex ustar archive format
  8467. The archive format defined by the @acronym{POSIX}.1-1988 specification is
  8468. called @code{ustar}. Although it is more flexible than the V7 format, it
  8469. still has many restrictions (@pxref{Formats,ustar}, for the detailed
  8470. description of @code{ustar} format). Along with V7 format,
  8471. @code{ustar} format is a good choice for archives intended to be read
  8472. with other implementations of @command{tar}.
  8473. To create an archive in @code{ustar} format, use the @option{--format=ustar}
  8474. option in conjunction with @option{--create} (@option{-c}).
  8475. @node gnu
  8476. @subsection @acronym{GNU} and old @GNUTAR{} format
  8477. @cindex GNU archive format
  8478. @cindex Old GNU archive format
  8479. @GNUTAR{} was based on an early draft of the
  8480. @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
  8481. @command{tar}, such as the support for file names longer than 100
  8482. characters, use portions of the @command{tar} header record which were
  8483. specified in that @acronym{POSIX} draft as unused. Subsequent changes in
  8484. @acronym{POSIX} have allocated the same parts of the header record for
  8485. other purposes. As a result, @GNUTAR{} format is
  8486. incompatible with the current @acronym{POSIX} specification, and with
  8487. @command{tar} programs that follow it.
  8488. In the majority of cases, @command{tar} will be configured to create
  8489. this format by default. This will change in future releases, since
  8490. we plan to make @samp{POSIX} format the default.
  8491. To force creation a @GNUTAR{} archive, use option
  8492. @option{--format=gnu}.
  8493. @node posix
  8494. @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
  8495. @cindex POSIX archive format
  8496. @cindex PAX archive format
  8497. Starting from version 1.14 @GNUTAR{} features full support for
  8498. @acronym{POSIX.1-2001} archives.
  8499. A @acronym{POSIX} conformant archive will be created if @command{tar}
  8500. was given @option{--format=posix} (@option{--format=pax}) option. No
  8501. special option is required to read and extract from a @acronym{POSIX}
  8502. archive.
  8503. @menu
  8504. * PAX keywords:: Controlling Extended Header Keywords.
  8505. @end menu
  8506. @node PAX keywords
  8507. @subsubsection Controlling Extended Header Keywords
  8508. @table @option
  8509. @opindex pax-option
  8510. @item --pax-option=@var{keyword-list}
  8511. Handle keywords in @acronym{PAX} extended headers. This option is
  8512. equivalent to @option{-o} option of the @command{pax} utility.
  8513. @end table
  8514. @var{Keyword-list} is a comma-separated
  8515. list of keyword options, each keyword option taking one of
  8516. the following forms:
  8517. @table @code
  8518. @item delete=@var{pattern}
  8519. When used with one of archive-creation commands,
  8520. this option instructs @command{tar} to omit from extended header records
  8521. that it produces any keywords matching the string @var{pattern}.
  8522. If the pattern contains shell metacharacters like @samp{*}, it should
  8523. be quoted to prevent the shell from expanding the pattern before
  8524. @command{tar} sees it.
  8525. When used in extract or list mode, this option instructs tar
  8526. to ignore any keywords matching the given @var{pattern} in the extended
  8527. header records. In both cases, matching is performed using the pattern
  8528. matching notation described in @acronym{POSIX 1003.2}, 3.13
  8529. (@pxref{wildcards}). For example:
  8530. @smallexample
  8531. --pax-option 'delete=security.*'
  8532. @end smallexample
  8533. would suppress security-related information.
  8534. @item exthdr.name=@var{string}
  8535. This keyword allows user control over the name that is written into the
  8536. ustar header blocks for the extended headers. The name is obtained
  8537. from @var{string} after making the following substitutions:
  8538. @multitable @columnfractions .25 .55
  8539. @headitem Meta-character @tab Replaced By
  8540. @item %d @tab The directory name of the file, equivalent to the
  8541. result of the @command{dirname} utility on the translated file name.
  8542. @item %f @tab The name of the file with the directory information
  8543. stripped, equivalent to the result of the @command{basename} utility
  8544. on the translated file name.
  8545. @item %p @tab The process @acronym{ID} of the @command{tar} process.
  8546. @item %% @tab A @samp{%} character.
  8547. @end multitable
  8548. Any other @samp{%} characters in @var{string} produce undefined
  8549. results.
  8550. If no option @samp{exthdr.name=string} is specified, @command{tar}
  8551. will use the following default value:
  8552. @smallexample
  8553. %d/PaxHeaders/%f
  8554. @end smallexample
  8555. This default helps make the archive more reproducible.
  8556. @xref{Reproducibility}. @acronym{POSIX} recommends using
  8557. @samp{%d/PaxHeaders.%p/%f} instead, which means the two archives
  8558. created with the same set of options and containing the same set
  8559. of files will be byte-to-byte different. This default will be used
  8560. if the environment variable @env{POSIXLY_CORRECT} is set.
  8561. @item exthdr.mtime=@var{value}
  8562. This keyword defines the value of the @samp{mtime} field that
  8563. is written into the ustar header blocks for the extended headers.
  8564. By default, the @samp{mtime} field is set to the modification time
  8565. of the archive member described by that extended header (or to the
  8566. value of the @option{--mtime} option, if supplied).
  8567. @item globexthdr.name=@var{string}
  8568. This keyword allows user control over the name that is written into
  8569. the ustar header blocks for global extended header records. The name
  8570. is obtained from the contents of @var{string}, after making
  8571. the following substitutions:
  8572. @multitable @columnfractions .25 .55
  8573. @headitem Meta-character @tab Replaced By
  8574. @item %n @tab An integer that represents the
  8575. sequence number of the global extended header record in the archive,
  8576. starting at 1.
  8577. @item %p @tab The process @acronym{ID} of the @command{tar} process.
  8578. @item %% @tab A @samp{%} character.
  8579. @end multitable
  8580. Any other @samp{%} characters in @var{string} produce undefined results.
  8581. If no option @samp{globexthdr.name=string} is specified, @command{tar}
  8582. will use the following default value:
  8583. @smallexample
  8584. $TMPDIR/GlobalHead.%n
  8585. @end smallexample
  8586. If the environment variable @env{POSIXLY_CORRECT} is set, the
  8587. following value is used instead:
  8588. @smallexample
  8589. $TMPDIR/GlobalHead.%p.%n
  8590. @end smallexample
  8591. In both cases, @samp{$TMPDIR} stands for the value of the @var{TMPDIR}
  8592. environment variable. If @var{TMPDIR} is not set, @command{tar}
  8593. uses @samp{/tmp}.
  8594. @item globexthdr.mtime=@var{value}
  8595. This keyword defines the value of the @samp{mtime} field that
  8596. is written into the ustar header blocks for the global extended headers.
  8597. By default, the @samp{mtime} field is set to the time when
  8598. @command{tar} was invoked.
  8599. @item @var{keyword}=@var{value}
  8600. When used with one of archive-creation commands, these keyword/value pairs
  8601. will be included at the beginning of the archive in a global extended
  8602. header record. When used with one of archive-reading commands,
  8603. @command{tar} will behave as if it has encountered these keyword/value
  8604. pairs at the beginning of the archive in a global extended header
  8605. record.
  8606. @item @var{keyword}:=@var{value}
  8607. When used with one of archive-creation commands, these keyword/value pairs
  8608. will be included as records at the beginning of an extended header for
  8609. each file. This is effectively equivalent to @var{keyword}=@var{value}
  8610. form except that it creates no global extended header records.
  8611. When used with one of archive-reading commands, @command{tar} will
  8612. behave as if these keyword/value pairs were included as records at the
  8613. end of each extended header; thus, they will override any global or
  8614. file-specific extended header record keywords of the same names.
  8615. For example, in the command:
  8616. @smallexample
  8617. tar --format=posix --create \
  8618. --file archive --pax-option gname:=user .
  8619. @end smallexample
  8620. the group name will be forced to a new value for all files
  8621. stored in the archive.
  8622. @end table
  8623. In any of the forms described above, the @var{value} may be
  8624. a string enclosed in curly braces. In that case, the string
  8625. between the braces is understood either as a textual time
  8626. representation, as described in @ref{Date input formats}, or a name of
  8627. the existing file, starting with @samp{/} or @samp{.}. In the latter
  8628. case, the modification time of that file is used.
  8629. For example, to set all modification times to the current date, you
  8630. use the following option:
  8631. @smallexample
  8632. --pax-option 'mtime:=@{now@}'
  8633. @end smallexample
  8634. @cindex archives, binary equivalent
  8635. @cindex binary equivalent archives, creating
  8636. As another example, the following option helps make the archive
  8637. more reproducible. @xref{Reproducibility}.
  8638. @smallexample
  8639. --pax-option delete=atime
  8640. @end smallexample
  8641. @noindent
  8642. If you extract files from such an archive and recreate the archive
  8643. from them, you will also need to eliminate changes due to ctime:
  8644. @smallexample
  8645. --pax-option 'delete=atime,delete=ctime'
  8646. @end smallexample
  8647. Normally @command{tar} saves an mtime value with subsecond resolution
  8648. in an extended header for any file with a timestamp that is not on a
  8649. one-second boundary. This is in addition to the traditional mtime
  8650. timestamp in the header block. Although you can suppress subsecond
  8651. timestamp resolution with @option{--pax-option delete=mtime},
  8652. this hack will not work for timestamps before 1970 or after 2242-03-16
  8653. 12:56:31 @sc{utc}.
  8654. If the environment variable @env{POSIXLY_CORRECT} is set, two POSIX
  8655. archives created using the same options on the same set of files might
  8656. not be byte-to-byte equivalent even with the above options. This is
  8657. because the POSIX default for extended header names includes
  8658. the @command{tar} process @acronym{ID}, which typically differs at each
  8659. run. To produce byte-to-byte equivalent archives in this case, either
  8660. unset @env{POSIXLY_CORRECT}, or use the following option, which can be
  8661. combined with the above options:
  8662. @smallexample
  8663. --pax-option exthdr.name=%d/PaxHeaders/%f
  8664. @end smallexample
  8665. @node Checksumming
  8666. @subsection Checksumming Problems
  8667. SunOS and HP-UX @command{tar} fail to accept archives created using
  8668. @GNUTAR{} and containing non-@acronym{ASCII} file names, that
  8669. is, file names having characters with the eighth bit set, because they
  8670. use signed checksums, while @GNUTAR{} uses unsigned
  8671. checksums while creating archives, as per @acronym{POSIX} standards. On
  8672. reading, @GNUTAR{} computes both checksums and accepts either of them.
  8673. It is somewhat worrying that a lot of people may go
  8674. around doing backup of their files using faulty (or at least
  8675. non-standard) software, not learning about it until it's time to
  8676. restore their missing files with an incompatible file extractor, or
  8677. vice versa.
  8678. @GNUTAR{} computes checksums both ways, and accepts either of them
  8679. on read, so @acronym{GNU} tar can read Sun tapes even with their
  8680. wrong checksums. @GNUTAR{} produces the standard
  8681. checksum, however, raising incompatibilities with Sun. That is to
  8682. say, @GNUTAR{} has not been modified to
  8683. @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
  8684. I've been told that more recent Sun @command{tar} now read standard
  8685. archives, so maybe Sun did a similar patch, after all?
  8686. The story seems to be that when Sun first imported @command{tar}
  8687. sources on their system, they recompiled it without realizing that
  8688. the checksums were computed differently, because of a change in
  8689. the default signing of @code{char}'s in their compiler. So they
  8690. started computing checksums wrongly. When they later realized their
  8691. mistake, they merely decided to stay compatible with it, and with
  8692. themselves afterwards. Presumably, but I do not really know, HP-UX
  8693. has chosen their @command{tar} archives to be compatible with Sun's.
  8694. The current standards do not favor Sun @command{tar} format. In any
  8695. case, it now falls on the shoulders of SunOS and HP-UX users to get
  8696. a @command{tar} able to read the good archives they receive.
  8697. @node Large or Negative Values
  8698. @subsection Large or Negative Values
  8699. @cindex large values
  8700. @cindex future time stamps
  8701. @cindex negative time stamps
  8702. @UNREVISED{}
  8703. The above sections suggest to use @samp{oldest possible} archive
  8704. format if in doubt. However, sometimes it is not possible. If you
  8705. attempt to archive a file whose metadata cannot be represented using
  8706. required format, @GNUTAR{} will print error message and ignore such a
  8707. file. You will than have to switch to a format that is able to
  8708. handle such values. The format summary table (@pxref{Formats}) will
  8709. help you to do so.
  8710. In particular, when trying to archive files 8 GiB or larger, or with
  8711. timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
  8712. 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
  8713. @acronym{POSIX} archive formats. When considering which format to
  8714. choose, bear in mind that the @acronym{GNU} format uses
  8715. two's-complement base-256 notation to store values that do not fit
  8716. into standard @acronym{ustar} range. Such archives can generally be
  8717. read only by a @GNUTAR{} implementation. Moreover, they sometimes
  8718. cannot be correctly restored on another hosts even by @GNUTAR{}. For
  8719. example, using two's complement representation for negative time
  8720. stamps that assumes a signed 32-bit @code{time_t} generates archives
  8721. that are not portable to hosts with differing @code{time_t}
  8722. representations.
  8723. On the other hand, @acronym{POSIX} archives, generally speaking, can
  8724. be extracted by any tar implementation that understands older
  8725. @acronym{ustar} format. The exceptions are files 8 GiB or larger,
  8726. or files dated before 1970-01-01 00:00:00 or after 2242-03-16
  8727. 12:56:31 @sc{utc}
  8728. @FIXME{Describe how @acronym{POSIX} archives are extracted by non
  8729. POSIX-aware tars.}
  8730. @node Other Tars
  8731. @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
  8732. In previous sections you became acquainted with various quirks
  8733. necessary to make your archives portable. Sometimes you may need to
  8734. extract archives containing GNU-specific members using some
  8735. third-party @command{tar} implementation or an older version of
  8736. @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
  8737. but if it is for some reason impossible, this section will explain
  8738. how to cope without it.
  8739. When we speak about @dfn{GNU-specific} members we mean two classes of
  8740. them: members split between the volumes of a multi-volume archive and
  8741. sparse members. You will be able to always recover such members if
  8742. the archive is in PAX format. In addition split members can be
  8743. recovered from archives in old GNU format. The following subsections
  8744. describe the required procedures in detail.
  8745. @menu
  8746. * Split Recovery:: Members Split Between Volumes
  8747. * Sparse Recovery:: Sparse Members
  8748. @end menu
  8749. @node Split Recovery
  8750. @subsubsection Extracting Members Split Between Volumes
  8751. @cindex Multi-volume archives, extracting using non-GNU tars
  8752. If a member is split between several volumes of an old GNU format archive
  8753. most third party @command{tar} implementation will fail to extract
  8754. it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
  8755. This program is available from
  8756. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
  8757. home page}. It concatenates several archive volumes into a single
  8758. valid archive. For example, if you have three volumes named from
  8759. @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
  8760. extract them using a third-party @command{tar}:
  8761. @smallexample
  8762. $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
  8763. @end smallexample
  8764. @cindex Multi-volume archives in PAX format, extracting using non-GNU tars
  8765. You could use this approach for most (although not all) PAX
  8766. format archives as well. However, extracting split members from a PAX
  8767. archive is a much easier task, because PAX volumes are constructed in
  8768. such a way that each part of a split member is extracted to a
  8769. different file by @command{tar} implementations that are not aware of
  8770. GNU extensions. More specifically, the very first part retains its
  8771. original name, and all subsequent parts are named using the pattern:
  8772. @smallexample
  8773. %d/GNUFileParts/%f.%n
  8774. @end smallexample
  8775. @noindent
  8776. where symbols preceded by @samp{%} are @dfn{macro characters} that
  8777. have the following meaning:
  8778. @multitable @columnfractions .25 .55
  8779. @headitem Meta-character @tab Replaced By
  8780. @item %d @tab The directory name of the file, equivalent to the
  8781. result of the @command{dirname} utility on its full name.
  8782. @item %f @tab The file name of the file, equivalent to the result
  8783. of the @command{basename} utility on its full name.
  8784. @item %p @tab The process @acronym{ID} of the @command{tar} process that
  8785. created the archive.
  8786. @item %n @tab Ordinal number of this particular part.
  8787. @end multitable
  8788. For example, if the file @file{var/longfile} was split during archive
  8789. creation between three volumes, then the member names will be:
  8790. @smallexample
  8791. var/longfile
  8792. var/GNUFileParts/longfile.1
  8793. var/GNUFileParts/longfile.2
  8794. @end smallexample
  8795. When you extract your archive using a third-party @command{tar}, these
  8796. files will be created on your disk, and the only thing you will need
  8797. to do to restore your file in its original form is concatenate them in
  8798. the proper order, for example:
  8799. @smallexample
  8800. @group
  8801. $ @kbd{cd var}
  8802. $ @kbd{cat GNUFileParts/longfile.1 \
  8803. GNUFileParts/longfile.2 >> longfile}
  8804. $ rm -f GNUFileParts
  8805. @end group
  8806. @end smallexample
  8807. Notice, that if the @command{tar} implementation you use supports PAX
  8808. format archives, it will probably emit warnings about unknown keywords
  8809. during extraction. They will look like this:
  8810. @smallexample
  8811. @group
  8812. Tar file too small
  8813. Unknown extended header keyword 'GNU.volume.filename' ignored.
  8814. Unknown extended header keyword 'GNU.volume.size' ignored.
  8815. Unknown extended header keyword 'GNU.volume.offset' ignored.
  8816. @end group
  8817. @end smallexample
  8818. @noindent
  8819. You can safely ignore these warnings.
  8820. If your @command{tar} implementation is not PAX-aware, you will get
  8821. more warnings and more files generated on your disk, e.g.:
  8822. @smallexample
  8823. @group
  8824. $ @kbd{tar xf vol-1.tar}
  8825. var/PaxHeaders/longfile: Unknown file type 'x', extracted as
  8826. normal file
  8827. Unexpected EOF in archive
  8828. $ @kbd{tar xf vol-2.tar}
  8829. tmp/GlobalHead.1: Unknown file type 'g', extracted as normal file
  8830. GNUFileParts/PaxHeaders/sparsefile.1: Unknown file type
  8831. 'x', extracted as normal file
  8832. @end group
  8833. @end smallexample
  8834. Ignore these warnings. The @file{PaxHeaders.*} directories created
  8835. will contain files with @dfn{extended header keywords} describing the
  8836. extracted files. You can delete them, unless they describe sparse
  8837. members. Read further to learn more about them.
  8838. @node Sparse Recovery
  8839. @subsubsection Extracting Sparse Members
  8840. @cindex sparse files, extracting with non-GNU tars
  8841. Any @command{tar} implementation will be able to extract sparse members from a
  8842. PAX archive. However, the extracted files will be @dfn{condensed},
  8843. i.e., any zero blocks will be removed from them. When we restore such
  8844. a condensed file to its original form, by adding zero blocks (or
  8845. @dfn{holes}) back to their original locations, we call this process
  8846. @dfn{expanding} a compressed sparse file.
  8847. @pindex xsparse
  8848. To expand a file, you will need a simple auxiliary program called
  8849. @command{xsparse}. It is available in source form from
  8850. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
  8851. home page}.
  8852. @cindex sparse files v.1.0, extracting with non-GNU tars
  8853. Let's begin with archive members in @dfn{sparse format
  8854. version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
  8855. The condensed file will contain both file map and file data, so no
  8856. additional data will be needed to restore it. If the original file
  8857. name was @file{@var{dir}/@var{name}}, then the condensed file will be
  8858. named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
  8859. @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
  8860. @dfn{process @acronym{ID}} of the @command{tar} process which created the
  8861. archive (@pxref{PAX keywords}).}.
  8862. To expand a version 1.0 file, run @command{xsparse} as follows:
  8863. @smallexample
  8864. $ @kbd{xsparse @file{cond-file}}
  8865. @end smallexample
  8866. @noindent
  8867. where @file{cond-file} is the name of the condensed file. The utility
  8868. will deduce the name for the resulting expanded file using the
  8869. following algorithm:
  8870. @enumerate 1
  8871. @item If @file{cond-file} does not contain any directories,
  8872. @file{../cond-file} will be used;
  8873. @item If @file{cond-file} has the form
  8874. @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
  8875. are simple names, with no @samp{/} characters in them, the output file
  8876. name will be @file{@var{dir}/@var{name}}.
  8877. @item Otherwise, if @file{cond-file} has the form
  8878. @file{@var{dir}/@var{name}}, the output file name will be
  8879. @file{@var{name}}.
  8880. @end enumerate
  8881. In the unlikely case when this algorithm does not suit your needs,
  8882. you can explicitly specify output file name as a second argument to
  8883. the command:
  8884. @smallexample
  8885. $ @kbd{xsparse @file{cond-file} @file{out-file}}
  8886. @end smallexample
  8887. It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
  8888. first. In this mode, the command does not actually expand the file,
  8889. but verbosely lists all actions it would be taking to do so. The dry
  8890. run mode is enabled by @option{-n} command line argument:
  8891. @smallexample
  8892. @group
  8893. $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
  8894. Reading v.1.0 sparse map
  8895. Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
  8896. '/home/gray/sparsefile'
  8897. Finished dry run
  8898. @end group
  8899. @end smallexample
  8900. To actually expand the file, you would run:
  8901. @smallexample
  8902. $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
  8903. @end smallexample
  8904. @noindent
  8905. The program behaves the same way all UNIX utilities do: it will keep
  8906. quiet unless it has something important to tell you (e.g. an error
  8907. condition or something). If you wish it to produce verbose output,
  8908. similar to that from the dry run mode, use @option{-v} option:
  8909. @smallexample
  8910. @group
  8911. $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
  8912. Reading v.1.0 sparse map
  8913. Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
  8914. '/home/gray/sparsefile'
  8915. Done
  8916. @end group
  8917. @end smallexample
  8918. Additionally, if your @command{tar} implementation has extracted the
  8919. @dfn{extended headers} for this file, you can instruct @command{xstar}
  8920. to use them in order to verify the integrity of the expanded file.
  8921. The option @option{-x} sets the name of the extended header file to
  8922. use. Continuing our example:
  8923. @smallexample
  8924. @group
  8925. $ @kbd{xsparse -v -x /home/gray/PaxHeaders/sparsefile \
  8926. /home/gray/GNUSparseFile/sparsefile}
  8927. Reading extended header file
  8928. Found variable GNU.sparse.major = 1
  8929. Found variable GNU.sparse.minor = 0
  8930. Found variable GNU.sparse.name = sparsefile
  8931. Found variable GNU.sparse.realsize = 217481216
  8932. Reading v.1.0 sparse map
  8933. Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
  8934. '/home/gray/sparsefile'
  8935. Done
  8936. @end group
  8937. @end smallexample
  8938. @anchor{extracting sparse v0x}
  8939. @cindex sparse files v.0.1, extracting with non-GNU tars
  8940. @cindex sparse files v.0.0, extracting with non-GNU tars
  8941. An @dfn{extended header} is a special @command{tar} archive header
  8942. that precedes an archive member and contains a set of
  8943. @dfn{variables}, describing the member properties that cannot be
  8944. stored in the standard @code{ustar} header. While optional for
  8945. expanding sparse version 1.0 members, the use of extended headers is
  8946. mandatory when expanding sparse members in older sparse formats: v.0.0
  8947. and v.0.1 (The sparse formats are described in detail in @ref{Sparse
  8948. Formats}.) So, for these formats, the question is: how to obtain
  8949. extended headers from the archive?
  8950. If you use a @command{tar} implementation that does not support PAX
  8951. format, extended headers for each member will be extracted as a
  8952. separate file. If we represent the member name as
  8953. @file{@var{dir}/@var{name}}, then the extended header file will be
  8954. named @file{@var{dir}/@/PaxHeaders/@/@var{name}}.
  8955. Things become more difficult if your @command{tar} implementation
  8956. does support PAX headers, because in this case you will have to
  8957. manually extract the headers. We recommend the following algorithm:
  8958. @enumerate 1
  8959. @item
  8960. Consult the documentation of your @command{tar} implementation for an
  8961. option that prints @dfn{block numbers} along with the archive
  8962. listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
  8963. @command{star} has @option{-block-number}.
  8964. @item
  8965. Obtain verbose listing using the @samp{block number} option, and
  8966. find block numbers of the sparse member in question and the member
  8967. immediately following it. For example, running @command{star} on our
  8968. archive we obtain:
  8969. @smallexample
  8970. @group
  8971. $ @kbd{star -t -v -block-number -f arc.tar}
  8972. @dots{}
  8973. star: Unknown extended header keyword 'GNU.sparse.size' ignored.
  8974. star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
  8975. star: Unknown extended header keyword 'GNU.sparse.name' ignored.
  8976. star: Unknown extended header keyword 'GNU.sparse.map' ignored.
  8977. block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
  8978. block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
  8979. @dots{}
  8980. @end group
  8981. @end smallexample
  8982. @noindent
  8983. (as usual, ignore the warnings about unknown keywords.)
  8984. @item
  8985. Let @var{size} be the size of the sparse member, @var{Bs} be its block number
  8986. and @var{Bn} be the block number of the next member.
  8987. Compute:
  8988. @smallexample
  8989. @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
  8990. @end smallexample
  8991. @noindent
  8992. This number gives the size of the extended header part in tar @dfn{blocks}.
  8993. In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
  8994. = 7}.
  8995. @item
  8996. Use @command{dd} to extract the headers:
  8997. @smallexample
  8998. @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
  8999. @end smallexample
  9000. @noindent
  9001. where @var{archive} is the archive name, @var{hname} is a name of the
  9002. file to store the extended header in, @var{Bs} and @var{N} are
  9003. computed in previous steps.
  9004. In our example, this command will be
  9005. @smallexample
  9006. $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
  9007. @end smallexample
  9008. @end enumerate
  9009. Finally, you can expand the condensed file, using the obtained header:
  9010. @smallexample
  9011. @group
  9012. $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
  9013. Reading extended header file
  9014. Found variable GNU.sparse.size = 217481216
  9015. Found variable GNU.sparse.numblocks = 208
  9016. Found variable GNU.sparse.name = sparsefile
  9017. Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
  9018. Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
  9019. Done
  9020. @end group
  9021. @end smallexample
  9022. @node Reproducibility
  9023. @section Making @command{tar} Archives More Reproducible
  9024. @cindex reproducible archives
  9025. Sometimes it is important for an archive to be @dfn{reproducible},
  9026. so that one can easily verify it to have been derived solely from
  9027. its input. We call an archive reproducible, if an archive
  9028. created from the same set of input files with the same command line
  9029. options is byte-to-byte equivalent to the original one.
  9030. However, two archives created by @GNUTAR{} from two sets of input
  9031. files normally might differ even if the input files have the same
  9032. contents and @GNUTAR{} was invoked the same way on both sets of input.
  9033. This can happen if the inputs have different modification dates or
  9034. other metadata, or if the input directories' entries are in different orders.
  9035. To avoid this problem when creating an archive, and thus make the
  9036. archive reproducible, you can run @GNUTAR{} in the C locale with
  9037. some or all of the following options:
  9038. @table @option
  9039. @item --sort=name
  9040. Omit irrelevant information about directory entry order.
  9041. @item --format=posix
  9042. Avoid problems with large files or files with unusual timestamps.
  9043. This also enables @option{--pax-option} options mentioned below.
  9044. @item --pax-option='exthdr.name=%d/PaxHeaders/%f'
  9045. Omit the process ID of @command{tar}.
  9046. This option is needed only if @env{POSIXLY_CORRECT} is set in the environment.
  9047. @item --pax-option='delete=atime,delete=ctime'
  9048. Omit irrelevant information about file access or status change time.
  9049. @item --clamp-mtime --mtime="$SOURCE_EPOCH"
  9050. Omit irrelevant information about file timestamps after
  9051. @samp{$SOURCE_EPOCH}, which should be a time no less than any
  9052. timestamp of any source file.
  9053. @item --numeric-owner
  9054. Omit irrelevant information about user and group names.
  9055. @item --owner=0
  9056. @itemx --group=0
  9057. Omit irrelevant information about file ownership and group.
  9058. @item --mode='go+u,go-w'
  9059. Omit irrelevant information about file permissions.
  9060. @end table
  9061. When creating a reproducible archive from version-controlled source files,
  9062. it can be useful to set each file's modification time
  9063. to be that of its last commit, so that the timestamps
  9064. are reproducible from the version-control repository.
  9065. If these timestamps are all on integer second boundaries, and if you use
  9066. @option{--format=posix --pax-option='delete=atime,delete=ctime'
  9067. --clamp-mtime --mtime="$SOURCE_EPOCH"}
  9068. where @code{$SOURCE_EPOCH} is the the time of the most recent commit,
  9069. and if all non-source files have timestamps greater than @code{$SOURCE_EPOCH},
  9070. then @GNUTAR{} should generate an archive in @acronym{ustar} format,
  9071. since no POSIX features will be needed and the archive will be in the
  9072. @acronym{ustar} subset of @acronym{posix} format.
  9073. Also, if compressing, use a reproducible compression format; e.g.,
  9074. with @command{gzip} you should use the @option{--no-name} (@option{-n}) option.
  9075. Here is an example set of shell commands to produce a reproducible
  9076. tarball with @command{git} and @command{gzip}, which you can tailor to
  9077. your project's needs.
  9078. @example
  9079. function get_commit_time() @{
  9080. TZ=UTC0 git log -1 \
  9081. --format=tformat:%cd \
  9082. --date=format:%Y-%m-%dT%H:%M:%SZ \
  9083. "$@@"
  9084. @}
  9085. #
  9086. # Set each source file timestamp to that of its latest commit.
  9087. git ls-files | while read -r file; do
  9088. commit_time=$(get_commit_time "$file") &&
  9089. touch -md $commit_time "$file"
  9090. done
  9091. #
  9092. # Set timestamp of each directory under $FILES
  9093. # to the latest timestamp of any descendant.
  9094. find $FILES -depth -type d -exec sh -c \
  9095. 'touch -r "$0/$(ls -At "$0" | head -n 1)" "$0"' \
  9096. @{@} ';'
  9097. #
  9098. # Create $ARCHIVE.tgz from $FILES, pretending that
  9099. # the modification time for each newer file
  9100. # is that of the most recent commit of any source file.
  9101. SOURCE_EPOCH=$(get_commit_time)
  9102. TARFLAGS="
  9103. --sort=name --format=posix
  9104. --pax-option=exthdr.name=%d/PaxHeaders/%f
  9105. --pax-option=delete=atime,delete=ctime
  9106. --clamp-mtime --mtime=$SOURCE_EPOCH
  9107. --numeric-owner --owner=0 --group=0
  9108. --mode=go+u,go-w
  9109. "
  9110. GZIPFLAGS="--no-name --best"
  9111. LC_ALL=C tar $TARFLAGS -cf - $FILES |
  9112. gzip $GZIPFLAGS > $ARCHIVE.tgz
  9113. @end example
  9114. @node cpio
  9115. @section Comparison of @command{tar} and @command{cpio}
  9116. @UNREVISED{}
  9117. @FIXME{Reorganize the following material}
  9118. The @command{cpio} archive formats, like @command{tar}, do have maximum
  9119. file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
  9120. length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
  9121. file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
  9122. with arbitrary file name lengths, but other @command{cpio} implementations
  9123. may crash unexplainedly trying to read them.
  9124. @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
  9125. @command{cpio} doesn't handle symbolic links in the form in which it comes
  9126. in System V prior to SVR4, and some vendors may have added symlinks
  9127. to their system without enhancing @command{cpio} to know about them.
  9128. Others may have enhanced it in a way other than the way I did it
  9129. at Sun, and which was adopted by AT&T (and which is, I think, also
  9130. present in the @command{cpio} that Berkeley picked up from AT&T and put
  9131. into a later @acronym{BSD} release---I think I gave them my changes).
  9132. (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
  9133. can handle @command{tar} format input, and write it on output, and it
  9134. probably handles symbolic links. They may not have bothered doing
  9135. anything to enhance @command{tar} as a result.)
  9136. @command{cpio} handles special files; traditional @command{tar} doesn't.
  9137. @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
  9138. @command{cpio} comes only with System III, System V, and later @acronym{BSD}
  9139. (4.3-tahoe and later).
  9140. @command{tar}'s way of handling multiple hard links to a file can handle
  9141. file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
  9142. @command{cpio}s way requires you to play some games (in its ``binary''
  9143. format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
  9144. they're 18 bits---it would have to play games with the "file system @acronym{ID}"
  9145. field of the header to make sure that the file system @acronym{ID}/i-number pairs
  9146. of different files were always different), and I don't know which
  9147. @command{cpio}s, if any, play those games. Those that don't might get
  9148. confused and think two files are the same file when they're not, and
  9149. make hard links between them.
  9150. @command{tar}s way of handling multiple hard links to a file places only
  9151. one copy of the link on the tape, but the name attached to that copy
  9152. is the @emph{only} one you can use to retrieve the file; @command{cpio}s
  9153. way puts one copy for every link, but you can retrieve it using any
  9154. of the names.
  9155. @quotation
  9156. What type of check sum (if any) is used, and how is this calculated.
  9157. @end quotation
  9158. See the attached manual pages for @command{tar} and @command{cpio} format.
  9159. @command{tar} uses a checksum which is the sum of all the bytes in the
  9160. @command{tar} header for a file; @command{cpio} uses no checksum.
  9161. @quotation
  9162. If anyone knows why @command{cpio} was made when @command{tar} was present
  9163. at the unix scene,
  9164. @end quotation
  9165. It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
  9166. generally-available version of UNIX had @command{tar} at the time. I don't
  9167. know whether any version that was generally available @emph{within AT&T}
  9168. had @command{tar}, or, if so, whether the people within AT&T who did
  9169. @command{cpio} knew about it.
  9170. On restore, if there is a corruption on a tape @command{tar} will stop at
  9171. that point, while @command{cpio} will skip over it and try to restore the
  9172. rest of the files.
  9173. The main difference is just in the command syntax and header format.
  9174. @command{tar} is a little more tape-oriented in that everything is blocked
  9175. to start on a record boundary.
  9176. @quotation
  9177. Is there any differences between the ability to recover crashed
  9178. archives between the two of them. (Is there any chance of recovering
  9179. crashed archives at all.)
  9180. @end quotation
  9181. Theoretically it should be easier under @command{tar} since the blocking
  9182. lets you find a header with some variation of @samp{dd skip=@var{nn}}.
  9183. However, modern @command{cpio}'s and variations have an option to just
  9184. search for the next file header after an error with a reasonable chance
  9185. of resyncing. However, lots of tape driver software won't allow you to
  9186. continue past a media error which should be the only reason for getting
  9187. out of sync unless a file changed sizes while you were writing the
  9188. archive.
  9189. @quotation
  9190. If anyone knows why @command{cpio} was made when @command{tar} was present
  9191. at the unix scene, please tell me about this too.
  9192. @end quotation
  9193. Probably because it is more media efficient (by not blocking everything
  9194. and using only the space needed for the headers where @command{tar}
  9195. always uses 512 bytes per file header) and it knows how to archive
  9196. special files.
  9197. You might want to look at the freely available alternatives. The
  9198. major ones are @command{afio}, @GNUTAR{}, and
  9199. @command{pax}, each of which have their own extensions with some
  9200. backwards compatibility.
  9201. Sparse files were @command{tar}red as sparse files (which you can
  9202. easily test, because the resulting archive gets smaller, and
  9203. @acronym{GNU} @command{cpio} can no longer read it).
  9204. @node Media
  9205. @chapter Tapes and Other Archive Media
  9206. @UNREVISED{}
  9207. A few special cases about tape handling warrant more detailed
  9208. description. These special cases are discussed below.
  9209. Many complexities surround the use of @command{tar} on tape drives. Since
  9210. the creation and manipulation of archives located on magnetic tape was
  9211. the original purpose of @command{tar}, it contains many features making
  9212. such manipulation easier.
  9213. Archives are usually written on dismountable media---tape cartridges,
  9214. mag tapes, or floppy disks.
  9215. The amount of data a tape or disk holds depends not only on its size,
  9216. but also on how it is formatted. A 2400 foot long reel of mag tape
  9217. holds 40 megabytes of data when formatted at 1600 bits per inch. The
  9218. physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
  9219. Magnetic media are re-usable---once the archive on a tape is no longer
  9220. needed, the archive can be erased and the tape or disk used over.
  9221. Media quality does deteriorate with use, however. Most tapes or disks
  9222. should be discarded when they begin to produce data errors. EXABYTE
  9223. tape cartridges should be discarded when they generate an @dfn{error
  9224. count} (number of non-usable bits) of more than 10k.
  9225. Magnetic media are written and erased using magnetic fields, and
  9226. should be protected from such fields to avoid damage to stored data.
  9227. Sticking a floppy disk to a filing cabinet using a magnet is probably
  9228. not a good idea.
  9229. @menu
  9230. * Device:: Device selection and switching
  9231. * Remote Tape Server::
  9232. * Common Problems and Solutions::
  9233. * Blocking:: Blocking
  9234. * Many:: Many archives on one tape
  9235. * Using Multiple Tapes:: Using Multiple Tapes
  9236. * label:: Including a Label in the Archive
  9237. * verify::
  9238. * Write Protection::
  9239. @end menu
  9240. @node Device
  9241. @section Device Selection and Switching
  9242. @UNREVISED{}
  9243. @table @option
  9244. @item -f [@var{hostname}:]@var{file}
  9245. @itemx --file=[@var{hostname}:]@var{file}
  9246. Use archive file or device @var{file} on @var{hostname}.
  9247. @end table
  9248. This option is used to specify the file name of the archive @command{tar}
  9249. works on.
  9250. If the file name is @samp{-}, @command{tar} reads the archive from standard
  9251. input (when listing or extracting), or writes it to standard output
  9252. (when creating). If the @samp{-} file name is given when updating an
  9253. archive, @command{tar} will read the original archive from its standard
  9254. input, and will write the entire new archive to its standard output.
  9255. If the file name contains a @samp{:}, it is interpreted as
  9256. @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
  9257. sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
  9258. either case, @command{tar} will invoke the command @command{rsh} (or
  9259. @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
  9260. machine. If you give an alternate login name, it will be given to the
  9261. @command{rsh}.
  9262. Naturally, the remote machine must have an executable
  9263. @command{/usr/libexec/rmt}. This program is free software from the
  9264. University of California, and a copy of the source code can be found
  9265. with the sources for @command{tar}; it's compiled and installed by default.
  9266. The exact path to this utility is determined when configuring the package.
  9267. It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
  9268. your installation prefix. This location may also be overridden at
  9269. runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
  9270. ---rmt-command}, for detailed description of this option. @xref{Remote
  9271. Tape Server}, for the description of @command{rmt} command).
  9272. If this option is not given, but the environment variable @env{TAPE}
  9273. is set, its value is used; otherwise, old versions of @command{tar}
  9274. used a default archive name (which was picked when @command{tar} was
  9275. compiled). The default is normally set up to be the @dfn{first} tape
  9276. drive or other transportable I/O medium on the system.
  9277. Starting with version 1.11.5, @GNUTAR{} uses
  9278. standard input and standard output as the default device, and I will
  9279. not try anymore supporting automatic device detection at installation
  9280. time. This was failing really in too many cases, it was hopeless.
  9281. This is now completely left to the installer to override standard
  9282. input and standard output for default device, if this seems
  9283. preferable. Further, I think @emph{most} actual usages of
  9284. @command{tar} are done with pipes or disks, not really tapes,
  9285. cartridges or diskettes.
  9286. Some users think that using standard input and output is running
  9287. after trouble. This could lead to a nasty surprise on your screen if
  9288. you forget to specify an output file name---especially if you are going
  9289. through a network or terminal server capable of buffering large amounts
  9290. of output. We had so many bug reports in that area of configuring
  9291. default tapes automatically, and so many contradicting requests, that
  9292. we finally consider the problem to be portably intractable. We could
  9293. of course use something like @samp{/dev/tape} as a default, but this
  9294. is @emph{also} running after various kind of trouble, going from hung
  9295. processes to accidental destruction of real tapes. After having seen
  9296. all this mess, using standard input and output as a default really
  9297. sounds like the only clean choice left, and a very useful one too.
  9298. @GNUTAR{} reads and writes archive in records, I
  9299. suspect this is the main reason why block devices are preferred over
  9300. character devices. Most probably, block devices are more efficient
  9301. too. The installer could also check for @samp{DEFTAPE} in
  9302. @file{<sys/mtio.h>}.
  9303. @table @option
  9304. @xopindex{force-local, short description}
  9305. @item --force-local
  9306. Archive file is local even if it contains a colon.
  9307. @opindex rsh-command
  9308. @item --rsh-command=@var{command}
  9309. Use remote @var{command} instead of @command{rsh}. This option exists
  9310. so that people who use something other than the standard @command{rsh}
  9311. (e.g., a Kerberized @command{rsh}) can access a remote device.
  9312. When this command is not used, the shell command found when
  9313. the @command{tar} program was installed is used instead. This is
  9314. the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
  9315. @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
  9316. The installer may have overridden this by defining the environment
  9317. variable @env{RSH} @emph{at installation time}.
  9318. @item -[0-7][lmh]
  9319. Specify drive and density.
  9320. @xopindex{multi-volume, short description}
  9321. @item -M
  9322. @itemx --multi-volume
  9323. Create/list/extract multi-volume archive.
  9324. This option causes @command{tar} to write a @dfn{multi-volume} archive---one
  9325. that may be larger than will fit on the medium used to hold it.
  9326. @xref{Multi-Volume Archives}.
  9327. @xopindex{tape-length, short description}
  9328. @item -L @var{num}
  9329. @itemx --tape-length=@var{size}[@var{suf}]
  9330. Change tape after writing @var{size} units of data. Unless @var{suf} is
  9331. given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
  9332. 1024} bytes. The following suffixes alter this behavior:
  9333. @float Table, size-suffixes
  9334. @caption{Size Suffixes}
  9335. @multitable @columnfractions 0.2 0.3 0.3
  9336. @headitem Suffix @tab Units @tab Byte Equivalent
  9337. @item b @tab Blocks @tab @var{size} x 512
  9338. @item B @tab Kilobytes @tab @var{size} x 1024
  9339. @item c @tab Bytes @tab @var{size}
  9340. @item G @tab Gigabytes @tab @var{size} x 1024^3
  9341. @item K @tab Kilobytes @tab @var{size} x 1024
  9342. @item k @tab Kilobytes @tab @var{size} x 1024
  9343. @item M @tab Megabytes @tab @var{size} x 1024^2
  9344. @item P @tab Petabytes @tab @var{size} x 1024^5
  9345. @item T @tab Terabytes @tab @var{size} x 1024^4
  9346. @item w @tab Words @tab @var{size} x 2
  9347. @end multitable
  9348. @end float
  9349. This option might be useful when your tape drivers do not properly
  9350. detect end of physical tapes. By being slightly conservative on the
  9351. maximum tape length, you might avoid the problem entirely.
  9352. @xopindex{info-script, short description}
  9353. @xopindex{new-volume-script, short description}
  9354. @item -F @var{command}
  9355. @itemx --info-script=@var{command}
  9356. @itemx --new-volume-script=@var{command}
  9357. Execute @var{command} at end of each tape. This implies
  9358. @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
  9359. description of this option.
  9360. @end table
  9361. @node Remote Tape Server
  9362. @section Remote Tape Server
  9363. @cindex remote tape drive
  9364. @pindex rmt
  9365. In order to access the tape drive on a remote machine, @command{tar}
  9366. uses the remote tape server written at the University of California at
  9367. Berkeley. The remote tape server must be installed as
  9368. @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
  9369. want to use. @command{tar} calls @command{rmt} by running an
  9370. @command{rsh} or @command{remsh} to the remote machine, optionally
  9371. using a different login name if one is supplied.
  9372. A copy of the source for the remote tape server is provided. Its
  9373. source code can be freely distributed. It is compiled and
  9374. installed by default.
  9375. @cindex absolute file names
  9376. Unless you use the @option{--absolute-names} (@option{-P}) option,
  9377. @GNUTAR{} will not allow you to create an archive that contains
  9378. absolute file names (a file name beginning with @samp{/}). If you try,
  9379. @command{tar} will automatically remove the leading @samp{/} from the
  9380. file names it stores in the archive. It will also type a warning
  9381. message telling you what it is doing.
  9382. When reading an archive that was created with a different
  9383. @command{tar} program, @GNUTAR{} automatically
  9384. extracts entries in the archive which have absolute file names as if
  9385. the file names were not absolute. This is an important feature. A
  9386. visitor here once gave a @command{tar} tape to an operator to restore;
  9387. the operator used Sun @command{tar} instead of @GNUTAR{},
  9388. and the result was that it replaced large portions of
  9389. our @file{/bin} and friends with versions from the tape; needless to
  9390. say, we were unhappy about having to recover the file system from
  9391. backup tapes.
  9392. For example, if the archive contained a file @file{/usr/bin/computoy},
  9393. @GNUTAR{} would extract the file to @file{usr/bin/computoy},
  9394. relative to the current directory. If you want to extract the files in
  9395. an archive to the same absolute names that they had when the archive
  9396. was created, you should do a @samp{cd /} before extracting the files
  9397. from the archive, or you should either use the @option{--absolute-names}
  9398. option, or use the command @samp{tar -C / @dots{}}.
  9399. @cindex Ultrix 3.1 and write failure
  9400. Some versions of Unix (Ultrix 3.1 is known to have this problem),
  9401. can claim that a short write near the end of a tape succeeded,
  9402. when it actually failed. This will result in the -M option not
  9403. working correctly. The best workaround at the moment is to use a
  9404. significantly larger blocking factor than the default 20.
  9405. In order to update an archive, @command{tar} must be able to backspace the
  9406. archive in order to reread or rewrite a record that was just read (or
  9407. written). This is currently possible only on two kinds of files: normal
  9408. disk files (or any other file that can be backspaced with @samp{lseek}),
  9409. and industry-standard 9-track magnetic tape (or any other kind of tape
  9410. that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
  9411. This means that the @option{--append}, @option{--concatenate}, and
  9412. @option{--delete} commands will not work on any other kind of file.
  9413. Some media simply cannot be backspaced, which means these commands and
  9414. options will never be able to work on them. These non-backspacing
  9415. media include pipes and cartridge tape drives.
  9416. Some other media can be backspaced, and @command{tar} will work on them
  9417. once @command{tar} is modified to do so.
  9418. Archives created with the @option{--multi-volume}, @option{--label}, and
  9419. @option{--incremental} (@option{-G}) options may not be readable by other version
  9420. of @command{tar}. In particular, restoring a file that was split over
  9421. a volume boundary will require some careful work with @command{dd}, if
  9422. it can be done at all. Other versions of @command{tar} may also create
  9423. an empty file whose name is that of the volume header. Some versions
  9424. of @command{tar} may create normal files instead of directories archived
  9425. with the @option{--incremental} (@option{-G}) option.
  9426. @node Common Problems and Solutions
  9427. @section Some Common Problems and their Solutions
  9428. @ifclear PUBLISH
  9429. @format
  9430. errors from system:
  9431. permission denied
  9432. no such file or directory
  9433. not owner
  9434. errors from @command{tar}:
  9435. directory checksum error
  9436. header format error
  9437. errors from media/system:
  9438. i/o error
  9439. device busy
  9440. @end format
  9441. @end ifclear
  9442. @node Blocking
  9443. @section Blocking
  9444. @cindex block
  9445. @cindex record
  9446. @dfn{Block} and @dfn{record} terminology is rather confused, and it
  9447. is also confusing to the expert reader. On the other hand, readers
  9448. who are new to the field have a fresh mind, and they may safely skip
  9449. the next two paragraphs, as the remainder of this manual uses those
  9450. two terms in a quite consistent way.
  9451. John Gilmore, the writer of the public domain @command{tar} from which
  9452. @GNUTAR{} was originally derived, wrote (June 1995):
  9453. @quotation
  9454. The nomenclature of tape drives comes from IBM, where I believe
  9455. they were invented for the IBM 650 or so. On IBM mainframes, what
  9456. is recorded on tape are tape blocks. The logical organization of
  9457. data is into records. There are various ways of putting records into
  9458. blocks, including @code{F} (fixed sized records), @code{V} (variable
  9459. sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
  9460. to a block), @code{VB} (variable size records, @var{n} to a block),
  9461. @code{VSB} (variable spanned blocked: variable sized records that can
  9462. occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
  9463. parameter specified this to the operating system.
  9464. The Unix man page on @command{tar} was totally confused about this.
  9465. When I wrote @code{PD TAR}, I used the historically correct terminology
  9466. (@command{tar} writes data records, which are grouped into blocks).
  9467. It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
  9468. here), and now Fran@,{c}ois has migrated that terminology back
  9469. into the source code too.
  9470. @end quotation
  9471. The term @dfn{physical block} means the basic transfer chunk from or
  9472. to a device, after which reading or writing may stop without anything
  9473. being lost. In this manual, the term @dfn{block} usually refers to
  9474. a disk physical block, @emph{assuming} that each disk block is 512
  9475. bytes in length. It is true that some disk devices have different
  9476. physical blocks, but @command{tar} ignore these differences in its own
  9477. format, which is meant to be portable, so a @command{tar} block is always
  9478. 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
  9479. The term @dfn{logical block} often represents the basic chunk of
  9480. allocation of many disk blocks as a single entity, which the operating
  9481. system treats somewhat atomically; this concept is only barely used
  9482. in @GNUTAR{}.
  9483. The term @dfn{physical record} is another way to speak of a physical
  9484. block, those two terms are somewhat interchangeable. In this manual,
  9485. the term @dfn{record} usually refers to a tape physical block,
  9486. @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
  9487. It is true that archives may be put on disk or used with pipes,
  9488. but nevertheless, @command{tar} tries to read and write the archive one
  9489. @dfn{record} at a time, whatever the medium in use. One record is made
  9490. up of an integral number of blocks, and this operation of putting many
  9491. disk blocks into a single tape block is called @dfn{reblocking}, or
  9492. more simply, @dfn{blocking}. The term @dfn{logical record} refers to
  9493. the logical organization of many characters into something meaningful
  9494. to the application. The term @dfn{unit record} describes a small set
  9495. of characters which are transmitted whole to or by the application,
  9496. and often refers to a line of text. Those two last terms are unrelated
  9497. to what we call a @dfn{record} in @GNUTAR{}.
  9498. When writing to tapes, @command{tar} writes the contents of the archive
  9499. in chunks known as @dfn{records}. To change the default blocking
  9500. factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
  9501. @var{512-size}}) option. Each record will then be composed of
  9502. @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
  9503. @xref{Standard}.) Each file written to the archive uses at least one
  9504. full record. As a result, using a larger record size can result in
  9505. more wasted space for small files. On the other hand, a larger record
  9506. size can often be read and written much more efficiently.
  9507. Further complicating the problem is that some tape drives ignore the
  9508. blocking entirely. For these, a larger record size can still improve
  9509. performance (because the software layers above the tape drive still
  9510. honor the blocking), but not as dramatically as on tape drives that
  9511. honor blocking.
  9512. When reading an archive, @command{tar} can usually figure out the
  9513. record size on itself. When this is the case, and a non-standard
  9514. record size was used when the archive was created, @command{tar} will
  9515. print a message about a non-standard blocking factor, and then operate
  9516. normally@footnote{If this message is not needed, you can turn it off
  9517. using the @option{--warning=no-record-size} option.}. On some tape
  9518. devices, however, @command{tar} cannot figure out the record size
  9519. itself. On most of those, you can specify a blocking factor (with
  9520. @option{--blocking-factor}) larger than the actual blocking factor,
  9521. and then use the @option{--read-full-records} (@option{-B}) option.
  9522. (If you specify a blocking factor with @option{--blocking-factor} and
  9523. don't use the @option{--read-full-records} option, then @command{tar}
  9524. will not attempt to figure out the recording size itself.) On some
  9525. devices, you must always specify the record size exactly with
  9526. @option{--blocking-factor} when reading, because @command{tar} cannot
  9527. figure it out. In any case, use @option{--list} (@option{-t}) before
  9528. doing any extractions to see whether @command{tar} is reading the archive
  9529. correctly.
  9530. @command{tar} blocks are all fixed size (512 bytes), and its scheme for
  9531. putting them into records is to put a whole number of them (one or
  9532. more) into each record. @command{tar} records are all the same size;
  9533. at the end of the file there's a block containing all zeros, which
  9534. is how you tell that the remainder of the last record(s) are garbage.
  9535. In a standard @command{tar} file (no options), the block size is 512
  9536. and the record size is 10240, for a blocking factor of 20. What the
  9537. @option{--blocking-factor} option does is sets the blocking factor,
  9538. changing the record size while leaving the block size at 512 bytes.
  9539. 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
  9540. most tape drives these days prefer much bigger records in order to
  9541. stream and not waste tape. When writing tapes for myself, some tend
  9542. to use a factor of the order of 2048, say, giving a record size of
  9543. around one megabyte.
  9544. If you use a blocking factor larger than 20, older @command{tar}
  9545. programs might not be able to read the archive, so we recommend this
  9546. as a limit to use in practice. @GNUTAR{}, however,
  9547. will support arbitrarily large record sizes, limited only by the
  9548. amount of virtual memory or the physical characteristics of the tape
  9549. device.
  9550. @menu
  9551. * Format Variations:: Format Variations
  9552. * Blocking Factor:: The Blocking Factor of an Archive
  9553. @end menu
  9554. @node Format Variations
  9555. @subsection Format Variations
  9556. @cindex Format Parameters
  9557. @cindex Format Options
  9558. @cindex Options, archive format specifying
  9559. @cindex Options, format specifying
  9560. @UNREVISED{}
  9561. Format parameters specify how an archive is written on the archive
  9562. media. The best choice of format parameters will vary depending on
  9563. the type and number of files being archived, and on the media used to
  9564. store the archive.
  9565. To specify format parameters when accessing or creating an archive,
  9566. you can use the options described in the following sections.
  9567. If you do not specify any format parameters, @command{tar} uses
  9568. default parameters. You cannot modify a compressed archive.
  9569. If you create an archive with the @option{--blocking-factor} option
  9570. specified (@pxref{Blocking Factor}), you must specify that
  9571. blocking-factor when operating on the archive. @xref{Formats}, for other
  9572. examples of format parameter considerations.
  9573. @node Blocking Factor
  9574. @subsection The Blocking Factor of an Archive
  9575. @cindex Blocking Factor
  9576. @cindex Record Size
  9577. @cindex Number of blocks per record
  9578. @cindex Number of bytes per record
  9579. @cindex Bytes per record
  9580. @cindex Blocks per record
  9581. @UNREVISED{}
  9582. @opindex blocking-factor
  9583. The data in an archive is grouped into blocks, which are 512 bytes.
  9584. Blocks are read and written in whole number multiples called
  9585. @dfn{records}. The number of blocks in a record (i.e., the size of a
  9586. record in units of 512 bytes) is called the @dfn{blocking factor}.
  9587. The @option{--blocking-factor=@var{512-size}} (@option{-b
  9588. @var{512-size}}) option specifies the blocking factor of an archive.
  9589. The default blocking factor is typically 20 (i.e., 10240 bytes), but
  9590. can be specified at installation. To find out the blocking factor of
  9591. an existing archive, use @samp{tar --list --file=@var{archive-name}}.
  9592. This may not work on some devices.
  9593. Records are separated by gaps, which waste space on the archive media.
  9594. If you are archiving on magnetic tape, using a larger blocking factor
  9595. (and therefore larger records) provides faster throughput and allows you
  9596. to fit more data on a tape (because there are fewer gaps). If you are
  9597. archiving on cartridge, a very large blocking factor (say 126 or more)
  9598. greatly increases performance. A smaller blocking factor, on the other
  9599. hand, may be useful when archiving small files, to avoid archiving lots
  9600. of nulls as @command{tar} fills out the archive to the end of the record.
  9601. In general, the ideal record size depends on the size of the
  9602. inter-record gaps on the tape you are using, and the average size of the
  9603. files you are archiving. @xref{create}, for information on
  9604. writing archives.
  9605. @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
  9606. Archives with blocking factors larger than 20 cannot be read
  9607. by very old versions of @command{tar}, or by some newer versions
  9608. of @command{tar} running on old machines with small address spaces.
  9609. With @GNUTAR{}, the blocking factor of an archive is limited
  9610. only by the maximum record size of the device containing the archive,
  9611. or by the amount of available virtual memory.
  9612. Also, on some systems, not using adequate blocking factors, as sometimes
  9613. imposed by the device drivers, may yield unexpected diagnostics. For
  9614. example, this has been reported:
  9615. @smallexample
  9616. Cannot write to /dev/dlt: Invalid argument
  9617. @end smallexample
  9618. @noindent
  9619. In such cases, it sometimes happen that the @command{tar} bundled by
  9620. the system is aware of block size idiosyncrasies, while @GNUTAR{}
  9621. requires an explicit specification for the block size,
  9622. which it cannot guess. This yields some people to consider
  9623. @GNUTAR{} is misbehaving, because by comparison,
  9624. @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
  9625. for example, might resolve the problem.
  9626. If you use a non-default blocking factor when you create an archive, you
  9627. must specify the same blocking factor when you modify that archive. Some
  9628. archive devices will also require you to specify the blocking factor when
  9629. reading that archive, however this is not typically the case. Usually, you
  9630. can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
  9631. reports a non-default record size and then lists the archive members as
  9632. it would normally. To extract files from an archive with a non-standard
  9633. blocking factor (particularly if you're not sure what the blocking factor
  9634. is), you can usually use the @option{--read-full-records} (@option{-B}) option while
  9635. specifying a blocking factor larger then the blocking factor of the archive
  9636. (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
  9637. @xref{list}, for more information on the @option{--list} (@option{-t})
  9638. operation. @xref{Reading}, for a more detailed explanation of that option.
  9639. @table @option
  9640. @item --blocking-factor=@var{number}
  9641. @itemx -b @var{number}
  9642. Specifies the blocking factor of an archive. Can be used with any
  9643. operation, but is usually not necessary with @option{--list} (@option{-t}).
  9644. @end table
  9645. Device blocking
  9646. @table @option
  9647. @item -b @var{blocks}
  9648. @itemx --blocking-factor=@var{blocks}
  9649. Set record size to @math{@var{blocks}*512} bytes.
  9650. This option is used to specify a @dfn{blocking factor} for the archive.
  9651. When reading or writing the archive, @command{tar}, will do reads and writes
  9652. of the archive in records of @math{@var{block}*512} bytes. This is true
  9653. even when the archive is compressed. Some devices requires that all
  9654. write operations be a multiple of a certain size, and so, @command{tar}
  9655. pads the archive out to the next record boundary.
  9656. The default blocking factor is set when @command{tar} is compiled, and is
  9657. typically 20. Blocking factors larger than 20 cannot be read by very
  9658. old versions of @command{tar}, or by some newer versions of @command{tar}
  9659. running on old machines with small address spaces.
  9660. With a magnetic tape, larger records give faster throughput and fit
  9661. more data on a tape (because there are fewer inter-record gaps).
  9662. If the archive is in a disk file or a pipe, you may want to specify
  9663. a smaller blocking factor, since a large one will result in a large
  9664. number of null bytes at the end of the archive.
  9665. When writing cartridge or other streaming tapes, a much larger
  9666. blocking factor (say 126 or more) will greatly increase performance.
  9667. However, you must specify the same blocking factor when reading or
  9668. updating the archive.
  9669. Apparently, Exabyte drives have a physical block size of 8K bytes.
  9670. If we choose our blocksize as a multiple of 8k bytes, then the problem
  9671. seems to disappear. Id est, we are using block size of 112 right
  9672. now, and we haven't had the problem since we switched@dots{}
  9673. With @GNUTAR{} the blocking factor is limited only
  9674. by the maximum record size of the device containing the archive, or by
  9675. the amount of available virtual memory.
  9676. However, deblocking or reblocking is virtually avoided in a special
  9677. case which often occurs in practice, but which requires all the
  9678. following conditions to be simultaneously true:
  9679. @itemize @bullet
  9680. @item
  9681. the archive is subject to a compression option,
  9682. @item
  9683. the archive is not handled through standard input or output, nor
  9684. redirected nor piped,
  9685. @item
  9686. the archive is directly handled to a local disk, instead of any special
  9687. device,
  9688. @item
  9689. @option{--blocking-factor} is not explicitly specified on the @command{tar}
  9690. invocation.
  9691. @end itemize
  9692. If the output goes directly to a local disk, and not through
  9693. stdout, then the last write is not extended to a full record size.
  9694. Otherwise, reblocking occurs. Here are a few other remarks on this
  9695. topic:
  9696. @itemize @bullet
  9697. @item
  9698. @command{gzip} will complain about trailing garbage if asked to
  9699. uncompress a compressed archive on tape, there is an option to turn
  9700. the message off, but it breaks the regularity of simply having to use
  9701. @samp{@var{prog} -d} for decompression. It would be nice if gzip was
  9702. silently ignoring any number of trailing zeros. I'll ask Jean-loup
  9703. Gailly, by sending a copy of this message to him.
  9704. @item
  9705. @command{compress} does not show this problem, but as Jean-loup pointed
  9706. out to Michael, @samp{compress -d} silently adds garbage after
  9707. the result of decompression, which tar ignores because it already
  9708. recognized its end-of-file indicator. So this bug may be safely
  9709. ignored.
  9710. @item
  9711. @samp{gzip -d -q} will be silent about the trailing zeros indeed,
  9712. but will still return an exit status of 2 which tar reports in turn.
  9713. @command{tar} might ignore the exit status returned, but I hate doing
  9714. that, as it weakens the protection @command{tar} offers users against
  9715. other possible problems at decompression time. If @command{gzip} was
  9716. silently skipping trailing zeros @emph{and} also avoiding setting the
  9717. exit status in this innocuous case, that would solve this situation.
  9718. @item
  9719. @command{tar} should become more solid at not stopping to read a pipe at
  9720. the first null block encountered. This inelegantly breaks the pipe.
  9721. @command{tar} should rather drain the pipe out before exiting itself.
  9722. @end itemize
  9723. @xopindex{ignore-zeros, short description}
  9724. @item -i
  9725. @itemx --ignore-zeros
  9726. Ignore blocks of zeros in archive (means EOF).
  9727. The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
  9728. of zeros in the archive. Normally a block of zeros indicates the
  9729. end of the archive, but when reading a damaged archive, or one which
  9730. was created by concatenating several archives together, this option
  9731. allows @command{tar} to read the entire archive. This option is not on
  9732. by default because many versions of @command{tar} write garbage after
  9733. the zeroed blocks.
  9734. Note that this option causes @command{tar} to read to the end of the
  9735. archive file, which may sometimes avoid problems when multiple files
  9736. are stored on a single physical tape.
  9737. @xopindex{read-full-records, short description}
  9738. @item -B
  9739. @itemx --read-full-records
  9740. Reblock as we read (for reading 4.2@acronym{BSD} pipes).
  9741. If @option{--read-full-records} is used, @command{tar}
  9742. will not panic if an attempt to read a record from the archive does
  9743. not return a full record. Instead, @command{tar} will keep reading
  9744. until it has obtained a full
  9745. record.
  9746. This option is turned on by default when @command{tar} is reading
  9747. an archive from standard input, or from a remote machine. This is
  9748. because on @acronym{BSD} Unix systems, a read of a pipe will return however
  9749. much happens to be in the pipe, even if it is less than @command{tar}
  9750. requested. If this option was not used, @command{tar} would fail as
  9751. soon as it read an incomplete record from the pipe.
  9752. This option is also useful with the commands for updating an archive.
  9753. @end table
  9754. Tape blocking
  9755. @FIXME{Appropriate options should be moved here from elsewhere.}
  9756. @cindex blocking factor
  9757. @cindex tape blocking
  9758. When handling various tapes or cartridges, you have to take care of
  9759. selecting a proper blocking, that is, the number of disk blocks you
  9760. put together as a single tape block on the tape, without intervening
  9761. tape gaps. A @dfn{tape gap} is a small landing area on the tape
  9762. with no information on it, used for decelerating the tape to a
  9763. full stop, and for later regaining the reading or writing speed.
  9764. When the tape driver starts reading a record, the record has to
  9765. be read whole without stopping, as a tape gap is needed to stop the
  9766. tape motion without losing information.
  9767. @cindex Exabyte blocking
  9768. @cindex DAT blocking
  9769. Using higher blocking (putting more disk blocks per tape block) will use
  9770. the tape more efficiently as there will be less tape gaps. But reading
  9771. such tapes may be more difficult for the system, as more memory will be
  9772. required to receive at once the whole record. Further, if there is a
  9773. reading error on a huge record, this is less likely that the system will
  9774. succeed in recovering the information. So, blocking should not be too
  9775. low, nor it should be too high. @command{tar} uses by default a blocking of
  9776. 20 for historical reasons, and it does not really matter when reading or
  9777. writing to disk. Current tape technology would easily accommodate higher
  9778. blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
  9779. We were told that for some DLT drives, the blocking should be a multiple
  9780. of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
  9781. Other manufacturers may use different recommendations for the same tapes.
  9782. This might also depends of the buffering techniques used inside modern
  9783. tape controllers. Some imposes a minimum blocking, or a maximum blocking.
  9784. Others request blocking to be some exponent of two.
  9785. So, there is no fixed rule for blocking. But blocking at read time
  9786. should ideally be the same as blocking used at write time. At one place
  9787. I know, with a wide variety of equipment, they found it best to use a
  9788. blocking of 32 to guarantee that their tapes are fully interchangeable.
  9789. I was also told that, for recycled tapes, prior erasure (by the same
  9790. drive unit that will be used to create the archives) sometimes lowers
  9791. the error rates observed at rewriting time.
  9792. I might also use @option{--number-blocks} instead of
  9793. @option{--block-number}, so @option{--block} will then expand to
  9794. @option{--blocking-factor} unambiguously.
  9795. @node Many
  9796. @section Many Archives on One Tape
  9797. @FIXME{Appropriate options should be moved here from elsewhere.}
  9798. @findex ntape @r{device}
  9799. Most tape devices have two entries in the @file{/dev} directory, or
  9800. entries that come in pairs, which differ only in the minor number for
  9801. this device. Let's take for example @file{/dev/tape}, which often
  9802. points to the only or usual tape device of a given system. There might
  9803. be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
  9804. name is the @emph{rewinding} version of the device, while the name
  9805. having @samp{nr} in it is the @emph{no rewinding} version of the same
  9806. device.
  9807. A rewinding tape device will bring back the tape to its beginning point
  9808. automatically when this device is opened or closed. Since @command{tar}
  9809. opens the archive file before using it and closes it afterwards, this
  9810. means that a simple:
  9811. @smallexample
  9812. $ @kbd{tar cf /dev/tape @var{directory}}
  9813. @end smallexample
  9814. @noindent
  9815. will reposition the tape to its beginning both prior and after saving
  9816. @var{directory} contents to it, thus erasing prior tape contents and
  9817. making it so that any subsequent write operation will destroy what has
  9818. just been saved.
  9819. @cindex tape positioning
  9820. So, a rewinding device is normally meant to hold one and only one file.
  9821. If you want to put more than one @command{tar} archive on a given tape, you
  9822. will need to avoid using the rewinding version of the tape device. You
  9823. will also have to pay special attention to tape positioning. Errors in
  9824. positioning may overwrite the valuable data already on your tape. Many
  9825. people, burnt by past experiences, will only use rewinding devices and
  9826. limit themselves to one file per tape, precisely to avoid the risk of
  9827. such errors. Be fully aware that writing at the wrong position on a
  9828. tape loses all information past this point and most probably until the
  9829. end of the tape, and this destroyed information @emph{cannot} be
  9830. recovered.
  9831. To save @var{directory-1} as a first archive at the beginning of a
  9832. tape, and leave that tape ready for a second archive, you should use:
  9833. @smallexample
  9834. $ @kbd{mt -f /dev/nrtape rewind}
  9835. $ @kbd{tar cf /dev/nrtape @var{directory-1}}
  9836. @end smallexample
  9837. @cindex tape marks
  9838. @dfn{Tape marks} are special magnetic patterns written on the tape
  9839. media, which are later recognizable by the reading hardware. These
  9840. marks are used after each file, when there are many on a single tape.
  9841. An empty file (that is to say, two tape marks in a row) signal the
  9842. logical end of the tape, after which no file exist. Usually,
  9843. non-rewinding tape device drivers will react to the close request issued
  9844. by @command{tar} by first writing two tape marks after your archive, and by
  9845. backspacing over one of these. So, if you remove the tape at that time
  9846. from the tape drive, it is properly terminated. But if you write
  9847. another file at the current position, the second tape mark will be
  9848. erased by the new information, leaving only one tape mark between files.
  9849. So, you may now save @var{directory-2} as a second archive after the
  9850. first on the same tape by issuing the command:
  9851. @smallexample
  9852. $ @kbd{tar cf /dev/nrtape @var{directory-2}}
  9853. @end smallexample
  9854. @noindent
  9855. and so on for all the archives you want to put on the same tape.
  9856. Another usual case is that you do not write all the archives the same
  9857. day, and you need to remove and store the tape between two archive
  9858. sessions. In general, you must remember how many files are already
  9859. saved on your tape. Suppose your tape already has 16 files on it, and
  9860. that you are ready to write the 17th. You have to take care of skipping
  9861. the first 16 tape marks before saving @var{directory-17}, say, by using
  9862. these commands:
  9863. @smallexample
  9864. $ @kbd{mt -f /dev/nrtape rewind}
  9865. $ @kbd{mt -f /dev/nrtape fsf 16}
  9866. $ @kbd{tar cf /dev/nrtape @var{directory-17}}
  9867. @end smallexample
  9868. In all the previous examples, we put aside blocking considerations, but
  9869. you should do the proper things for that as well. @xref{Blocking}.
  9870. @menu
  9871. * Tape Positioning:: Tape Positions and Tape Marks
  9872. * mt:: The @command{mt} Utility
  9873. @end menu
  9874. @node Tape Positioning
  9875. @subsection Tape Positions and Tape Marks
  9876. @UNREVISED{}
  9877. Just as archives can store more than one file from the file system,
  9878. tapes can store more than one archive file. To keep track of where
  9879. archive files (or any other type of file stored on tape) begin and
  9880. end, tape archive devices write magnetic @dfn{tape marks} on the
  9881. archive media. Tape drives write one tape mark between files,
  9882. two at the end of all the file entries.
  9883. If you think of data as a series of records "rrrr"'s, and tape marks as
  9884. "*"'s, a tape might look like the following:
  9885. @smallexample
  9886. rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
  9887. @end smallexample
  9888. Tape devices read and write tapes using a read/write @dfn{tape
  9889. head}---a physical part of the device which can only access one
  9890. point on the tape at a time. When you use @command{tar} to read or
  9891. write archive data from a tape device, the device will begin reading
  9892. or writing from wherever on the tape the tape head happens to be,
  9893. regardless of which archive or what part of the archive the tape
  9894. head is on. Before writing an archive, you should make sure that no
  9895. data on the tape will be overwritten (unless it is no longer needed).
  9896. Before reading an archive, you should make sure the tape head is at
  9897. the beginning of the archive you want to read. You can do it manually
  9898. via @code{mt} utility (@pxref{mt}). The @code{restore} script does
  9899. that automatically (@pxref{Scripted Restoration}).
  9900. If you want to add new archive file entries to a tape, you should
  9901. advance the tape to the end of the existing file entries, backspace
  9902. over the last tape mark, and write the new archive file. If you were
  9903. to add two archives to the example above, the tape might look like the
  9904. following:
  9905. @smallexample
  9906. rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
  9907. @end smallexample
  9908. @node mt
  9909. @subsection The @command{mt} Utility
  9910. @UNREVISED{}
  9911. @FIXME{Is it true that this only works on non-block devices?
  9912. should explain the difference, (fixed or variable).}
  9913. @xref{Blocking Factor}.
  9914. You can use the @command{mt} utility to advance or rewind a tape past a
  9915. specified number of archive files on the tape. This will allow you
  9916. to move to the beginning of an archive before extracting or reading
  9917. it, or to the end of all the archives before writing a new one.
  9918. @FIXME{Why isn't there an "advance 'til you find two tape marks
  9919. together"?}
  9920. The syntax of the @command{mt} command is:
  9921. @smallexample
  9922. @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
  9923. @end smallexample
  9924. where @var{tapename} is the name of the tape device, @var{number} is
  9925. the number of times an operation is performed (with a default of one),
  9926. and @var{operation} is one of the following:
  9927. @FIXME{is there any use for record operations?}
  9928. @table @option
  9929. @item eof
  9930. @itemx weof
  9931. Writes @var{number} tape marks at the current position on the tape.
  9932. @item fsf
  9933. Moves tape position forward @var{number} files.
  9934. @item bsf
  9935. Moves tape position back @var{number} files.
  9936. @item rewind
  9937. Rewinds the tape. (Ignores @var{number}.)
  9938. @item offline
  9939. @itemx rewoff1
  9940. Rewinds the tape and takes the tape device off-line. (Ignores @var{number}.)
  9941. @item status
  9942. Prints status information about the tape unit.
  9943. @end table
  9944. If you don't specify a @var{tapename}, @command{mt} uses the environment
  9945. variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
  9946. the default device specified in your @file{sys/mtio.h} file
  9947. (@code{DEFTAPE} variable). If this is not defined, the program will
  9948. display a descriptive error message and exit with code 1.
  9949. @command{mt} returns a 0 exit status when the operation(s) were
  9950. successful, 1 if the command was unrecognized, and 2 if an operation
  9951. failed.
  9952. @node Using Multiple Tapes
  9953. @section Using Multiple Tapes
  9954. Often you might want to write a large archive, one larger than will fit
  9955. on the actual tape you are using. In such a case, you can run multiple
  9956. @command{tar} commands, but this can be inconvenient, particularly if you
  9957. are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
  9958. Therefore, @command{tar} provides a special mode for creating
  9959. multi-volume archives.
  9960. @dfn{Multi-volume} archive is a single @command{tar} archive, stored
  9961. on several media volumes of fixed size. Although in this section we will
  9962. often call @samp{volume} a @dfn{tape}, there is absolutely no
  9963. requirement for multi-volume archives to be stored on tapes. Instead,
  9964. they can use whatever media type the user finds convenient, they can
  9965. even be located on files.
  9966. When creating a multi-volume archive, @GNUTAR{} continues to fill
  9967. current volume until it runs out of space, then it switches to
  9968. next volume (usually the operator is queried to replace the tape on
  9969. this point), and continues working on the new volume. This operation
  9970. continues until all requested files are dumped. If @GNUTAR{} detects
  9971. end of media while dumping a file, such a file is archived in split
  9972. form. Some very big files can even be split across several volumes.
  9973. Each volume is itself a valid @GNUTAR{} archive, so it can be read
  9974. without any special options. Consequently any file member residing
  9975. entirely on one volume can be extracted or otherwise operated upon
  9976. without needing the other volume. Sure enough, to extract a split
  9977. member you would need all volumes its parts reside on.
  9978. Multi-volume archives suffer from several limitations. In particular,
  9979. they cannot be compressed.
  9980. @GNUTAR{} is able to create multi-volume archives of two formats
  9981. (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
  9982. @menu
  9983. * Multi-Volume Archives:: Archives Longer than One Tape or Disk
  9984. * Tape Files:: Tape Files
  9985. * Tarcat:: Concatenate Volumes into a Single Archive
  9986. @end menu
  9987. @node Multi-Volume Archives
  9988. @subsection Archives Longer than One Tape or Disk
  9989. @cindex Multi-volume archives
  9990. @opindex multi-volume
  9991. To create an archive that is larger than will fit on a single unit of
  9992. the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
  9993. the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
  9994. archive can be manipulated like any other archive (provided the
  9995. @option{--multi-volume} option is specified), but is stored on more
  9996. than one tape or file.
  9997. When you specify @option{--multi-volume}, @command{tar} does not report an
  9998. error when it comes to the end of an archive volume (when reading), or
  9999. the end of the media (when writing). Instead, it prompts you to load
  10000. a new storage volume. If the archive is on a magnetic tape, you
  10001. should change tapes when you see the prompt; if the archive is on a
  10002. floppy disk, you should change disks; etc.
  10003. @table @option
  10004. @item --multi-volume
  10005. @itemx -M
  10006. Creates a multi-volume archive, when used in conjunction with
  10007. @option{--create} (@option{-c}). To perform any other operation on a multi-volume
  10008. archive, specify @option{--multi-volume} in conjunction with that
  10009. operation.
  10010. For example:
  10011. @smallexample
  10012. $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
  10013. @end smallexample
  10014. @end table
  10015. The method @command{tar} uses to detect end of tape is not perfect, and
  10016. fails on some operating systems or on some devices. If @command{tar}
  10017. cannot detect the end of the tape itself, you can use
  10018. @option{--tape-length} option to inform it about the capacity of the
  10019. tape:
  10020. @anchor{tape-length}
  10021. @table @option
  10022. @opindex tape-length
  10023. @item --tape-length=@var{size}[@var{suf}]
  10024. @itemx -L @var{size}[@var{suf}]
  10025. Set maximum length of a volume. The @var{suf}, if given, specifies
  10026. units in which @var{size} is expressed, e.g. @samp{2M} mean 2
  10027. megabytes (@pxref{size-suffixes}, for a list of allowed size
  10028. suffixes). Without @var{suf}, units of 1024 bytes (kilobyte) are
  10029. assumed.
  10030. This option selects @option{--multi-volume} automatically. For example:
  10031. @smallexample
  10032. $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
  10033. @end smallexample
  10034. @noindent
  10035. or, which is equivalent:
  10036. @smallexample
  10037. $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
  10038. @end smallexample
  10039. @end table
  10040. @anchor{change volume prompt}
  10041. When @GNUTAR{} comes to the end of a storage media, it asks you to
  10042. change the volume. The built-in prompt for POSIX locale
  10043. is@footnote{If you run @GNUTAR{} under a different locale, the
  10044. translation to the locale's language will be used.}:
  10045. @smallexample
  10046. Prepare volume #@var{n} for '@var{archive}' and hit return:
  10047. @end smallexample
  10048. @noindent
  10049. where @var{n} is the ordinal number of the volume to be created and
  10050. @var{archive} is archive file or device name.
  10051. When prompting for a new tape, @command{tar} accepts any of the following
  10052. responses:
  10053. @table @kbd
  10054. @item ?
  10055. Request @command{tar} to explain possible responses.
  10056. @item q
  10057. Request @command{tar} to exit immediately.
  10058. @item n @var{file-name}
  10059. Request @command{tar} to write the next volume on the file @var{file-name}.
  10060. @item !
  10061. Request @command{tar} to run a subshell. This option can be disabled
  10062. by giving @option{--restrict} command line option to
  10063. @command{tar}@footnote{@xref{--restrict}, for more information about
  10064. this option.}.
  10065. @item y
  10066. Request @command{tar} to begin writing the next volume.
  10067. @end table
  10068. (You should only type @samp{y} after you have changed the tape;
  10069. otherwise @command{tar} will write over the volume it just finished.)
  10070. @cindex Volume number file
  10071. @cindex volno file
  10072. @anchor{volno-file}
  10073. @opindex volno-file
  10074. The volume number used by @command{tar} in its tape-changing prompt
  10075. can be changed; if you give the
  10076. @option{--volno-file=@var{file-of-number}} option, then
  10077. @var{file-of-number} should be an non-existing file to be created, or
  10078. else, a file already containing a decimal number. That number will be
  10079. used as the volume number of the first volume written. When
  10080. @command{tar} is finished, it will rewrite the file with the
  10081. now-current volume number. (This does not change the volume number
  10082. written on a tape label, as per @ref{label}, it @emph{only} affects
  10083. the number used in the prompt.)
  10084. @cindex End-of-archive info script
  10085. @cindex Info script
  10086. @anchor{info-script}
  10087. @opindex info-script
  10088. @opindex new-volume-script
  10089. If you want more elaborate behavior than this, you can write a special
  10090. @dfn{new volume script}, that will be responsible for changing the
  10091. volume, and instruct @command{tar} to use it instead of its normal
  10092. prompting procedure:
  10093. @table @option
  10094. @item --info-script=@var{command}
  10095. @itemx --new-volume-script=@var{command}
  10096. @itemx -F @var{command}
  10097. Specify the command to invoke when switching volumes. The @var{command}
  10098. can be used to eject cassettes, or to broadcast messages such as
  10099. @samp{Someone please come change my tape} when performing unattended
  10100. backups.
  10101. @end table
  10102. The @var{command} can contain additional options, if such are needed.
  10103. @xref{external, Running External Commands}, for a detailed discussion
  10104. of the way @GNUTAR{} runs external commands. It inherits
  10105. @command{tar}'s shell environment. Additional data is passed to it
  10106. via the following environment variables:
  10107. @table @env
  10108. @vrindex TAR_VERSION, info script environment variable
  10109. @item TAR_VERSION
  10110. @GNUTAR{} version number.
  10111. @vrindex TAR_ARCHIVE, info script environment variable
  10112. @item TAR_ARCHIVE
  10113. The name of the archive @command{tar} is processing.
  10114. @vrindex TAR_BLOCKING_FACTOR, info script environment variable
  10115. @item TAR_BLOCKING_FACTOR
  10116. Current blocking factor (@pxref{Blocking}).
  10117. @vrindex TAR_VOLUME, info script environment variable
  10118. @item TAR_VOLUME
  10119. Ordinal number of the volume @command{tar} is about to start.
  10120. @vrindex TAR_SUBCOMMAND, info script environment variable
  10121. @item TAR_SUBCOMMAND
  10122. A short option describing the operation @command{tar} is executing.
  10123. @xref{Operations}, for a complete list of subcommand options.
  10124. @vrindex TAR_FORMAT, info script environment variable
  10125. @item TAR_FORMAT
  10126. Format of the archive being processed. @xref{Formats}, for a complete
  10127. list of archive format names.
  10128. @vrindex TAR_FD, info script environment variable
  10129. @item TAR_FD
  10130. File descriptor which can be used to communicate the new volume
  10131. name to @command{tar}.
  10132. @end table
  10133. These variables can be used in the @var{command} itself, provided that
  10134. they are properly quoted to prevent them from being expanded by the
  10135. shell that invokes @command{tar}.
  10136. The volume script can instruct @command{tar} to use new archive name,
  10137. by writing in to file descriptor @env{$TAR_FD} (see below for an example).
  10138. If the info script fails, @command{tar} exits; otherwise, it begins
  10139. writing the next volume.
  10140. If you want @command{tar} to cycle through a series of files or tape
  10141. drives, there are three approaches to choose from. First of all, you
  10142. can give @command{tar} multiple @option{--file} options. In this case
  10143. the specified files will be used, in sequence, as the successive
  10144. volumes of the archive. Only when the first one in the sequence needs
  10145. to be used again will @command{tar} prompt for a tape change (or run
  10146. the info script). For example, suppose someone has two tape drives on
  10147. a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
  10148. @GNUTAR{} to switch to the second drive when it needs to write the
  10149. second tape, and then back to the first tape, etc., just do either of:
  10150. @smallexample
  10151. $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
  10152. $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
  10153. @end smallexample
  10154. The second method is to use the @samp{n} response to the tape-change
  10155. prompt.
  10156. Finally, the most flexible approach is to use a volume script, that
  10157. writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
  10158. following volume script will create a series of archive files, named
  10159. @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
  10160. archive being created (as given by @option{--file} option) and
  10161. @var{vol} is the ordinal number of the archive being created:
  10162. @smallexample
  10163. @group
  10164. #! /bin/bash
  10165. # For this script it's advisable to use a shell, such as Bash,
  10166. # that supports a TAR_FD value greater than 9.
  10167. echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
  10168. name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
  10169. case $TAR_SUBCOMMAND in
  10170. -c) ;;
  10171. -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
  10172. ;;
  10173. *) exit 1
  10174. esac
  10175. echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
  10176. @end group
  10177. @end smallexample
  10178. The same script can be used while listing, comparing or extracting
  10179. from the created archive. For example:
  10180. @smallexample
  10181. @group
  10182. # @r{Create a multi-volume archive:}
  10183. $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
  10184. # @r{Extract from the created archive:}
  10185. $ @kbd{tar -x -f archive.tar -F new-volume .}
  10186. @end group
  10187. @end smallexample
  10188. @noindent
  10189. Notice, that the first command had to use @option{-L} option, since
  10190. otherwise @GNUTAR{} will end up writing everything to file
  10191. @file{archive.tar}.
  10192. You can read each individual volume of a multi-volume archive as if it
  10193. were an archive by itself. For example, to list the contents of one
  10194. volume, use @option{--list}, without @option{--multi-volume} specified.
  10195. To extract an archive member from one volume (assuming it is described
  10196. that volume), use @option{--extract}, again without
  10197. @option{--multi-volume}.
  10198. If an archive member is split across volumes (i.e., its entry begins on
  10199. one volume of the media and ends on another), you need to specify
  10200. @option{--multi-volume} to extract it successfully. In this case, you
  10201. should load the volume where the archive member starts, and use
  10202. @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
  10203. volumes as it needs them. @xref{extracting archives}, for more
  10204. information about extracting archives.
  10205. Multi-volume archives can be modified like any other archive. To add
  10206. files to a multi-volume archive, you need to only mount the last
  10207. volume of the archive media (and new volumes, if needed). For all
  10208. other operations, you need to use the entire archive.
  10209. If a multi-volume archive was labeled using
  10210. @option{--label=@var{archive-label}} (@pxref{label}) when it was
  10211. created, @command{tar} will not automatically label volumes which are
  10212. added later. To label subsequent volumes, specify
  10213. @option{--label=@var{archive-label}} again in conjunction with the
  10214. @option{--append}, @option{--update} or @option{--concatenate} operation.
  10215. Notice that multi-volume support is a GNU extension and the archives
  10216. created in this mode should be read only using @GNUTAR{}. If you
  10217. absolutely have to process such archives using a third-party @command{tar}
  10218. implementation, read @ref{Split Recovery}.
  10219. @node Tape Files
  10220. @subsection Tape Files
  10221. @cindex labeling archives
  10222. @opindex label
  10223. @UNREVISED{}
  10224. To give the archive a name which will be recorded in it, use the
  10225. @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
  10226. option. This will write a special block identifying
  10227. @var{volume-label} as the name of the archive to the front of the
  10228. archive which will be displayed when the archive is listed with
  10229. @option{--list}. If you are creating a multi-volume archive with
  10230. @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
  10231. volume label will have @samp{Volume @var{nnn}} appended to the name
  10232. you give, where @var{nnn} is the number of the volume of the archive.
  10233. If you use the @option{--label=@var{volume-label}} option when
  10234. reading an archive, it checks to make sure the label on the tape
  10235. matches the one you gave. @xref{label}.
  10236. When @command{tar} writes an archive to tape, it creates a single
  10237. tape file. If multiple archives are written to the same tape, one
  10238. after the other, they each get written as separate tape files. When
  10239. extracting, it is necessary to position the tape at the right place
  10240. before running @command{tar}. To do this, use the @command{mt} command.
  10241. For more information on the @command{mt} command and on the organization
  10242. of tapes into a sequence of tape files, see @ref{mt}.
  10243. People seem to often do:
  10244. @smallexample
  10245. @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
  10246. @end smallexample
  10247. or such, for pushing a common date in all volumes or an archive set.
  10248. @node Tarcat
  10249. @subsection Concatenate Volumes into a Single Archive
  10250. @pindex tarcat
  10251. Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
  10252. archive to a single @command{tar} archive. Simply concatenating all
  10253. volumes into one will not work, since each volume carries an additional
  10254. information at the beginning. @GNUTAR{} is shipped with the shell
  10255. script @command{tarcat} designed for this purpose.
  10256. The script takes a list of files comprising a multi-volume archive
  10257. and creates the resulting archive at the standard output. For example:
  10258. @smallexample
  10259. @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
  10260. @end smallexample
  10261. The script implements a simple heuristics to determine the format of
  10262. the first volume file and to decide how to process the rest of the
  10263. files. However, it makes no attempt to verify whether the files are
  10264. given in order or even if they are valid @command{tar} archives.
  10265. It uses @command{dd} and does not filter its standard error, so you
  10266. will usually see lots of spurious messages.
  10267. @FIXME{The script is not installed. Should we install it?}
  10268. @node label
  10269. @section Including a Label in the Archive
  10270. @cindex Labeling an archive
  10271. @cindex Labels on the archive media
  10272. @cindex Labeling multi-volume archives
  10273. @opindex label
  10274. To avoid problems caused by misplaced paper labels on the archive
  10275. media, you can include a @dfn{label} entry --- an archive member which
  10276. contains the name of the archive --- in the archive itself. Use the
  10277. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  10278. option@footnote{Until version 1.10, that option was called
  10279. @option{--volume}, but is not available under that name anymore.} in
  10280. conjunction with the @option{--create} operation to include a label
  10281. entry in the archive as it is being created.
  10282. @table @option
  10283. @item --label=@var{archive-label}
  10284. @itemx -V @var{archive-label}
  10285. Includes an @dfn{archive-label} at the beginning of the archive when
  10286. the archive is being created, when used in conjunction with the
  10287. @option{--create} operation. Checks to make sure the archive label
  10288. matches the one specified (when used in conjunction with any other
  10289. operation).
  10290. @end table
  10291. If you create an archive using both
  10292. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  10293. and @option{--multi-volume} (@option{-M}), each volume of the archive
  10294. will have an archive label of the form @samp{@var{archive-label}
  10295. Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
  10296. next, and so on. @xref{Using Multiple Tapes}, for information on
  10297. creating multiple volume archives.
  10298. @cindex Volume label, listing
  10299. @cindex Listing volume label
  10300. The volume label will be displayed by @option{--list} along with
  10301. the file contents. If verbose display is requested, it will also be
  10302. explicitly marked as in the example below:
  10303. @smallexample
  10304. @group
  10305. $ @kbd{tar --verbose --list --file=iamanarchive}
  10306. V--------- 0/0 0 1992-03-07 12:01 iamalabel--Volume Header--
  10307. -rw-r--r-- ringo/user 40 1990-05-21 13:30 iamafilename
  10308. @end group
  10309. @end smallexample
  10310. @opindex test-label
  10311. @anchor{--test-label option}
  10312. However, @option{--list} option will cause listing entire
  10313. contents of the archive, which may be undesirable (for example, if the
  10314. archive is stored on a tape). You can request checking only the volume
  10315. label by specifying @option{--test-label} option. This option reads only the
  10316. first block of an archive, so it can be used with slow storage
  10317. devices. For example:
  10318. @smallexample
  10319. @group
  10320. $ @kbd{tar --test-label --file=iamanarchive}
  10321. iamalabel
  10322. @end group
  10323. @end smallexample
  10324. If @option{--test-label} is used with one or more command line
  10325. arguments, @command{tar} compares the volume label with each
  10326. argument. It exits with code 0 if a match is found, and with code 1
  10327. otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
  10328. mismatch with an exit code 2 and printed a spurious diagnostics on
  10329. stderr.}. No output is displayed, unless you also used the
  10330. @option{--verbose} option. For example:
  10331. @smallexample
  10332. @group
  10333. $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
  10334. @result{} 0
  10335. $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
  10336. @result{} 1
  10337. @end group
  10338. @end smallexample
  10339. When used with the @option{--verbose} option, @command{tar}
  10340. prints the actual volume label (if any), and a verbose diagnostics in
  10341. case of a mismatch:
  10342. @smallexample
  10343. @group
  10344. $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
  10345. iamalabel
  10346. @result{} 0
  10347. $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
  10348. iamalabel
  10349. tar: Archive label mismatch
  10350. @result{} 1
  10351. @end group
  10352. @end smallexample
  10353. If you request any operation, other than @option{--create}, along
  10354. with using @option{--label} option, @command{tar} will first check if
  10355. the archive label matches the one specified and will refuse to proceed
  10356. if it does not. Use this as a safety precaution to avoid accidentally
  10357. overwriting existing archives. For example, if you wish to add files
  10358. to @file{archive}, presumably labeled with string @samp{My volume},
  10359. you will get:
  10360. @smallexample
  10361. @group
  10362. $ @kbd{tar -rf archive --label 'My volume' .}
  10363. tar: Archive not labeled to match 'My volume'
  10364. @end group
  10365. @end smallexample
  10366. @noindent
  10367. in case its label does not match. This will work even if
  10368. @file{archive} is not labeled at all.
  10369. Similarly, @command{tar} will refuse to list or extract the
  10370. archive if its label doesn't match the @var{archive-label}
  10371. specified. In those cases, @var{archive-label} argument is interpreted
  10372. as a globbing-style pattern which must match the actual magnetic
  10373. volume label. @xref{exclude}, for a precise description of how match
  10374. is attempted@footnote{Previous versions of @command{tar} used full
  10375. regular expression matching, or before that, only exact string
  10376. matching, instead of wildcard matchers. We decided for the sake of
  10377. simplicity to use a uniform matching device through
  10378. @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
  10379. the volume label matcher will also suffix @var{archive-label} by
  10380. @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
  10381. up. Since the volume numbering is automatically added in labels at
  10382. creation time, it sounded logical to equally help the user taking care
  10383. of it when the archive is being read.
  10384. You can also use @option{--label} to get a common information on
  10385. all tapes of a series. For having this information different in each
  10386. series created through a single script used on a regular basis, just
  10387. manage to get some date string as part of the label. For example:
  10388. @smallexample
  10389. @group
  10390. $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
  10391. $ @kbd{tar --create --file=/dev/tape --multi-volume \
  10392. --label="Daily backup for `date +%Y-%m-%d`"}
  10393. @end group
  10394. @end smallexample
  10395. Some more notes about volume labels:
  10396. @itemize @bullet
  10397. @item Each label has its own date and time, which corresponds
  10398. to the time when @GNUTAR{} initially attempted to write it,
  10399. often soon after the operator launches @command{tar} or types the
  10400. carriage return telling that the next tape is ready.
  10401. @item Comparing date labels to get an idea of tape throughput is
  10402. unreliable. It gives correct results only if the delays for rewinding
  10403. tapes and the operator switching them were negligible, which is
  10404. usually not the case.
  10405. @end itemize
  10406. @node verify
  10407. @section Verifying Data as It is Stored
  10408. @cindex Verifying a write operation
  10409. @cindex Double-checking a write operation
  10410. @table @option
  10411. @item -W
  10412. @itemx --verify
  10413. @opindex verify, short description
  10414. Attempt to verify the archive after writing.
  10415. @end table
  10416. This option causes @command{tar} to verify the archive after writing it.
  10417. Each volume is checked after it is written, and any discrepancies
  10418. are recorded on the standard error output.
  10419. Verification requires that the archive be on a back-space-able medium.
  10420. This means pipes, some cartridge tape drives, and some other devices
  10421. cannot be verified.
  10422. You can insure the accuracy of an archive by comparing files in the
  10423. system with archive members. @command{tar} can compare an archive to the
  10424. file system as the archive is being written, to verify a write
  10425. operation, or can compare a previously written archive, to insure that
  10426. it is up to date.
  10427. @xopindex{verify, using with @option{--create}}
  10428. @xopindex{create, using with @option{--verify}}
  10429. To check for discrepancies in an archive immediately after it is
  10430. written, use the @option{--verify} (@option{-W}) option in conjunction with
  10431. the @option{--create} operation. When this option is
  10432. specified, @command{tar} checks archive members against their counterparts
  10433. in the file system, and reports discrepancies on the standard error.
  10434. To verify an archive, you must be able to read it from before the end
  10435. of the last written entry. This option is useful for detecting data
  10436. errors on some tapes. Archives written to pipes, some cartridge tape
  10437. drives, and some other devices cannot be verified.
  10438. One can explicitly compare an already made archive with the file
  10439. system by using the @option{--compare} (@option{--diff}, @option{-d})
  10440. option, instead of using the more automatic @option{--verify} option.
  10441. @xref{compare}.
  10442. Note that these two options have a slightly different intent. The
  10443. @option{--compare} option checks how identical are the logical contents of some
  10444. archive with what is on your disks, while the @option{--verify} option is
  10445. really for checking if the physical contents agree and if the recording
  10446. media itself is of dependable quality. So, for the @option{--verify}
  10447. operation, @command{tar} tries to defeat all in-memory cache pertaining to
  10448. the archive, while it lets the speed optimization undisturbed for the
  10449. @option{--compare} option. If you nevertheless use @option{--compare} for
  10450. media verification, you may have to defeat the in-memory cache yourself,
  10451. maybe by opening and reclosing the door latch of your recording unit,
  10452. forcing some doubt in your operating system about the fact this is really
  10453. the same volume as the one just written or read.
  10454. The @option{--verify} option would not be necessary if drivers were indeed
  10455. able to detect dependably all write failures. This sometimes require many
  10456. magnetic heads, some able to read after the writes occurred. One would
  10457. not say that drivers unable to detect all cases are necessarily flawed,
  10458. as long as programming is concerned.
  10459. The @option{--verify} (@option{-W}) option will not work in
  10460. conjunction with the @option{--multi-volume} (@option{-M}) option or
  10461. the @option{--append} (@option{-r}), @option{--update} (@option{-u})
  10462. and @option{--delete} operations. @xref{Operations}, for more
  10463. information on these operations.
  10464. Also, since @command{tar} normally strips leading @samp{/} from file
  10465. names (@pxref{absolute}), a command like @samp{tar --verify -cf
  10466. /tmp/foo.tar /etc} will work as desired only if the working directory is
  10467. @file{/}, as @command{tar} uses the archive's relative member names
  10468. (e.g., @file{etc/motd}) when verifying the archive.
  10469. @node Write Protection
  10470. @section Write Protection
  10471. Almost all tapes and diskettes, and in a few rare cases, even disks can
  10472. be @dfn{write protected}, to protect data on them from being changed.
  10473. Once an archive is written, you should write protect the media to prevent
  10474. the archive from being accidentally overwritten or deleted. (This will
  10475. protect the archive from being changed with a tape or floppy drive---it
  10476. will not protect it from magnet fields or other physical hazards.)
  10477. The write protection device itself is usually an integral part of the
  10478. physical media, and can be a two position (write enabled/write
  10479. disabled) switch, a notch which can be popped out or covered, a ring
  10480. which can be removed from the center of a tape reel, or some other
  10481. changeable feature.
  10482. @node Reliability and security
  10483. @chapter Reliability and Security
  10484. The @command{tar} command reads and writes files as any other
  10485. application does, and is subject to the usual caveats about
  10486. reliability and security. This section contains some commonsense
  10487. advice on the topic.
  10488. @menu
  10489. * Reliability::
  10490. * Security::
  10491. @end menu
  10492. @node Reliability
  10493. @section Reliability
  10494. Ideally, when @command{tar} is creating an archive, it reads from a
  10495. file system that is not being modified, and encounters no errors or
  10496. inconsistencies while reading and writing. If this is the case, the
  10497. archive should faithfully reflect what was read. Similarly, when
  10498. extracting from an archive, ideally @command{tar} ideally encounters
  10499. no errors and the extracted files faithfully reflect what was in the
  10500. archive.
  10501. However, when reading or writing real-world file systems, several
  10502. things can go wrong; these include permissions problems, corruption of
  10503. data, and race conditions.
  10504. @menu
  10505. * Permissions problems::
  10506. * Data corruption and repair::
  10507. * Race conditions::
  10508. @end menu
  10509. @node Permissions problems
  10510. @subsection Permissions Problems
  10511. If @command{tar} encounters errors while reading or writing files, it
  10512. normally reports an error and exits with nonzero status. The work it
  10513. does may therefore be incomplete. For example, when creating an
  10514. archive, if @command{tar} cannot read a file then it cannot copy the
  10515. file into the archive.
  10516. @node Data corruption and repair
  10517. @subsection Data Corruption and Repair
  10518. If an archive becomes corrupted by an I/O error, this may corrupt the
  10519. data in an extracted file. Worse, it may corrupt the file's metadata,
  10520. which may cause later parts of the archive to become misinterpreted.
  10521. An tar-format archive contains a checksum that most likely will detect
  10522. errors in the metadata, but it will not detect errors in the data.
  10523. If data corruption is a concern, you can compute and check your own
  10524. checksums of an archive by using other programs, such as
  10525. @command{cksum}.
  10526. When attempting to recover from a read error or data corruption in an
  10527. archive, you may need to skip past the questionable data and read the
  10528. rest of the archive. This requires some expertise in the archive
  10529. format and in other software tools.
  10530. @node Race conditions
  10531. @subsection Race conditions
  10532. If some other process is modifying the file system while @command{tar}
  10533. is reading or writing files, the result may well be inconsistent due
  10534. to race conditions. For example, if another process creates some
  10535. files in a directory while @command{tar} is creating an archive
  10536. containing the directory's files, @command{tar} may see some of the
  10537. files but not others, or it may see a file that is in the process of
  10538. being created. The resulting archive may not be a snapshot of the
  10539. file system at any point in time. If an application such as a
  10540. database system depends on an accurate snapshot, restoring from the
  10541. @command{tar} archive of a live file system may therefore break that
  10542. consistency and may break the application. The simplest way to avoid
  10543. the consistency issues is to avoid making other changes to the file
  10544. system while tar is reading it or writing it.
  10545. When creating an archive, several options are available to avoid race
  10546. conditions. Some hosts have a way of snapshotting a file system, or
  10547. of temporarily suspending all changes to a file system, by (say)
  10548. suspending the only virtual machine that can modify a file system; if
  10549. you use these facilities and have @command{tar -c} read from a
  10550. snapshot when creating an archive, you can avoid inconsistency
  10551. problems. More drastically, before starting @command{tar} you could
  10552. suspend or shut down all processes other than @command{tar} that have
  10553. access to the file system, or you could unmount the file system and
  10554. then mount it read-only.
  10555. When extracting from an archive, one approach to avoid race conditions
  10556. is to create a directory that no other process can write to, and
  10557. extract into that.
  10558. @node Security
  10559. @section Security
  10560. In some cases @command{tar} may be used in an adversarial situation,
  10561. where an untrusted user is attempting to gain information about or
  10562. modify otherwise-inaccessible files. Dealing with untrusted data
  10563. (that is, data generated by an untrusted user) typically requires
  10564. extra care, because even the smallest mistake in the use of
  10565. @command{tar} is more likely to be exploited by an adversary than by a
  10566. race condition.
  10567. @menu
  10568. * Privacy::
  10569. * Integrity::
  10570. * Live untrusted data::
  10571. * Security rules of thumb::
  10572. @end menu
  10573. @node Privacy
  10574. @subsection Privacy
  10575. Standard privacy concerns apply when using @command{tar}. For
  10576. example, suppose you are archiving your home directory into a file
  10577. @file{/archive/myhome.tar}. Any secret information in your home
  10578. directory, such as your SSH secret keys, are copied faithfully into
  10579. the archive. Therefore, if your home directory contains any file that
  10580. should not be read by some other user, the archive itself should be
  10581. not be readable by that user. And even if the archive's data are
  10582. inaccessible to untrusted users, its metadata (such as size or
  10583. last-modified date) may reveal some information about your home
  10584. directory; if the metadata are intended to be private, the archive's
  10585. parent directory should also be inaccessible to untrusted users.
  10586. One precaution is to create @file{/archive} so that it is not
  10587. accessible to any user, unless that user also has permission to access
  10588. all the files in your home directory.
  10589. Similarly, when extracting from an archive, take care that the
  10590. permissions of the extracted files are not more generous than what you
  10591. want. Even if the archive itself is readable only to you, files
  10592. extracted from it have their own permissions that may differ.
  10593. @node Integrity
  10594. @subsection Integrity
  10595. When creating archives, take care that they are not writable by a
  10596. untrusted user; otherwise, that user could modify the archive, and
  10597. when you later extract from the archive you will get incorrect data.
  10598. When @command{tar} extracts from an archive, by default it writes into
  10599. files relative to the working directory. If the archive was generated
  10600. by an untrusted user, that user therefore can write into any file
  10601. under the working directory. If the working directory contains a
  10602. symbolic link to another directory, the untrusted user can also write
  10603. into any file under the referenced directory. When extracting from an
  10604. untrusted archive, it is therefore good practice to create an empty
  10605. directory and run @command{tar} in that directory.
  10606. When extracting from two or more untrusted archives, each one should
  10607. be extracted independently, into different empty directories.
  10608. Otherwise, the first archive could create a symbolic link into an area
  10609. outside the working directory, and the second one could follow the
  10610. link and overwrite data that is not under the working directory. For
  10611. example, when restoring from a series of incremental dumps, the
  10612. archives should have been created by a trusted process, as otherwise
  10613. the incremental restores might alter data outside the working
  10614. directory.
  10615. If you use the @option{--absolute-names} (@option{-P}) option when
  10616. extracting, @command{tar} respects any file names in the archive, even
  10617. file names that begin with @file{/} or contain @file{..}. As this
  10618. lets the archive overwrite any file in your system that you can write,
  10619. the @option{--absolute-names} (@option{-P}) option should be used only
  10620. for trusted archives.
  10621. Conversely, with the @option{--keep-old-files} (@option{-k}) and
  10622. @option{--skip-old-files} options, @command{tar} refuses to replace
  10623. existing files when extracting. The difference between the two
  10624. options is that the former treats existing files as errors whereas the
  10625. latter just silently ignores them.
  10626. Finally, with the @option{--no-overwrite-dir} option, @command{tar}
  10627. refuses to replace the permissions or ownership of already-existing
  10628. directories. These options may help when extracting from untrusted
  10629. archives.
  10630. @node Live untrusted data
  10631. @subsection Dealing with Live Untrusted Data
  10632. Extra care is required when creating from or extracting into a file
  10633. system that is accessible to untrusted users. For example, superusers
  10634. who invoke @command{tar} must be wary about its actions being hijacked
  10635. by an adversary who is reading or writing the file system at the same
  10636. time that @command{tar} is operating.
  10637. When creating an archive from a live file system, @command{tar} is
  10638. vulnerable to denial-of-service attacks. For example, an adversarial
  10639. user could create the illusion of an indefinitely-deep directory
  10640. hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
  10641. @command{tar}, or the illusion of an indefinitely-long file by
  10642. creating a sparse file but arranging for blocks to be allocated just
  10643. before @command{tar} reads them. There is no easy way for
  10644. @command{tar} to distinguish these scenarios from legitimate uses, so
  10645. you may need to monitor @command{tar}, just as you'd need to monitor
  10646. any other system service, to detect such attacks.
  10647. While a superuser is extracting from an archive into a live file
  10648. system, an untrusted user might replace a directory with a symbolic
  10649. link, in hopes that @command{tar} will follow the symbolic link and
  10650. extract data into files that the untrusted user does not have access
  10651. to. Even if the archive was generated by the superuser, it may
  10652. contain a file such as @file{d/etc/passwd} that the untrusted user
  10653. earlier created in order to break in; if the untrusted user replaces
  10654. the directory @file{d/etc} with a symbolic link to @file{/etc} while
  10655. @command{tar} is running, @command{tar} will overwrite
  10656. @file{/etc/passwd}. This attack can be prevented by extracting into a
  10657. directory that is inaccessible to untrusted users.
  10658. Similar attacks via symbolic links are also possible when creating an
  10659. archive, if the untrusted user can modify an ancestor of a top-level
  10660. argument of @command{tar}. For example, an untrusted user that can
  10661. modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
  10662. - /home/eve/Documents/yesterday} by replacing
  10663. @file{/home/eve/Documents} with a symbolic link to some other
  10664. location. Attacks like these can be prevented by making sure that
  10665. untrusted users cannot modify any files that are top-level arguments
  10666. to @command{tar}, or any ancestor directories of these files.
  10667. @node Security rules of thumb
  10668. @subsection Security Rules of Thumb
  10669. This section briefly summarizes rules of thumb for avoiding security
  10670. pitfalls.
  10671. @itemize @bullet
  10672. @item
  10673. Protect archives at least as much as you protect any of the files
  10674. being archived.
  10675. @item
  10676. Extract from an untrusted archive only into an otherwise-empty
  10677. directory. This directory and its parent should be accessible only to
  10678. trusted users. For example:
  10679. @example
  10680. @group
  10681. $ @kbd{chmod go-rwx .}
  10682. $ @kbd{mkdir -m go-rwx dir}
  10683. $ @kbd{cd dir}
  10684. $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
  10685. @end group
  10686. @end example
  10687. As a corollary, do not do an incremental restore from an untrusted archive.
  10688. @item
  10689. Do not let untrusted users access files extracted from untrusted
  10690. archives without checking first for problems such as setuid programs.
  10691. @item
  10692. Do not let untrusted users modify directories that are ancestors of
  10693. top-level arguments of @command{tar}. For example, while you are
  10694. executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
  10695. untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
  10696. @item
  10697. Pay attention to the diagnostics and exit status of @command{tar}.
  10698. @item
  10699. When archiving live file systems, monitor running instances of
  10700. @command{tar} to detect denial-of-service attacks.
  10701. @item
  10702. Avoid unusual options such as @option{--absolute-names} (@option{-P}),
  10703. @option{--dereference} (@option{-h}), @option{--overwrite},
  10704. @option{--recursive-unlink}, and @option{--remove-files} unless you
  10705. understand their security implications.
  10706. @end itemize
  10707. @node Changes
  10708. @appendix Changes
  10709. This appendix lists some important user-visible changes between
  10710. various versions of @GNUTAR{}. An up-to-date version of this document
  10711. is available at
  10712. @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
  10713. @GNUTAR{} documentation page}.
  10714. @table @asis
  10715. @item Use of globbing patterns when listing and extracting.
  10716. Previous versions of GNU tar assumed shell-style globbing when
  10717. extracting from or listing an archive. For example:
  10718. @smallexample
  10719. $ @kbd{tar xf foo.tar '*.c'}
  10720. @end smallexample
  10721. would extract all files whose names end in @samp{.c}. This behavior
  10722. was not documented and was incompatible with traditional tar
  10723. implementations. Therefore, starting from version 1.15.91, GNU tar
  10724. no longer uses globbing by default. For example, the above invocation
  10725. is now interpreted as a request to extract from the archive the file
  10726. named @file{*.c}.
  10727. To facilitate transition to the new behavior for those users who got
  10728. used to the previous incorrect one, @command{tar} will print a warning
  10729. if it finds out that a requested member was not found in the archive
  10730. and its name looks like a globbing pattern. For example:
  10731. @smallexample
  10732. $ @kbd{tar xf foo.tar '*.c'}
  10733. tar: Pattern matching characters used in file names. Please,
  10734. tar: use --wildcards to enable pattern matching, or --no-wildcards to
  10735. tar: suppress this warning.
  10736. tar: *.c: Not found in archive
  10737. tar: Error exit delayed from previous errors
  10738. @end smallexample
  10739. To treat member names as globbing patterns, use the @option{--wildcards} option.
  10740. If you want to tar to mimic the behavior of versions prior to 1.15.91,
  10741. add this option to your @env{TAR_OPTIONS} variable.
  10742. @xref{wildcards}, for the detailed discussion of the use of globbing
  10743. patterns by @GNUTAR{}.
  10744. @item Use of short option @option{-o}.
  10745. Earlier versions of @GNUTAR{} understood @option{-o} command line
  10746. option as a synonym for @option{--old-archive}.
  10747. @GNUTAR{} starting from version 1.13.90 understands this option as
  10748. a synonym for @option{--no-same-owner}. This is compatible with
  10749. UNIX98 @command{tar} implementations.
  10750. However, to facilitate transition, @option{-o} option retains its
  10751. old semantics when it is used with one of archive-creation commands.
  10752. Users are encouraged to use @option{--format=oldgnu} instead.
  10753. It is especially important, since versions of @acronym{GNU} Automake
  10754. up to and including 1.8.4 invoke tar with this option to produce
  10755. distribution tarballs. @xref{Formats,v7}, for the detailed discussion
  10756. of this issue and its implications.
  10757. @xref{Options, tar-formats, Changing Automake's Behavior,
  10758. automake, GNU Automake}, for a description on how to use various
  10759. archive formats with @command{automake}.
  10760. Future versions of @GNUTAR{} will understand @option{-o} only as a
  10761. synonym for @option{--no-same-owner}.
  10762. @item Use of short option @option{-l}
  10763. Earlier versions of @GNUTAR{} understood @option{-l} option as a
  10764. synonym for @option{--one-file-system}. Since such usage contradicted
  10765. to UNIX98 specification and harmed compatibility with other
  10766. implementations, it was declared deprecated in version 1.14. However,
  10767. to facilitate transition to its new semantics, it was supported by
  10768. versions 1.15 and 1.15.90. The present use of @option{-l} as a short
  10769. variant of @option{--check-links} was introduced in version 1.15.91.
  10770. @item Use of options @option{--portability} and @option{--old-archive}
  10771. These options are deprecated. Please use @option{--format=v7} instead.
  10772. @item Use of option @option{--posix}
  10773. This option is deprecated. Please use @option{--format=posix} instead.
  10774. @end table
  10775. @node Recipes
  10776. @appendix Recipes
  10777. @include recipes.texi
  10778. @node Configuring Help Summary
  10779. @appendix Configuring Help Summary
  10780. Running @kbd{tar --help} displays the short @command{tar} option
  10781. summary (@pxref{help}). This summary is organized by @dfn{groups} of
  10782. semantically close options. The options within each group are printed
  10783. in the following order: a short option, eventually followed by a list
  10784. of corresponding long option names, followed by a short description of
  10785. the option. For example, here is an excerpt from the actual @kbd{tar
  10786. --help} output:
  10787. @verbatim
  10788. Main operation mode:
  10789. -A, --catenate, --concatenate append tar files to an archive
  10790. -c, --create create a new archive
  10791. -d, --diff, --compare find differences between archive and
  10792. file system
  10793. --delete delete from the archive
  10794. @end verbatim
  10795. @vrindex ARGP_HELP_FMT, environment variable
  10796. The exact visual representation of the help output is configurable via
  10797. @env{ARGP_HELP_FMT} environment variable. The value of this variable
  10798. is a comma-separated list of @dfn{format variable} assignments. There
  10799. are two kinds of format variables. An @dfn{offset variable} keeps the
  10800. offset of some part of help output text from the leftmost column on
  10801. the screen. A @dfn{boolean} variable is a flag that toggles some
  10802. output feature on or off. Depending on the type of the corresponding
  10803. variable, there are two kinds of assignments:
  10804. @table @asis
  10805. @item Offset assignment
  10806. The assignment to an offset variable has the following syntax:
  10807. @smallexample
  10808. @var{variable}=@var{value}
  10809. @end smallexample
  10810. @noindent
  10811. where @var{variable} is the variable name, and @var{value} is a
  10812. numeric value to be assigned to the variable.
  10813. @item Boolean assignment
  10814. To assign @code{true} value to a variable, simply put this variable name. To
  10815. assign @code{false} value, prefix the variable name with @samp{no-}. For
  10816. example:
  10817. @smallexample
  10818. @group
  10819. # Assign @code{true} value:
  10820. dup-args
  10821. # Assign @code{false} value:
  10822. no-dup-args
  10823. @end group
  10824. @end smallexample
  10825. @end table
  10826. Following variables are declared:
  10827. @deftypevr {Help Output} boolean dup-args
  10828. If true, arguments for an option are shown with both short and long
  10829. options, even when a given option has both forms, for example:
  10830. @smallexample
  10831. -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
  10832. @end smallexample
  10833. If false, then if an option has both short and long forms, the
  10834. argument is only shown with the long one, for example:
  10835. @smallexample
  10836. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10837. @end smallexample
  10838. @noindent
  10839. and a message indicating that the argument is applicable to both
  10840. forms is printed below the options. This message can be disabled
  10841. using @code{dup-args-note} (see below).
  10842. The default is false.
  10843. @end deftypevr
  10844. @deftypevr {Help Output} boolean dup-args-note
  10845. If this variable is true, which is the default, the following notice
  10846. is displayed at the end of the help output:
  10847. @quotation
  10848. Mandatory or optional arguments to long options are also mandatory or
  10849. optional for any corresponding short options.
  10850. @end quotation
  10851. Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
  10852. variables @code{dup-args} or @code{dup-args-note} should be set.
  10853. @end deftypevr
  10854. @deftypevr {Help Output} offset short-opt-col
  10855. Column in which short options start. Default is 2.
  10856. @smallexample
  10857. @group
  10858. $ @kbd{tar --help|grep ARCHIVE}
  10859. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10860. $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
  10861. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10862. @end group
  10863. @end smallexample
  10864. @end deftypevr
  10865. @deftypevr {Help Output} offset long-opt-col
  10866. Column in which long options start. Default is 6. For example:
  10867. @smallexample
  10868. @group
  10869. $ @kbd{tar --help|grep ARCHIVE}
  10870. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10871. $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
  10872. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10873. @end group
  10874. @end smallexample
  10875. @end deftypevr
  10876. @deftypevr {Help Output} offset doc-opt-col
  10877. Column in which @dfn{doc options} start. A doc option isn't actually
  10878. an option, but rather an arbitrary piece of documentation that is
  10879. displayed in much the same manner as the options. For example, in
  10880. the description of @option{--format} option:
  10881. @smallexample
  10882. @group
  10883. -H, --format=FORMAT create archive of the given format.
  10884. FORMAT is one of the following:
  10885. gnu GNU tar 1.13.x format
  10886. oldgnu GNU format as per tar <= 1.12
  10887. pax POSIX 1003.1-2001 (pax) format
  10888. posix same as pax
  10889. ustar POSIX 1003.1-1988 (ustar) format
  10890. v7 old V7 tar format
  10891. @end group
  10892. @end smallexample
  10893. @noindent
  10894. the format names are doc options. Thus, if you set
  10895. @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
  10896. will look as follows:
  10897. @smallexample
  10898. @group
  10899. -H, --format=FORMAT create archive of the given format.
  10900. FORMAT is one of the following:
  10901. gnu GNU tar 1.13.x format
  10902. oldgnu GNU format as per tar <= 1.12
  10903. pax POSIX 1003.1-2001 (pax) format
  10904. posix same as pax
  10905. ustar POSIX 1003.1-1988 (ustar) format
  10906. v7 old V7 tar format
  10907. @end group
  10908. @end smallexample
  10909. @end deftypevr
  10910. @deftypevr {Help Output} offset opt-doc-col
  10911. Column in which option description starts. Default is 29.
  10912. @smallexample
  10913. @group
  10914. $ @kbd{tar --help|grep ARCHIVE}
  10915. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10916. $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
  10917. -f, --file=ARCHIVE use archive file or device ARCHIVE
  10918. $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
  10919. -f, --file=ARCHIVE
  10920. use archive file or device ARCHIVE
  10921. @end group
  10922. @end smallexample
  10923. @noindent
  10924. Notice, that the description starts on a separate line if
  10925. @code{opt-doc-col} value is too small.
  10926. @end deftypevr
  10927. @deftypevr {Help Output} offset header-col
  10928. Column in which @dfn{group headers} are printed. A group header is a
  10929. descriptive text preceding an option group. For example, in the
  10930. following text:
  10931. @verbatim
  10932. Main operation mode:
  10933. -A, --catenate, --concatenate append tar files to
  10934. an archive
  10935. -c, --create create a new archive
  10936. @end verbatim
  10937. @noindent
  10938. @samp{Main operation mode:} is the group header.
  10939. The default value is 1.
  10940. @end deftypevr
  10941. @deftypevr {Help Output} offset usage-indent
  10942. Indentation of wrapped usage lines. Affects @option{--usage}
  10943. output. Default is 12.
  10944. @end deftypevr
  10945. @deftypevr {Help Output} offset rmargin
  10946. Right margin of the text output. Used for wrapping.
  10947. @end deftypevr
  10948. @node Fixing Snapshot Files
  10949. @appendix Fixing Snapshot Files
  10950. @include tar-snapshot-edit.texi
  10951. @node Tar Internals
  10952. @appendix Tar Internals
  10953. @include intern.texi
  10954. @node Genfile
  10955. @appendix Genfile
  10956. @include genfile.texi
  10957. @node GNU Free Documentation License
  10958. @appendix GNU Free Documentation License
  10959. @include fdl.texi
  10960. @node Index of Command Line Options
  10961. @appendix Index of Command Line Options
  10962. This appendix contains an index of all @GNUTAR{} long command line
  10963. options. The options are listed without the preceding double-dash.
  10964. For a cross-reference of short command line options, see
  10965. @ref{Short Option Summary}.
  10966. @printindex op
  10967. @node Index
  10968. @appendix Index
  10969. @printindex cp
  10970. @summarycontents
  10971. @contents
  10972. @bye
  10973. @c Local variables:
  10974. @c texinfo-column-for-description: 32
  10975. @c End: