tar.texi 402 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829
  1. \input texinfo @c -*-texinfo-*-
  2. @comment %**start of header
  3. @setfilename tar.info
  4. @include version.texi
  5. @settitle GNU tar @value{VERSION}
  6. @setchapternewpage odd
  7. @finalout
  8. @smallbook
  9. @c %**end of header
  10. @c Maintenance notes:
  11. @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
  12. @c 2. Before creating final variant:
  13. @c 1.1. Run `make check-options' to make sure all options are properly
  14. @c documented;
  15. @c 2.1. Run `make master-menu' (see comment before the master menu).
  16. @include rendition.texi
  17. @include value.texi
  18. @defcodeindex op
  19. @c Put everything in one index (arbitrarily chosen to be the concept index).
  20. @syncodeindex fn cp
  21. @syncodeindex ky cp
  22. @syncodeindex pg cp
  23. @syncodeindex vr cp
  24. @copying
  25. This manual is for @acronym{GNU} @command{tar} (version
  26. @value{VERSION}, @value{UPDATED}), which creates and extracts files
  27. from archives.
  28. Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
  29. 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
  30. @quotation
  31. Permission is granted to copy, distribute and/or modify this document
  32. under the terms of the GNU Free Documentation License, Version 1.1 or
  33. any later version published by the Free Software Foundation; with no
  34. Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
  35. and with the Back-Cover Texts as in (a) below. A copy of the license
  36. is included in the section entitled "GNU Free Documentation License".
  37. (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
  38. this GNU Manual. Buying copies from GNU Press supports the FSF in
  39. developing GNU and promoting software freedom.''
  40. @end quotation
  41. @end copying
  42. @dircategory Archiving
  43. @direntry
  44. * Tar: (tar). Making tape (or disk) archives.
  45. @end direntry
  46. @dircategory Individual utilities
  47. @direntry
  48. * tar: (tar)tar invocation. Invoking @GNUTAR{}.
  49. @end direntry
  50. @shorttitlepage @acronym{GNU} @command{tar}
  51. @titlepage
  52. @title @acronym{GNU} tar: an archiver tool
  53. @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
  54. @author John Gilmore, Jay Fenlason et al.
  55. @page
  56. @vskip 0pt plus 1filll
  57. @insertcopying
  58. @end titlepage
  59. @ifnottex
  60. @node Top
  61. @top @acronym{GNU} tar: an archiver tool
  62. @insertcopying
  63. @cindex file archival
  64. @cindex archiving files
  65. The first part of this master menu lists the major nodes in this Info
  66. document. The rest of the menu lists all the lower level nodes.
  67. @end ifnottex
  68. @c The master menu goes here.
  69. @c
  70. @c NOTE: To update it from within Emacs, make sure mastermenu.el is
  71. @c loaded and run texinfo-master-menu.
  72. @c To update it from the command line, run
  73. @c
  74. @c make master-menu
  75. @menu
  76. * Introduction::
  77. * Tutorial::
  78. * tar invocation::
  79. * operations::
  80. * Backups::
  81. * Choosing::
  82. * Date input formats::
  83. * Formats::
  84. * Media::
  85. Appendices
  86. * Changes::
  87. * Configuring Help Summary::
  88. * Tar Internals::
  89. * Genfile::
  90. * Free Software Needs Free Documentation::
  91. * Copying This Manual::
  92. * Index of Command Line Options::
  93. * Index::
  94. @detailmenu
  95. --- The Detailed Node Listing ---
  96. Introduction
  97. * Book Contents:: What this Book Contains
  98. * Definitions:: Some Definitions
  99. * What tar Does:: What @command{tar} Does
  100. * Naming tar Archives:: How @command{tar} Archives are Named
  101. * Authors:: @GNUTAR{} Authors
  102. * Reports:: Reporting bugs or suggestions
  103. Tutorial Introduction to @command{tar}
  104. * assumptions::
  105. * stylistic conventions::
  106. * basic tar options:: Basic @command{tar} Operations and Options
  107. * frequent operations::
  108. * Two Frequent Options::
  109. * create:: How to Create Archives
  110. * list:: How to List Archives
  111. * extract:: How to Extract Members from an Archive
  112. * going further::
  113. Two Frequently Used Options
  114. * file tutorial::
  115. * verbose tutorial::
  116. * help tutorial::
  117. How to Create Archives
  118. * prepare for examples::
  119. * Creating the archive::
  120. * create verbose::
  121. * short create::
  122. * create dir::
  123. How to List Archives
  124. * list dir::
  125. How to Extract Members from an Archive
  126. * extracting archives::
  127. * extracting files::
  128. * extract dir::
  129. * extracting untrusted archives::
  130. * failing commands::
  131. Invoking @GNUTAR{}
  132. * Synopsis::
  133. * using tar options::
  134. * Styles::
  135. * All Options::
  136. * help::
  137. * defaults::
  138. * verbose::
  139. * interactive::
  140. The Three Option Styles
  141. * Long Options:: Long Option Style
  142. * Short Options:: Short Option Style
  143. * Old Options:: Old Option Style
  144. * Mixing:: Mixing Option Styles
  145. All @command{tar} Options
  146. * Operation Summary::
  147. * Option Summary::
  148. * Short Option Summary::
  149. @GNUTAR{} Operations
  150. * Basic tar::
  151. * Advanced tar::
  152. * create options::
  153. * extract options::
  154. * backup::
  155. * Applications::
  156. * looking ahead::
  157. Advanced @GNUTAR{} Operations
  158. * Operations::
  159. * append::
  160. * update::
  161. * concatenate::
  162. * delete::
  163. * compare::
  164. How to Add Files to Existing Archives: @option{--append}
  165. * appending files:: Appending Files to an Archive
  166. * multiple::
  167. Updating an Archive
  168. * how to update::
  169. Options Used by @option{--create}
  170. * override:: Overriding File Metadata.
  171. * Ignore Failed Read::
  172. Options Used by @option{--extract}
  173. * Reading:: Options to Help Read Archives
  174. * Writing:: Changing How @command{tar} Writes Files
  175. * Scarce:: Coping with Scarce Resources
  176. Options to Help Read Archives
  177. * read full records::
  178. * Ignore Zeros::
  179. Changing How @command{tar} Writes Files
  180. * Dealing with Old Files::
  181. * Overwrite Old Files::
  182. * Keep Old Files::
  183. * Keep Newer Files::
  184. * Unlink First::
  185. * Recursive Unlink::
  186. * Data Modification Times::
  187. * Setting Access Permissions::
  188. * Directory Modification Times and Permissions::
  189. * Writing to Standard Output::
  190. * Writing to an External Program::
  191. * remove files::
  192. Coping with Scarce Resources
  193. * Starting File::
  194. * Same Order::
  195. Performing Backups and Restoring Files
  196. * Full Dumps:: Using @command{tar} to Perform Full Dumps
  197. * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
  198. * Backup Levels:: Levels of Backups
  199. * Backup Parameters:: Setting Parameters for Backups and Restoration
  200. * Scripted Backups:: Using the Backup Scripts
  201. * Scripted Restoration:: Using the Restore Script
  202. Setting Parameters for Backups and Restoration
  203. * General-Purpose Variables::
  204. * Magnetic Tape Control::
  205. * User Hooks::
  206. * backup-specs example:: An Example Text of @file{Backup-specs}
  207. Choosing Files and Names for @command{tar}
  208. * file:: Choosing the Archive's Name
  209. * Selecting Archive Members::
  210. * files:: Reading Names from a File
  211. * exclude:: Excluding Some Files
  212. * wildcards:: Wildcards Patterns and Matching
  213. * quoting styles:: Ways of Quoting Special Characters in Names
  214. * transform:: Modifying File and Member Names
  215. * after:: Operating Only on New Files
  216. * recurse:: Descending into Directories
  217. * one:: Crossing File System Boundaries
  218. Reading Names from a File
  219. * nul::
  220. Excluding Some Files
  221. * problems with exclude::
  222. Wildcards Patterns and Matching
  223. * controlling pattern-matching::
  224. Crossing File System Boundaries
  225. * directory:: Changing Directory
  226. * absolute:: Absolute File Names
  227. Date input formats
  228. * General date syntax:: Common rules.
  229. * Calendar date items:: 19 Dec 1994.
  230. * Time of day items:: 9:20pm.
  231. * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
  232. * Day of week items:: Monday and others.
  233. * Relative items in date strings:: next tuesday, 2 years ago.
  234. * Pure numbers in date strings:: 19931219, 1440.
  235. * Seconds since the Epoch:: @@1078100502.
  236. * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
  237. * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
  238. Controlling the Archive Format
  239. * Portability:: Making @command{tar} Archives More Portable
  240. * Compression:: Using Less Space through Compression
  241. * Attributes:: Handling File Attributes
  242. * cpio:: Comparison of @command{tar} and @command{cpio}
  243. Making @command{tar} Archives More Portable
  244. * Portable Names:: Portable Names
  245. * dereference:: Symbolic Links
  246. * old:: Old V7 Archives
  247. * ustar:: Ustar Archives
  248. * gnu:: GNU and old GNU format archives.
  249. * posix:: @acronym{POSIX} archives
  250. * Checksumming:: Checksumming Problems
  251. * Large or Negative Values:: Large files, negative time stamps, etc.
  252. * Other Tars:: How to Extract GNU-Specific Data Using
  253. Other @command{tar} Implementations
  254. @GNUTAR{} and @acronym{POSIX} @command{tar}
  255. * PAX keywords:: Controlling Extended Header Keywords.
  256. How to Extract GNU-Specific Data Using Other @command{tar} Implementations
  257. * Split Recovery:: Members Split Between Volumes
  258. * Sparse Recovery:: Sparse Members
  259. Using Less Space through Compression
  260. * gzip:: Creating and Reading Compressed Archives
  261. * sparse:: Archiving Sparse Files
  262. Tapes and Other Archive Media
  263. * Device:: Device selection and switching
  264. * Remote Tape Server::
  265. * Common Problems and Solutions::
  266. * Blocking:: Blocking
  267. * Many:: Many archives on one tape
  268. * Using Multiple Tapes:: Using Multiple Tapes
  269. * label:: Including a Label in the Archive
  270. * verify::
  271. * Write Protection::
  272. Blocking
  273. * Format Variations:: Format Variations
  274. * Blocking Factor:: The Blocking Factor of an Archive
  275. Many Archives on One Tape
  276. * Tape Positioning:: Tape Positions and Tape Marks
  277. * mt:: The @command{mt} Utility
  278. Using Multiple Tapes
  279. * Multi-Volume Archives:: Archives Longer than One Tape or Disk
  280. * Tape Files:: Tape Files
  281. * Tarcat:: Concatenate Volumes into a Single Archive
  282. Tar Internals
  283. * Standard:: Basic Tar Format
  284. * Extensions:: @acronym{GNU} Extensions to the Archive Format
  285. * Sparse Formats:: Storing Sparse Files
  286. * Snapshot Files::
  287. * Dumpdir::
  288. Storing Sparse Files
  289. * Old GNU Format::
  290. * PAX 0:: PAX Format, Versions 0.0 and 0.1
  291. * PAX 1:: PAX Format, Version 1.0
  292. Genfile
  293. * Generate Mode:: File Generation Mode.
  294. * Status Mode:: File Status Mode.
  295. * Exec Mode:: Synchronous Execution mode.
  296. Copying This Manual
  297. * GNU Free Documentation License:: License for copying this manual
  298. @end detailmenu
  299. @end menu
  300. @node Introduction
  301. @chapter Introduction
  302. @GNUTAR{} creates
  303. and manipulates @dfn{archives} which are actually collections of
  304. many other files; the program provides users with an organized and
  305. systematic method for controlling a large amount of data.
  306. The name ``tar'' originally came from the phrase ``Tape ARchive'', but
  307. archives need not (and these days, typically do not) reside on tapes.
  308. @menu
  309. * Book Contents:: What this Book Contains
  310. * Definitions:: Some Definitions
  311. * What tar Does:: What @command{tar} Does
  312. * Naming tar Archives:: How @command{tar} Archives are Named
  313. * Authors:: @GNUTAR{} Authors
  314. * Reports:: Reporting bugs or suggestions
  315. @end menu
  316. @node Book Contents
  317. @section What this Book Contains
  318. The first part of this chapter introduces you to various terms that will
  319. recur throughout the book. It also tells you who has worked on @GNUTAR{}
  320. and its documentation, and where you should send bug reports
  321. or comments.
  322. The second chapter is a tutorial (@pxref{Tutorial}) which provides a
  323. gentle introduction for people who are new to using @command{tar}. It is
  324. meant to be self contained, not requiring any reading from subsequent
  325. chapters to make sense. It moves from topic to topic in a logical,
  326. progressive order, building on information already explained.
  327. Although the tutorial is paced and structured to allow beginners to
  328. learn how to use @command{tar}, it is not intended solely for beginners.
  329. The tutorial explains how to use the three most frequently used
  330. operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
  331. two frequently used options (@samp{file} and @samp{verbose}). The other
  332. chapters do not refer to the tutorial frequently; however, if a section
  333. discusses something which is a complex variant of a basic concept, there
  334. may be a cross reference to that basic concept. (The entire book,
  335. including the tutorial, assumes that the reader understands some basic
  336. concepts of using a Unix-type operating system; @pxref{Tutorial}.)
  337. The third chapter presents the remaining five operations, and
  338. information about using @command{tar} options and option syntax.
  339. @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
  340. than the reality. should think about whether this makes sense to say
  341. here, or not.} The other chapters are meant to be used as a
  342. reference. Each chapter presents everything that needs to be said
  343. about a specific topic.
  344. One of the chapters (@pxref{Date input formats}) exists in its
  345. entirety in other @acronym{GNU} manuals, and is mostly self-contained.
  346. In addition, one section of this manual (@pxref{Standard}) contains a
  347. big quote which is taken directly from @command{tar} sources.
  348. In general, we give both long and short (abbreviated) option names
  349. at least once in each section where the relevant option is covered, so
  350. that novice readers will become familiar with both styles. (A few
  351. options have no short versions, and the relevant sections will
  352. indicate this.)
  353. @node Definitions
  354. @section Some Definitions
  355. @cindex archive
  356. @cindex tar archive
  357. The @command{tar} program is used to create and manipulate @command{tar}
  358. archives. An @dfn{archive} is a single file which contains the contents
  359. of many files, while still identifying the names of the files, their
  360. owner(s), and so forth. (In addition, archives record access
  361. permissions, user and group, size in bytes, and data modification time.
  362. Some archives also record the file names in each archived directory, as
  363. well as other file and directory information.) You can use @command{tar}
  364. to @dfn{create} a new archive in a specified directory.
  365. @cindex member
  366. @cindex archive member
  367. @cindex file name
  368. @cindex member name
  369. The files inside an archive are called @dfn{members}. Within this
  370. manual, we use the term @dfn{file} to refer only to files accessible in
  371. the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
  372. @dfn{member} to refer only to the members of an archive. Similarly, a
  373. @dfn{file name} is the name of a file, as it resides in the file system,
  374. and a @dfn{member name} is the name of an archive member within the
  375. archive.
  376. @cindex extraction
  377. @cindex unpacking
  378. The term @dfn{extraction} refers to the process of copying an archive
  379. member (or multiple members) into a file in the file system. Extracting
  380. all the members of an archive is often called @dfn{extracting the
  381. archive}. The term @dfn{unpack} can also be used to refer to the
  382. extraction of many or all the members of an archive. Extracting an
  383. archive does not destroy the archive's structure, just as creating an
  384. archive does not destroy the copies of the files that exist outside of
  385. the archive. You may also @dfn{list} the members in a given archive
  386. (this is often thought of as ``printing'' them to the standard output,
  387. or the command line), or @dfn{append} members to a pre-existing archive.
  388. All of these operations can be performed using @command{tar}.
  389. @node What tar Does
  390. @section What @command{tar} Does
  391. @cindex tar
  392. The @command{tar} program provides the ability to create @command{tar}
  393. archives, as well as various other kinds of manipulation. For example,
  394. you can use @command{tar} on previously created archives to extract files,
  395. to store additional files, or to update or list files which were already
  396. stored.
  397. Initially, @command{tar} archives were used to store files conveniently on
  398. magnetic tape. The name @command{tar} comes from this use; it stands for
  399. @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
  400. direct its output to available devices, files, or other programs (using
  401. pipes). @command{tar} may even access remote devices or files (as archives).
  402. You can use @command{tar} archives in many ways. We want to stress a few
  403. of them: storage, backup, and transportation.
  404. @FIXME{the following table entries need a bit of work..}
  405. @table @asis
  406. @item Storage
  407. Often, @command{tar} archives are used to store related files for
  408. convenient file transfer over a network. For example, the
  409. @acronym{GNU} Project distributes its software bundled into
  410. @command{tar} archives, so that all the files relating to a particular
  411. program (or set of related programs) can be transferred as a single
  412. unit.
  413. A magnetic tape can store several files in sequence. However, the tape
  414. has no names for these files; it only knows their relative position on
  415. the tape. One way to store several files on one tape and retain their
  416. names is by creating a @command{tar} archive. Even when the basic transfer
  417. mechanism can keep track of names, as FTP can, the nuisance of handling
  418. multiple files, directories, and multiple links makes @command{tar}
  419. archives useful.
  420. Archive files are also used for long-term storage. You can think of
  421. this as transportation from the present into the future. (It is a
  422. science-fiction idiom that you can move through time as well as in
  423. space; the idea here is that @command{tar} can be used to move archives in
  424. all dimensions, even time!)
  425. @item Backup
  426. Because the archive created by @command{tar} is capable of preserving
  427. file information and directory structure, @command{tar} is commonly
  428. used for performing full and incremental backups of disks. A backup
  429. puts a collection of files (possibly pertaining to many users and
  430. projects) together on a disk or a tape. This guards against
  431. accidental destruction of the information in those files.
  432. @GNUTAR{} has special features that allow it to be
  433. used to make incremental and full dumps of all the files in a
  434. file system.
  435. @item Transportation
  436. You can create an archive on one system, transfer it to another system,
  437. and extract the contents there. This allows you to transport a group of
  438. files from one system to another.
  439. @end table
  440. @node Naming tar Archives
  441. @section How @command{tar} Archives are Named
  442. Conventionally, @command{tar} archives are given names ending with
  443. @samp{.tar}. This is not necessary for @command{tar} to operate properly,
  444. but this manual follows that convention in order to accustom readers to
  445. it and to make examples more clear.
  446. @cindex tar file
  447. @cindex entry
  448. @cindex tar entry
  449. Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
  450. archive members as ``files'' or ``entries''. For people familiar with
  451. the operation of @command{tar}, this causes no difficulty. However, in
  452. this manual, we consistently refer to ``archives'' and ``archive
  453. members'' to make learning to use @command{tar} easier for novice users.
  454. @node Authors
  455. @section @GNUTAR{} Authors
  456. @GNUTAR{} was originally written by John Gilmore,
  457. and modified by many people. The @acronym{GNU} enhancements were
  458. written by Jay Fenlason, then Joy Kendall, and the whole package has
  459. been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
  460. Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
  461. numerous and kind users.
  462. We wish to stress that @command{tar} is a collective work, and owes much to
  463. all those people who reported problems, offered solutions and other
  464. insights, or shared their thoughts and suggestions. An impressive, yet
  465. partial list of those contributors can be found in the @file{THANKS}
  466. file from the @GNUTAR{} distribution.
  467. @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
  468. sure i want to spell out the history in this detail, at least not for
  469. the printed book. i'm just not sure it needs to be said this way.
  470. i'll think about it.}
  471. @FIXME{History is more important, and surely more interesting, than
  472. actual names. Quoting names without history would be meaningless. FP}
  473. Jay Fenlason put together a draft of a @GNUTAR{}
  474. manual, borrowing notes from the original man page from John Gilmore.
  475. This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
  476. Gorin worked on a tutorial and manual for @GNUTAR{}.
  477. Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
  478. taking information from all these sources and merging them. Melissa
  479. Weisshaus finally edited and redesigned the book to create version
  480. 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
  481. by the current maintainer, Sergey Poznyakoff.
  482. For version 1.12, Daniel Hagerty contributed a great deal of technical
  483. consulting. In particular, he is the primary author of @ref{Backups}.
  484. In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
  485. (see @url{http://savannah.gnu.org/projects/tar}), and
  486. active development and maintenance work has started
  487. again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
  488. Poznyakoff and Jeff Bailey.
  489. Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
  490. @node Reports
  491. @section Reporting bugs or suggestions
  492. @cindex bug reports
  493. @cindex reporting bugs
  494. If you find problems or have suggestions about this program or manual,
  495. please report them to @file{bug-tar@@gnu.org}.
  496. When reporting a bug, please be sure to include as much detail as
  497. possible, in order to reproduce it. @FIXME{Be more specific, I'd
  498. like to make this node as detailed as 'Bug reporting' node in Emacs
  499. manual}.
  500. @node Tutorial
  501. @chapter Tutorial Introduction to @command{tar}
  502. This chapter guides you through some basic examples of three @command{tar}
  503. operations: @option{--create}, @option{--list}, and @option{--extract}. If
  504. you already know how to use some other version of @command{tar}, then you
  505. may not need to read this chapter. This chapter omits most complicated
  506. details about how @command{tar} works.
  507. @menu
  508. * assumptions::
  509. * stylistic conventions::
  510. * basic tar options:: Basic @command{tar} Operations and Options
  511. * frequent operations::
  512. * Two Frequent Options::
  513. * create:: How to Create Archives
  514. * list:: How to List Archives
  515. * extract:: How to Extract Members from an Archive
  516. * going further::
  517. @end menu
  518. @node assumptions
  519. @section Assumptions this Tutorial Makes
  520. This chapter is paced to allow beginners to learn about @command{tar}
  521. slowly. At the same time, we will try to cover all the basic aspects of
  522. these three operations. In order to accomplish both of these tasks, we
  523. have made certain assumptions about your knowledge before reading this
  524. manual, and the hardware you will be using:
  525. @itemize @bullet
  526. @item
  527. Before you start to work through this tutorial, you should understand
  528. what the terms ``archive'' and ``archive member'' mean
  529. (@pxref{Definitions}). In addition, you should understand something
  530. about how Unix-type operating systems work, and you should know how to
  531. use some basic utilities. For example, you should know how to create,
  532. list, copy, rename, edit, and delete files and directories; how to
  533. change between directories; and how to figure out where you are in the
  534. file system. You should have some basic understanding of directory
  535. structure and how files are named according to which directory they are
  536. in. You should understand concepts such as standard output and standard
  537. input, what various definitions of the term ``argument'' mean, and the
  538. differences between relative and absolute path names. @FIXME{and what
  539. else?}
  540. @item
  541. This manual assumes that you are working from your own home directory
  542. (unless we state otherwise). In this tutorial, you will create a
  543. directory to practice @command{tar} commands in. When we show path names,
  544. we will assume that those paths are relative to your home directory.
  545. For example, my home directory path is @file{/home/fsf/melissa}. All of
  546. my examples are in a subdirectory of the directory named by that path
  547. name; the subdirectory is called @file{practice}.
  548. @item
  549. In general, we show examples of archives which exist on (or can be
  550. written to, or worked with from) a directory on a hard disk. In most
  551. cases, you could write those archives to, or work with them on any other
  552. device, such as a tape drive. However, some of the later examples in
  553. the tutorial and next chapter will not work on tape drives.
  554. Additionally, working with tapes is much more complicated than working
  555. with hard disks. For these reasons, the tutorial does not cover working
  556. with tape drives. @xref{Media}, for complete information on using
  557. @command{tar} archives with tape drives.
  558. @FIXME{this is a cop out. need to add some simple tape drive info.}
  559. @end itemize
  560. @node stylistic conventions
  561. @section Stylistic Conventions
  562. In the examples, @samp{$} represents a typical shell prompt. It
  563. precedes lines you should type; to make this more clear, those lines are
  564. shown in @kbd{this font}, as opposed to lines which represent the
  565. computer's response; those lines are shown in @code{this font}, or
  566. sometimes @samp{like this}.
  567. @c When we have lines which are too long to be
  568. @c displayed in any other way, we will show them like this:
  569. @node basic tar options
  570. @section Basic @command{tar} Operations and Options
  571. @command{tar} can take a wide variety of arguments which specify and define
  572. the actions it will have on the particular set of files or the archive.
  573. The main types of arguments to @command{tar} fall into one of two classes:
  574. operations, and options.
  575. Some arguments fall into a class called @dfn{operations}; exactly one of
  576. these is both allowed and required for any instance of using @command{tar};
  577. you may @emph{not} specify more than one. People sometimes speak of
  578. @dfn{operating modes}. You are in a particular operating mode when you
  579. have specified the operation which specifies it; there are eight
  580. operations in total, and thus there are eight operating modes.
  581. The other arguments fall into the class known as @dfn{options}. You are
  582. not required to specify any options, and you are allowed to specify more
  583. than one at a time (depending on the way you are using @command{tar} at
  584. that time). Some options are used so frequently, and are so useful for
  585. helping you type commands more carefully that they are effectively
  586. ``required''. We will discuss them in this chapter.
  587. You can write most of the @command{tar} operations and options in any
  588. of three forms: long (mnemonic) form, short form, and old style. Some
  589. of the operations and options have no short or ``old'' forms; however,
  590. the operations and options which we will cover in this tutorial have
  591. corresponding abbreviations. @FIXME{make sure this is still the case,
  592. at the end}We will indicate those abbreviations appropriately to get
  593. you used to seeing them. (Note that the ``old style'' option forms
  594. exist in @GNUTAR{} for compatibility with Unix
  595. @command{tar}. In this book we present a full discussion of this way
  596. of writing options and operations (@pxref{Old Options}), and we discuss
  597. the other two styles of writing options (@xref{Long Options}, and
  598. @pxref{Short Options}).
  599. In the examples and in the text of this tutorial, we usually use the
  600. long forms of operations and options; but the ``short'' forms produce
  601. the same result and can make typing long @command{tar} commands easier.
  602. For example, instead of typing
  603. @smallexample
  604. @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
  605. @end smallexample
  606. @noindent
  607. you can type
  608. @smallexample
  609. @kbd{tar -c -v -f afiles.tar apple angst aspic}
  610. @end smallexample
  611. @noindent
  612. or even
  613. @smallexample
  614. @kbd{tar -cvf afiles.tar apple angst aspic}
  615. @end smallexample
  616. @noindent
  617. For more information on option syntax, see @ref{Advanced tar}. In
  618. discussions in the text, when we name an option by its long form, we
  619. also give the corresponding short option in parentheses.
  620. The term, ``option'', can be confusing at times, since ``operations''
  621. are often lumped in with the actual, @emph{optional} ``options'' in certain
  622. general class statements. For example, we just talked about ``short and
  623. long forms of options and operations''. However, experienced @command{tar}
  624. users often refer to these by shorthand terms such as, ``short and long
  625. options''. This term assumes that the ``operations'' are included, also.
  626. Context will help you determine which definition of ``options'' to use.
  627. Similarly, the term ``command'' can be confusing, as it is often used in
  628. two different ways. People sometimes refer to @command{tar} ``commands''.
  629. A @command{tar} @dfn{command} is the entire command line of user input
  630. which tells @command{tar} what to do --- including the operation, options,
  631. and any arguments (file names, pipes, other commands, etc). However,
  632. you will also sometimes hear the term ``the @command{tar} command''. When
  633. the word ``command'' is used specifically like this, a person is usually
  634. referring to the @command{tar} @emph{operation}, not the whole line.
  635. Again, use context to figure out which of the meanings the speaker
  636. intends.
  637. @node frequent operations
  638. @section The Three Most Frequently Used Operations
  639. Here are the three most frequently used operations (both short and long
  640. forms), as well as a brief description of their meanings. The rest of
  641. this chapter will cover how to use these operations in detail. We will
  642. present the rest of the operations in the next chapter.
  643. @table @option
  644. @item --create
  645. @itemx -c
  646. Create a new @command{tar} archive.
  647. @item --list
  648. @itemx -t
  649. List the contents of an archive.
  650. @item --extract
  651. @itemx -x
  652. Extract one or more members from an archive.
  653. @end table
  654. @node Two Frequent Options
  655. @section Two Frequently Used Options
  656. To understand how to run @command{tar} in the three operating modes listed
  657. previously, you also need to understand how to use two of the options to
  658. @command{tar}: @option{--file} (which takes an archive file as an argument)
  659. and @option{--verbose}. (You are usually not @emph{required} to specify
  660. either of these options when you run @command{tar}, but they can be very
  661. useful in making things more clear and helping you avoid errors.)
  662. @menu
  663. * file tutorial::
  664. * verbose tutorial::
  665. * help tutorial::
  666. @end menu
  667. @node file tutorial
  668. @unnumberedsubsec The @option{--file} Option
  669. @table @option
  670. @xopindex{file, tutorial}
  671. @item --file=@var{archive-name}
  672. @itemx -f @var{archive-name}
  673. Specify the name of an archive file.
  674. @end table
  675. You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
  676. use @command{tar}; this option determines the name of the archive file
  677. that @command{tar} will work on.
  678. @vrindex TAPE
  679. If you don't specify this argument, then @command{tar} will examine
  680. the environment variable @env{TAPE}. If it is set, its value will be
  681. used as the archive name. Otherwise, @command{tar} will use the
  682. default archive, determined at the compile time. Usually it is
  683. standard output or some physical tape drive attached to your machine
  684. (you can verify what the default is by running @kbd{tar
  685. --show-defaults}, @pxref{defaults}). If there is no tape drive
  686. attached, or the default is not meaningful, then @command{tar} will
  687. print an error message. The error message might look roughly like one
  688. of the following:
  689. @smallexample
  690. tar: can't open /dev/rmt8 : No such device or address
  691. tar: can't open /dev/rsmt0 : I/O error
  692. @end smallexample
  693. @noindent
  694. To avoid confusion, we recommend that you always specify an archive file
  695. name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
  696. For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
  697. @ref{file}.
  698. @node verbose tutorial
  699. @unnumberedsubsec The @option{--verbose} Option
  700. @table @option
  701. @xopindex{verbose, introduced}
  702. @item --verbose
  703. @itemx -v
  704. Show the files being worked on as @command{tar} is running.
  705. @end table
  706. @option{--verbose} (@option{-v}) shows details about the results of running
  707. @command{tar}. This can be especially useful when the results might not be
  708. obvious. For example, if you want to see the progress of @command{tar} as
  709. it writes files into the archive, you can use the @option{--verbose}
  710. option. In the beginning, you may find it useful to use
  711. @option{--verbose} at all times; when you are more accustomed to
  712. @command{tar}, you will likely want to use it at certain times but not at
  713. others. We will use @option{--verbose} at times to help make something
  714. clear, and we will give many examples both using and not using
  715. @option{--verbose} to show the differences.
  716. Each instance of @option{--verbose} on the command line increases the
  717. verbosity level by one, so if you need more details on the output,
  718. specify it twice.
  719. When reading archives (@option{--list}, @option{--extract},
  720. @option{--diff}), @command{tar} by default prints only the names of
  721. the members being extracted. Using @option{--verbose} will show a full,
  722. @command{ls} style member listing.
  723. In contrast, when writing archives (@option{--create}, @option{--append},
  724. @option{--update}), @command{tar} does not print file names by
  725. default. So, a single @option{--verbose} option shows the file names
  726. being added to the archive, while two @option{--verbose} options
  727. enable the full listing.
  728. For example, to create an archive in verbose mode:
  729. @smallexample
  730. $ @kbd{tar -cvf afiles.tar apple angst aspic}
  731. apple
  732. angst
  733. aspic
  734. @end smallexample
  735. @noindent
  736. Creating the same archive with the verbosity level 2 could give:
  737. @smallexample
  738. $ @kbd{tar -cvvf afiles.tar apple angst aspic}
  739. -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
  740. -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
  741. -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
  742. @end smallexample
  743. @noindent
  744. This works equally well using short or long forms of options. Using
  745. long forms, you would simply write out the mnemonic form of the option
  746. twice, like this:
  747. @smallexample
  748. $ @kbd{tar --create --verbose --verbose @dots{}}
  749. @end smallexample
  750. @noindent
  751. Note that you must double the hyphens properly each time.
  752. Later in the tutorial, we will give examples using @w{@option{--verbose
  753. --verbose}}.
  754. @anchor{verbose member listing}
  755. The full output consists of six fields:
  756. @itemize @bullet
  757. @item File type and permissions in symbolic form.
  758. These are displayed in the same format as the first column of
  759. @command{ls -l} output (@pxref{What information is listed,
  760. format=verbose, Verbose listing, fileutils, GNU file utilities}).
  761. @item Owner name and group separated by a slash character.
  762. If these data are not available (for example, when listing a @samp{v7} format
  763. archive), numeric ID values are printed instead.
  764. @item Size of the file, in bytes.
  765. @item File modification date in ISO 8601 format.
  766. @item File modification time.
  767. @item File name.
  768. If the name contains any special characters (white space, newlines,
  769. etc.) these are displayed in an unambiguous form using so called
  770. @dfn{quoting style}. For the detailed discussion of available styles
  771. and on how to use them, see @ref{quoting styles}.
  772. Depending on the file type, the name can be followed by some
  773. additional information, described in the following table:
  774. @table @samp
  775. @item -> @var{link-name}
  776. The file or archive member is a @dfn{symbolic link} and
  777. @var{link-name} is the name of file it links to.
  778. @item link to @var{link-name}
  779. The file or archive member is a @dfn{hard link} and @var{link-name} is
  780. the name of file it links to.
  781. @item --Long Link--
  782. The archive member is an old GNU format long link. You will normally
  783. not encounter this.
  784. @item --Long Name--
  785. The archive member is an old GNU format long name. You will normally
  786. not encounter this.
  787. @item --Volume Header--
  788. The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
  789. @item --Continued at byte @var{n}--
  790. Encountered only at the beginning of a multy-volume archive
  791. (@pxref{Using Multiple Tapes}). This archive member is a continuation
  792. from the previous volume. The number @var{n} gives the offset where
  793. the original file was split.
  794. @item --Mangled file names--
  795. This archive member contains @dfn{mangled file names} declarations,
  796. a special member type that was used by early versions of @GNUTAR{}.
  797. You probably will never encounter this, unless you are reading a very
  798. old archive.
  799. @item unknown file type @var{c}
  800. An archive member of unknown type. @var{c} is the type character from
  801. the archive header. If you encounter such a message, it means that
  802. either your archive contains proprietary member types @GNUTAR{} is not
  803. able to handle, or the archive is corrupted.
  804. @end table
  805. @end itemize
  806. For example, here is an archive listing containing most of the special
  807. suffixes explained above:
  808. @smallexample
  809. @group
  810. V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
  811. -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
  812. byte 32456--
  813. -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
  814. lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
  815. -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
  816. hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
  817. @end group
  818. @end smallexample
  819. @smallexample
  820. @end smallexample
  821. @node help tutorial
  822. @unnumberedsubsec Getting Help: Using the @option{--help} Option
  823. @table @option
  824. @opindex help
  825. @item --help
  826. The @option{--help} option to @command{tar} prints out a very brief list of
  827. all operations and option available for the current version of
  828. @command{tar} available on your system.
  829. @end table
  830. @node create
  831. @section How to Create Archives
  832. @UNREVISED
  833. @cindex Creation of the archive
  834. @cindex Archive, creation of
  835. One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
  836. you use to create a @command{tar} archive. We will explain
  837. @option{--create} first because, in order to learn about the other
  838. operations, you will find it useful to have an archive available to
  839. practice on.
  840. To make this easier, in this section you will first create a directory
  841. containing three files. Then, we will show you how to create an
  842. @emph{archive} (inside the new directory). Both the directory, and
  843. the archive are specifically for you to practice on. The rest of this
  844. chapter and the next chapter will show many examples using this
  845. directory and the files you will create: some of those files may be
  846. other directories and other archives.
  847. The three files you will archive in this example are called
  848. @file{blues}, @file{folk}, and @file{jazz}. The archive is called
  849. @file{collection.tar}.
  850. This section will proceed slowly, detailing how to use @option{--create}
  851. in @code{verbose} mode, and showing examples using both short and long
  852. forms. In the rest of the tutorial, and in the examples in the next
  853. chapter, we will proceed at a slightly quicker pace. This section
  854. moves more slowly to allow beginning users to understand how
  855. @command{tar} works.
  856. @menu
  857. * prepare for examples::
  858. * Creating the archive::
  859. * create verbose::
  860. * short create::
  861. * create dir::
  862. @end menu
  863. @node prepare for examples
  864. @subsection Preparing a Practice Directory for Examples
  865. To follow along with this and future examples, create a new directory
  866. called @file{practice} containing files called @file{blues}, @file{folk}
  867. and @file{jazz}. The files can contain any information you like:
  868. ideally, they should contain information which relates to their names,
  869. and be of different lengths. Our examples assume that @file{practice}
  870. is a subdirectory of your home directory.
  871. Now @command{cd} to the directory named @file{practice}; @file{practice}
  872. is now your @dfn{working directory}. (@emph{Please note}: Although
  873. the full path name of this directory is
  874. @file{/@var{homedir}/practice}, in our examples we will refer to
  875. this directory as @file{practice}; the @var{homedir} is presumed.
  876. In general, you should check that the files to be archived exist where
  877. you think they do (in the working directory) by running @command{ls}.
  878. Because you just created the directory and the files and have changed to
  879. that directory, you probably don't need to do that this time.
  880. It is very important to make sure there isn't already a file in the
  881. working directory with the archive name you intend to use (in this case,
  882. @samp{collection.tar}), or that you don't care about its contents.
  883. Whenever you use @samp{create}, @command{tar} will erase the current
  884. contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
  885. will not tell you if you are about to overwrite an archive unless you
  886. specify an option which does this (@pxref{backup}, for the
  887. information on how to do so). To add files to an existing archive,
  888. you need to use a different option, such as @option{--append} (@option{-r}); see
  889. @ref{append} for information on how to do this.
  890. @node Creating the archive
  891. @subsection Creating the Archive
  892. @xopindex{create, introduced}
  893. To place the files @file{blues}, @file{folk}, and @file{jazz} into an
  894. archive named @file{collection.tar}, use the following command:
  895. @smallexample
  896. $ @kbd{tar --create --file=collection.tar blues folk jazz}
  897. @end smallexample
  898. The order of the arguments is not very important, @emph{when using long
  899. option forms}. You could also say:
  900. @smallexample
  901. $ @kbd{tar blues --create folk --file=collection.tar jazz}
  902. @end smallexample
  903. @noindent
  904. However, you can see that this order is harder to understand; this is
  905. why we will list the arguments in the order that makes the commands
  906. easiest to understand (and we encourage you to do the same when you use
  907. @command{tar}, to avoid errors).
  908. Note that the sequence
  909. @option{--file=@-collection.tar} is considered to be @emph{one} argument.
  910. If you substituted any other string of characters for
  911. @kbd{collection.tar}, then that string would become the name of the
  912. archive file you create.
  913. The order of the options becomes more important when you begin to use
  914. short forms. With short forms, if you type commands in the wrong order
  915. (even if you type them correctly in all other ways), you may end up with
  916. results you don't expect. For this reason, it is a good idea to get
  917. into the habit of typing options in the order that makes inherent sense.
  918. @xref{short create}, for more information on this.
  919. In this example, you type the command as shown above: @option{--create}
  920. is the operation which creates the new archive
  921. (@file{collection.tar}), and @option{--file} is the option which lets
  922. you give it the name you chose. The files, @file{blues}, @file{folk},
  923. and @file{jazz}, are now members of the archive, @file{collection.tar}
  924. (they are @dfn{file name arguments} to the @option{--create} operation.
  925. @xref{Choosing}, for the detailed discussion on these.) Now that they are
  926. in the archive, they are called @emph{archive members}, not files.
  927. (@pxref{Definitions,members}).
  928. When you create an archive, you @emph{must} specify which files you
  929. want placed in the archive. If you do not specify any archive
  930. members, @GNUTAR{} will complain.
  931. If you now list the contents of the working directory (@command{ls}), you will
  932. find the archive file listed as well as the files you saw previously:
  933. @smallexample
  934. blues folk jazz collection.tar
  935. @end smallexample
  936. @noindent
  937. Creating the archive @samp{collection.tar} did not destroy the copies of
  938. the files in the directory.
  939. Keep in mind that if you don't indicate an operation, @command{tar} will not
  940. run and will prompt you for one. If you don't name any files, @command{tar}
  941. will complain. You must have write access to the working directory,
  942. or else you will not be able to create an archive in that directory.
  943. @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
  944. an existing archive; it will delete the archive and write a new one.
  945. Use @option{--append} (@option{-r}) instead. @xref{append}.
  946. @node create verbose
  947. @subsection Running @option{--create} with @option{--verbose}
  948. @xopindex{create, using with @option{--verbose}}
  949. @xopindex{verbose, using with @option{--create}}
  950. If you include the @option{--verbose} (@option{-v}) option on the command line,
  951. @command{tar} will list the files it is acting on as it is working. In
  952. verbose mode, the @code{create} example above would appear as:
  953. @smallexample
  954. $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
  955. blues
  956. folk
  957. jazz
  958. @end smallexample
  959. This example is just like the example we showed which did not use
  960. @option{--verbose}, except that @command{tar} generated the remaining lines
  961. @iftex
  962. (note the different font styles).
  963. @end iftex
  964. @ifinfo
  965. .
  966. @end ifinfo
  967. In the rest of the examples in this chapter, we will frequently use
  968. @code{verbose} mode so we can show actions or @command{tar} responses that
  969. you would otherwise not see, and which are important for you to
  970. understand.
  971. @node short create
  972. @subsection Short Forms with @samp{create}
  973. As we said before, the @option{--create} (@option{-c}) operation is one of the most
  974. basic uses of @command{tar}, and you will use it countless times.
  975. Eventually, you will probably want to use abbreviated (or ``short'')
  976. forms of options. A full discussion of the three different forms that
  977. options can take appears in @ref{Styles}; for now, here is what the
  978. previous example (including the @option{--verbose} (@option{-v}) option) looks like
  979. using short option forms:
  980. @smallexample
  981. $ @kbd{tar -cvf collection.tar blues folk jazz}
  982. blues
  983. folk
  984. jazz
  985. @end smallexample
  986. @noindent
  987. As you can see, the system responds the same no matter whether you use
  988. long or short option forms.
  989. @FIXME{i don't like how this is worded:} One difference between using
  990. short and long option forms is that, although the exact placement of
  991. arguments following options is no more specific when using short forms,
  992. it is easier to become confused and make a mistake when using short
  993. forms. For example, suppose you attempted the above example in the
  994. following way:
  995. @smallexample
  996. $ @kbd{tar -cfv collection.tar blues folk jazz}
  997. @end smallexample
  998. @noindent
  999. In this case, @command{tar} will make an archive file called @file{v},
  1000. containing the files @file{blues}, @file{folk}, and @file{jazz}, because
  1001. the @samp{v} is the closest ``file name'' to the @option{-f} option, and
  1002. is thus taken to be the chosen archive file name. @command{tar} will try
  1003. to add a file called @file{collection.tar} to the @file{v} archive file;
  1004. if the file @file{collection.tar} did not already exist, @command{tar} will
  1005. report an error indicating that this file does not exist. If the file
  1006. @file{collection.tar} does already exist (e.g., from a previous command
  1007. you may have run), then @command{tar} will add this file to the archive.
  1008. Because the @option{-v} option did not get registered, @command{tar} will not
  1009. run under @samp{verbose} mode, and will not report its progress.
  1010. The end result is that you may be quite confused about what happened,
  1011. and possibly overwrite a file. To illustrate this further, we will show
  1012. you how an example we showed previously would look using short forms.
  1013. This example,
  1014. @smallexample
  1015. $ @kbd{tar blues --create folk --file=collection.tar jazz}
  1016. @end smallexample
  1017. @noindent
  1018. is confusing as it is. When shown using short forms, however, it
  1019. becomes much more so:
  1020. @smallexample
  1021. $ @kbd{tar blues -c folk -f collection.tar jazz}
  1022. @end smallexample
  1023. @noindent
  1024. It would be very easy to put the wrong string of characters
  1025. immediately following the @option{-f}, but doing that could sacrifice
  1026. valuable data.
  1027. For this reason, we recommend that you pay very careful attention to
  1028. the order of options and placement of file and archive names,
  1029. especially when using short option forms. Not having the option name
  1030. written out mnemonically can affect how well you remember which option
  1031. does what, and therefore where different names have to be placed.
  1032. @node create dir
  1033. @subsection Archiving Directories
  1034. @cindex Archiving Directories
  1035. @cindex Directories, Archiving
  1036. You can archive a directory by specifying its directory name as a
  1037. file name argument to @command{tar}. The files in the directory will be
  1038. archived relative to the working directory, and the directory will be
  1039. re-created along with its contents when the archive is extracted.
  1040. To archive a directory, first move to its superior directory. If you
  1041. have followed the previous instructions in this tutorial, you should
  1042. type:
  1043. @smallexample
  1044. $ @kbd{cd ..}
  1045. $
  1046. @end smallexample
  1047. @noindent
  1048. This will put you into the directory which contains @file{practice},
  1049. i.e., your home directory. Once in the superior directory, you can
  1050. specify the subdirectory, @file{practice}, as a file name argument. To
  1051. store @file{practice} in the new archive file @file{music.tar}, type:
  1052. @smallexample
  1053. $ @kbd{tar --create --verbose --file=music.tar practice}
  1054. @end smallexample
  1055. @noindent
  1056. @command{tar} should output:
  1057. @smallexample
  1058. practice/
  1059. practice/blues
  1060. practice/folk
  1061. practice/jazz
  1062. practice/collection.tar
  1063. @end smallexample
  1064. Note that the archive thus created is not in the subdirectory
  1065. @file{practice}, but rather in the current working directory---the
  1066. directory from which @command{tar} was invoked. Before trying to archive a
  1067. directory from its superior directory, you should make sure you have
  1068. write access to the superior directory itself, not only the directory
  1069. you are trying archive with @command{tar}. For example, you will probably
  1070. not be able to store your home directory in an archive by invoking
  1071. @command{tar} from the root directory; @xref{absolute}. (Note
  1072. also that @file{collection.tar}, the original archive file, has itself
  1073. been archived. @command{tar} will accept any file as a file to be
  1074. archived, regardless of its content. When @file{music.tar} is
  1075. extracted, the archive file @file{collection.tar} will be re-written
  1076. into the file system).
  1077. If you give @command{tar} a command such as
  1078. @smallexample
  1079. $ @kbd{tar --create --file=foo.tar .}
  1080. @end smallexample
  1081. @noindent
  1082. @command{tar} will report @samp{tar: ./foo.tar is the archive; not
  1083. dumped}. This happens because @command{tar} creates the archive
  1084. @file{foo.tar} in the current directory before putting any files into
  1085. it. Then, when @command{tar} attempts to add all the files in the
  1086. directory @file{.} to the archive, it notices that the file
  1087. @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
  1088. it. (It makes no sense to put an archive into itself.) @GNUTAR{}
  1089. will continue in this case, and create the archive
  1090. normally, except for the exclusion of that one file. (@emph{Please
  1091. note:} Other implementations of @command{tar} may not be so clever;
  1092. they will enter an infinite loop when this happens, so you should not
  1093. depend on this behavior unless you are certain you are running
  1094. @GNUTAR{}. In general, it is wise to always place the archive outside
  1095. of the directory being dumped.
  1096. @node list
  1097. @section How to List Archives
  1098. @opindex list
  1099. Frequently, you will find yourself wanting to determine exactly what a
  1100. particular archive contains. You can use the @option{--list}
  1101. (@option{-t}) operation to get the member names as they currently
  1102. appear in the archive, as well as various attributes of the files at
  1103. the time they were archived. For example, you can examine the archive
  1104. @file{collection.tar} that you created in the last section with the
  1105. command,
  1106. @smallexample
  1107. $ @kbd{tar --list --file=collection.tar}
  1108. @end smallexample
  1109. @noindent
  1110. The output of @command{tar} would then be:
  1111. @smallexample
  1112. blues
  1113. folk
  1114. jazz
  1115. @end smallexample
  1116. @noindent
  1117. The archive @file{bfiles.tar} would list as follows:
  1118. @smallexample
  1119. ./birds
  1120. baboon
  1121. ./box
  1122. @end smallexample
  1123. @noindent
  1124. Be sure to use a @option{--file=@var{archive-name}} (@option{-f
  1125. @var{archive-name}}) option just as with @option{--create}
  1126. (@option{-c}) to specify the name of the archive.
  1127. @xopindex{list, using with @option{--verbose}}
  1128. @xopindex{verbose, using with @option{--list}}
  1129. If you use the @option{--verbose} (@option{-v}) option with
  1130. @option{--list}, then @command{tar} will print out a listing
  1131. reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
  1132. forth. This output is described in detail in @ref{verbose member listing}.
  1133. If you had used @option{--verbose} (@option{-v}) mode, the example
  1134. above would look like:
  1135. @smallexample
  1136. $ @kbd{tar --list --verbose --file=collection.tar folk}
  1137. -rw-r--r-- myself user 62 1990-05-23 10:55 folk
  1138. @end smallexample
  1139. @cindex listing member and file names
  1140. @anchor{listing member and file names}
  1141. It is important to notice that the output of @kbd{tar --list
  1142. --verbose} does not necessarily match that produced by @kbd{tar
  1143. --create --verbose} while creating the archive. It is because
  1144. @GNUTAR{}, unless told explicitly not to do so, removes some directory
  1145. prefixes from file names before storing them in the archive
  1146. (@xref{absolute}, for more information). In other
  1147. words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
  1148. an archive and @dfn{member names} when listing it. Consider this
  1149. example:
  1150. @smallexample
  1151. @group
  1152. $ @kbd{tar cfv archive /etc/mail}
  1153. tar: Removing leading `/' from member names
  1154. /etc/mail/
  1155. /etc/mail/sendmail.cf
  1156. /etc/mail/aliases
  1157. $ @kbd{tar tf archive}
  1158. etc/mail/
  1159. etc/mail/sendmail.cf
  1160. etc/mail/aliases
  1161. @end group
  1162. @end smallexample
  1163. @opindex show-stored-names
  1164. This default behavior can sometimes be inconvenient. You can force
  1165. @GNUTAR{} show member names when creating archive by supplying
  1166. @option{--show-stored-names} option.
  1167. @table @option
  1168. @item --show-stored-names
  1169. Print member (as opposed to @emph{file}) names when creating the archive.
  1170. @end table
  1171. @cindex File name arguments, using @option{--list} with
  1172. @xopindex{list, using with file name arguments}
  1173. You can specify one or more individual member names as arguments when
  1174. using @samp{list}. In this case, @command{tar} will only list the
  1175. names of members you identify. For example, @w{@kbd{tar --list
  1176. --file=afiles.tar apple}} would only print @file{apple}.
  1177. Because @command{tar} preserves paths, file names must be specified as
  1178. they appear in the archive (i.e., relative to the directory from which
  1179. the archive was created). Therefore, it is essential when specifying
  1180. member names to @command{tar} that you give the exact member names.
  1181. For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
  1182. error message something like @samp{tar: birds: Not found in archive},
  1183. because there is no member named @file{birds}, only one named
  1184. @file{./birds}. While the names @file{birds} and @file{./birds} name
  1185. the same file, @emph{member} names by default are compared verbatim.
  1186. However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
  1187. with @file{baboon}, because this exact member name is in the archive file
  1188. @file{bfiles.tar}. If you are not sure of the exact file name,
  1189. use @dfn{globbing patterns}, for example:
  1190. @smallexample
  1191. $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
  1192. @end smallexample
  1193. @noindent
  1194. will list all members whose name contains @samp{b}. @xref{wildcards},
  1195. for a detailed discussion of globbing patterns and related
  1196. @command{tar} command line options.
  1197. @menu
  1198. * list dir::
  1199. @end menu
  1200. @node list dir
  1201. @unnumberedsubsec Listing the Contents of a Stored Directory
  1202. To get information about the contents of an archived directory,
  1203. use the directory name as a file name argument in conjunction with
  1204. @option{--list} (@option{-t}). To find out file attributes, include the
  1205. @option{--verbose} (@option{-v}) option.
  1206. For example, to find out about files in the directory @file{practice}, in
  1207. the archive file @file{music.tar}, type:
  1208. @smallexample
  1209. $ @kbd{tar --list --verbose --file=music.tar practice}
  1210. @end smallexample
  1211. @command{tar} responds:
  1212. @smallexample
  1213. drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
  1214. -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
  1215. -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
  1216. -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
  1217. -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
  1218. @end smallexample
  1219. When you use a directory name as a file name argument, @command{tar} acts on
  1220. all the files (including sub-directories) in that directory.
  1221. @node extract
  1222. @section How to Extract Members from an Archive
  1223. @UNREVISED
  1224. @cindex Extraction
  1225. @cindex Retrieving files from an archive
  1226. @cindex Resurrecting files from an archive
  1227. @opindex extract
  1228. Creating an archive is only half the job---there is no point in storing
  1229. files in an archive if you can't retrieve them. The act of retrieving
  1230. members from an archive so they can be used and manipulated as
  1231. unarchived files again is called @dfn{extraction}. To extract files
  1232. from an archive, use the @option{--extract} (@option{--get} or
  1233. @option{-x}) operation. As with @option{--create}, specify the name
  1234. of the archive with @option{--file} (@option{-f}) option. Extracting
  1235. an archive does not modify the archive in any way; you can extract it
  1236. multiple times if you want or need to.
  1237. Using @option{--extract}, you can extract an entire archive, or specific
  1238. files. The files can be directories containing other files, or not. As
  1239. with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
  1240. long form of the operation without affecting the performance.
  1241. @menu
  1242. * extracting archives::
  1243. * extracting files::
  1244. * extract dir::
  1245. * extracting untrusted archives::
  1246. * failing commands::
  1247. @end menu
  1248. @node extracting archives
  1249. @subsection Extracting an Entire Archive
  1250. To extract an entire archive, specify the archive file name only, with
  1251. no individual file names as arguments. For example,
  1252. @smallexample
  1253. $ @kbd{tar -xvf collection.tar}
  1254. @end smallexample
  1255. @noindent
  1256. produces this:
  1257. @smallexample
  1258. -rw-r--r-- me user 28 1996-10-18 16:31 jazz
  1259. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  1260. -rw-r--r-- me user 20 1996-09-23 16:44 folk
  1261. @end smallexample
  1262. @node extracting files
  1263. @subsection Extracting Specific Files
  1264. To extract specific archive members, give their exact member names as
  1265. arguments, as printed by @option{--list} (@option{-t}). If you had
  1266. mistakenly deleted one of the files you had placed in the archive
  1267. @file{collection.tar} earlier (say, @file{blues}), you can extract it
  1268. from the archive without changing the archive's structure. Its
  1269. contents will be identical to the original file @file{blues} that you
  1270. deleted.
  1271. First, make sure you are in the @file{practice} directory, and list the
  1272. files in the directory. Now, delete the file, @samp{blues}, and list
  1273. the files in the directory again.
  1274. You can now extract the member @file{blues} from the archive file
  1275. @file{collection.tar} like this:
  1276. @smallexample
  1277. $ @kbd{tar --extract --file=collection.tar blues}
  1278. @end smallexample
  1279. @noindent
  1280. If you list the files in the directory again, you will see that the file
  1281. @file{blues} has been restored, with its original permissions, data
  1282. modification times, and owner.@footnote{This is only accidentally
  1283. true, but not in general. Whereas modification times are always
  1284. restored, in most cases, one has to be root for restoring the owner,
  1285. and use a special option for restoring permissions. Here, it just
  1286. happens that the restoring user is also the owner of the archived
  1287. members, and that the current @code{umask} is compatible with original
  1288. permissions.} (These parameters will be identical to those which
  1289. the file had when you originally placed it in the archive; any changes
  1290. you may have made before deleting the file from the file system,
  1291. however, will @emph{not} have been made to the archive member.) The
  1292. archive file, @samp{collection.tar}, is the same as it was before you
  1293. extracted @samp{blues}. You can confirm this by running @command{tar} with
  1294. @option{--list} (@option{-t}).
  1295. Remember that as with other operations, specifying the exact member
  1296. name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
  1297. will fail, because there is no member named @file{birds}. To extract
  1298. the member named @file{./birds}, you must specify @w{@kbd{tar
  1299. --extract --file=bfiles.tar ./birds}}. If you don't remember the
  1300. exact member names, use @option{--list} (@option{-t}) option
  1301. (@pxref{list}). You can also extract those members that match a
  1302. specific @dfn{globbing pattern}. For example, to extract from
  1303. @file{bfiles.tar} all files that begin with @samp{b}, no matter their
  1304. directory prefix, you could type:
  1305. @smallexample
  1306. $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
  1307. @end smallexample
  1308. @noindent
  1309. Here, @option{--wildcards} instructs @command{tar} to treat
  1310. command line arguments as globbing patterns and @option{--no-anchored}
  1311. informs it that the patterns apply to member names after any @samp{/}
  1312. delimiter. The use of globbing patterns is discussed in detail in
  1313. @xref{wildcards}.
  1314. You can extract a file to standard output by combining the above options
  1315. with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
  1316. Output}).
  1317. If you give the @option{--verbose} option, then @option{--extract}
  1318. will print the names of the archive members as it extracts them.
  1319. @node extract dir
  1320. @subsection Extracting Files that are Directories
  1321. Extracting directories which are members of an archive is similar to
  1322. extracting other files. The main difference to be aware of is that if
  1323. the extracted directory has the same name as any directory already in
  1324. the working directory, then files in the extracted directory will be
  1325. placed into the directory of the same name. Likewise, if there are
  1326. files in the pre-existing directory with the same names as the members
  1327. which you extract, the files from the extracted archive will replace
  1328. the files already in the working directory (and possible
  1329. subdirectories). This will happen regardless of whether or not the
  1330. files in the working directory were more recent than those extracted
  1331. (there exist, however, special options that alter this behavior
  1332. @pxref{Writing}).
  1333. However, if a file was stored with a directory name as part of its file
  1334. name, and that directory does not exist under the working directory when
  1335. the file is extracted, @command{tar} will create the directory.
  1336. We can demonstrate how to use @option{--extract} to extract a directory
  1337. file with an example. Change to the @file{practice} directory if you
  1338. weren't there, and remove the files @file{folk} and @file{jazz}. Then,
  1339. go back to the parent directory and extract the archive
  1340. @file{music.tar}. You may either extract the entire archive, or you may
  1341. extract only the files you just deleted. To extract the entire archive,
  1342. don't give any file names as arguments after the archive name
  1343. @file{music.tar}. To extract only the files you deleted, use the
  1344. following command:
  1345. @smallexample
  1346. $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
  1347. practice/folk
  1348. practice/jazz
  1349. @end smallexample
  1350. @noindent
  1351. If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
  1352. would have displayed more detail about the extracted files, as shown
  1353. in the example below:
  1354. @smallexample
  1355. $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
  1356. -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
  1357. -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
  1358. @end smallexample
  1359. @noindent
  1360. Because you created the directory with @file{practice} as part of the
  1361. file names of each of the files by archiving the @file{practice}
  1362. directory as @file{practice}, you must give @file{practice} as part
  1363. of the file names when you extract those files from the archive.
  1364. @node extracting untrusted archives
  1365. @subsection Extracting Archives from Untrusted Sources
  1366. Extracting files from archives can overwrite files that already exist.
  1367. If you receive an archive from an untrusted source, you should make a
  1368. new directory and extract into that directory, so that you don't have
  1369. to worry about the extraction overwriting one of your existing files.
  1370. For example, if @file{untrusted.tar} came from somewhere else on the
  1371. Internet, and you don't necessarily trust its contents, you can
  1372. extract it as follows:
  1373. @smallexample
  1374. $ @kbd{mkdir newdir}
  1375. $ @kbd{cd newdir}
  1376. $ @kbd{tar -xvf ../untrusted.tar}
  1377. @end smallexample
  1378. It is also a good practice to examine contents of the archive
  1379. before extracting it, using @option{--list} (@option{-t}) option, possibly combined
  1380. with @option{--verbose} (@option{-v}).
  1381. @node failing commands
  1382. @subsection Commands That Will Fail
  1383. Here are some sample commands you might try which will not work, and why
  1384. they won't work.
  1385. If you try to use this command,
  1386. @smallexample
  1387. $ @kbd{tar -xvf music.tar folk jazz}
  1388. @end smallexample
  1389. @noindent
  1390. you will get the following response:
  1391. @smallexample
  1392. tar: folk: Not found in archive
  1393. tar: jazz: Not found in archive
  1394. $
  1395. @end smallexample
  1396. @noindent
  1397. This is because these files were not originally @emph{in} the parent
  1398. directory @file{..}, where the archive is located; they were in the
  1399. @file{practice} directory, and their file names reflect this:
  1400. @smallexample
  1401. $ @kbd{tar -tvf music.tar}
  1402. practice/folk
  1403. practice/jazz
  1404. practice/rock
  1405. @end smallexample
  1406. @FIXME{make sure the above works when going through the examples in
  1407. order...}
  1408. @noindent
  1409. Likewise, if you try to use this command,
  1410. @smallexample
  1411. $ @kbd{tar -tvf music.tar folk jazz}
  1412. @end smallexample
  1413. @noindent
  1414. you would get a similar response. Members with those names are not in the
  1415. archive. You must use the correct member names, or wildcards, in order
  1416. to extract the files from the archive.
  1417. If you have forgotten the correct names of the files in the archive,
  1418. use @w{@kbd{tar --list --verbose}} to list them correctly.
  1419. @FIXME{more examples, here? hag thinks it's a good idea.}
  1420. @node going further
  1421. @section Going Further Ahead in this Manual
  1422. @FIXME{need to write up a node here about the things that are going to
  1423. be in the rest of the manual.}
  1424. @node tar invocation
  1425. @chapter Invoking @GNUTAR{}
  1426. @UNREVISED
  1427. This chapter is about how one invokes the @GNUTAR{}
  1428. command, from the command synopsis (@pxref{Synopsis}). There are
  1429. numerous options, and many styles for writing them. One mandatory
  1430. option specifies the operation @command{tar} should perform
  1431. (@pxref{Operation Summary}), other options are meant to detail how
  1432. this operation should be performed (@pxref{Option Summary}).
  1433. Non-option arguments are not always interpreted the same way,
  1434. depending on what the operation is.
  1435. You will find in this chapter everything about option styles and rules for
  1436. writing them (@pxref{Styles}). On the other hand, operations and options
  1437. are fully described elsewhere, in other chapters. Here, you will find
  1438. only synthetic descriptions for operations and options, together with
  1439. pointers to other parts of the @command{tar} manual.
  1440. Some options are so special they are fully described right in this
  1441. chapter. They have the effect of inhibiting the normal operation of
  1442. @command{tar} or else, they globally alter the amount of feedback the user
  1443. receives about what is going on. These are the @option{--help} and
  1444. @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
  1445. and @option{--interactive} options (@pxref{interactive}).
  1446. @menu
  1447. * Synopsis::
  1448. * using tar options::
  1449. * Styles::
  1450. * All Options::
  1451. * help::
  1452. * defaults::
  1453. * verbose::
  1454. * interactive::
  1455. @end menu
  1456. @node Synopsis
  1457. @section General Synopsis of @command{tar}
  1458. The @GNUTAR{} program is invoked as either one of:
  1459. @smallexample
  1460. @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
  1461. @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
  1462. @end smallexample
  1463. The second form is for when old options are being used.
  1464. You can use @command{tar} to store files in an archive, to extract them from
  1465. an archive, and to do other types of archive manipulation. The primary
  1466. argument to @command{tar}, which is called the @dfn{operation}, specifies
  1467. which action to take. The other arguments to @command{tar} are either
  1468. @dfn{options}, which change the way @command{tar} performs an operation,
  1469. or file names or archive members, which specify the files or members
  1470. @command{tar} is to act on.
  1471. You can actually type in arguments in any order, even if in this manual
  1472. the options always precede the other arguments, to make examples easier
  1473. to understand. Further, the option stating the main operation mode
  1474. (the @command{tar} main command) is usually given first.
  1475. Each @var{name} in the synopsis above is interpreted as an archive member
  1476. name when the main command is one of @option{--compare}
  1477. (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
  1478. (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
  1479. @option{--update} (@option{-u}). When naming archive members, you
  1480. must give the exact name of the member in the archive, as it is
  1481. printed by @option{--list}. For @option{--append} (@option{-r}) and
  1482. @option{--create} (@option{-c}), these @var{name} arguments specify
  1483. the names of either files or directory hierarchies to place in the archive.
  1484. These files or hierarchies should already exist in the file system,
  1485. prior to the execution of the @command{tar} command.
  1486. @command{tar} interprets relative file names as being relative to the
  1487. working directory. @command{tar} will make all file names relative
  1488. (by removing leading slashes when archiving or restoring files),
  1489. unless you specify otherwise (using the @option{--absolute-names}
  1490. option). @xref{absolute}, for more information about
  1491. @option{--absolute-names}.
  1492. If you give the name of a directory as either a file name or a member
  1493. name, then @command{tar} acts recursively on all the files and directories
  1494. beneath that directory. For example, the name @file{/} identifies all
  1495. the files in the file system to @command{tar}.
  1496. The distinction between file names and archive member names is especially
  1497. important when shell globbing is used, and sometimes a source of confusion
  1498. for newcomers. @xref{wildcards}, for more information about globbing.
  1499. The problem is that shells may only glob using existing files in the
  1500. file system. Only @command{tar} itself may glob on archive members, so when
  1501. needed, you must ensure that wildcard characters reach @command{tar} without
  1502. being interpreted by the shell first. Using a backslash before @samp{*}
  1503. or @samp{?}, or putting the whole argument between quotes, is usually
  1504. sufficient for this.
  1505. Even if @var{name}s are often specified on the command line, they
  1506. can also be read from a text file in the file system, using the
  1507. @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
  1508. If you don't use any file name arguments, @option{--append} (@option{-r}),
  1509. @option{--delete} and @option{--concatenate} (@option{--catenate},
  1510. @option{-A}) will do nothing, while @option{--create} (@option{-c})
  1511. will usually yield a diagnostic and inhibit @command{tar} execution.
  1512. The other operations of @command{tar} (@option{--list},
  1513. @option{--extract}, @option{--compare}, and @option{--update})
  1514. will act on the entire contents of the archive.
  1515. @cindex exit status
  1516. @cindex return status
  1517. Besides successful exits, @GNUTAR{} may fail for
  1518. many reasons. Some reasons correspond to bad usage, that is, when the
  1519. @command{tar} command is improperly written. Errors may be
  1520. encountered later, while encountering an error processing the archive
  1521. or the files. Some errors are recoverable, in which case the failure
  1522. is delayed until @command{tar} has completed all its work. Some
  1523. errors are such that it would not meaningful, or at least risky, to
  1524. continue processing: @command{tar} then aborts processing immediately.
  1525. All abnormal exits, whether immediate or delayed, should always be
  1526. clearly diagnosed on @code{stderr}, after a line stating the nature of
  1527. the error.
  1528. @GNUTAR{} returns only a few exit statuses. I'm really
  1529. aiming simplicity in that area, for now. If you are not using the
  1530. @option{--compare} @option{--diff}, @option{-d}) option, zero means
  1531. that everything went well, besides maybe innocuous warnings. Nonzero
  1532. means that something went wrong. Right now, as of today, ``nonzero''
  1533. is almost always 2, except for remote operations, where it may be
  1534. 128.
  1535. @node using tar options
  1536. @section Using @command{tar} Options
  1537. @GNUTAR{} has a total of eight operating modes which
  1538. allow you to perform a variety of tasks. You are required to choose
  1539. one operating mode each time you employ the @command{tar} program by
  1540. specifying one, and only one operation as an argument to the
  1541. @command{tar} command (two lists of four operations each may be found
  1542. at @ref{frequent operations} and @ref{Operations}). Depending on
  1543. circumstances, you may also wish to customize how the chosen operating
  1544. mode behaves. For example, you may wish to change the way the output
  1545. looks, or the format of the files that you wish to archive may require
  1546. you to do something special in order to make the archive look right.
  1547. You can customize and control @command{tar}'s performance by running
  1548. @command{tar} with one or more options (such as @option{--verbose}
  1549. (@option{-v}), which we used in the tutorial). As we said in the
  1550. tutorial, @dfn{options} are arguments to @command{tar} which are (as
  1551. their name suggests) optional. Depending on the operating mode, you
  1552. may specify one or more options. Different options will have different
  1553. effects, but in general they all change details of the operation, such
  1554. as archive format, archive name, or level of user interaction. Some
  1555. options make sense with all operating modes, while others are
  1556. meaningful only with particular modes. You will likely use some
  1557. options frequently, while you will only use others infrequently, or
  1558. not at all. (A full list of options is available in @pxref{All Options}.)
  1559. @vrindex TAR_OPTIONS, environment variable
  1560. @anchor{TAR_OPTIONS}
  1561. The @env{TAR_OPTIONS} environment variable specifies default options to
  1562. be placed in front of any explicit options. For example, if
  1563. @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
  1564. if the two options @option{-v} and @option{--unlink-first} had been
  1565. specified before any explicit options. Option specifications are
  1566. separated by whitespace. A backslash escapes the next character, so it
  1567. can be used to specify an option containing whitespace or a backslash.
  1568. Note that @command{tar} options are case sensitive. For example, the
  1569. options @option{-T} and @option{-t} are different; the first requires an
  1570. argument for stating the name of a file providing a list of @var{name}s,
  1571. while the second does not require an argument and is another way to
  1572. write @option{--list} (@option{-t}).
  1573. In addition to the eight operations, there are many options to
  1574. @command{tar}, and three different styles for writing both: long (mnemonic)
  1575. form, short form, and old style. These styles are discussed below.
  1576. Both the options and the operations can be written in any of these three
  1577. styles.
  1578. @FIXME{menu at end of this node. need to think of an actual outline
  1579. for this chapter; probably do that after stuff from chapter 4 is
  1580. incorporated.}
  1581. @node Styles
  1582. @section The Three Option Styles
  1583. There are three styles for writing operations and options to the command
  1584. line invoking @command{tar}. The different styles were developed at
  1585. different times during the history of @command{tar}. These styles will be
  1586. presented below, from the most recent to the oldest.
  1587. Some options must take an argument. (For example, @option{--file}
  1588. (@option{-f})) takes the name of an archive file as an argument. If
  1589. you do not supply an archive file name, @command{tar} will use a
  1590. default, but this can be confusing; thus, we recommend that you always
  1591. supply a specific archive file name.) Where you @emph{place} the
  1592. arguments generally depends on which style of options you choose. We
  1593. will detail specific information relevant to each option style in the
  1594. sections on the different option styles, below. The differences are
  1595. subtle, yet can often be very important; incorrect option placement
  1596. can cause you to overwrite a number of important files. We urge you
  1597. to note these differences, and only use the option style(s) which
  1598. makes the most sense to you until you feel comfortable with the others.
  1599. Some options @emph{may} take an argument. Such options may have at
  1600. most long and short forms, they do not have old style equivalent. The
  1601. rules for specifying an argument for such options are stricter than
  1602. those for specifying mandatory arguments. Please, pay special
  1603. attention to them.
  1604. @menu
  1605. * Long Options:: Long Option Style
  1606. * Short Options:: Short Option Style
  1607. * Old Options:: Old Option Style
  1608. * Mixing:: Mixing Option Styles
  1609. @end menu
  1610. @node Long Options
  1611. @subsection Long Option Style
  1612. Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
  1613. dashes in a row, e.g., @option{--list}. The long names are more clear than
  1614. their corresponding short or old names. It sometimes happens that a
  1615. single long option has many different different names which are
  1616. synonymous, such as @option{--compare} and @option{--diff}. In addition,
  1617. long option names can be given unique abbreviations. For example,
  1618. @option{--cre} can be used in place of @option{--create} because there is no
  1619. other long option which begins with @samp{cre}. (One way to find
  1620. this out is by trying it and seeing what happens; if a particular
  1621. abbreviation could represent more than one option, @command{tar} will tell
  1622. you that that abbreviation is ambiguous and you'll know that that
  1623. abbreviation won't work. You may also choose to run @samp{tar --help}
  1624. to see a list of options. Be aware that if you run @command{tar} with a
  1625. unique abbreviation for the long name of an option you didn't want to
  1626. use, you are stuck; @command{tar} will perform the command as ordered.)
  1627. Long options are meant to be obvious and easy to remember, and their
  1628. meanings are generally easier to discern than those of their
  1629. corresponding short options (see below). For example:
  1630. @smallexample
  1631. $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
  1632. @end smallexample
  1633. @noindent
  1634. gives a fairly good set of hints about what the command does, even
  1635. for those not fully acquainted with @command{tar}.
  1636. Long options which require arguments take those arguments
  1637. immediately following the option name. There are two ways of
  1638. specifying a mandatory argument. It can be separated from the
  1639. option name either by an equal sign, or by any amount of
  1640. white space characters. For example, the @option{--file} option (which
  1641. tells the name of the @command{tar} archive) is given a file such as
  1642. @file{archive.tar} as argument by using any of the following notations:
  1643. @option{--file=archive.tar} or @option{--file archive.tar}.
  1644. In contrast, optional arguments must always be introduced using
  1645. an equal sign. For example, the @option{--backup} option takes
  1646. an optional argument specifying backup type. It must be used
  1647. as @option{--backup=@var{backup-type}}.
  1648. @node Short Options
  1649. @subsection Short Option Style
  1650. Most options also have a @dfn{short option} name. Short options start with
  1651. a single dash, and are followed by a single character, e.g., @option{-t}
  1652. (which is equivalent to @option{--list}). The forms are absolutely
  1653. identical in function; they are interchangeable.
  1654. The short option names are faster to type than long option names.
  1655. Short options which require arguments take their arguments immediately
  1656. following the option, usually separated by white space. It is also
  1657. possible to stick the argument right after the short option name, using
  1658. no intervening space. For example, you might write @w{@option{-f
  1659. archive.tar}} or @option{-farchive.tar} instead of using
  1660. @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
  1661. @w{@option{-f @var{archive-name}}} denote the option which indicates a
  1662. specific archive, here named @file{archive.tar}.
  1663. Short options which take optional arguments take their arguments
  1664. immediately following the option letter, @emph{without any intervening
  1665. white space characters}.
  1666. Short options' letters may be clumped together, but you are not
  1667. required to do this (as compared to old options; see below). When
  1668. short options are clumped as a set, use one (single) dash for them
  1669. all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
  1670. such a set is allowed to have an argument@footnote{Clustering many
  1671. options, the last of which has an argument, is a rather opaque way to
  1672. write options. Some wonder if @acronym{GNU} @code{getopt} should not
  1673. even be made helpful enough for considering such usages as invalid.}.
  1674. When the options are separated, the argument for each option which requires
  1675. an argument directly follows that option, as is usual for Unix programs.
  1676. For example:
  1677. @smallexample
  1678. $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
  1679. @end smallexample
  1680. If you reorder short options' locations, be sure to move any arguments
  1681. that belong to them. If you do not move the arguments properly, you may
  1682. end up overwriting files.
  1683. @node Old Options
  1684. @subsection Old Option Style
  1685. @UNREVISED
  1686. Like short options, @dfn{old options} are single letters. However, old options
  1687. must be written together as a single clumped set, without spaces separating
  1688. them or dashes preceding them@footnote{Beware that if you precede options
  1689. with a dash, you are announcing the short option style instead of the
  1690. old option style; short options are decoded differently.}. This set
  1691. of letters must be the first to appear on the command line, after the
  1692. @command{tar} program name and some white space; old options cannot appear
  1693. anywhere else. The letter of an old option is exactly the same letter as
  1694. the corresponding short option. For example, the old option @samp{t} is
  1695. the same as the short option @option{-t}, and consequently, the same as the
  1696. long option @option{--list}. So for example, the command @w{@samp{tar
  1697. cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
  1698. When options that need arguments are given together with the command,
  1699. all the associated arguments follow, in the same order as the options.
  1700. Thus, the example given previously could also be written in the old
  1701. style as follows:
  1702. @smallexample
  1703. $ @kbd{tar cvbf 20 /dev/rmt0}
  1704. @end smallexample
  1705. @noindent
  1706. Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
  1707. the argument of @option{-f}.
  1708. On the other hand, this old style syntax makes it difficult to match
  1709. option letters with their corresponding arguments, and is often
  1710. confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
  1711. @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
  1712. argument for @option{-f}, and @option{-v} does not have a corresponding
  1713. argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
  1714. /dev/rmt0}} is clearer, putting all arguments next to the option they
  1715. pertain to.
  1716. If you want to reorder the letters in the old option argument, be
  1717. sure to reorder any corresponding argument appropriately.
  1718. This old way of writing @command{tar} options can surprise even experienced
  1719. users. For example, the two commands:
  1720. @smallexample
  1721. @kbd{tar cfz archive.tar.gz file}
  1722. @kbd{tar -cfz archive.tar.gz file}
  1723. @end smallexample
  1724. @noindent
  1725. are quite different. The first example uses @file{archive.tar.gz} as
  1726. the value for option @samp{f} and recognizes the option @samp{z}. The
  1727. second example, however, uses @file{z} as the value for option
  1728. @samp{f} --- probably not what was intended.
  1729. Old options are kept for compatibility with old versions of @command{tar}.
  1730. This second example could be corrected in many ways, among which the
  1731. following are equivalent:
  1732. @smallexample
  1733. @kbd{tar -czf archive.tar.gz file}
  1734. @kbd{tar -cf archive.tar.gz -z file}
  1735. @kbd{tar cf archive.tar.gz -z file}
  1736. @end smallexample
  1737. @cindex option syntax, traditional
  1738. As far as we know, all @command{tar} programs, @acronym{GNU} and
  1739. non-@acronym{GNU}, support old options. @GNUTAR{}
  1740. supports them not only for historical reasons, but also because many
  1741. people are used to them. For compatibility with Unix @command{tar},
  1742. the first argument is always treated as containing command and option
  1743. letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
  1744. equivalent to @w{@samp{tar -c}:} both of them specify the
  1745. @option{--create} (@option{-c}) command to create an archive.
  1746. @node Mixing
  1747. @subsection Mixing Option Styles
  1748. All three styles may be intermixed in a single @command{tar} command,
  1749. so long as the rules for each style are fully
  1750. respected@footnote{Before @GNUTAR{} version 1.11.6,
  1751. a bug prevented intermixing old style options with long options in
  1752. some cases.}. Old style options and either of the modern styles of
  1753. options may be mixed within a single @command{tar} command. However,
  1754. old style options must be introduced as the first arguments only,
  1755. following the rule for old options (old options must appear directly
  1756. after the @command{tar} command and some white space). Modern options
  1757. may be given only after all arguments to the old options have been
  1758. collected. If this rule is not respected, a modern option might be
  1759. falsely interpreted as the value of the argument to one of the old
  1760. style options.
  1761. For example, all the following commands are wholly equivalent, and
  1762. illustrate the many combinations and orderings of option styles.
  1763. @smallexample
  1764. @kbd{tar --create --file=archive.tar}
  1765. @kbd{tar --create -f archive.tar}
  1766. @kbd{tar --create -farchive.tar}
  1767. @kbd{tar --file=archive.tar --create}
  1768. @kbd{tar --file=archive.tar -c}
  1769. @kbd{tar -c --file=archive.tar}
  1770. @kbd{tar -c -f archive.tar}
  1771. @kbd{tar -c -farchive.tar}
  1772. @kbd{tar -cf archive.tar}
  1773. @kbd{tar -cfarchive.tar}
  1774. @kbd{tar -f archive.tar --create}
  1775. @kbd{tar -f archive.tar -c}
  1776. @kbd{tar -farchive.tar --create}
  1777. @kbd{tar -farchive.tar -c}
  1778. @kbd{tar c --file=archive.tar}
  1779. @kbd{tar c -f archive.tar}
  1780. @kbd{tar c -farchive.tar}
  1781. @kbd{tar cf archive.tar}
  1782. @kbd{tar f archive.tar --create}
  1783. @kbd{tar f archive.tar -c}
  1784. @kbd{tar fc archive.tar}
  1785. @end smallexample
  1786. On the other hand, the following commands are @emph{not} equivalent to
  1787. the previous set:
  1788. @smallexample
  1789. @kbd{tar -f -c archive.tar}
  1790. @kbd{tar -fc archive.tar}
  1791. @kbd{tar -fcarchive.tar}
  1792. @kbd{tar -farchive.tarc}
  1793. @kbd{tar cfarchive.tar}
  1794. @end smallexample
  1795. @noindent
  1796. These last examples mean something completely different from what the
  1797. user intended (judging based on the example in the previous set which
  1798. uses long options, whose intent is therefore very clear). The first
  1799. four specify that the @command{tar} archive would be a file named
  1800. @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
  1801. respectively. The first two examples also specify a single non-option,
  1802. @var{name} argument having the value @samp{archive.tar}. The last
  1803. example contains only old style option letters (repeating option
  1804. @samp{c} twice), not all of which are meaningful (eg., @samp{.},
  1805. @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
  1806. the first sentence of this paragraph..}
  1807. @node All Options
  1808. @section All @command{tar} Options
  1809. The coming manual sections contain an alphabetical listing of all
  1810. @command{tar} operations and options, with brief descriptions and cross
  1811. references to more in-depth explanations in the body of the manual.
  1812. They also contain an alphabetically arranged table of the short option
  1813. forms with their corresponding long option. You can use this table as
  1814. a reference for deciphering @command{tar} commands in scripts.
  1815. @menu
  1816. * Operation Summary::
  1817. * Option Summary::
  1818. * Short Option Summary::
  1819. @end menu
  1820. @node Operation Summary
  1821. @subsection Operations
  1822. @table @option
  1823. @opsummary{append}
  1824. @item --append
  1825. @itemx -r
  1826. Appends files to the end of the archive. @xref{append}.
  1827. @opsummary{catenate}
  1828. @item --catenate
  1829. @itemx -A
  1830. Same as @option{--concatenate}. @xref{concatenate}.
  1831. @opsummary{compare}
  1832. @item --compare
  1833. @itemx -d
  1834. Compares archive members with their counterparts in the file
  1835. system, and reports differences in file size, mode, owner,
  1836. modification date and contents. @xref{compare}.
  1837. @opsummary{concatenate}
  1838. @item --concatenate
  1839. @itemx -A
  1840. Appends other @command{tar} archives to the end of the archive.
  1841. @xref{concatenate}.
  1842. @opsummary{create}
  1843. @item --create
  1844. @itemx -c
  1845. Creates a new @command{tar} archive. @xref{create}.
  1846. @opsummary{delete}
  1847. @item --delete
  1848. Deletes members from the archive. Don't try this on a archive on a
  1849. tape! @xref{delete}.
  1850. @opsummary{diff}
  1851. @item --diff
  1852. @itemx -d
  1853. Same @option{--compare}. @xref{compare}.
  1854. @opsummary{extract}
  1855. @item --extract
  1856. @itemx -x
  1857. Extracts members from the archive into the file system. @xref{extract}.
  1858. @opsummary{get}
  1859. @item --get
  1860. @itemx -x
  1861. Same as @option{--extract}. @xref{extract}.
  1862. @opsummary{list}
  1863. @item --list
  1864. @itemx -t
  1865. Lists the members in an archive. @xref{list}.
  1866. @opsummary{update}
  1867. @item --update
  1868. @itemx -u
  1869. Adds files to the end of the archive, but only if they are newer than
  1870. their counterparts already in the archive, or if they do not already
  1871. exist in the archive. @xref{update}.
  1872. @end table
  1873. @node Option Summary
  1874. @subsection @command{tar} Options
  1875. @table @option
  1876. @opsummary{absolute-names}
  1877. @item --absolute-names
  1878. @itemx -P
  1879. Normally when creating an archive, @command{tar} strips an initial
  1880. @samp{/} from member names. This option disables that behavior.
  1881. @xref{absolute}.
  1882. @opsummary{after-date}
  1883. @item --after-date
  1884. (See @option{--newer}, @pxref{after})
  1885. @opsummary{anchored}
  1886. @item --anchored
  1887. A pattern must match an initial subsequence of the name's components.
  1888. @xref{controlling pattern-matching}.
  1889. @opsummary{atime-preserve}
  1890. @item --atime-preserve
  1891. @itemx --atime-preserve=replace
  1892. @itemx --atime-preserve=system
  1893. Attempt to preserve the access time of files when reading them. This
  1894. option currently is effective only on files that you own, unless you
  1895. have superuser privileges.
  1896. @option{--atime-preserve=replace} remembers the access time of a file
  1897. before reading it, and then restores the access time afterwards. This
  1898. may cause problems if other programs are reading the file at the same
  1899. time, as the times of their accesses will be lost. On most platforms
  1900. restoring the access time also requires @command{tar} to restore the
  1901. data modification time too, so this option may also cause problems if
  1902. other programs are writing the file at the same time. (Tar attempts
  1903. to detect this situation, but cannot do so reliably due to race
  1904. conditions.) Worse, on most platforms restoring the access time also
  1905. updates the status change time, which means that this option is
  1906. incompatible with incremental backups.
  1907. @option{--atime-preserve=system} avoids changing time stamps on files,
  1908. without interfering with time stamp updates
  1909. caused by other programs, so it works better with incremental backups.
  1910. However, it requires a special @code{O_NOATIME} option from the
  1911. underlying operating and file system implementation, and it also requires
  1912. that searching directories does not update their access times. As of
  1913. this writing (November 2005) this works only with Linux, and only with
  1914. Linux kernels 2.6.8 and later. Worse, there is currently no reliable
  1915. way to know whether this feature actually works. Sometimes
  1916. @command{tar} knows that it does not work, and if you use
  1917. @option{--atime-preserve=system} then @command{tar} complains and
  1918. exits right away. But other times @command{tar} might think that the
  1919. option works when it actually does not.
  1920. Currently @option{--atime-preserve} with no operand defaults to
  1921. @option{--atime-preserve=replace}, but this may change in the future
  1922. as support for @option{--atime-preserve=system} improves.
  1923. If your operating system does not support
  1924. @option{--atime-preserve=@-system}, you might be able to preserve access
  1925. times reliably by by using the @command{mount} command. For example,
  1926. you can mount the file system read-only, or access the file system via
  1927. a read-only loopback mount, or use the @samp{noatime} mount option
  1928. available on some systems. However, mounting typically requires
  1929. superuser privileges and can be a pain to manage.
  1930. @opsummary{backup}
  1931. @item --backup=@var{backup-type}
  1932. Rather than deleting files from the file system, @command{tar} will
  1933. back them up using simple or numbered backups, depending upon
  1934. @var{backup-type}. @xref{backup}.
  1935. @opsummary{block-number}
  1936. @item --block-number
  1937. @itemx -R
  1938. With this option present, @command{tar} prints error messages for read errors
  1939. with the block number in the archive file. @xref{block-number}.
  1940. @opsummary{blocking-factor}
  1941. @item --blocking-factor=@var{blocking}
  1942. @itemx -b @var{blocking}
  1943. Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
  1944. record. @xref{Blocking Factor}.
  1945. @opsummary{bzip2}
  1946. @item --bzip2
  1947. @itemx -j
  1948. This option tells @command{tar} to read or write archives through
  1949. @code{bzip2}. @xref{gzip}.
  1950. @opsummary{checkpoint}
  1951. @item --checkpoint[=@var{number}]
  1952. This option directs @command{tar} to print periodic checkpoint
  1953. messages as it reads through the archive. It is intended for when you
  1954. want a visual indication that @command{tar} is still running, but
  1955. don't want to see @option{--verbose} output. For a detailed
  1956. description, see @ref{Progress information}.
  1957. @opsummary{check-links}
  1958. @item --check-links
  1959. @itemx -l
  1960. If this option was given, @command{tar} will check the number of links
  1961. dumped for each processed file. If this number does not match the
  1962. total number of hard links for the file, a warning message will be
  1963. output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
  1964. synonym for @option{--one-file-system}. The current semantics, which
  1965. complies to UNIX98, was introduced with version
  1966. 1.15.91. @xref{Changes}, for more information.}.
  1967. @opsummary{compress}
  1968. @opsummary{uncompress}
  1969. @item --compress
  1970. @itemx --uncompress
  1971. @itemx -Z
  1972. @command{tar} will use the @command{compress} program when reading or
  1973. writing the archive. This allows you to directly act on archives
  1974. while saving space. @xref{gzip}.
  1975. @opsummary{confirmation}
  1976. @item --confirmation
  1977. (See @option{--interactive}.) @xref{interactive}.
  1978. @opsummary{delay-directory-restore}
  1979. @item --delay-directory-restore
  1980. Delay setting modification times and permissions of extracted
  1981. directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
  1982. @opsummary{dereference}
  1983. @item --dereference
  1984. @itemx -h
  1985. When creating a @command{tar} archive, @command{tar} will archive the
  1986. file that a symbolic link points to, rather than archiving the
  1987. symlink. @xref{dereference}.
  1988. @opsummary{directory}
  1989. @item --directory=@var{dir}
  1990. @itemx -C @var{dir}
  1991. When this option is specified, @command{tar} will change its current directory
  1992. to @var{dir} before performing any operations. When this option is used
  1993. during archive creation, it is order sensitive. @xref{directory}.
  1994. @opsummary{exclude}
  1995. @item --exclude=@var{pattern}
  1996. When performing operations, @command{tar} will skip files that match
  1997. @var{pattern}. @xref{exclude}.
  1998. @opsummary{exclude-from}
  1999. @item --exclude-from=@var{file}
  2000. @itemx -X @var{file}
  2001. Similar to @option{--exclude}, except @command{tar} will use the list of
  2002. patterns in the file @var{file}. @xref{exclude}.
  2003. @opsummary{exclude-caches}
  2004. @item --exclude-caches
  2005. Automatically excludes all directories
  2006. containing a cache directory tag. @xref{exclude}.
  2007. @opsummary{file}
  2008. @item --file=@var{archive}
  2009. @itemx -f @var{archive}
  2010. @command{tar} will use the file @var{archive} as the @command{tar} archive it
  2011. performs operations on, rather than @command{tar}'s compilation dependent
  2012. default. @xref{file tutorial}.
  2013. @opsummary{files-from}
  2014. @item --files-from=@var{file}
  2015. @itemx -T @var{file}
  2016. @command{tar} will use the contents of @var{file} as a list of archive members
  2017. or files to operate on, in addition to those specified on the
  2018. command-line. @xref{files}.
  2019. @opsummary{force-local}
  2020. @item --force-local
  2021. Forces @command{tar} to interpret the filename given to @option{--file}
  2022. as a local file, even if it looks like a remote tape drive name.
  2023. @xref{local and remote archives}.
  2024. @opsummary{format}
  2025. @item --format=@var{format}
  2026. @itemx -H @var{format}
  2027. Selects output archive format. @var{Format} may be one of the
  2028. following:
  2029. @table @samp
  2030. @item v7
  2031. Creates an archive that is compatible with Unix V7 @command{tar}.
  2032. @item oldgnu
  2033. Creates an archive that is compatible with GNU @command{tar} version
  2034. 1.12 or earlier.
  2035. @item gnu
  2036. Creates archive in GNU tar 1.13 format. Basically it is the same as
  2037. @samp{oldgnu} with the only difference in the way it handles long
  2038. numeric fields.
  2039. @item ustar
  2040. Creates a @acronym{POSIX.1-1988} compatible archive.
  2041. @item posix
  2042. Creates a @acronym{POSIX.1-2001 archive}.
  2043. @end table
  2044. @xref{Formats}, for a detailed discussion of these formats.
  2045. @opsummary{group}
  2046. @item --group=@var{group}
  2047. Files added to the @command{tar} archive will have a group id of @var{group},
  2048. rather than the group from the source file. @var{group} is first decoded
  2049. as a group symbolic name, but if this interpretation fails, it has to be
  2050. a decimal numeric group ID. @xref{override}.
  2051. Also see the comments for the @option{--owner=@var{user}} option.
  2052. @opsummary{gzip}
  2053. @opsummary{gunzip}
  2054. @opsummary{ungzip}
  2055. @item --gzip
  2056. @itemx --gunzip
  2057. @itemx --ungzip
  2058. @itemx -z
  2059. This option tells @command{tar} to read or write archives through
  2060. @command{gzip}, allowing @command{tar} to directly operate on several
  2061. kinds of compressed archives transparently. @xref{gzip}.
  2062. @opsummary{help}
  2063. @item --help
  2064. @itemx -?
  2065. @command{tar} will print out a short message summarizing the operations and
  2066. options to @command{tar} and exit. @xref{help}.
  2067. @opsummary{ignore-case}
  2068. @item --ignore-case
  2069. Ignore case when matching member or file names with
  2070. patterns. @xref{controlling pattern-matching}.
  2071. @opsummary{ignore-command-error}
  2072. @item --ignore-command-error
  2073. Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
  2074. @opsummary{ignore-failed-read}
  2075. @item --ignore-failed-read
  2076. Do not exit unsuccessfully merely because an unreadable file was encountered.
  2077. @xref{Reading}.
  2078. @opsummary{ignore-zeros}
  2079. @item --ignore-zeros
  2080. @itemx -i
  2081. With this option, @command{tar} will ignore zeroed blocks in the
  2082. archive, which normally signals EOF. @xref{Reading}.
  2083. @opsummary{incremental}
  2084. @item --incremental
  2085. @itemx -G
  2086. Used to inform @command{tar} that it is working with an old
  2087. @acronym{GNU}-format incremental backup archive. It is intended
  2088. primarily for backwards compatibility only. @xref{Incremental Dumps},
  2089. for a detailed discussion of incremental archives.
  2090. @opsummary{index-file}
  2091. @item --index-file=@var{file}
  2092. Send verbose output to @var{file} instead of to standard output.
  2093. @opsummary{info-script}
  2094. @opsummary{new-volume-script}
  2095. @item --info-script=@var{script-file}
  2096. @itemx --new-volume-script=@var{script-file}
  2097. @itemx -F @var{script-file}
  2098. When @command{tar} is performing multi-tape backups, @var{script-file} is run
  2099. at the end of each tape. If @var{script-file} exits with nonzero status,
  2100. @command{tar} fails immediately. @xref{info-script}, for a detailed
  2101. discussion of @var{script-file}.
  2102. @opsummary{interactive}
  2103. @item --interactive
  2104. @itemx --confirmation
  2105. @itemx -w
  2106. Specifies that @command{tar} should ask the user for confirmation before
  2107. performing potentially destructive options, such as overwriting files.
  2108. @xref{interactive}.
  2109. @opsummary{keep-newer-files}
  2110. @item --keep-newer-files
  2111. Do not replace existing files that are newer than their archive copies
  2112. when extracting files from an archive.
  2113. @opsummary{keep-old-files}
  2114. @item --keep-old-files
  2115. @itemx -k
  2116. Do not overwrite existing files when extracting files from an archive.
  2117. @xref{Keep Old Files}.
  2118. @opsummary{label}
  2119. @item --label=@var{name}
  2120. @itemx -V @var{name}
  2121. When creating an archive, instructs @command{tar} to write @var{name}
  2122. as a name record in the archive. When extracting or listing archives,
  2123. @command{tar} will only operate on archives that have a label matching
  2124. the pattern specified in @var{name}. @xref{Tape Files}.
  2125. @opsummary{listed-incremental}
  2126. @item --listed-incremental=@var{snapshot-file}
  2127. @itemx -g @var{snapshot-file}
  2128. During a @option{--create} operation, specifies that the archive that
  2129. @command{tar} creates is a new @acronym{GNU}-format incremental
  2130. backup, using @var{snapshot-file} to determine which files to backup.
  2131. With other operations, informs @command{tar} that the archive is in
  2132. incremental format. @xref{Incremental Dumps}.
  2133. @opsummary{mode}
  2134. @item --mode=@var{permissions}
  2135. When adding files to an archive, @command{tar} will use
  2136. @var{permissions} for the archive members, rather than the permissions
  2137. from the files. @var{permissions} can be specified either as an octal
  2138. number or as symbolic permissions, like with
  2139. @command{chmod}. @xref{override}.
  2140. @opsummary{mtime}
  2141. @item --mtime=@var{date}
  2142. When adding files to an archive, @command{tar} will use @var{date} as
  2143. the modification time of members when creating archives, instead of
  2144. their actual modification times. The value of @var{date} can be
  2145. either a textual date representation (@pxref{Date input formats}) or a
  2146. name of the existing file, starting with @samp{/} or @samp{.}. In the
  2147. latter case, the modification time of that file is used. @xref{override}.
  2148. @opsummary{multi-volume}
  2149. @item --multi-volume
  2150. @itemx -M
  2151. Informs @command{tar} that it should create or otherwise operate on a
  2152. multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
  2153. @opsummary{new-volume-script}
  2154. @item --new-volume-script
  2155. (see --info-script)
  2156. @opsummary{seek}
  2157. @item --seek
  2158. @itemx -n
  2159. Assume that the archive media supports seeks to arbitrary
  2160. locations. Usually @command{tar} determines automatically whether
  2161. the archive can be seeked or not. This option is intended for use
  2162. in cases when such recognition fails.
  2163. @opsummary{newer}
  2164. @item --newer=@var{date}
  2165. @itemx --after-date=@var{date}
  2166. @itemx -N
  2167. When creating an archive, @command{tar} will only add files that have changed
  2168. since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
  2169. is taken to be the name of a file whose data modification time specifies
  2170. the date. @xref{after}.
  2171. @opsummary{newer-mtime}
  2172. @item --newer-mtime=@var{date}
  2173. Like @option{--newer}, but add only files whose
  2174. contents have changed (as opposed to just @option{--newer}, which will
  2175. also back up files for which any status information has
  2176. changed). @xref{after}.
  2177. @opsummary{no-anchored}
  2178. @item --no-anchored
  2179. An exclude pattern can match any subsequence of the name's components.
  2180. @xref{controlling pattern-matching}.
  2181. @opsummary{no-delay-directory-restore}
  2182. @item --no-delay-directory-restore
  2183. Setting modification times and permissions of extracted
  2184. directories when all files from this directory has been
  2185. extracted. This is the default. @xref{Directory Modification Times and Permissions}.
  2186. @opsummary{no-ignore-case}
  2187. @item --no-ignore-case
  2188. Use case-sensitive matching.
  2189. @xref{controlling pattern-matching}.
  2190. @opsummary{no-ignore-command-error}
  2191. @item --no-ignore-command-error
  2192. Print warnings about subprocesses terminated with a non-zero exit
  2193. code. @xref{Writing to an External Program}.
  2194. @opsummary{no-overwrite-dir}
  2195. @item --no-overwrite-dir
  2196. Preserve metadata of existing directories when extracting files
  2197. from an archive. @xref{Overwrite Old Files}.
  2198. @opsummary{no-quote-chars}
  2199. @item --no-quote-chars=@var{string}
  2200. Remove characters listed in @var{string} from the list of quoted
  2201. characters set by the previous @option{--quote-chars} option
  2202. (@pxref{quoting styles}).
  2203. @opsummary{no-recursion}
  2204. @item --no-recursion
  2205. With this option, @command{tar} will not recurse into directories.
  2206. @xref{recurse}.
  2207. @opsummary{no-same-owner}
  2208. @item --no-same-owner
  2209. @itemx -o
  2210. When extracting an archive, do not attempt to preserve the owner
  2211. specified in the @command{tar} archive. This the default behavior
  2212. for ordinary users.
  2213. @opsummary{no-same-permissions}
  2214. @item --no-same-permissions
  2215. When extracting an archive, subtract the user's umask from files from
  2216. the permissions specified in the archive. This is the default behavior
  2217. for ordinary users.
  2218. @opsummary{no-unquote}
  2219. @item --no-unquote
  2220. Treat all input file or member names literally, do not interpret
  2221. escape sequences. @xref{input name quoting}.
  2222. @opsummary{no-wildcards}
  2223. @item --no-wildcards
  2224. Do not use wildcards.
  2225. @xref{controlling pattern-matching}.
  2226. @opsummary{no-wildcards-match-slash}
  2227. @item --no-wildcards-match-slash
  2228. Wildcards do not match @samp{/}.
  2229. @xref{controlling pattern-matching}.
  2230. @opsummary{null}
  2231. @item --null
  2232. When @command{tar} is using the @option{--files-from} option, this option
  2233. instructs @command{tar} to expect filenames terminated with @option{NUL}, so
  2234. @command{tar} can correctly work with file names that contain newlines.
  2235. @xref{nul}.
  2236. @opsummary{numeric-owner}
  2237. @item --numeric-owner
  2238. This option will notify @command{tar} that it should use numeric user
  2239. and group IDs when creating a @command{tar} file, rather than names.
  2240. @xref{Attributes}.
  2241. @item -o
  2242. The function of this option depends on the action @command{tar} is
  2243. performing. When extracting files, @option{-o} is a synonym for
  2244. @option{--no-same-owner}, i.e. it prevents @command{tar} from
  2245. restoring ownership of files being extracted.
  2246. When creating an archive, it is a synonym for
  2247. @option{--old-archive}. This behavior is for compatibility
  2248. with previous versions of @GNUTAR{}, and will be
  2249. removed in the future releases.
  2250. @xref{Changes}, for more information.
  2251. @opsummary{occurrence}
  2252. @item --occurrence[=@var{number}]
  2253. This option can be used in conjunction with one of the subcommands
  2254. @option{--delete}, @option{--diff}, @option{--extract} or
  2255. @option{--list} when a list of files is given either on the command
  2256. line or via @option{-T} option.
  2257. This option instructs @command{tar} to process only the @var{number}th
  2258. occurrence of each named file. @var{Number} defaults to 1, so
  2259. @smallexample
  2260. tar -x -f archive.tar --occurrence filename
  2261. @end smallexample
  2262. @noindent
  2263. will extract the first occurrence of the member @file{filename} from @file{archive.tar}
  2264. and will terminate without scanning to the end of the archive.
  2265. @opsummary{old-archive}
  2266. @item --old-archive
  2267. Synonym for @option{--format=v7}.
  2268. @opsummary{one-file-system}
  2269. @item --one-file-system
  2270. Used when creating an archive. Prevents @command{tar} from recursing into
  2271. directories that are on different file systems from the current
  2272. directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
  2273. synonym for @option{--one-file-system}. This has changed in version
  2274. 1.15.91. @xref{Changes}, for more information.}.
  2275. @opsummary{overwrite}
  2276. @item --overwrite
  2277. Overwrite existing files and directory metadata when extracting files
  2278. from an archive. @xref{Overwrite Old Files}.
  2279. @opsummary{overwrite-dir}
  2280. @item --overwrite-dir
  2281. Overwrite the metadata of existing directories when extracting files
  2282. from an archive. @xref{Overwrite Old Files}.
  2283. @opsummary{owner}
  2284. @item --owner=@var{user}
  2285. Specifies that @command{tar} should use @var{user} as the owner of members
  2286. when creating archives, instead of the user associated with the source
  2287. file. @var{user} is first decoded as a user symbolic name, but if
  2288. this interpretation fails, it has to be a decimal numeric user ID.
  2289. @xref{override}.
  2290. This option does not affect extraction from archives.
  2291. @opsummary{transform}
  2292. @item --transform=@var{sed-expr}
  2293. Transform file or member names using @command{sed} replacement expression
  2294. @var{sed-expr}. For example,
  2295. @smallexample
  2296. $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
  2297. @end smallexample
  2298. @noindent
  2299. will add to @file{archive} files from the current working directory,
  2300. replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
  2301. discussion, @xref{transform}.
  2302. To see transformed member names in verbose listings, use
  2303. @option{--show-transformed-names} option
  2304. (@pxref{show-transformed-names}).
  2305. @opsummary{quote-chars}
  2306. @item --quote-chars=@var{string}
  2307. Always quote characters from @var{string}, even if the selected
  2308. quoting style would not quote them (@pxref{quoting styles}).
  2309. @opsummary{quoting-style}
  2310. @item --quoting-style=@var{style}
  2311. Set quoting style to use when printing member and file names
  2312. (@pxref{quoting styles}). Valid @var{style} values are:
  2313. @code{literal}, @code{shell}, @code{shell-always}, @code{c},
  2314. @code{escape}, @code{locale}, and @code{clocale}. Default quoting
  2315. style is @code{escape}, unless overridden while configuring the
  2316. package.
  2317. @opsummary{pax-option}
  2318. @item --pax-option=@var{keyword-list}
  2319. This option is meaningful only with @acronym{POSIX.1-2001} archives
  2320. (@pxref{posix}). It modifies the way @command{tar} handles the
  2321. extended header keywords. @var{Keyword-list} is a comma-separated
  2322. list of keyword options. @xref{PAX keywords}, for a detailed
  2323. discussion.
  2324. @opsummary{portability}
  2325. @item --portability
  2326. @itemx --old-archive
  2327. Synonym for @option{--format=v7}.
  2328. @opsummary{posix}
  2329. @item --posix
  2330. Same as @option{--format=posix}.
  2331. @opsummary{preserve}
  2332. @item --preserve
  2333. Synonymous with specifying both @option{--preserve-permissions} and
  2334. @option{--same-order}. @xref{Setting Access Permissions}.
  2335. @opsummary{preserve-order}
  2336. @item --preserve-order
  2337. (See @option{--same-order}; @pxref{Reading}.)
  2338. @opsummary{preserve-permissions}
  2339. @opsummary{same-permissions}
  2340. @item --preserve-permissions
  2341. @itemx --same-permissions
  2342. @itemx -p
  2343. When @command{tar} is extracting an archive, it normally subtracts the
  2344. users' umask from the permissions specified in the archive and uses
  2345. that number as the permissions to create the destination file.
  2346. Specifying this option instructs @command{tar} that it should use the
  2347. permissions directly from the archive. @xref{Setting Access Permissions}.
  2348. @opsummary{read-full-records}
  2349. @item --read-full-records
  2350. @itemx -B
  2351. Specifies that @command{tar} should reblock its input, for reading
  2352. from pipes on systems with buggy implementations. @xref{Reading}.
  2353. @opsummary{record-size}
  2354. @item --record-size=@var{size}
  2355. Instructs @command{tar} to use @var{size} bytes per record when accessing the
  2356. archive. @xref{Blocking Factor}.
  2357. @opsummary{recursion}
  2358. @item --recursion
  2359. With this option, @command{tar} recurses into directories.
  2360. @xref{recurse}.
  2361. @opsummary{recursive-unlink}
  2362. @item --recursive-unlink
  2363. Remove existing
  2364. directory hierarchies before extracting directories of the same name
  2365. from the archive. @xref{Recursive Unlink}.
  2366. @opsummary{remove-files}
  2367. @item --remove-files
  2368. Directs @command{tar} to remove the source file from the file system after
  2369. appending it to an archive. @xref{remove files}.
  2370. @opsummary{restrict}
  2371. @item --restrict
  2372. Disable use of some potentially harmful @command{tar} options.
  2373. Currently this option disables shell invocaton from multi-volume menu
  2374. (@pxref{Using Multiple Tapes}).
  2375. @opsummary{rmt-command}
  2376. @item --rmt-command=@var{cmd}
  2377. Notifies @command{tar} that it should use @var{cmd} instead of
  2378. the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
  2379. @opsummary{rsh-command}
  2380. @item --rsh-command=@var{cmd}
  2381. Notifies @command{tar} that is should use @var{cmd} to communicate with remote
  2382. devices. @xref{Device}.
  2383. @opsummary{same-order}
  2384. @item --same-order
  2385. @itemx --preserve-order
  2386. @itemx -s
  2387. This option is an optimization for @command{tar} when running on machines with
  2388. small amounts of memory. It informs @command{tar} that the list of file
  2389. arguments has already been sorted to match the order of files in the
  2390. archive. @xref{Reading}.
  2391. @opsummary{same-owner}
  2392. @item --same-owner
  2393. When extracting an archive, @command{tar} will attempt to preserve the owner
  2394. specified in the @command{tar} archive with this option present.
  2395. This is the default behavior for the superuser; this option has an
  2396. effect only for ordinary users. @xref{Attributes}.
  2397. @opsummary{same-permissions}
  2398. @item --same-permissions
  2399. (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
  2400. @opsummary{show-defaults}
  2401. @item --show-defaults
  2402. Displays the default options used by @command{tar} and exits
  2403. successfully. This option is intended for use in shell scripts.
  2404. Here is an example of what you can see using this option:
  2405. @smallexample
  2406. $ tar --show-defaults
  2407. --format=gnu -f- -b20 --quoting-style=escape \
  2408. --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
  2409. @end smallexample
  2410. @opsummary{show-omitted-dirs}
  2411. @item --show-omitted-dirs
  2412. Instructs @command{tar} to mention directories its skipping over when
  2413. operating on a @command{tar} archive. @xref{show-omitted-dirs}.
  2414. @opsummary{show-transformed-names}
  2415. @opsummary{show-stored-names}
  2416. @item --show-transformed-names
  2417. @itemx --show-stored-names
  2418. Display file or member names after applying any transformations
  2419. (@pxref{transform}). In particular, when used in conjunction with one of
  2420. archive creation operations it instructs tar to list the member names
  2421. stored in the archive, as opposed to the actual file
  2422. names. @xref{listing member and file names}.
  2423. @opsummary{sparse}
  2424. @item --sparse
  2425. @itemx -S
  2426. Invokes a @acronym{GNU} extension when adding files to an archive that handles
  2427. sparse files efficiently. @xref{sparse}.
  2428. @opsummary{starting-file}
  2429. @item --starting-file=@var{name}
  2430. @itemx -K @var{name}
  2431. This option affects extraction only; @command{tar} will skip extracting
  2432. files in the archive until it finds one that matches @var{name}.
  2433. @xref{Scarce}.
  2434. @opsummary{strip-components}
  2435. @item --strip-components=@var{number}
  2436. Strip given @var{number} of leading components from file names before
  2437. extraction.@footnote{This option was called @option{--strip-path} in
  2438. version 1.14.} For example, if archive @file{archive.tar} contained
  2439. @file{/some/file/name}, then running
  2440. @smallexample
  2441. tar --extract --file archive.tar --strip-components=2
  2442. @end smallexample
  2443. @noindent
  2444. would extract this file to file @file{name}.
  2445. @opsummary{suffix}, summary
  2446. @item --suffix=@var{suffix}
  2447. Alters the suffix @command{tar} uses when backing up files from the default
  2448. @samp{~}. @xref{backup}.
  2449. @opsummary{tape-length}
  2450. @item --tape-length=@var{num}
  2451. @itemx -L @var{num}
  2452. Specifies the length of tapes that @command{tar} is writing as being
  2453. @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
  2454. @opsummary{test-label}
  2455. @item --test-label
  2456. Reads the volume label. If an argument is specified, test whether it
  2457. matches the volume label. @xref{--test-label option}.
  2458. @opsummary{to-command}
  2459. @item --to-command=@var{command}
  2460. During extraction @command{tar} will pipe extracted files to the
  2461. standard input of @var{command}. @xref{Writing to an External Program}.
  2462. @opsummary{to-stdout}
  2463. @item --to-stdout
  2464. @itemx -O
  2465. During extraction, @command{tar} will extract files to stdout rather
  2466. than to the file system. @xref{Writing to Standard Output}.
  2467. @opsummary{totals}
  2468. @item --totals[=@var{signo}]
  2469. Displays the total number of bytes transferred when processing an
  2470. archive. If an argument is given, these data are displayed on
  2471. request, when signal @var{signo} is delivered to @command{tar}.
  2472. @xref{totals}.
  2473. @opsummary{touch}
  2474. @item --touch
  2475. @itemx -m
  2476. Sets the data modification time of extracted files to the extraction time,
  2477. rather than the data modification time stored in the archive.
  2478. @xref{Data Modification Times}.
  2479. @opsummary{uncompress}
  2480. @item --uncompress
  2481. (See @option{--compress}. @pxref{gzip})
  2482. @opsummary{ungzip}
  2483. @item --ungzip
  2484. (See @option{--gzip}. @pxref{gzip})
  2485. @opsummary{unlink-first}
  2486. @item --unlink-first
  2487. @itemx -U
  2488. Directs @command{tar} to remove the corresponding file from the file
  2489. system before extracting it from the archive. @xref{Unlink First}.
  2490. @opsummary{unquote}
  2491. @item --unquote
  2492. Enable unquoting input file or member names (default). @xref{input
  2493. name quoting}.
  2494. @opsummary{use-compress-program}
  2495. @item --use-compress-program=@var{prog}
  2496. Instructs @command{tar} to access the archive through @var{prog}, which is
  2497. presumed to be a compression program of some sort. @xref{gzip}.
  2498. @opsummary{utc}
  2499. @item --utc
  2500. Display file modification dates in @acronym{UTC}. This option implies
  2501. @option{--verbose}.
  2502. @opsummary{verbose}
  2503. @item --verbose
  2504. @itemx -v
  2505. Specifies that @command{tar} should be more verbose about the operations its
  2506. performing. This option can be specified multiple times for some
  2507. operations to increase the amount of information displayed.
  2508. @xref{verbose}.
  2509. @opsummary{verify}
  2510. @item --verify
  2511. @itemx -W
  2512. Verifies that the archive was correctly written when creating an
  2513. archive. @xref{verify}.
  2514. @opsummary{version}
  2515. @item --version
  2516. Print information about the program's name, version, origin and legal
  2517. status, all on standard output, and then exit successfully.
  2518. @xref{help}.
  2519. @opsummary{volno-file}
  2520. @item --volno-file=@var{file}
  2521. Used in conjunction with @option{--multi-volume}. @command{tar} will
  2522. keep track of which volume of a multi-volume archive its working in
  2523. @var{file}. @xref{volno-file}.
  2524. @opsummary{wildcards}
  2525. @item --wildcards
  2526. Use wildcards when matching member names with patterns.
  2527. @xref{controlling pattern-matching}.
  2528. @opsummary{wildcards-match-slash}
  2529. @item --wildcards-match-slash
  2530. Wildcards match @samp{/}.
  2531. @xref{controlling pattern-matching}.
  2532. @end table
  2533. @node Short Option Summary
  2534. @subsection Short Options Cross Reference
  2535. Here is an alphabetized list of all of the short option forms, matching
  2536. them with the equivalent long option.
  2537. @multitable @columnfractions 0.20 0.80
  2538. @headitem Short Option @tab Reference
  2539. @item -A @tab @ref{--concatenate}.
  2540. @item -B @tab @ref{--read-full-records}.
  2541. @item -C @tab @ref{--directory}.
  2542. @item -F @tab @ref{--info-script}.
  2543. @item -G @tab @ref{--incremental}.
  2544. @item -K @tab @ref{--starting-file}.
  2545. @item -L @tab @ref{--tape-length}.
  2546. @item -M @tab @ref{--multi-volume}.
  2547. @item -N @tab @ref{--newer}.
  2548. @item -O @tab @ref{--to-stdout}.
  2549. @item -P @tab @ref{--absolute-names}.
  2550. @item -R @tab @ref{--block-number}.
  2551. @item -S @tab @ref{--sparse}.
  2552. @item -T @tab @ref{--files-from}.
  2553. @item -U @tab @ref{--unlink-first}.
  2554. @item -V @tab @ref{--label}.
  2555. @item -W @tab @ref{--verify}.
  2556. @item -X @tab @ref{--exclude-from}.
  2557. @item -Z @tab @ref{--compress}.
  2558. @item -b @tab @ref{--blocking-factor}.
  2559. @item -c @tab @ref{--create}.
  2560. @item -d @tab @ref{--compare}.
  2561. @item -f @tab @ref{--file}.
  2562. @item -g @tab @ref{--listed-incremental}.
  2563. @item -h @tab @ref{--dereference}.
  2564. @item -i @tab @ref{--ignore-zeros}.
  2565. @item -j @tab @ref{--bzip2}.
  2566. @item -k @tab @ref{--keep-old-files}.
  2567. @item -l @tab @ref{--check-links}.
  2568. @item -m @tab @ref{--touch}.
  2569. @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
  2570. @ref{--portability}.
  2571. The later usage is deprecated. It is retained for compatibility with
  2572. the earlier versions of @GNUTAR{}. In the future releases
  2573. @option{-o} will be equivalent to @option{--no-same-owner} only.
  2574. @item -p @tab @ref{--preserve-permissions}.
  2575. @item -r @tab @ref{--append}.
  2576. @item -s @tab @ref{--same-order}.
  2577. @item -t @tab @ref{--list}.
  2578. @item -u @tab @ref{--update}.
  2579. @item -v @tab @ref{--verbose}.
  2580. @item -w @tab @ref{--interactive}.
  2581. @item -x @tab @ref{--extract}.
  2582. @item -z @tab @ref{--gzip}.
  2583. @end multitable
  2584. @node help
  2585. @section @GNUTAR{} documentation
  2586. @cindex Getting program version number
  2587. @opindex version
  2588. @cindex Version of the @command{tar} program
  2589. Being careful, the first thing is really checking that you are using
  2590. @GNUTAR{}, indeed. The @option{--version} option
  2591. causes @command{tar} to print information about its name, version,
  2592. origin and legal status, all on standard output, and then exit
  2593. successfully. For example, @w{@samp{tar --version}} might print:
  2594. @smallexample
  2595. tar (GNU tar) @value{VERSION}
  2596. Copyright (C) 2006 Free Software Foundation, Inc.
  2597. This is free software. You may redistribute copies of it under the terms
  2598. of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
  2599. There is NO WARRANTY, to the extent permitted by law.
  2600. Written by John Gilmore and Jay Fenlason.
  2601. @end smallexample
  2602. @noindent
  2603. The first occurrence of @samp{tar} in the result above is the program
  2604. name in the package (for example, @command{rmt} is another program),
  2605. while the second occurrence of @samp{tar} is the name of the package
  2606. itself, containing possibly many programs. The package is currently
  2607. named @samp{tar}, after the name of the main program it
  2608. contains@footnote{There are plans to merge the @command{cpio} and
  2609. @command{tar} packages into a single one which would be called
  2610. @code{paxutils}. So, who knows if, one of this days, the
  2611. @option{--version} would not output @w{@samp{tar (@acronym{GNU}
  2612. paxutils) 3.2}}}.
  2613. @cindex Obtaining help
  2614. @cindex Listing all @command{tar} options
  2615. @xopindex{help, introduction}
  2616. Another thing you might want to do is checking the spelling or meaning
  2617. of some particular @command{tar} option, without resorting to this
  2618. manual, for once you have carefully read it. @GNUTAR{}
  2619. has a short help feature, triggerable through the
  2620. @option{--help} option. By using this option, @command{tar} will
  2621. print a usage message listing all available options on standard
  2622. output, then exit successfully, without doing anything else and
  2623. ignoring all other options. Even if this is only a brief summary, it
  2624. may be several screens long. So, if you are not using some kind of
  2625. scrollable window, you might prefer to use something like:
  2626. @smallexample
  2627. $ @kbd{tar --help | less}
  2628. @end smallexample
  2629. @noindent
  2630. presuming, here, that you like using @command{less} for a pager. Other
  2631. popular pagers are @command{more} and @command{pg}. If you know about some
  2632. @var{keyword} which interests you and do not want to read all the
  2633. @option{--help} output, another common idiom is doing:
  2634. @smallexample
  2635. tar --help | grep @var{keyword}
  2636. @end smallexample
  2637. @noindent
  2638. for getting only the pertinent lines. Notice, however, that some
  2639. @command{tar} options have long description lines and the above
  2640. command will list only the first of them.
  2641. The exact look of the option summary displayed by @kbd{tar --help} is
  2642. configurable. @xref{Configuring Help Summary}, for a detailed description.
  2643. @opindex usage
  2644. If you only wish to check the spelling of an option, running @kbd{tar
  2645. --usage} may be a better choice. This will display a terse list of
  2646. @command{tar} option without accompanying explanations.
  2647. The short help output is quite succinct, and you might have to get
  2648. back to the full documentation for precise points. If you are reading
  2649. this paragraph, you already have the @command{tar} manual in some
  2650. form. This manual is available in a variety of forms from
  2651. @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
  2652. distribution, provided you have @TeX{} already installed somewhere,
  2653. and a laser printer around. Just configure the distribution, execute
  2654. the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
  2655. usual way (contact your local guru to know how). If @GNUTAR{}
  2656. has been conveniently installed at your place, this
  2657. manual is also available in interactive, hypertextual form as an Info
  2658. file. Just call @w{@samp{info tar}} or, if you do not have the
  2659. @command{info} program handy, use the Info reader provided within
  2660. @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
  2661. There is currently no @code{man} page for @GNUTAR{}.
  2662. If you observe such a @code{man} page on the system you are running,
  2663. either it does not belong to @GNUTAR{}, or it has not
  2664. been produced by @acronym{GNU}. Some package maintainers convert
  2665. @kbd{tar --help} output to a man page, using @command{help2man}. In
  2666. any case, please bear in mind that the authoritative source of
  2667. information about @GNUTAR{} is this Texinfo documentation.
  2668. @node defaults
  2669. @section Obtaining @GNUTAR{} default values
  2670. @opindex show-defaults
  2671. @GNUTAR{} has some predefined defaults that are used when you do not
  2672. explicitely specify another values. To obtain a list of such
  2673. defaults, use @option{--show-defaults} option. This will output the
  2674. values in the form of @command{tar} command line options:
  2675. @smallexample
  2676. @group
  2677. @kbd{tar --show-defaults}
  2678. --format=gnu -f- -b20 --quoting-style=escape
  2679. --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
  2680. @end group
  2681. @end smallexample
  2682. @noindent
  2683. Notice, that this option outputs only one line. The example output above
  2684. has been split to fit page boundaries.
  2685. @noindent
  2686. The above output shows that this version of @GNUTAR{} defaults to
  2687. using @samp{gnu} archive format (@pxref{Formats}), it uses standard
  2688. output as the archive, if no @option{--file} option has been given
  2689. (@pxref{file tutorial}), the default blocking factor is 20
  2690. (@pxref{Blocking Factor}). It also shows the default locations where
  2691. @command{tar} will look for @command{rmt} and @command{rsh} binaries.
  2692. @node verbose
  2693. @section Checking @command{tar} progress
  2694. Typically, @command{tar} performs most operations without reporting any
  2695. information to the user except error messages. When using @command{tar}
  2696. with many options, particularly ones with complicated or
  2697. difficult-to-predict behavior, it is possible to make serious mistakes.
  2698. @command{tar} provides several options that make observing @command{tar}
  2699. easier. These options cause @command{tar} to print information as it
  2700. progresses in its job, and you might want to use them just for being
  2701. more careful about what is going on, or merely for entertaining
  2702. yourself. If you have encountered a problem when operating on an
  2703. archive, however, you may need more information than just an error
  2704. message in order to solve the problem. The following options can be
  2705. helpful diagnostic tools.
  2706. @cindex Verbose operation
  2707. @opindex verbose
  2708. Normally, the @option{--list} (@option{-t}) command to list an archive
  2709. prints just the file names (one per line) and the other commands are
  2710. silent. When used with most operations, the @option{--verbose}
  2711. (@option{-v}) option causes @command{tar} to print the name of each
  2712. file or archive member as it is processed. This and the other options
  2713. which make @command{tar} print status information can be useful in
  2714. monitoring @command{tar}.
  2715. With @option{--create} or @option{--extract}, @option{--verbose} used
  2716. once just prints the names of the files or members as they are processed.
  2717. Using it twice causes @command{tar} to print a longer listing
  2718. (@xref{verbose member listing}, for the description) for each member.
  2719. Since @option{--list} already prints the names of the members,
  2720. @option{--verbose} used once with @option{--list} causes @command{tar}
  2721. to print an @samp{ls -l} type listing of the files in the archive.
  2722. The following examples both extract members with long list output:
  2723. @smallexample
  2724. $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
  2725. $ @kbd{tar xvvf archive.tar}
  2726. @end smallexample
  2727. Verbose output appears on the standard output except when an archive is
  2728. being written to the standard output, as with @samp{tar --create
  2729. --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
  2730. installer let standard output be the default archive). In that case
  2731. @command{tar} writes verbose output to the standard error stream.
  2732. If @option{--index-file=@var{file}} is specified, @command{tar} sends
  2733. verbose output to @var{file} rather than to standard output or standard
  2734. error.
  2735. @anchor{totals}
  2736. @cindex Obtaining total status information
  2737. @opindex totals
  2738. The @option{--totals} option causes @command{tar} to print on the
  2739. standard error the total amount of bytes transferred when processing
  2740. an archive. When creating or appending to an archive, this option
  2741. prints the number of bytes written to the archive and the average
  2742. speed at which they have been written, e.g.:
  2743. @smallexample
  2744. @group
  2745. $ @kbd{tar -c -f archive.tar --totals /home}
  2746. Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
  2747. @end group
  2748. @end smallexample
  2749. When reading an archive, this option displays the number of bytes
  2750. read:
  2751. @smallexample
  2752. @group
  2753. $ @kbd{tar -x -f archive.tar --totals}
  2754. Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
  2755. @end group
  2756. @end smallexample
  2757. Finally, when deleting from an archive, the @option{--totals} option
  2758. displays both numbers plus number of bytes removed from the archive:
  2759. @smallexample
  2760. @group
  2761. $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
  2762. Total bytes read: 9543680 (9.2MiB, 201MiB/s)
  2763. Total bytes written: 3829760 (3.7MiB, 81MiB/s)
  2764. Total bytes deleted: 1474048
  2765. @end group
  2766. @end smallexample
  2767. You can also obtain this information on request. When
  2768. @option{--totals} is used with an argument, this argument is
  2769. interpreted as a symbolic name of a signal, upon delivery of which the
  2770. statistics is to be printed:
  2771. @table @option
  2772. @item --totals=@var{signo}
  2773. Print statistics upon delivery of signal @var{signo}. Valid arguments
  2774. are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
  2775. @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
  2776. accepted.
  2777. @end table
  2778. Both forms of @option{--totals} option can be used simultaneously.
  2779. Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
  2780. extract all members from its default archive and print statistics
  2781. after finishing the extraction, as well as when receiving signal
  2782. @code{SIGUSR1}.
  2783. @anchor{Progress information}
  2784. @cindex Progress information
  2785. @opindex checkpoint
  2786. The @option{--checkpoint} option prints an occasional message
  2787. as @command{tar} reads or writes the archive. It is designed for
  2788. those who don't need the more detailed (and voluminous) output of
  2789. @option{--block-number} (@option{-R}), but do want visual confirmation
  2790. that @command{tar} is actually making forward progress. By default it
  2791. prints a message each 10 records read or written. This can be changed
  2792. by giving it a numeric argument after an equal sign:
  2793. @smallexample
  2794. $ @kbd{tar -c --checkpoint=1000} /var
  2795. tar: Write checkpoint 1000
  2796. tar: Write checkpoint 2000
  2797. tar: Write checkpoint 3000
  2798. @end smallexample
  2799. This example shows the default checkpoint message used by
  2800. @command{tar}. If you place a dot immediately after the equal
  2801. sign, it will print a @samp{.} at each checkpoint. For example:
  2802. @smallexample
  2803. $ @kbd{tar -c --checkpoint=.1000} /var
  2804. ...
  2805. @end smallexample
  2806. @opindex show-omitted-dirs
  2807. @anchor{show-omitted-dirs}
  2808. The @option{--show-omitted-dirs} option, when reading an archive---with
  2809. @option{--list} or @option{--extract}, for example---causes a message
  2810. to be printed for each directory in the archive which is skipped.
  2811. This happens regardless of the reason for skipping: the directory might
  2812. not have been named on the command line (implicitly or explicitly),
  2813. it might be excluded by the use of the
  2814. @option{--exclude=@var{pattern}} option, or some other reason.
  2815. @opindex block-number
  2816. @cindex Block number where error occurred
  2817. @anchor{block-number}
  2818. If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
  2819. every message it would normally produce, the block number within the
  2820. archive where the message was triggered. Also, supplementary messages
  2821. are triggered when reading blocks full of NULs, or when hitting end of
  2822. file on the archive. As of now, if the archive if properly terminated
  2823. with a NUL block, the reading of the file may stop before end of file
  2824. is met, so the position of end of file will not usually show when
  2825. @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
  2826. drains the archive before exiting when reading the
  2827. archive from a pipe.
  2828. @cindex Error message, block number of
  2829. This option is especially useful when reading damaged archives, since
  2830. it helps pinpoint the damaged sections. It can also be used with
  2831. @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
  2832. choose among several backup tapes when retrieving a file later, in
  2833. favor of the tape where the file appears earliest (closest to the
  2834. front of the tape). @xref{backup}.
  2835. @node interactive
  2836. @section Asking for Confirmation During Operations
  2837. @cindex Interactive operation
  2838. Typically, @command{tar} carries out a command without stopping for
  2839. further instructions. In some situations however, you may want to
  2840. exclude some files and archive members from the operation (for instance
  2841. if disk or storage space is tight). You can do this by excluding
  2842. certain files automatically (@pxref{Choosing}), or by performing
  2843. an operation interactively, using the @option{--interactive} (@option{-w}) option.
  2844. @command{tar} also accepts @option{--confirmation} for this option.
  2845. @opindex interactive
  2846. When the @option{--interactive} (@option{-w}) option is specified, before
  2847. reading, writing, or deleting files, @command{tar} first prints a message
  2848. for each such file, telling what operation it intends to take, then asks
  2849. for confirmation on the terminal. The actions which require
  2850. confirmation include adding a file to the archive, extracting a file
  2851. from the archive, deleting a file from the archive, and deleting a file
  2852. from disk. To confirm the action, you must type a line of input
  2853. beginning with @samp{y}. If your input line begins with anything other
  2854. than @samp{y}, @command{tar} skips that file.
  2855. If @command{tar} is reading the archive from the standard input,
  2856. @command{tar} opens the file @file{/dev/tty} to support the interactive
  2857. communications.
  2858. Verbose output is normally sent to standard output, separate from
  2859. other error messages. However, if the archive is produced directly
  2860. on standard output, then verbose output is mixed with errors on
  2861. @code{stderr}. Producing the archive on standard output may be used
  2862. as a way to avoid using disk space, when the archive is soon to be
  2863. consumed by another process reading it, say. Some people felt the need
  2864. of producing an archive on stdout, still willing to segregate between
  2865. verbose output and error output. A possible approach would be using a
  2866. named pipe to receive the archive, and having the consumer process to
  2867. read from that named pipe. This has the advantage of letting standard
  2868. output free to receive verbose output, all separate from errors.
  2869. @node operations
  2870. @chapter @GNUTAR{} Operations
  2871. @menu
  2872. * Basic tar::
  2873. * Advanced tar::
  2874. * create options::
  2875. * extract options::
  2876. * backup::
  2877. * Applications::
  2878. * looking ahead::
  2879. @end menu
  2880. @node Basic tar
  2881. @section Basic @GNUTAR{} Operations
  2882. The basic @command{tar} operations, @option{--create} (@option{-c}),
  2883. @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
  2884. @option{-x}), are currently presented and described in the tutorial
  2885. chapter of this manual. This section provides some complementary notes
  2886. for these operations.
  2887. @table @option
  2888. @xopindex{create, complementary notes}
  2889. @item --create
  2890. @itemx -c
  2891. Creating an empty archive would have some kind of elegance. One can
  2892. initialize an empty archive and later use @option{--append}
  2893. (@option{-r}) for adding all members. Some applications would not
  2894. welcome making an exception in the way of adding the first archive
  2895. member. On the other hand, many people reported that it is
  2896. dangerously too easy for @command{tar} to destroy a magnetic tape with
  2897. an empty archive@footnote{This is well described in @cite{Unix-haters
  2898. Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
  2899. Books, ISBN 1-56884-203-1.}. The two most common errors are:
  2900. @enumerate
  2901. @item
  2902. Mistakingly using @code{create} instead of @code{extract}, when the
  2903. intent was to extract the full contents of an archive. This error
  2904. is likely: keys @kbd{c} and @kbd{x} are right next to each other on
  2905. the QWERTY keyboard. Instead of being unpacked, the archive then
  2906. gets wholly destroyed. When users speak about @dfn{exploding} an
  2907. archive, they usually mean something else :-).
  2908. @item
  2909. Forgetting the argument to @code{file}, when the intent was to create
  2910. an archive with a single file in it. This error is likely because a
  2911. tired user can easily add the @kbd{f} key to the cluster of option
  2912. letters, by the mere force of habit, without realizing the full
  2913. consequence of doing so. The usual consequence is that the single
  2914. file, which was meant to be saved, is rather destroyed.
  2915. @end enumerate
  2916. So, recognizing the likelihood and the catastrophical nature of these
  2917. errors, @GNUTAR{} now takes some distance from elegance, and
  2918. cowardly refuses to create an archive when @option{--create} option is
  2919. given, there are no arguments besides options, and
  2920. @option{--files-from} (@option{-T}) option is @emph{not} used. To get
  2921. around the cautiousness of @GNUTAR{} and nevertheless create an
  2922. archive with nothing in it, one may still use, as the value for the
  2923. @option{--files-from} option, a file with no names in it, as shown in
  2924. the following commands:
  2925. @smallexample
  2926. @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
  2927. @kbd{tar cfT empty-archive.tar /dev/null}
  2928. @end smallexample
  2929. @xopindex{extract, complementary notes}
  2930. @item --extract
  2931. @itemx --get
  2932. @itemx -x
  2933. A socket is stored, within a @GNUTAR{} archive, as a pipe.
  2934. @item @option{--list} (@option{-t})
  2935. @GNUTAR{} now shows dates as @samp{1996-08-30},
  2936. while it used to show them as @samp{Aug 30 1996}. Preferably,
  2937. people should get used to ISO 8601 dates. Local American dates should
  2938. be made available again with full date localization support, once
  2939. ready. In the meantime, programs not being localizable for dates
  2940. should prefer international dates, that's really the way to go.
  2941. Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
  2942. are curious, it contains a detailed explanation of the ISO 8601 standard.
  2943. @end table
  2944. @node Advanced tar
  2945. @section Advanced @GNUTAR{} Operations
  2946. Now that you have learned the basics of using @GNUTAR{}, you may want
  2947. to learn about further ways in which @command{tar} can help you.
  2948. This chapter presents five, more advanced operations which you probably
  2949. won't use on a daily basis, but which serve more specialized functions.
  2950. We also explain the different styles of options and why you might want
  2951. to use one or another, or a combination of them in your @command{tar}
  2952. commands. Additionally, this chapter includes options which allow you to
  2953. define the output from @command{tar} more carefully, and provide help and
  2954. error correction in special circumstances.
  2955. @FIXME{check this after the chapter is actually revised to make sure
  2956. it still introduces the info in the chapter correctly : ).}
  2957. @menu
  2958. * Operations::
  2959. * append::
  2960. * update::
  2961. * concatenate::
  2962. * delete::
  2963. * compare::
  2964. @end menu
  2965. @node Operations
  2966. @subsection The Five Advanced @command{tar} Operations
  2967. @UNREVISED
  2968. In the last chapter, you learned about the first three operations to
  2969. @command{tar}. This chapter presents the remaining five operations to
  2970. @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
  2971. @option{--delete}, and @option{--compare}.
  2972. You are not likely to use these operations as frequently as those
  2973. covered in the last chapter; however, since they perform specialized
  2974. functions, they are quite useful when you do need to use them. We
  2975. will give examples using the same directory and files that you created
  2976. in the last chapter. As you may recall, the directory is called
  2977. @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
  2978. @samp{rock}, and the two archive files you created are
  2979. @samp{collection.tar} and @samp{music.tar}.
  2980. We will also use the archive files @samp{afiles.tar} and
  2981. @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
  2982. @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
  2983. @samp{./birds}, @samp{baboon}, and @samp{./box}.
  2984. Unless we state otherwise, all practicing you do and examples you follow
  2985. in this chapter will take place in the @file{practice} directory that
  2986. you created in the previous chapter; see @ref{prepare for examples}.
  2987. (Below in this section, we will remind you of the state of the examples
  2988. where the last chapter left them.)
  2989. The five operations that we will cover in this chapter are:
  2990. @table @option
  2991. @item --append
  2992. @itemx -r
  2993. Add new entries to an archive that already exists.
  2994. @item --update
  2995. @itemx -r
  2996. Add more recent copies of archive members to the end of an archive, if
  2997. they exist.
  2998. @item --concatenate
  2999. @itemx --catenate
  3000. @itemx -A
  3001. Add one or more pre-existing archives to the end of another archive.
  3002. @item --delete
  3003. Delete items from an archive (does not work on tapes).
  3004. @item --compare
  3005. @itemx --diff
  3006. @itemx -d
  3007. Compare archive members to their counterparts in the file system.
  3008. @end table
  3009. @node append
  3010. @subsection How to Add Files to Existing Archives: @option{--append}
  3011. @UNREVISED
  3012. @opindex append
  3013. If you want to add files to an existing archive, you don't need to
  3014. create a new archive; you can use @option{--append} (@option{-r}).
  3015. The archive must already exist in order to use @option{--append}. (A
  3016. related operation is the @option{--update} operation; you can use this
  3017. to add newer versions of archive members to an existing archive. To learn how to
  3018. do this with @option{--update}, @pxref{update}.)
  3019. If you use @option{--append} to add a file that has the same name as an
  3020. archive member to an archive containing that archive member, then the
  3021. old member is not deleted. What does happen, however, is somewhat
  3022. complex. @command{tar} @emph{allows} you to have infinite number of files
  3023. with the same name. Some operations treat these same-named members no
  3024. differently than any other set of archive members: for example, if you
  3025. view an archive with @option{--list} (@option{-t}), you will see all
  3026. of those members listed, with their data modification times, owners, etc.
  3027. Other operations don't deal with these members as perfectly as you might
  3028. prefer; if you were to use @option{--extract} to extract the archive,
  3029. only the most recently added copy of a member with the same name as four
  3030. other members would end up in the working directory. This is because
  3031. @option{--extract} extracts an archive in the order the members appeared
  3032. in the archive; the most recently archived members will be extracted
  3033. last. Additionally, an extracted member will @emph{replace} a file of
  3034. the same name which existed in the directory already, and @command{tar}
  3035. will not prompt you about this@footnote{Unless you give it
  3036. @option{--keep-old-files} option, or the disk copy is newer than the
  3037. the one in the archive and you invoke @command{tar} with
  3038. @option{--keep-newer-files} option}. Thus, only the most recently archived
  3039. member will end up being extracted, as it will replace the one
  3040. extracted before it, and so on.
  3041. There exists a special option that allows you to get around this
  3042. behavior and extract (or list) only a particular copy of the file.
  3043. This is @option{--occurrence} option. If you run @command{tar} with
  3044. this option, it will extract only the first copy of the file. You
  3045. may also give this option an argument specifying the number of
  3046. copy to be extracted. Thus, for example if the archive
  3047. @file{archive.tar} contained three copies of file @file{myfile}, then
  3048. the command
  3049. @smallexample
  3050. tar --extract --file archive.tar --occurrence=2 myfile
  3051. @end smallexample
  3052. @noindent
  3053. would extract only the second copy. @xref{Option
  3054. Summary,---occurrence}, for the description of @option{--occurrence}
  3055. option.
  3056. @FIXME{ hag -- you might want to incorporate some of the above into the
  3057. MMwtSN node; not sure. i didn't know how to make it simpler...
  3058. There are a few ways to get around this. (maybe xref Multiple Members
  3059. with the Same Name.}
  3060. @cindex Members, replacing with other members
  3061. @cindex Replacing members with other members
  3062. If you want to replace an archive member, use @option{--delete} to
  3063. delete the member you want to remove from the archive, , and then use
  3064. @option{--append} to add the member you want to be in the archive. Note
  3065. that you can not change the order of the archive; the most recently
  3066. added member will still appear last. In this sense, you cannot truly
  3067. ``replace'' one member with another. (Replacing one member with another
  3068. will not work on certain types of media, such as tapes; see @ref{delete}
  3069. and @ref{Media}, for more information.)
  3070. @menu
  3071. * appending files:: Appending Files to an Archive
  3072. * multiple::
  3073. @end menu
  3074. @node appending files
  3075. @subsubsection Appending Files to an Archive
  3076. @UNREVISED
  3077. @cindex Adding files to an Archive
  3078. @cindex Appending files to an Archive
  3079. @cindex Archives, Appending files to
  3080. The simplest way to add a file to an already existing archive is the
  3081. @option{--append} (@option{-r}) operation, which writes specified
  3082. files into the archive whether or not they are already among the
  3083. archived files.
  3084. When you use @option{--append}, you @emph{must} specify file name
  3085. arguments, as there is no default. If you specify a file that already
  3086. exists in the archive, another copy of the file will be added to the
  3087. end of the archive. As with other operations, the member names of the
  3088. newly added files will be exactly the same as their names given on the
  3089. command line. The @option{--verbose} (@option{-v}) option will print
  3090. out the names of the files as they are written into the archive.
  3091. @option{--append} cannot be performed on some tape drives, unfortunately,
  3092. due to deficiencies in the formats those tape drives use. The archive
  3093. must be a valid @command{tar} archive, or else the results of using this
  3094. operation will be unpredictable. @xref{Media}.
  3095. To demonstrate using @option{--append} to add a file to an archive,
  3096. create a file called @file{rock} in the @file{practice} directory.
  3097. Make sure you are in the @file{practice} directory. Then, run the
  3098. following @command{tar} command to add @file{rock} to
  3099. @file{collection.tar}:
  3100. @smallexample
  3101. $ @kbd{tar --append --file=collection.tar rock}
  3102. @end smallexample
  3103. @noindent
  3104. If you now use the @option{--list} (@option{-t}) operation, you will see that
  3105. @file{rock} has been added to the archive:
  3106. @smallexample
  3107. $ @kbd{tar --list --file=collection.tar}
  3108. -rw-r--r-- me user 28 1996-10-18 16:31 jazz
  3109. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  3110. -rw-r--r-- me user 20 1996-09-23 16:44 folk
  3111. -rw-r--r-- me user 20 1996-09-23 16:44 rock
  3112. @end smallexample
  3113. @node multiple
  3114. @subsubsection Multiple Members with the Same Name
  3115. You can use @option{--append} (@option{-r}) to add copies of files
  3116. which have been updated since the archive was created. (However, we
  3117. do not recommend doing this since there is another @command{tar}
  3118. option called @option{--update}; @xref{update}, for more information.
  3119. We describe this use of @option{--append} here for the sake of
  3120. completeness.) When you extract the archive, the older version will
  3121. be effectively lost. This works because files are extracted from an
  3122. archive in the order in which they were archived. Thus, when the
  3123. archive is extracted, a file archived later in time will replace a
  3124. file of the same name which was archived earlier, even though the
  3125. older version of the file will remain in the archive unless you delete
  3126. all versions of the file.
  3127. Supposing you change the file @file{blues} and then append the changed
  3128. version to @file{collection.tar}. As you saw above, the original
  3129. @file{blues} is in the archive @file{collection.tar}. If you change the
  3130. file and append the new version of the file to the archive, there will
  3131. be two copies in the archive. When you extract the archive, the older
  3132. version of the file will be extracted first, and then replaced by the
  3133. newer version when it is extracted.
  3134. You can append the new, changed copy of the file @file{blues} to the
  3135. archive in this way:
  3136. @smallexample
  3137. $ @kbd{tar --append --verbose --file=collection.tar blues}
  3138. blues
  3139. @end smallexample
  3140. @noindent
  3141. Because you specified the @option{--verbose} option, @command{tar} has
  3142. printed the name of the file being appended as it was acted on. Now
  3143. list the contents of the archive:
  3144. @smallexample
  3145. $ @kbd{tar --list --verbose --file=collection.tar}
  3146. -rw-r--r-- me user 28 1996-10-18 16:31 jazz
  3147. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  3148. -rw-r--r-- me user 20 1996-09-23 16:44 folk
  3149. -rw-r--r-- me user 20 1996-09-23 16:44 rock
  3150. -rw-r--r-- me user 58 1996-10-24 18:30 blues
  3151. @end smallexample
  3152. @noindent
  3153. The newest version of @file{blues} is now at the end of the archive
  3154. (note the different creation dates and file sizes). If you extract
  3155. the archive, the older version of the file @file{blues} will be
  3156. replaced by the newer version. You can confirm this by extracting
  3157. the archive and running @samp{ls} on the directory.
  3158. If you wish to extract the first occurrence of the file @file{blues}
  3159. from the archive, use @option{--occurrence} option, as shown in
  3160. the following example:
  3161. @smallexample
  3162. $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
  3163. -rw-r--r-- me user 21 1996-09-23 16:44 blues
  3164. @end smallexample
  3165. @xref{Writing}, for more information on @option{--extract} and
  3166. @xref{Option Summary, --occurrence}, for the description of
  3167. @option{--occurrence} option.
  3168. @node update
  3169. @subsection Updating an Archive
  3170. @UNREVISED
  3171. @cindex Updating an archive
  3172. @opindex update
  3173. In the previous section, you learned how to use @option{--append} to
  3174. add a file to an existing archive. A related operation is
  3175. @option{--update} (@option{-u}). The @option{--update} operation
  3176. updates a @command{tar} archive by comparing the date of the specified
  3177. archive members against the date of the file with the same name. If
  3178. the file has been modified more recently than the archive member, then
  3179. the newer version of the file is added to the archive (as with
  3180. @option{--append}).
  3181. Unfortunately, you cannot use @option{--update} with magnetic tape drives.
  3182. The operation will fail.
  3183. @FIXME{other examples of media on which --update will fail? need to ask
  3184. charles and/or mib/thomas/dave shevett..}
  3185. Both @option{--update} and @option{--append} work by adding to the end
  3186. of the archive. When you extract a file from the archive, only the
  3187. version stored last will wind up in the file system, unless you use
  3188. the @option{--backup} option. @xref{multiple}, for a detailed discussion.
  3189. @menu
  3190. * how to update::
  3191. @end menu
  3192. @node how to update
  3193. @subsubsection How to Update an Archive Using @option{--update}
  3194. You must use file name arguments with the @option{--update}
  3195. (@option{-u}) operation. If you don't specify any files,
  3196. @command{tar} won't act on any files and won't tell you that it didn't
  3197. do anything (which may end up confusing you).
  3198. @c note: the above parenthetical added because in fact, this
  3199. @c behavior just confused the author. :-)
  3200. To see the @option{--update} option at work, create a new file,
  3201. @file{classical}, in your practice directory, and some extra text to the
  3202. file @file{blues}, using any text editor. Then invoke @command{tar} with
  3203. the @samp{update} operation and the @option{--verbose} (@option{-v})
  3204. option specified, using the names of all the files in the practice
  3205. directory as file name arguments:
  3206. @smallexample
  3207. $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
  3208. blues
  3209. classical
  3210. $
  3211. @end smallexample
  3212. @noindent
  3213. Because we have specified verbose mode, @command{tar} prints out the names
  3214. of the files it is working on, which in this case are the names of the
  3215. files that needed to be updated. If you run @samp{tar --list} and look
  3216. at the archive, you will see @file{blues} and @file{classical} at its
  3217. end. There will be a total of two versions of the member @samp{blues};
  3218. the one at the end will be newer and larger, since you added text before
  3219. updating it.
  3220. (The reason @command{tar} does not overwrite the older file when updating
  3221. it is because writing to the middle of a section of tape is a difficult
  3222. process. Tapes are not designed to go backward. @xref{Media}, for more
  3223. information about tapes.
  3224. @option{--update} (@option{-u}) is not suitable for performing backups for two
  3225. reasons: it does not change directory content entries, and it
  3226. lengthens the archive every time it is used. The @GNUTAR{}
  3227. options intended specifically for backups are more
  3228. efficient. If you need to run backups, please consult @ref{Backups}.
  3229. @node concatenate
  3230. @subsection Combining Archives with @option{--concatenate}
  3231. @cindex Adding archives to an archive
  3232. @cindex Concatenating Archives
  3233. @opindex concatenate
  3234. @opindex catenate
  3235. @c @cindex @option{-A} described
  3236. Sometimes it may be convenient to add a second archive onto the end of
  3237. an archive rather than adding individual files to the archive. To add
  3238. one or more archives to the end of another archive, you should use the
  3239. @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
  3240. To use @option{--concatenate}, give the first archive with
  3241. @option{--file} option and name the rest of archives to be
  3242. concatenated on the command line. The members, and their member
  3243. names, will be copied verbatim from those archives to the first one.
  3244. @footnote{This can cause multiple members to have the same name, for
  3245. information on how this affects reading the archive, @ref{multiple}.}
  3246. The new, concatenated archive will be called by the same name as the
  3247. one given with the @option{--file} option. As usual, if you omit
  3248. @option{--file}, @command{tar} will use the value of the environment
  3249. variable @env{TAPE}, or, if this has not been set, the default archive name.
  3250. @FIXME{There is no way to specify a new name...}
  3251. To demonstrate how @option{--concatenate} works, create two small archives
  3252. called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
  3253. files from @file{practice}:
  3254. @smallexample
  3255. $ @kbd{tar -cvf bluesrock.tar blues rock}
  3256. blues
  3257. rock
  3258. $ @kbd{tar -cvf folkjazz.tar folk jazz}
  3259. folk
  3260. jazz
  3261. @end smallexample
  3262. @noindent
  3263. If you like, You can run @samp{tar --list} to make sure the archives
  3264. contain what they are supposed to:
  3265. @smallexample
  3266. $ @kbd{tar -tvf bluesrock.tar}
  3267. -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
  3268. -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
  3269. $ @kbd{tar -tvf jazzfolk.tar}
  3270. -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
  3271. -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
  3272. @end smallexample
  3273. We can concatenate these two archives with @command{tar}:
  3274. @smallexample
  3275. $ @kbd{cd ..}
  3276. $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
  3277. @end smallexample
  3278. If you now list the contents of the @file{bluesrock.tar}, you will see
  3279. that now it also contains the archive members of @file{jazzfolk.tar}:
  3280. @smallexample
  3281. $ @kbd{tar --list --file=bluesrock.tar}
  3282. blues
  3283. rock
  3284. folk
  3285. jazz
  3286. @end smallexample
  3287. When you use @option{--concatenate}, the source and target archives must
  3288. already exist and must have been created using compatible format
  3289. parameters. Notice, that @command{tar} does not check whether the
  3290. archives it concatenates have compatible formats, it does not
  3291. even check if the files are really tar archives.
  3292. Like @option{--append} (@option{-r}), this operation cannot be performed on some
  3293. tape drives, due to deficiencies in the formats those tape drives use.
  3294. @cindex @code{concatenate} vs @command{cat}
  3295. @cindex @command{cat} vs @code{concatenate}
  3296. It may seem more intuitive to you to want or try to use @command{cat} to
  3297. concatenate two archives instead of using the @option{--concatenate}
  3298. operation; after all, @command{cat} is the utility for combining files.
  3299. However, @command{tar} archives incorporate an end-of-file marker which
  3300. must be removed if the concatenated archives are to be read properly as
  3301. one archive. @option{--concatenate} removes the end-of-archive marker
  3302. from the target archive before each new archive is appended. If you use
  3303. @command{cat} to combine the archives, the result will not be a valid
  3304. @command{tar} format archive. If you need to retrieve files from an
  3305. archive that was added to using the @command{cat} utility, use the
  3306. @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
  3307. information on dealing with archives improperly combined using the
  3308. @command{cat} shell utility.
  3309. @node delete
  3310. @subsection Removing Archive Members Using @option{--delete}
  3311. @UNREVISED
  3312. @cindex Deleting files from an archive
  3313. @cindex Removing files from an archive
  3314. @opindex delete
  3315. You can remove members from an archive by using the @option{--delete}
  3316. option. Specify the name of the archive with @option{--file}
  3317. (@option{-f}) and then specify the names of the members to be deleted;
  3318. if you list no member names, nothing will be deleted. The
  3319. @option{--verbose} option will cause @command{tar} to print the names
  3320. of the members as they are deleted. As with @option{--extract}, you
  3321. must give the exact member names when using @samp{tar --delete}.
  3322. @option{--delete} will remove all versions of the named file from the
  3323. archive. The @option{--delete} operation can run very slowly.
  3324. Unlike other operations, @option{--delete} has no short form.
  3325. @cindex Tapes, using @option{--delete} and
  3326. @cindex Deleting from tape archives
  3327. This operation will rewrite the archive. You can only use
  3328. @option{--delete} on an archive if the archive device allows you to
  3329. write to any point on the media, such as a disk; because of this, it
  3330. does not work on magnetic tapes. Do not try to delete an archive member
  3331. from a magnetic tape; the action will not succeed, and you will be
  3332. likely to scramble the archive and damage your tape. There is no safe
  3333. way (except by completely re-writing the archive) to delete files from
  3334. most kinds of magnetic tape. @xref{Media}.
  3335. To delete all versions of the file @file{blues} from the archive
  3336. @file{collection.tar} in the @file{practice} directory, make sure you
  3337. are in that directory, and then,
  3338. @smallexample
  3339. $ @kbd{tar --list --file=collection.tar}
  3340. blues
  3341. folk
  3342. jazz
  3343. rock
  3344. $ @kbd{tar --delete --file=collection.tar blues}
  3345. $ @kbd{tar --list --file=collection.tar}
  3346. folk
  3347. jazz
  3348. rock
  3349. $
  3350. @end smallexample
  3351. @FIXME{Check if the above listing is actually produced after running
  3352. all the examples on collection.tar.}
  3353. The @option{--delete} option has been reported to work properly when
  3354. @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
  3355. @node compare
  3356. @subsection Comparing Archive Members with the File System
  3357. @cindex Verifying the currency of an archive
  3358. @UNREVISED
  3359. @opindex compare
  3360. The @option{--compare} (@option{-d}), or @option{--diff} operation compares
  3361. specified archive members against files with the same names, and then
  3362. reports differences in file size, mode, owner, modification date and
  3363. contents. You should @emph{only} specify archive member names, not file
  3364. names. If you do not name any members, then @command{tar} will compare the
  3365. entire archive. If a file is represented in the archive but does not
  3366. exist in the file system, @command{tar} reports a difference.
  3367. You have to specify the record size of the archive when modifying an
  3368. archive with a non-default record size.
  3369. @command{tar} ignores files in the file system that do not have
  3370. corresponding members in the archive.
  3371. The following example compares the archive members @file{rock},
  3372. @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
  3373. files of the same name in the file system. (Note that there is no file,
  3374. @file{funk}; @command{tar} will report an error message.)
  3375. @smallexample
  3376. $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
  3377. rock
  3378. blues
  3379. tar: funk not found in archive
  3380. @end smallexample
  3381. The spirit behind the @option{--compare} (@option{--diff},
  3382. @option{-d}) option is to check whether the archive represents the
  3383. current state of files on disk, more than validating the integrity of
  3384. the archive media. For this later goal, @xref{verify}.
  3385. @node create options
  3386. @section Options Used by @option{--create}
  3387. @xopindex{create, additional options}
  3388. The previous chapter described the basics of how to use
  3389. @option{--create} (@option{-c}) to create an archive from a set of files.
  3390. @xref{create}. This section described advanced options to be used with
  3391. @option{--create}.
  3392. @menu
  3393. * override:: Overriding File Metadata.
  3394. * Ignore Failed Read::
  3395. @end menu
  3396. @node override
  3397. @subsection Overriding File Metadata
  3398. As described above, a @command{tar} archive keeps, for each member it contains,
  3399. its @dfn{metadata}, such as modification time, mode and ownership of
  3400. the file. @GNUTAR{} allows to replace these data with other values
  3401. when adding files to the archive. The options described in this
  3402. section affect creation of archives of any type. For POSIX archives,
  3403. see also @ref{PAX keywords}, for additional ways of controlling
  3404. metadata, stored in the archive.
  3405. @table @option
  3406. @opindex mode
  3407. @item --mode=@var{permissions}
  3408. When adding files to an archive, @command{tar} will use
  3409. @var{permissions} for the archive members, rather than the permissions
  3410. from the files. @var{permissions} can be specified either as an octal
  3411. number or as symbolic permissions, like with
  3412. @command{chmod} (@xref{File permissions, Permissions, File
  3413. permissions, fileutils, @acronym{GNU} file utilities}. This reference
  3414. also has useful information for those not being overly familiar with
  3415. the UNIX permission system). Using latter syntax allows for
  3416. more flexibility. For example, the value @samp{a+rw} adds read and write
  3417. permissions for everybody, while retaining executable bits on directories
  3418. or on any other file already marked as executable:
  3419. @smallexample
  3420. $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
  3421. @end smallexample
  3422. @item --mtime=@var{date}
  3423. @opindex mtime
  3424. When adding files to an archive, @command{tar} will use @var{date} as
  3425. the modification time of members when creating archives, instead of
  3426. their actual modification times. The argument @var{date} can be
  3427. either a textual date representation in almost arbitrary format
  3428. (@pxref{Date input formats}) or a name of the existing file, starting
  3429. with @samp{/} or @samp{.}. In the latter case, the modification time
  3430. of that file will be used.
  3431. The following example will set the modification date to 00:00:00 UTC,
  3432. January 1, 1970:
  3433. @smallexample
  3434. $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
  3435. @end smallexample
  3436. @noindent
  3437. When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
  3438. will try to convert the specified date back to its textual
  3439. representation and compare it with the one given with
  3440. @option{--mtime} options. If the two dates differ, @command{tar} will
  3441. print a warning saying what date it will use. This is to help user
  3442. ensure he is using the right date.
  3443. For example:
  3444. @smallexample
  3445. $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
  3446. tar: Option --mtime: Treating date `yesterday' as 2006-06-20
  3447. 13:06:29.152478
  3448. @dots{}
  3449. @end smallexample
  3450. @item --owner=@var{user}
  3451. @opindex owner
  3452. Specifies that @command{tar} should use @var{user} as the owner of members
  3453. when creating archives, instead of the user associated with the source
  3454. file. The argument @var{user} can be either an existing user symbolic
  3455. name, or a decimal numeric user ID.
  3456. There is no value indicating a missing number, and @samp{0} usually means
  3457. @code{root}. Some people like to force @samp{0} as the value to offer in
  3458. their distributions for the owner of files, because the @code{root} user is
  3459. anonymous anyway, so that might as well be the owner of anonymous
  3460. archives. For example:
  3461. @smallexample
  3462. @group
  3463. $ @kbd{tar -c -f archive.tar --owner=0 .}
  3464. # @r{Or:}
  3465. $ @kbd{tar -c -f archive.tar --owner=root .}
  3466. @end group
  3467. @end smallexample
  3468. @item --group=@var{group}
  3469. @opindex group
  3470. Files added to the @command{tar} archive will have a group id of @var{group},
  3471. rather than the group from the source file. The argument @var{group}
  3472. can be either an existing group symbolic name, or a decimal numeric group ID.
  3473. @end table
  3474. @node Ignore Failed Read
  3475. @subsection Ignore Fail Read
  3476. @table @option
  3477. @item --ignore-failed-read
  3478. @opindex ignore-failed-read
  3479. Do not exit with nonzero on unreadable files or directories.
  3480. @end table
  3481. @node extract options
  3482. @section Options Used by @option{--extract}
  3483. @UNREVISED
  3484. @xopindex{extract, additional options}
  3485. The previous chapter showed how to use @option{--extract} to extract
  3486. an archive into the file system. Various options cause @command{tar} to
  3487. extract more information than just file contents, such as the owner,
  3488. the permissions, the modification date, and so forth. This section
  3489. presents options to be used with @option{--extract} when certain special
  3490. considerations arise. You may review the information presented in
  3491. @ref{extract} for more basic information about the
  3492. @option{--extract} operation.
  3493. @menu
  3494. * Reading:: Options to Help Read Archives
  3495. * Writing:: Changing How @command{tar} Writes Files
  3496. * Scarce:: Coping with Scarce Resources
  3497. @end menu
  3498. @node Reading
  3499. @subsection Options to Help Read Archives
  3500. @cindex Options when reading archives
  3501. @UNREVISED
  3502. @cindex Reading incomplete records
  3503. @cindex Records, incomplete
  3504. @opindex read-full-records
  3505. Normally, @command{tar} will request data in full record increments from
  3506. an archive storage device. If the device cannot return a full record,
  3507. @command{tar} will report an error. However, some devices do not always
  3508. return full records, or do not require the last record of an archive to
  3509. be padded out to the next record boundary. To keep reading until you
  3510. obtain a full record, or to accept an incomplete record if it contains
  3511. an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
  3512. in conjunction with the @option{--extract} or @option{--list} operations.
  3513. @xref{Blocking}.
  3514. The @option{--read-full-records} (@option{-B}) option is turned on by default when
  3515. @command{tar} reads an archive from standard input, or from a remote
  3516. machine. This is because on BSD Unix systems, attempting to read a
  3517. pipe returns however much happens to be in the pipe, even if it is
  3518. less than was requested. If this option were not enabled, @command{tar}
  3519. would fail as soon as it read an incomplete record from the pipe.
  3520. If you're not sure of the blocking factor of an archive, you can
  3521. read the archive by specifying @option{--read-full-records} (@option{-B}) and
  3522. @option{--blocking-factor=@var{512-size}} (@option{-b
  3523. @var{512-size}}), using a blocking factor larger than what the archive
  3524. uses. This lets you avoid having to determine the blocking factor
  3525. of an archive. @xref{Blocking Factor}.
  3526. @menu
  3527. * read full records::
  3528. * Ignore Zeros::
  3529. @end menu
  3530. @node read full records
  3531. @unnumberedsubsubsec Reading Full Records
  3532. @FIXME{need sentence or so of intro here}
  3533. @table @option
  3534. @opindex read-full-records
  3535. @item --read-full-records
  3536. @item -B
  3537. Use in conjunction with @option{--extract} (@option{--get},
  3538. @option{-x}) to read an archive which contains incomplete records, or
  3539. one which has a blocking factor less than the one specified.
  3540. @end table
  3541. @node Ignore Zeros
  3542. @unnumberedsubsubsec Ignoring Blocks of Zeros
  3543. @cindex End-of-archive blocks, ignoring
  3544. @cindex Ignoring end-of-archive blocks
  3545. @opindex ignore-zeros
  3546. Normally, @command{tar} stops reading when it encounters a block of zeros
  3547. between file entries (which usually indicates the end of the archive).
  3548. @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
  3549. completely read an archive which contains a block of zeros before the
  3550. end (i.e., a damaged archive, or one that was created by concatenating
  3551. several archives together).
  3552. The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
  3553. versions of @command{tar} write garbage after the end-of-archive entry,
  3554. since that part of the media is never supposed to be read. @GNUTAR{}
  3555. does not write after the end of an archive, but seeks to
  3556. maintain compatiblity among archiving utilities.
  3557. @table @option
  3558. @item --ignore-zeros
  3559. @itemx -i
  3560. To ignore blocks of zeros (i.e., end-of-archive entries) which may be
  3561. encountered while reading an archive. Use in conjunction with
  3562. @option{--extract} or @option{--list}.
  3563. @end table
  3564. @node Writing
  3565. @subsection Changing How @command{tar} Writes Files
  3566. @UNREVISED
  3567. @FIXME{Introductory paragraph}
  3568. @menu
  3569. * Dealing with Old Files::
  3570. * Overwrite Old Files::
  3571. * Keep Old Files::
  3572. * Keep Newer Files::
  3573. * Unlink First::
  3574. * Recursive Unlink::
  3575. * Data Modification Times::
  3576. * Setting Access Permissions::
  3577. * Directory Modification Times and Permissions::
  3578. * Writing to Standard Output::
  3579. * Writing to an External Program::
  3580. * remove files::
  3581. @end menu
  3582. @node Dealing with Old Files
  3583. @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
  3584. @xopindex{overwrite-dir, introduced}
  3585. When extracting files, if @command{tar} discovers that the extracted
  3586. file already exists, it normally replaces the file by removing it before
  3587. extracting it, to prevent confusion in the presence of hard or symbolic
  3588. links. (If the existing file is a symbolic link, it is removed, not
  3589. followed.) However, if a directory cannot be removed because it is
  3590. nonempty, @command{tar} normally overwrites its metadata (ownership,
  3591. permission, etc.). The @option{--overwrite-dir} option enables this
  3592. default behavior. To be more cautious and preserve the metadata of
  3593. such a directory, use the @option{--no-overwrite-dir} option.
  3594. @cindex Overwriting old files, prevention
  3595. @xopindex{keep-old-files, introduced}
  3596. To be even more cautious and prevent existing files from being replaced, use
  3597. the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
  3598. to replace or update a file that already exists, i.e., a file with the
  3599. same name as an archive member prevents extraction of that archive
  3600. member. Instead, it reports an error.
  3601. @xopindex{overwrite, introduced}
  3602. To be more aggressive about altering existing files, use the
  3603. @option{--overwrite} option. It causes @command{tar} to overwrite
  3604. existing files and to follow existing symbolic links when extracting.
  3605. @cindex Protecting old files
  3606. Some people argue that @GNUTAR{} should not hesitate
  3607. to overwrite files with other files when extracting. When extracting
  3608. a @command{tar} archive, they expect to see a faithful copy of the
  3609. state of the file system when the archive was created. It is debatable
  3610. that this would always be a proper behavior. For example, suppose one
  3611. has an archive in which @file{usr/local} is a link to
  3612. @file{usr/local2}. Since then, maybe the site removed the link and
  3613. renamed the whole hierarchy from @file{/usr/local2} to
  3614. @file{/usr/local}. Such things happen all the time. I guess it would
  3615. not be welcome at all that @GNUTAR{} removes the
  3616. whole hierarchy just to make room for the link to be reinstated
  3617. (unless it @emph{also} simultaneously restores the full
  3618. @file{/usr/local2}, of course!) @GNUTAR{} is indeed
  3619. able to remove a whole hierarchy to reestablish a symbolic link, for
  3620. example, but @emph{only if} @option{--recursive-unlink} is specified
  3621. to allow this behavior. In any case, single files are silently
  3622. removed.
  3623. @xopindex{unlink-first, introduced}
  3624. Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
  3625. some cases by causing @command{tar} to remove files unconditionally
  3626. before extracting them.
  3627. @node Overwrite Old Files
  3628. @unnumberedsubsubsec Overwrite Old Files
  3629. @table @option
  3630. @opindex overwrite
  3631. @item --overwrite
  3632. Overwrite existing files and directory metadata when extracting files
  3633. from an archive.
  3634. This causes @command{tar} to write extracted files into the file system without
  3635. regard to the files already on the system; i.e., files with the same
  3636. names as archive members are overwritten when the archive is extracted.
  3637. It also causes @command{tar} to extract the ownership, permissions,
  3638. and time stamps onto any preexisting files or directories.
  3639. If the name of a corresponding file name is a symbolic link, the file
  3640. pointed to by the symbolic link will be overwritten instead of the
  3641. symbolic link itself (if this is possible). Moreover, special devices,
  3642. empty directories and even symbolic links are automatically removed if
  3643. they are in the way of extraction.
  3644. Be careful when using the @option{--overwrite} option, particularly when
  3645. combined with the @option{--absolute-names} (@option{-P}) option, as this combination
  3646. can change the contents, ownership or permissions of any file on your
  3647. system. Also, many systems do not take kindly to overwriting files that
  3648. are currently being executed.
  3649. @opindex overwrite-dir
  3650. @item --overwrite-dir
  3651. Overwrite the metadata of directories when extracting files from an
  3652. archive, but remove other files before extracting.
  3653. @end table
  3654. @node Keep Old Files
  3655. @unnumberedsubsubsec Keep Old Files
  3656. @table @option
  3657. @opindex keep-old-files
  3658. @item --keep-old-files
  3659. @itemx -k
  3660. Do not replace existing files from archive. The
  3661. @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
  3662. from replacing existing files with files with the same name from the
  3663. archive. The @option{--keep-old-files} option is meaningless with
  3664. @option{--list} (@option{-t}). Prevents @command{tar} from replacing
  3665. files in the file system during extraction.
  3666. @end table
  3667. @node Keep Newer Files
  3668. @unnumberedsubsubsec Keep Newer Files
  3669. @table @option
  3670. @opindex keep-newer-files
  3671. @item --keep-newer-files
  3672. Do not replace existing files that are newer than their archive
  3673. copies. This option is meaningless with @option{--list} (@option{-t}).
  3674. @end table
  3675. @node Unlink First
  3676. @unnumberedsubsubsec Unlink First
  3677. @table @option
  3678. @opindex unlink-first
  3679. @item --unlink-first
  3680. @itemx -U
  3681. Remove files before extracting over them.
  3682. This can make @command{tar} run a bit faster if you know in advance
  3683. that the extracted files all need to be removed. Normally this option
  3684. slows @command{tar} down slightly, so it is disabled by default.
  3685. @end table
  3686. @node Recursive Unlink
  3687. @unnumberedsubsubsec Recursive Unlink
  3688. @table @option
  3689. @opindex recursive-unlink
  3690. @item --recursive-unlink
  3691. When this option is specified, try removing files and directory hierarchies
  3692. before extracting over them. @emph{This is a dangerous option!}
  3693. @end table
  3694. If you specify the @option{--recursive-unlink} option,
  3695. @command{tar} removes @emph{anything} that keeps you from extracting a file
  3696. as far as current permissions will allow it. This could include removal
  3697. of the contents of a full directory hierarchy.
  3698. @node Data Modification Times
  3699. @unnumberedsubsubsec Setting Data Modification Times
  3700. @cindex Data modification times of extracted files
  3701. @cindex Modification times of extracted files
  3702. Normally, @command{tar} sets the data modification times of extracted
  3703. files to the corresponding times recorded for the files in the archive, but
  3704. limits the permissions of extracted files by the current @code{umask}
  3705. setting.
  3706. To set the data modification times of extracted files to the time when
  3707. the files were extracted, use the @option{--touch} (@option{-m}) option in
  3708. conjunction with @option{--extract} (@option{--get}, @option{-x}).
  3709. @table @option
  3710. @opindex touch
  3711. @item --touch
  3712. @itemx -m
  3713. Sets the data modification time of extracted archive members to the time
  3714. they were extracted, not the time recorded for them in the archive.
  3715. Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
  3716. @end table
  3717. @node Setting Access Permissions
  3718. @unnumberedsubsubsec Setting Access Permissions
  3719. @cindex Permissions of extracted files
  3720. @cindex Modes of extracted files
  3721. To set the modes (access permissions) of extracted files to those
  3722. recorded for those files in the archive, use @option{--same-permissions}
  3723. in conjunction with the @option{--extract} (@option{--get},
  3724. @option{-x}) operation.
  3725. @table @option
  3726. @opindex preserve-permissions
  3727. @opindex same-permissions
  3728. @item --preserve-permissions
  3729. @itemx --same-permissions
  3730. @c @itemx --ignore-umask
  3731. @itemx -p
  3732. Set modes of extracted archive members to those recorded in the
  3733. archive, instead of current umask settings. Use in conjunction with
  3734. @option{--extract} (@option{--get}, @option{-x}).
  3735. @end table
  3736. @node Directory Modification Times and Permissions
  3737. @unnumberedsubsubsec Directory Modification Times and Permissions
  3738. After sucessfully extracting a file member, @GNUTAR{} normally
  3739. restores its permissions and modification times, as described in the
  3740. previous sections. This cannot be done for directories, because
  3741. after extracting a directory @command{tar} will almost certainly
  3742. extract files into that directory and this will cause the directory
  3743. modification time to be updated. Moreover, restoring that directory
  3744. permissions may not permit file creation within it. Thus, restoring
  3745. directory permissions and modification times must be delayed at least
  3746. until all files have been extracted into that directory. @GNUTAR{}
  3747. restores directories using the following approach.
  3748. The extracted directories are created with the mode specified in the
  3749. archive, as modified by the umask of the user, which gives sufficient
  3750. permissions to allow file creation. The meta-information about the
  3751. directory is recorded in the temporary list of directories. When
  3752. preparing to extract next archive member, @GNUTAR{} checks if the
  3753. directory prefix of this file contains the remembered directory. If
  3754. it does not, the program assumes that all files have been extracted
  3755. into that directory, restores its modification time and permissions
  3756. and removes its entry from the internal list. This approach allows
  3757. to correctly restore directory meta-information in the majority of
  3758. cases, while keeping memory requirements sufficiently small. It is
  3759. based on the fact, that most @command{tar} archives use the predefined
  3760. order of members: first the directory, then all the files and
  3761. subdirectories in that directory.
  3762. However, this is not always true. The most important exception are
  3763. incremental archives (@pxref{Incremental Dumps}). The member order in
  3764. an incremental archive is reversed: first all directory members are
  3765. stored, followed by other (non-directory) members. So, when extracting
  3766. from incremental archives, @GNUTAR{} alters the above procedure. It
  3767. remebers all restored directories, and restores their meta-data
  3768. only after the entire archive has been processed. Notice, that you do
  3769. not need to specity any special options for that, as @GNUTAR{}
  3770. automatically detects archives in incremental format.
  3771. There may be cases, when such processing is required for normal archives
  3772. too. Consider the following example:
  3773. @smallexample
  3774. @group
  3775. $ @kbd{tar --no-recursion -cvf archive \
  3776. foo foo/file1 bar bar/file foo/file2}
  3777. foo/
  3778. foo/file1
  3779. bar/
  3780. bar/file
  3781. foo/file2
  3782. @end group
  3783. @end smallexample
  3784. During the normal operation, after encountering @file{bar}
  3785. @GNUTAR{} will assume that all files from the directory @file{foo}
  3786. were already extracted and will therefore restore its timestamp and
  3787. permission bits. However, after extracting @file{foo/file2} the
  3788. directory timestamp will be offset again.
  3789. To correctly restore directory meta-information in such cases, use
  3790. @option{delay-directory-restore} command line option:
  3791. @table @option
  3792. @opindex delay-directory-restore
  3793. @item --delay-directory-restore
  3794. Delays restoring of the modification times and permissions of extracted
  3795. directories until the end of extraction. This way, correct
  3796. meta-information is restored even if the archive has unusual member
  3797. ordering.
  3798. @opindex no-delay-directory-restore
  3799. @item --no-delay-directory-restore
  3800. Cancel the effect of the previous @option{--delay-directory-restore}.
  3801. Use this option if you have used @option{--delay-directory-restore} in
  3802. @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
  3803. temporarily disable it.
  3804. @end table
  3805. @node Writing to Standard Output
  3806. @unnumberedsubsubsec Writing to Standard Output
  3807. @cindex Writing extracted files to standard output
  3808. @cindex Standard output, writing extracted files to
  3809. To write the extracted files to the standard output, instead of
  3810. creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
  3811. conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
  3812. extracting files to send them through a pipe, and do not need to
  3813. preserve them in the file system. If you extract multiple members,
  3814. they appear on standard output concatenated, in the order they are
  3815. found in the archive.
  3816. @table @option
  3817. @opindex to-stdout
  3818. @item --to-stdout
  3819. @itemx -O
  3820. Writes files to the standard output. Use only in conjunction with
  3821. @option{--extract} (@option{--get}, @option{-x}). When this option is
  3822. used, instead of creating the files specified, @command{tar} writes
  3823. the contents of the files extracted to its standard output. This may
  3824. be useful if you are only extracting the files in order to send them
  3825. through a pipe. This option is meaningless with @option{--list}
  3826. (@option{-t}).
  3827. @end table
  3828. This can be useful, for example, if you have a tar archive containing
  3829. a big file and don't want to store the file on disk before processing
  3830. it. You can use a command like this:
  3831. @smallexample
  3832. tar -xOzf foo.tgz bigfile | process
  3833. @end smallexample
  3834. or even like this if you want to process the concatenation of the files:
  3835. @smallexample
  3836. tar -xOzf foo.tgz bigfile1 bigfile2 | process
  3837. @end smallexample
  3838. Hovewer, @option{--to-command} may be more convenient for use with
  3839. multiple files. See the next section.
  3840. @node Writing to an External Program
  3841. @unnumberedsubsubsec Writing to an External Program
  3842. You can instruct @command{tar} to send the contents of each extracted
  3843. file to the standard input of an external program:
  3844. @table @option
  3845. @opindex to-command
  3846. @item --to-command=@var{command}
  3847. Extract files and pipe their contents to the standard input of
  3848. @var{command}. When this option is used, instead of creating the
  3849. files specified, @command{tar} invokes @var{command} and pipes the
  3850. contents of the files to its standard output. @var{Command} may
  3851. contain command line arguments. The program is executed via
  3852. @code{sh -c}. Notice, that @var{command} is executed once for each regular file
  3853. extracted. Non-regular files (directories, etc.) are ignored when this
  3854. option is used.
  3855. @end table
  3856. The command can obtain the information about the file it processes
  3857. from the following environment variables:
  3858. @table @var
  3859. @vrindex TAR_FILETYPE, to-command environment
  3860. @item TAR_FILETYPE
  3861. Type of the file. It is a single letter with the following meaning:
  3862. @multitable @columnfractions 0.10 0.90
  3863. @item f @tab Regular file
  3864. @item d @tab Directory
  3865. @item l @tab Symbolic link
  3866. @item h @tab Hard link
  3867. @item b @tab Block device
  3868. @item c @tab Character device
  3869. @end multitable
  3870. Currently only regular files are supported.
  3871. @vrindex TAR_MODE, to-command environment
  3872. @item TAR_MODE
  3873. File mode, an octal number.
  3874. @vrindex TAR_FILENAME, to-command environment
  3875. @item TAR_FILENAME
  3876. The name of the file.
  3877. @vrindex TAR_REALNAME, to-command environment
  3878. @item TAR_REALNAME
  3879. Name of the file as stored in the archive.
  3880. @vrindex TAR_UNAME, to-command environment
  3881. @item TAR_UNAME
  3882. Name of the file owner.
  3883. @vrindex TAR_GNAME, to-command environment
  3884. @item TAR_GNAME
  3885. Name of the file owner group.
  3886. @vrindex TAR_ATIME, to-command environment
  3887. @item TAR_ATIME
  3888. Time of last access. It is a decimal number, representing seconds
  3889. since the epoch. If the archive provides times with nanosecond
  3890. precision, the nanoseconds are appended to the timestamp after a
  3891. decimal point.
  3892. @vrindex TAR_MTIME, to-command environment
  3893. @item TAR_MTIME
  3894. Time of last modification.
  3895. @vrindex TAR_CTIME, to-command environment
  3896. @item TAR_CTIME
  3897. Time of last status change.
  3898. @vrindex TAR_SIZE, to-command environment
  3899. @item TAR_SIZE
  3900. Size of the file.
  3901. @vrindex TAR_UID, to-command environment
  3902. @item TAR_UID
  3903. UID of the file owner.
  3904. @vrindex TAR_GID, to-command environment
  3905. @item TAR_GID
  3906. GID of the file owner.
  3907. @end table
  3908. In addition to these variables, @env{TAR_VERSION} contains the
  3909. @GNUTAR{} version number.
  3910. If @var{command} exits with a non-0 status, @command{tar} will print
  3911. an error message similar to the following:
  3912. @smallexample
  3913. tar: 2345: Child returned status 1
  3914. @end smallexample
  3915. Here, @samp{2345} is the PID of the finished process.
  3916. If this behavior is not wanted, use @option{--ignore-command-error}:
  3917. @table @option
  3918. @opindex ignore-command-error
  3919. @item --ignore-command-error
  3920. Ignore exit codes of subprocesses. Notice that if the program
  3921. exits on signal or otherwise terminates abnormally, the error message
  3922. will be printed even if this option is used.
  3923. @opindex no-ignore-command-error
  3924. @item --no-ignore-command-error
  3925. Cancel the effect of any previous @option{--ignore-command-error}
  3926. option. This option is useful if you have set
  3927. @option{--ignore-command-error} in @env{TAR_OPTIONS}
  3928. (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
  3929. @end table
  3930. @node remove files
  3931. @unnumberedsubsubsec Removing Files
  3932. @FIXME{The section is too terse. Something more to add? An example,
  3933. maybe?}
  3934. @table @option
  3935. @opindex remove-files
  3936. @item --remove-files
  3937. Remove files after adding them to the archive.
  3938. @end table
  3939. @node Scarce
  3940. @subsection Coping with Scarce Resources
  3941. @UNREVISED
  3942. @cindex Small memory
  3943. @cindex Running out of space
  3944. @menu
  3945. * Starting File::
  3946. * Same Order::
  3947. @end menu
  3948. @node Starting File
  3949. @unnumberedsubsubsec Starting File
  3950. @table @option
  3951. @opindex starting-file
  3952. @item --starting-file=@var{name}
  3953. @itemx -K @var{name}
  3954. Starts an operation in the middle of an archive. Use in conjunction
  3955. with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
  3956. @end table
  3957. @cindex Middle of the archive, starting in the
  3958. If a previous attempt to extract files failed due to lack of disk
  3959. space, you can use @option{--starting-file=@var{name}} (@option{-K
  3960. @var{name}}) to start extracting only after member @var{name} of the
  3961. archive. This assumes, of course, that there is now free space, or
  3962. that you are now extracting into a different file system. (You could
  3963. also choose to suspend @command{tar}, remove unnecessary files from
  3964. the file system, and then restart the same @command{tar} operation.
  3965. In this case, @option{--starting-file} is not necessary.
  3966. @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
  3967. @node Same Order
  3968. @unnumberedsubsubsec Same Order
  3969. @table @option
  3970. @cindex Large lists of file names on small machines
  3971. @opindex same-order
  3972. @opindex preserve-order
  3973. @item --same-order
  3974. @itemx --preserve-order
  3975. @itemx -s
  3976. To process large lists of file names on machines with small amounts of
  3977. memory. Use in conjunction with @option{--compare} (@option{--diff},
  3978. @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
  3979. (@option{--get}, @option{-x}).
  3980. @end table
  3981. The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
  3982. names to be listed or extracted is sorted in the same order as the
  3983. files in the archive. This allows a large list of names to be used,
  3984. even on a small machine that would not otherwise be able to hold all
  3985. the names in memory at the same time. Such a sorted list can easily be
  3986. created by running @samp{tar -t} on the archive and editing its output.
  3987. This option is probably never needed on modern computer systems.
  3988. @node backup
  3989. @section Backup options
  3990. @cindex backup options
  3991. @GNUTAR{} offers options for making backups of files
  3992. before writing new versions. These options control the details of
  3993. these backups. They may apply to the archive itself before it is
  3994. created or rewritten, as well as individual extracted members. Other
  3995. @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
  3996. and @command{mv}, for example) offer similar options.
  3997. Backup options may prove unexpectedly useful when extracting archives
  3998. containing many members having identical name, or when extracting archives
  3999. on systems having file name limitations, making different members appear
  4000. has having similar names through the side-effect of name truncation.
  4001. (This is true only if we have a good scheme for truncated backup names,
  4002. which I'm not sure at all: I suspect work is needed in this area.)
  4003. When any existing file is backed up before being overwritten by extraction,
  4004. then clashing files are automatically be renamed to be unique, and the
  4005. true name is kept for only the last file of a series of clashing files.
  4006. By using verbose mode, users may track exactly what happens.
  4007. At the detail level, some decisions are still experimental, and may
  4008. change in the future, we are waiting comments from our users. So, please
  4009. do not learn to depend blindly on the details of the backup features.
  4010. For example, currently, directories themselves are never renamed through
  4011. using these options, so, extracting a file over a directory still has
  4012. good chances to fail. Also, backup options apply to created archives,
  4013. not only to extracted members. For created archives, backups will not
  4014. be attempted when the archive is a block or character device, or when it
  4015. refers to a remote file.
  4016. For the sake of simplicity and efficiency, backups are made by renaming old
  4017. files prior to creation or extraction, and not by copying. The original
  4018. name is restored if the file creation fails. If a failure occurs after a
  4019. partial extraction of a file, both the backup and the partially extracted
  4020. file are kept.
  4021. @table @samp
  4022. @item --backup[=@var{method}]
  4023. @opindex backup
  4024. @vindex VERSION_CONTROL
  4025. @cindex backups
  4026. Back up files that are about to be overwritten or removed.
  4027. Without this option, the original versions are destroyed.
  4028. Use @var{method} to determine the type of backups made.
  4029. If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
  4030. environment variable. And if @env{VERSION_CONTROL} is not set,
  4031. use the @samp{existing} method.
  4032. @vindex version-control @r{Emacs variable}
  4033. This option corresponds to the Emacs variable @samp{version-control};
  4034. the same values for @var{method} are accepted as in Emacs. This option
  4035. also allows more descriptive names. The valid @var{method}s are:
  4036. @table @samp
  4037. @item t
  4038. @itemx numbered
  4039. @cindex numbered @r{backup method}
  4040. Always make numbered backups.
  4041. @item nil
  4042. @itemx existing
  4043. @cindex existing @r{backup method}
  4044. Make numbered backups of files that already have them, simple backups
  4045. of the others.
  4046. @item never
  4047. @itemx simple
  4048. @cindex simple @r{backup method}
  4049. Always make simple backups.
  4050. @end table
  4051. @item --suffix=@var{suffix}
  4052. @opindex suffix
  4053. @cindex backup suffix
  4054. @vindex SIMPLE_BACKUP_SUFFIX
  4055. Append @var{suffix} to each backup file made with @option{--backup}. If this
  4056. option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
  4057. environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
  4058. set, the default is @samp{~}, just as in Emacs.
  4059. @end table
  4060. @node Applications
  4061. @section Notable @command{tar} Usages
  4062. @UNREVISED
  4063. @FIXME{Using Unix file linking capability to recreate directory
  4064. structures---linking files into one subdirectory and then
  4065. @command{tar}ring that directory.}
  4066. @FIXME{Nice hairy example using absolute-names, newer, etc.}
  4067. @findex uuencode
  4068. You can easily use archive files to transport a group of files from
  4069. one system to another: put all relevant files into an archive on one
  4070. computer system, transfer the archive to another system, and extract
  4071. the contents there. The basic transfer medium might be magnetic tape,
  4072. Internet FTP, or even electronic mail (though you must encode the
  4073. archive with @command{uuencode} in order to transport it properly by
  4074. mail). Both machines do not have to use the same operating system, as
  4075. long as they both support the @command{tar} program.
  4076. For example, here is how you might copy a directory's contents from
  4077. one disk to another, while preserving the dates, modes, owners and
  4078. link-structure of all the files therein. In this case, the transfer
  4079. medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
  4080. @smallexample
  4081. $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
  4082. @end smallexample
  4083. @noindent
  4084. You can avoid subshells by using @option{-C} option:
  4085. @smallexample
  4086. $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
  4087. @end smallexample
  4088. @noindent
  4089. The command also works using short option forms:
  4090. @smallexample
  4091. $ @kbd{(cd sourcedir; tar --create --file=- . ) \
  4092. | (cd targetdir; tar --extract --file=-)}
  4093. # Or:
  4094. $ @kbd{tar --directory sourcedir --create --file=- . ) \
  4095. | tar --directory targetdir --extract --file=-}
  4096. @end smallexample
  4097. @noindent
  4098. This is one of the easiest methods to transfer a @command{tar} archive.
  4099. @node looking ahead
  4100. @section Looking Ahead: The Rest of this Manual
  4101. You have now seen how to use all eight of the operations available to
  4102. @command{tar}, and a number of the possible options. The next chapter
  4103. explains how to choose and change file and archive names, how to use
  4104. files to store names of other files which you can then call as
  4105. arguments to @command{tar} (this can help you save time if you expect to
  4106. archive the same list of files a number of times), and so forth.
  4107. @FIXME{in case it's not obvious, i'm making this up in some sense
  4108. based on my limited memory of what the next chapter *really* does. i
  4109. just wanted to flesh out this final section a little bit so i'd
  4110. remember to stick it in here. :-)}
  4111. If there are too many files to conveniently list on the command line,
  4112. you can list the names in a file, and @command{tar} will read that file.
  4113. @xref{files}.
  4114. There are various ways of causing @command{tar} to skip over some files,
  4115. and not archive them. @xref{Choosing}.
  4116. @node Backups
  4117. @chapter Performing Backups and Restoring Files
  4118. @UNREVISED
  4119. @GNUTAR{} is distributed along with the scripts
  4120. which the Free Software Foundation uses for performing backups. There
  4121. is no corresponding scripts available yet for doing restoration of
  4122. files. Even if there is a good chance those scripts may be satisfying
  4123. to you, they are not the only scripts or methods available for doing
  4124. backups and restore. You may well create your own, or use more
  4125. sophisticated packages dedicated to that purpose.
  4126. Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
  4127. Automatic Network Disk Archiver), a backup system developed by James
  4128. da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
  4129. This is free software, and it is available at these places:
  4130. @smallexample
  4131. http://www.cs.umd.edu/projects/amanda/amanda.html
  4132. ftp://ftp.cs.umd.edu/pub/amanda
  4133. @end smallexample
  4134. @FIXME{
  4135. Here is a possible plan for a future documentation about the backuping
  4136. scripts which are provided within the @GNUTAR{}
  4137. distribution.
  4138. @itemize @bullet
  4139. @item dumps
  4140. @itemize @minus
  4141. @item what are dumps
  4142. @item different levels of dumps
  4143. @itemize +
  4144. @item full dump = dump everything
  4145. @item level 1, level 2 dumps etc
  4146. A level @var{n} dump dumps everything changed since the last level
  4147. @var{n}-1 dump (?)
  4148. @end itemize
  4149. @item how to use scripts for dumps (ie, the concept)
  4150. @itemize +
  4151. @item scripts to run after editing backup specs (details)
  4152. @end itemize
  4153. @item Backup Specs, what is it.
  4154. @itemize +
  4155. @item how to customize
  4156. @item actual text of script [/sp/dump/backup-specs]
  4157. @end itemize
  4158. @item Problems
  4159. @itemize +
  4160. @item rsh doesn't work
  4161. @item rtape isn't installed
  4162. @item (others?)
  4163. @end itemize
  4164. @item the @option{--incremental} option of tar
  4165. @item tapes
  4166. @itemize +
  4167. @item write protection
  4168. @item types of media, different sizes and types, useful for different things
  4169. @item files and tape marks
  4170. one tape mark between files, two at end.
  4171. @item positioning the tape
  4172. MT writes two at end of write,
  4173. backspaces over one when writing again.
  4174. @end itemize
  4175. @end itemize
  4176. @end itemize
  4177. }
  4178. This chapter documents both the provided shell scripts and @command{tar}
  4179. options which are more specific to usage as a backup tool.
  4180. To @dfn{back up} a file system means to create archives that contain
  4181. all the files in that file system. Those archives can then be used to
  4182. restore any or all of those files (for instance if a disk crashes or a
  4183. file is accidentally deleted). File system @dfn{backups} are also
  4184. called @dfn{dumps}.
  4185. @menu
  4186. * Full Dumps:: Using @command{tar} to Perform Full Dumps
  4187. * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
  4188. * Backup Levels:: Levels of Backups
  4189. * Backup Parameters:: Setting Parameters for Backups and Restoration
  4190. * Scripted Backups:: Using the Backup Scripts
  4191. * Scripted Restoration:: Using the Restore Script
  4192. @end menu
  4193. @node Full Dumps
  4194. @section Using @command{tar} to Perform Full Dumps
  4195. @UNREVISED
  4196. @cindex full dumps
  4197. @cindex dumps, full
  4198. @cindex corrupted archives
  4199. Full dumps should only be made when no other people or programs
  4200. are modifying files in the file system. If files are modified while
  4201. @command{tar} is making the backup, they may not be stored properly in
  4202. the archive, in which case you won't be able to restore them if you
  4203. have to. (Files not being modified are written with no trouble, and do
  4204. not corrupt the entire archive.)
  4205. You will want to use the @option{--label=@var{archive-label}}
  4206. (@option{-V @var{archive-label}}) option to give the archive a
  4207. volume label, so you can tell what this archive is even if the label
  4208. falls off the tape, or anything like that.
  4209. Unless the file system you are dumping is guaranteed to fit on
  4210. one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
  4211. Make sure you have enough tapes on hand to complete the backup.
  4212. If you want to dump each file system separately you will need to use
  4213. the @option{--one-file-system} option to prevent
  4214. @command{tar} from crossing file system boundaries when storing
  4215. (sub)directories.
  4216. The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
  4217. option is not needed, since this is a complete copy of everything in
  4218. the file system, and a full restore from this backup would only be
  4219. done onto a completely
  4220. empty disk.
  4221. Unless you are in a hurry, and trust the @command{tar} program (and your
  4222. tapes), it is a good idea to use the @option{--verify} (@option{-W})
  4223. option, to make sure your files really made it onto the dump properly.
  4224. This will also detect cases where the file was modified while (or just
  4225. after) it was being archived. Not all media (notably cartridge tapes)
  4226. are capable of being verified, unfortunately.
  4227. @node Incremental Dumps
  4228. @section Using @command{tar} to Perform Incremental Dumps
  4229. @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
  4230. stores additional metadata so that exact state of the file system
  4231. can be restored when extracting the archive.
  4232. @GNUTAR{} currently offers two options for handling incremental
  4233. backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
  4234. @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
  4235. @opindex listed-incremental
  4236. The option @option{--listed-incremental} instructs tar to operate on
  4237. an incremental archive with additional metadata stored in a standalone
  4238. file, called a @dfn{snapshot file}. The purpose of this file is to help
  4239. determine which files have been changed, added or deleted since the
  4240. last backup, so that the next incremental backup will contain only
  4241. modified files. The name of the snapshot file is given as an argument
  4242. to the option:
  4243. @table @option
  4244. @item --listed-incremental=@var{file}
  4245. @itemx -g @var{file}
  4246. Handle incremental backups with snapshot data in @var{file}.
  4247. @end table
  4248. To create an incremental backup, you would use
  4249. @option{--listed-incremental} together with @option{--create}
  4250. (@pxref{create}). For example:
  4251. @smallexample
  4252. $ @kbd{tar --create \
  4253. --file=archive.1.tar \
  4254. --listed-incremental=/var/log/usr.snar \
  4255. /usr}
  4256. @end smallexample
  4257. This will create in @file{archive.1.tar} an incremental backup of
  4258. the @file{/usr} file system, storing additional metadata in the file
  4259. @file{/var/log/usr.snar}. If this file does not exist, it will be
  4260. created. The created archive will then be a @dfn{level 0 backup};
  4261. please see the next section for more on backup levels.
  4262. Otherwise, if the file @file{/var/log/usr.snar} exists, it
  4263. determines which files are modified. In this case only these files will be
  4264. stored in the archive. Suppose, for example, that after running the
  4265. above command, you delete file @file{/usr/doc/old} and create
  4266. directory @file{/usr/local/db} with the following contents:
  4267. @smallexample
  4268. $ @kbd{ls /usr/local/db}
  4269. /usr/local/db/data
  4270. /usr/local/db/index
  4271. @end smallexample
  4272. Some time later you create another incremental backup. You will
  4273. then see:
  4274. @smallexample
  4275. $ @kbd{tar --create \
  4276. --file=archive.2.tar \
  4277. --listed-incremental=/var/log/usr.snar \
  4278. /usr}
  4279. tar: usr/local/db: Directory is new
  4280. usr/local/db/
  4281. usr/local/db/data
  4282. usr/local/db/index
  4283. @end smallexample
  4284. @noindent
  4285. The created archive @file{archive.2.tar} will contain only these
  4286. three members. This archive is called a @dfn{level 1 backup}. Notice
  4287. that @file{/var/log/usr.snar} will be updated with the new data, so if
  4288. you plan to create more @samp{level 1} backups, it is necessary to
  4289. create a working copy of the snapshot file before running
  4290. @command{tar}. The above example will then be modified as follows:
  4291. @smallexample
  4292. $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
  4293. $ @kbd{tar --create \
  4294. --file=archive.2.tar \
  4295. --listed-incremental=/var/log/usr.snar-1 \
  4296. /usr}
  4297. @end smallexample
  4298. Incremental dumps depend crucially on time stamps, so the results are
  4299. unreliable if you modify a file's time stamps during dumping (e.g.,
  4300. with the @option{--atime-preserve=replace} option), or if you set the clock
  4301. backwards.
  4302. Metadata stored in snapshot files include device numbers, which,
  4303. obviously is supposed to be a non-volatile value. However, it turns
  4304. out that NFS devices have undependable values when an automounter
  4305. gets in the picture. This can lead to a great deal of spurious
  4306. redumping in incremental dumps, so it is somewhat useless to compare
  4307. two NFS devices numbers over time. The solution implemented currently
  4308. is to considers all NFS devices as being equal when it comes to
  4309. comparing directories; this is fairly gross, but there does not seem
  4310. to be a better way to go.
  4311. Note that incremental archives use @command{tar} extensions and may
  4312. not be readable by non-@acronym{GNU} versions of the @command{tar} program.
  4313. @xopindex{listed-incremental, using with @option{--extract}}
  4314. @xopindex{extract, using with @option{--listed-incremental}}
  4315. To extract from the incremental dumps, use
  4316. @option{--listed-incremental} together with @option{--extract}
  4317. option (@pxref{extracting files}). In this case, @command{tar} does
  4318. not need to access snapshot file, since all the data necessary for
  4319. extraction are stored in the archive itself. So, when extracting, you
  4320. can give whatever argument to @option{--listed-incremental}, the usual
  4321. practice is to use @option{--listed-incremental=/dev/null}.
  4322. Alternatively, you can use @option{--incremental}, which needs no
  4323. arguments. In general, @option{--incremental} (@option{-G}) can be
  4324. used as a shortcut for @option{--listed-incremental} when listing or
  4325. extracting incremental backups (for more information, regarding this
  4326. option, @pxref{incremental-op}).
  4327. When extracting from the incremental backup @GNUTAR{} attempts to
  4328. restore the exact state the file system had when the archive was
  4329. created. In particular, it will @emph{delete} those files in the file
  4330. system that did not exist in their directories when the archive was
  4331. created. If you have created several levels of incremental files,
  4332. then in order to restore the exact contents the file system had when
  4333. the last level was created, you will need to restore from all backups
  4334. in turn. Continuing our example, to restore the state of @file{/usr}
  4335. file system, one would do@footnote{Notice, that since both archives
  4336. were created withouth @option{-P} option (@pxref{absolute}), these
  4337. commands should be run from the root file system.}:
  4338. @smallexample
  4339. $ @kbd{tar --extract \
  4340. --listed-incremental=/dev/null \
  4341. --file archive.1.tar}
  4342. $ @kbd{tar --extract \
  4343. --listed-incremental=/dev/null \
  4344. --file archive.2.tar}
  4345. @end smallexample
  4346. To list the contents of an incremental archive, use @option{--list}
  4347. (@pxref{list}), as usual. To obtain more information about the
  4348. archive, use @option{--listed-incremental} or @option{--incremental}
  4349. combined with two @option{--verbose} options@footnote{Two
  4350. @option{--verbose} options were selected to avoid breaking usual
  4351. verbose listing output (@option{--list --verbose}) when using in
  4352. scripts.
  4353. @xopindex{incremental, using with @option{--list}}
  4354. @xopindex{listed-incremental, using with @option{--list}}
  4355. @xopindex{list, using with @option{--incremental}}
  4356. @xopindex{list, using with @option{--listed-incremental}}
  4357. Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
  4358. contents of the DUMPDIR header (with terminating nulls) when
  4359. @option{--incremental} or @option{--listed-incremental} option was
  4360. given, no matter what the verbosity level. This behavior, and,
  4361. especially, the binary output it produced were considered incovenient
  4362. and were changed in version 1.16}:
  4363. @smallexample
  4364. @kbd{tar --list --incremental --verbose --verbose archive.tar}
  4365. @end smallexample
  4366. This command will print, for each directory in the archive, the list
  4367. of files in that directory at the time the archive was created. This
  4368. information is put out in a format which is both human-readable and
  4369. unambiguous for a program: each file name is printed as
  4370. @smallexample
  4371. @var{x} @var{file}
  4372. @end smallexample
  4373. @noindent
  4374. where @var{x} is a letter describing the status of the file: @samp{Y}
  4375. if the file is present in the archive, @samp{N} if the file is not
  4376. included in the archive, or a @samp{D} if the file is a directory (and
  4377. is included in the archive). @xref{Dumpdir}, for the detailed
  4378. description of dumpdirs and status codes. Each such
  4379. line is terminated by a newline character. The last line is followed
  4380. by an additional newline to indicate the end of the data.
  4381. @anchor{incremental-op}The option @option{--incremental} (@option{-G})
  4382. gives the same behavior as @option{--listed-incremental} when used
  4383. with @option{--list} and @option{--extract} options. When used with
  4384. @option{--create} option, it creates an incremental archive without
  4385. creating snapshot file. Thus, it is impossible to create several
  4386. levels of incremental backups with @option{--incremental} option.
  4387. @node Backup Levels
  4388. @section Levels of Backups
  4389. An archive containing all the files in the file system is called a
  4390. @dfn{full backup} or @dfn{full dump}. You could insure your data by
  4391. creating a full dump every day. This strategy, however, would waste a
  4392. substantial amount of archive media and user time, as unchanged files
  4393. are daily re-archived.
  4394. It is more efficient to do a full dump only occasionally. To back up
  4395. files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
  4396. one} dump archives all the files that have changed since the last full
  4397. dump.
  4398. A typical dump strategy would be to perform a full dump once a week,
  4399. and a level one dump once a day. This means some versions of files
  4400. will in fact be archived more than once, but this dump strategy makes
  4401. it possible to restore a file system to within one day of accuracy by
  4402. only extracting two archives---the last weekly (full) dump and the
  4403. last daily (level one) dump. The only information lost would be in
  4404. files changed or created since the last daily backup. (Doing dumps
  4405. more than once a day is usually not worth the trouble).
  4406. @GNUTAR{} comes with scripts you can use to do full
  4407. and level-one (actually, even level-two and so on) dumps. Using
  4408. scripts (shell programs) to perform backups and restoration is a
  4409. convenient and reliable alternative to typing out file name lists
  4410. and @command{tar} commands by hand.
  4411. Before you use these scripts, you need to edit the file
  4412. @file{backup-specs}, which specifies parameters used by the backup
  4413. scripts and by the restore script. This file is usually located
  4414. in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
  4415. detailed description. Once the backup parameters are set, you can
  4416. perform backups or restoration by running the appropriate script.
  4417. The name of the backup script is @code{backup}. The name of the
  4418. restore script is @code{restore}. The following sections describe
  4419. their use in detail.
  4420. @emph{Please Note:} The backup and restoration scripts are
  4421. designed to be used together. While it is possible to restore files by
  4422. hand from an archive which was created using a backup script, and to create
  4423. an archive by hand which could then be extracted using the restore script,
  4424. it is easier to use the scripts. @xref{Incremental Dumps}, before
  4425. making such an attempt.
  4426. @node Backup Parameters
  4427. @section Setting Parameters for Backups and Restoration
  4428. The file @file{backup-specs} specifies backup parameters for the
  4429. backup and restoration scripts provided with @command{tar}. You must
  4430. edit @file{backup-specs} to fit your system configuration and schedule
  4431. before using these scripts.
  4432. Syntactically, @file{backup-specs} is a shell script, containing
  4433. mainly variable assignments. However, any valid shell construct
  4434. is allowed in this file. Particularly, you may wish to define
  4435. functions within that script (e.g., see @code{RESTORE_BEGIN} below).
  4436. For more information about shell script syntax, please refer to
  4437. @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
  4438. g_02, the definition of the Shell Command Language}. See also
  4439. @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
  4440. The shell variables controlling behavior of @code{backup} and
  4441. @code{restore} are described in the following subsections.
  4442. @menu
  4443. * General-Purpose Variables::
  4444. * Magnetic Tape Control::
  4445. * User Hooks::
  4446. * backup-specs example:: An Example Text of @file{Backup-specs}
  4447. @end menu
  4448. @node General-Purpose Variables
  4449. @subsection General-Purpose Variables
  4450. @defvr {Backup variable} ADMINISTRATOR
  4451. The user name of the backup administrator. @code{Backup} scripts
  4452. sends a backup report to this address.
  4453. @end defvr
  4454. @defvr {Backup variable} BACKUP_HOUR
  4455. The hour at which the backups are done. This can be a number from 0
  4456. to 23, or the time specification in form @var{hours}:@var{minutes},
  4457. or the string @samp{now}.
  4458. This variable is used by @code{backup}. Its value may be overridden
  4459. using @option{--time} option (@pxref{Scripted Backups}).
  4460. @end defvr
  4461. @defvr {Backup variable} TAPE_FILE
  4462. The device @command{tar} writes the archive to. If @var{TAPE_FILE}
  4463. is a remote archive (@pxref{remote-dev}), backup script will suppose
  4464. that your @command{mt} is able to access remote devices. If @var{RSH}
  4465. (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
  4466. invocations of @command{mt}.
  4467. @end defvr
  4468. @defvr {Backup variable} BLOCKING
  4469. The blocking factor @command{tar} will use when writing the dump archive.
  4470. @xref{Blocking Factor}.
  4471. @end defvr
  4472. @defvr {Backup variable} BACKUP_DIRS
  4473. A list of file systems to be dumped (for @code{backup}), or restored
  4474. (for @code{restore}). You can include any directory
  4475. name in the list --- subdirectories on that file system will be
  4476. included, regardless of how they may look to other networked machines.
  4477. Subdirectories on other file systems will be ignored.
  4478. The host name specifies which host to run @command{tar} on, and should
  4479. normally be the host that actually contains the file system. However,
  4480. the host machine must have @GNUTAR{} installed, and
  4481. must be able to access the directory containing the backup scripts and
  4482. their support files using the same file name that is used on the
  4483. machine where the scripts are run (i.e. what @command{pwd} will print
  4484. when in that directory on that machine). If the host that contains
  4485. the file system does not have this capability, you can specify another
  4486. host as long as it can access the file system through NFS.
  4487. If the list of file systems is very long you may wish to put it
  4488. in a separate file. This file is usually named
  4489. @file{/etc/backup/dirs}, but this name may be overridden in
  4490. @file{backup-specs} using @code{DIRLIST} variable.
  4491. @end defvr
  4492. @defvr {Backup variable} DIRLIST
  4493. A path to the file containing the list of the file systems to backup
  4494. or restore. By default it is @file{/etc/backup/dirs}.
  4495. @end defvr
  4496. @defvr {Backup variable} BACKUP_FILES
  4497. A list of individual files to be dumped (for @code{backup}), or restored
  4498. (for @code{restore}). These should be accessible from the machine on
  4499. which the backup script is run.
  4500. If the list of file systems is very long you may wish to store it
  4501. in a separate file. This file is usually named
  4502. @file{/etc/backup/files}, but this name may be overridden in
  4503. @file{backup-specs} using @code{FILELIST} variable.
  4504. @end defvr
  4505. @defvr {Backup variable} FILELIST
  4506. A path to the file containing the list of the individual files to backup
  4507. or restore. By default it is @file{/etc/backup/files}.
  4508. @end defvr
  4509. @defvr {Backup variable} MT
  4510. Full file name of @command{mt} binary.
  4511. @end defvr
  4512. @defvr {Backup variable} RSH
  4513. @anchor{RSH}
  4514. Full file name of @command{rsh} binary or its equivalent. You may wish to
  4515. set it to @code{ssh}, to improve security. In this case you will have
  4516. to use public key authentication.
  4517. @end defvr
  4518. @defvr {Backup variable} RSH_COMMAND
  4519. Full file name of @command{rsh} binary on remote mashines. This will
  4520. be passed via @option{--rsh-command} option to the remote invocation
  4521. of @GNUTAR{}.
  4522. @end defvr
  4523. @defvr {Backup variable} VOLNO_FILE
  4524. Name of temporary file to hold volume numbers. This needs to be accessible
  4525. by all the machines which have file systems to be dumped.
  4526. @end defvr
  4527. @defvr {Backup variable} XLIST
  4528. Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
  4529. located on the remote machine and containing the list of files to
  4530. be excluded from the backup. Exclude file lists are searched in
  4531. /etc/tar-backup directory. A common use for exclude file lists
  4532. is to exclude files containing security-sensitive information
  4533. (e.g., @file{/etc/shadow} from backups).
  4534. This variable affects only @code{backup}.
  4535. @end defvr
  4536. @defvr {Backup variable} SLEEP_TIME
  4537. Time to sleep between dumps of any two successive file systems
  4538. This variable affects only @code{backup}.
  4539. @end defvr
  4540. @defvr {Backup variable} DUMP_REMIND_SCRIPT
  4541. Script to be run when it's time to insert a new tape in for the next
  4542. volume. Administrators may want to tailor this script for their site.
  4543. If this variable isn't set, @GNUTAR{} will display its built-in
  4544. prompt, and will expect confirmation from the console. For the
  4545. description of the default prompt, see @ref{change volume prompt}.
  4546. @end defvr
  4547. @defvr {Backup variable} SLEEP_MESSAGE
  4548. Message to display on the terminal while waiting for dump time. Usually
  4549. this will just be some literal text.
  4550. @end defvr
  4551. @defvr {Backup variable} TAR
  4552. Full file name of the @GNUTAR{} executable. If this is not set, backup
  4553. scripts will search @command{tar} in the current shell path.
  4554. @end defvr
  4555. @node Magnetic Tape Control
  4556. @subsection Magnetic Tape Control
  4557. Backup scripts access tape device using special @dfn{hook functions}.
  4558. These functions take a single argument -- the name of the tape
  4559. device. Their names are kept in the following variables:
  4560. @defvr {Backup variable} MT_BEGIN
  4561. The name of @dfn{begin} function. This function is called before
  4562. accessing the drive. By default it retensions the tape:
  4563. @smallexample
  4564. MT_BEGIN=mt_begin
  4565. mt_begin() @{
  4566. mt -f "$1" retension
  4567. @}
  4568. @end smallexample
  4569. @end defvr
  4570. @defvr {Backup variable} MT_REWIND
  4571. The name of @dfn{rewind} function. The default definition is as
  4572. follows:
  4573. @smallexample
  4574. MT_REWIND=mt_rewind
  4575. mt_rewind() @{
  4576. mt -f "$1" rewind
  4577. @}
  4578. @end smallexample
  4579. @end defvr
  4580. @defvr {Backup variable} MT_OFFLINE
  4581. The name of the function switching the tape off line. By default
  4582. it is defined as follows:
  4583. @smallexample
  4584. MT_OFFLINE=mt_offline
  4585. mt_offline() @{
  4586. mt -f "$1" offl
  4587. @}
  4588. @end smallexample
  4589. @end defvr
  4590. @defvr {Backup variable} MT_STATUS
  4591. The name of the function used to obtain the status of the archive device,
  4592. including error count. Default definition:
  4593. @smallexample
  4594. MT_STATUS=mt_status
  4595. mt_status() @{
  4596. mt -f "$1" status
  4597. @}
  4598. @end smallexample
  4599. @end defvr
  4600. @node User Hooks
  4601. @subsection User Hooks
  4602. @dfn{User hooks} are shell functions executed before and after
  4603. each @command{tar} invocation. Thus, there are @dfn{backup
  4604. hooks}, which are executed before and after dumping each file
  4605. system, and @dfn{restore hooks}, executed before and
  4606. after restoring a file system. Each user hook is a shell function
  4607. taking four arguments:
  4608. @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
  4609. Its arguments are:
  4610. @table @var
  4611. @item level
  4612. Current backup or restore level.
  4613. @item host
  4614. Name or IP address of the host machine being dumped or restored.
  4615. @item fs
  4616. Full path name to the file system being dumped or restored.
  4617. @item fsname
  4618. File system name with directory separators replaced with colons. This
  4619. is useful, e.g., for creating unique files.
  4620. @end table
  4621. @end deffn
  4622. Following variables keep the names of user hook functions
  4623. @defvr {Backup variable} DUMP_BEGIN
  4624. Dump begin function. It is executed before dumping the file system.
  4625. @end defvr
  4626. @defvr {Backup variable} DUMP_END
  4627. Executed after dumping the file system.
  4628. @end defvr
  4629. @defvr {Backup variable} RESTORE_BEGIN
  4630. Executed before restoring the file system.
  4631. @end defvr
  4632. @defvr {Backup variable} RESTORE_END
  4633. Executed after restoring the file system.
  4634. @end defvr
  4635. @node backup-specs example
  4636. @subsection An Example Text of @file{Backup-specs}
  4637. The following is an example of @file{backup-specs}:
  4638. @smallexample
  4639. # site-specific parameters for file system backup.
  4640. ADMINISTRATOR=friedman
  4641. BACKUP_HOUR=1
  4642. TAPE_FILE=/dev/nrsmt0
  4643. # Use @code{ssh} instead of the less secure @code{rsh}
  4644. RSH=/usr/bin/ssh
  4645. RSH_COMMAND=/usr/bin/ssh
  4646. # Override MT_STATUS function:
  4647. my_status() @{
  4648. mts -t $TAPE_FILE
  4649. @}
  4650. MT_STATUS=my_status
  4651. # Disable MT_OFFLINE function
  4652. MT_OFFLINE=:
  4653. BLOCKING=124
  4654. BACKUP_DIRS="
  4655. albert:/fs/fsf
  4656. apple-gunkies:/gd
  4657. albert:/fs/gd2
  4658. albert:/fs/gp
  4659. geech:/usr/jla
  4660. churchy:/usr/roland
  4661. albert:/
  4662. albert:/usr
  4663. apple-gunkies:/
  4664. apple-gunkies:/usr
  4665. gnu:/hack
  4666. gnu:/u
  4667. apple-gunkies:/com/mailer/gnu
  4668. apple-gunkies:/com/archive/gnu"
  4669. BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
  4670. @end smallexample
  4671. @node Scripted Backups
  4672. @section Using the Backup Scripts
  4673. The syntax for running a backup script is:
  4674. @smallexample
  4675. backup --level=@var{level} --time=@var{time}
  4676. @end smallexample
  4677. The @option{level} option requests the dump level. Thus, to produce
  4678. a full dump, specify @code{--level=0} (this is the default, so
  4679. @option{--level} may be omitted if its value is @code{0}).
  4680. @footnote{For backward compatibility, the @code{backup} will also
  4681. try to deduce the requested dump level from the name of the
  4682. script itself. If the name consists of a string @samp{level-}
  4683. followed by a single decimal digit, that digit is taken as
  4684. the dump level number. Thus, you may create a link from @code{backup}
  4685. to @code{level-1} and then run @code{level-1} whenever you need to
  4686. create a level one dump.}
  4687. The @option{--time} option determines when should the backup be
  4688. run. @var{Time} may take three forms:
  4689. @table @asis
  4690. @item @var{hh}:@var{mm}
  4691. The dump must be run at @var{hh} hours @var{mm} minutes.
  4692. @item @var{hh}
  4693. The dump must be run at @var{hh} hours
  4694. @item now
  4695. The dump must be run immediately.
  4696. @end table
  4697. You should start a script with a tape or disk mounted. Once you
  4698. start a script, it prompts you for new tapes or disks as it
  4699. needs them. Media volumes don't have to correspond to archive
  4700. files --- a multi-volume archive can be started in the middle of a
  4701. tape that already contains the end of another multi-volume archive.
  4702. The @code{restore} script prompts for media by its archive volume,
  4703. so to avoid an error message you should keep track of which tape
  4704. (or disk) contains which volume of the archive (@pxref{Scripted
  4705. Restoration}).
  4706. The backup scripts write two files on the file system. The first is a
  4707. record file in @file{/etc/tar-backup/}, which is used by the scripts
  4708. to store and retrieve information about which files were dumped. This
  4709. file is not meant to be read by humans, and should not be deleted by
  4710. them. @xref{Snapshot Files}, for a more detailed explanation of this
  4711. file.
  4712. The second file is a log file containing the names of the file systems
  4713. and files dumped, what time the backup was made, and any error
  4714. messages that were generated, as well as how much space was left in
  4715. the media volume after the last volume of the archive was written.
  4716. You should check this log file after every backup. The file name is
  4717. @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
  4718. represents current date, and @var{n} represents current dump level number.
  4719. The script also prints the name of each system being dumped to the
  4720. standard output.
  4721. Following is the full list of options accepted by @code{backup}
  4722. script:
  4723. @table @option
  4724. @item -l @var{level}
  4725. @itemx --level=@var{level}
  4726. Do backup level @var{level} (default 0).
  4727. @item -f
  4728. @itemx --force
  4729. Force backup even if today's log file already exists.
  4730. @item -v[@var{level}]
  4731. @itemx --verbose[=@var{level}]
  4732. Set verbosity level. The higher the level is, the more debugging
  4733. information will be output during execution. Devault @var{level}
  4734. is 100, which means the highest debugging level.
  4735. @item -t @var{start-time}
  4736. @itemx --time=@var{start-time}
  4737. Wait till @var{time}, then do backup.
  4738. @item -h
  4739. @itemx --help
  4740. Display short help message and exit.
  4741. @item -V
  4742. @itemx --version
  4743. Display information about the program's name, version, origin and legal
  4744. status, all on standard output, and then exit successfully.
  4745. @end table
  4746. @node Scripted Restoration
  4747. @section Using the Restore Script
  4748. To restore files that were archived using a scripted backup, use the
  4749. @code{restore} script. Its usage is quite straightforward. In the
  4750. simplest form, invoke @code{restore --all}, it will
  4751. then restore all the file systems and files specified in
  4752. @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
  4753. You may select the file systems (and/or files) to restore by
  4754. giving @code{restore} list of @dfn{patterns} in its command
  4755. line. For example, running
  4756. @smallexample
  4757. restore 'albert:*'
  4758. @end smallexample
  4759. @noindent
  4760. will restore all file systems on the machine @samp{albert}. A more
  4761. complicated example:
  4762. @smallexample
  4763. restore 'albert:*' '*:/var'
  4764. @end smallexample
  4765. @noindent
  4766. This command will restore all file systems on the machine @samp{albert}
  4767. as well as @file{/var} file system on all machines.
  4768. By default @code{restore} will start restoring files from the lowest
  4769. available dump level (usually zero) and will continue through
  4770. all available dump levels. There may be situations where such a
  4771. thorough restore is not necessary. For example, you may wish to
  4772. restore only files from the recent level one backup. To do so,
  4773. use @option{--level} option, as shown in the example below:
  4774. @smallexample
  4775. restore --level=1
  4776. @end smallexample
  4777. The full list of options accepted by @code{restore} follows:
  4778. @table @option
  4779. @item -a
  4780. @itemx --all
  4781. Restore all file systems and files specified in @file{backup-specs}
  4782. @item -l @var{level}
  4783. @itemx --level=@var{level}
  4784. Start restoring from the given backup level, instead of the default 0.
  4785. @item -v[@var{level}]
  4786. @itemx --verbose[=@var{level}]
  4787. Set verbosity level. The higher the level is, the more debugging
  4788. information will be output during execution. Devault @var{level}
  4789. is 100, which means the highest debugging level.
  4790. @item -h
  4791. @itemx --help
  4792. Display short help message and exit.
  4793. @item -V
  4794. @itemx --version
  4795. Display information about the program's name, version, origin and legal
  4796. status, all on standard output, and then exit successfully.
  4797. @end table
  4798. You should start the restore script with the media containing the
  4799. first volume of the archive mounted. The script will prompt for other
  4800. volumes as they are needed. If the archive is on tape, you don't need
  4801. to rewind the tape to to its beginning---if the tape head is
  4802. positioned past the beginning of the archive, the script will rewind
  4803. the tape as needed. @xref{Tape Positioning}, for a discussion of tape
  4804. positioning.
  4805. @quotation
  4806. @strong{Warning:} The script will delete files from the active file
  4807. system if they were not in the file system when the archive was made.
  4808. @end quotation
  4809. @xref{Incremental Dumps}, for an explanation of how the script makes
  4810. that determination.
  4811. @node Choosing
  4812. @chapter Choosing Files and Names for @command{tar}
  4813. @UNREVISED
  4814. Certain options to @command{tar} enable you to specify a name for your
  4815. archive. Other options let you decide which files to include or exclude
  4816. from the archive, based on when or whether files were modified, whether
  4817. the file names do or don't match specified patterns, or whether files
  4818. are in specified directories.
  4819. This chapter discusses these options in detail.
  4820. @menu
  4821. * file:: Choosing the Archive's Name
  4822. * Selecting Archive Members::
  4823. * files:: Reading Names from a File
  4824. * exclude:: Excluding Some Files
  4825. * wildcards:: Wildcards Patterns and Matching
  4826. * quoting styles:: Ways of Quoting Special Characters in Names
  4827. * transform:: Modifying File and Member Names
  4828. * after:: Operating Only on New Files
  4829. * recurse:: Descending into Directories
  4830. * one:: Crossing File System Boundaries
  4831. @end menu
  4832. @node file
  4833. @section Choosing and Naming Archive Files
  4834. @UNREVISED
  4835. @cindex Naming an archive
  4836. @cindex Archive Name
  4837. @cindex Choosing an archive file
  4838. @cindex Where is the archive?
  4839. By default, @command{tar} uses an archive file name that was compiled when
  4840. it was built on the system; usually this name refers to some physical
  4841. tape drive on the machine. However, the person who installed @command{tar}
  4842. on the system may not have set the default to a meaningful value as far as
  4843. most users are concerned. As a result, you will usually want to tell
  4844. @command{tar} where to find (or create) the archive. The
  4845. @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
  4846. option allows you to either specify or name a file to use as the archive
  4847. instead of the default archive file location.
  4848. @table @option
  4849. @xopindex{file, short description}
  4850. @item --file=@var{archive-name}
  4851. @itemx -f @var{archive-name}
  4852. Name the archive to create or operate on. Use in conjunction with
  4853. any operation.
  4854. @end table
  4855. For example, in this @command{tar} command,
  4856. @smallexample
  4857. $ @kbd{tar -cvf collection.tar blues folk jazz}
  4858. @end smallexample
  4859. @noindent
  4860. @file{collection.tar} is the name of the archive. It must directly
  4861. follow the @option{-f} option, since whatever directly follows @option{-f}
  4862. @emph{will} end up naming the archive. If you neglect to specify an
  4863. archive name, you may end up overwriting a file in the working directory
  4864. with the archive you create since @command{tar} will use this file's name
  4865. for the archive name.
  4866. An archive can be saved as a file in the file system, sent through a
  4867. pipe or over a network, or written to an I/O device such as a tape,
  4868. floppy disk, or CD write drive.
  4869. @cindex Writing new archives
  4870. @cindex Archive creation
  4871. If you do not name the archive, @command{tar} uses the value of the
  4872. environment variable @env{TAPE} as the file name for the archive. If
  4873. that is not available, @command{tar} uses a default, compiled-in archive
  4874. name, usually that for tape unit zero (i.e. @file{/dev/tu00}).
  4875. @cindex Standard input and output
  4876. @cindex tar to standard input and output
  4877. If you use @file{-} as an @var{archive-name}, @command{tar} reads the
  4878. archive from standard input (when listing or extracting files), or
  4879. writes it to standard output (when creating an archive). If you use
  4880. @file{-} as an @var{archive-name} when modifying an archive,
  4881. @command{tar} reads the original archive from its standard input and
  4882. writes the entire new archive to its standard output.
  4883. The following example is a convenient way of copying directory
  4884. hierarchy from @file{sourcedir} to @file{targetdir}.
  4885. @smallexample
  4886. $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
  4887. @end smallexample
  4888. The @option{-C} option allows to avoid using subshells:
  4889. @smallexample
  4890. $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
  4891. @end smallexample
  4892. In both examples above, the leftmost @command{tar} invocation archives
  4893. the contents of @file{sourcedir} to the standard output, while the
  4894. rightmost one reads this archive from its standard input and
  4895. extracts it. The @option{-p} option tells it to restore permissions
  4896. of the extracted files.
  4897. @cindex Remote devices
  4898. @cindex tar to a remote device
  4899. @anchor{remote-dev}
  4900. To specify an archive file on a device attached to a remote machine,
  4901. use the following:
  4902. @smallexample
  4903. @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
  4904. @end smallexample
  4905. @noindent
  4906. @command{tar} will complete the remote connection, if possible, and
  4907. prompt you for a username and password. If you use
  4908. @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
  4909. will complete the remote connection, if possible, using your username
  4910. as the username on the remote machine.
  4911. @cindex Local and remote archives
  4912. @anchor{local and remote archives}
  4913. If the archive file name includes a colon (@samp{:}), then it is assumed
  4914. to be a file on another machine. If the archive file is
  4915. @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
  4916. host @var{host}. The remote host is accessed using the @command{rsh}
  4917. program, with a username of @var{user}. If the username is omitted
  4918. (along with the @samp{@@} sign), then your user name will be used.
  4919. (This is the normal @command{rsh} behavior.) It is necessary for the
  4920. remote machine, in addition to permitting your @command{rsh} access, to
  4921. have the @file{rmt} program installed (This command is included in
  4922. the @GNUTAR{} distribution and by default is installed under
  4923. @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
  4924. installation prefix). If you need to use a file whose name includes a
  4925. colon, then the remote tape drive behavior
  4926. can be inhibited by using the @option{--force-local} option.
  4927. When the archive is being created to @file{/dev/null}, @GNUTAR{}
  4928. tries to minimize input and output operations. The Amanda backup
  4929. system, when used with @GNUTAR{}, has an initial sizing pass which
  4930. uses this feature.
  4931. @node Selecting Archive Members
  4932. @section Selecting Archive Members
  4933. @cindex Specifying files to act on
  4934. @cindex Specifying archive members
  4935. @dfn{File Name arguments} specify which files in the file system
  4936. @command{tar} operates on, when creating or adding to an archive, or which
  4937. archive members @command{tar} operates on, when reading or deleting from
  4938. an archive. @xref{Operations}.
  4939. To specify file names, you can include them as the last arguments on
  4940. the command line, as follows:
  4941. @smallexample
  4942. @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
  4943. @end smallexample
  4944. If a file name begins with dash (@samp{-}), precede it with
  4945. @option{--add-file} option to prevent it from being treated as an
  4946. option.
  4947. @anchor{input name quoting}
  4948. By default @GNUTAR{} attempts to @dfn{unquote} each file or member
  4949. name, replacing @dfn{escape sequences} according to the following
  4950. table:
  4951. @multitable @columnfractions 0.20 0.60
  4952. @headitem Escape @tab Replaced with
  4953. @item \a @tab Audible bell (ASCII 7)
  4954. @item \b @tab Backspace (ASCII 8)
  4955. @item \f @tab Form feed (ASCII 12)
  4956. @item \n @tab New line (ASCII 10)
  4957. @item \r @tab Carriage return (ASCII 13)
  4958. @item \t @tab Horizontal tabulation (ASCII 9)
  4959. @item \v @tab Vertical tabulation (ASCII 11)
  4960. @item \? @tab ASCII 127
  4961. @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
  4962. of up to 3 digits)
  4963. @end multitable
  4964. A backslash followed by any other symbol is retained.
  4965. This default behavior is controlled by the following command line
  4966. option:
  4967. @table @option
  4968. @opindex unquote
  4969. @item --unquote
  4970. Enable unquoting input file or member names (default).
  4971. @opindex no-unquote
  4972. @item --no-unquote
  4973. Disable unquoting input file or member names.
  4974. @end table
  4975. If you specify a directory name as a file name argument, all the files
  4976. in that directory are operated on by @command{tar}.
  4977. If you do not specify files, @command{tar} behavior differs depending
  4978. on the operation mode as described below:
  4979. When @command{tar} is invoked with @option{--create} (@option{-c}),
  4980. @command{tar} will stop immediately, reporting the following:
  4981. @smallexample
  4982. @group
  4983. $ @kbd{tar cf a.tar}
  4984. tar: Cowardly refusing to create an empty archive
  4985. Try `tar --help' or `tar --usage' for more information.
  4986. @end group
  4987. @end smallexample
  4988. If you specify either @option{--list} (@option{-t}) or
  4989. @option{--extract} (@option{--get}, @option{-x}), @command{tar}
  4990. operates on all the archive members in the archive.
  4991. If run with @option{--diff} option, tar will compare the archive with
  4992. the contents of the current working directory.
  4993. If you specify any other operation, @command{tar} does nothing.
  4994. By default, @command{tar} takes file names from the command line. However,
  4995. there are other ways to specify file or member names, or to modify the
  4996. manner in which @command{tar} selects the files or members upon which to
  4997. operate. In general, these methods work both for specifying the names
  4998. of files and archive members.
  4999. @node files
  5000. @section Reading Names from a File
  5001. @cindex Reading file names from a file
  5002. @cindex Lists of file names
  5003. @cindex File Name arguments, alternatives
  5004. Instead of giving the names of files or archive members on the command
  5005. line, you can put the names into a file, and then use the
  5006. @option{--files-from=@var{file-of-names}} (@option{-T
  5007. @var{file-of-names}}) option to @command{tar}. Give the name of the
  5008. file which contains the list of files to include as the argument to
  5009. @option{--files-from}. In the list, the file names should be separated by
  5010. newlines. You will frequently use this option when you have generated
  5011. the list of files to archive with the @command{find} utility.
  5012. @table @option
  5013. @opindex files-from
  5014. @item --files-from=@var{file-name}
  5015. @itemx -T @var{file-name}
  5016. Get names to extract or create from file @var{file-name}.
  5017. @end table
  5018. If you give a single dash as a file name for @option{--files-from}, (i.e.,
  5019. you specify either @code{--files-from=-} or @code{-T -}), then the file
  5020. names are read from standard input.
  5021. Unless you are running @command{tar} with @option{--create}, you can not use
  5022. both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
  5023. command.
  5024. Any number of @option{-T} options can be given in the command line.
  5025. The following example shows how to use @command{find} to generate a list of
  5026. files smaller than 400K in length and put that list into a file
  5027. called @file{small-files}. You can then use the @option{-T} option to
  5028. @command{tar} to specify the files from that file, @file{small-files}, to
  5029. create the archive @file{little.tgz}. (The @option{-z} option to
  5030. @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
  5031. more information.)
  5032. @smallexample
  5033. $ @kbd{find . -size -400 -print > small-files}
  5034. $ @kbd{tar -c -v -z -T small-files -f little.tgz}
  5035. @end smallexample
  5036. @noindent
  5037. In the file list given by @option{-T} option, any file name beginning
  5038. with @samp{-} character is considered a @command{tar} option and is
  5039. processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
  5040. recognized only @option{-C} option in file lists, and only if the
  5041. option and its argument occupied two consecutive lines.} For example,
  5042. the common use of this feature is to change to another directory by
  5043. specifying @option{-C} option:
  5044. @smallexample
  5045. @group
  5046. $ @kbd{cat list}
  5047. -C/etc
  5048. passwd
  5049. hosts
  5050. -C/lib
  5051. libc.a
  5052. $ @kbd{tar -c -f foo.tar --files-from list}
  5053. @end group
  5054. @end smallexample
  5055. @noindent
  5056. In this example, @command{tar} will first switch to @file{/etc}
  5057. directory and add files @file{passwd} and @file{hosts} to the
  5058. archive. Then it will change to @file{/lib} directory and will archive
  5059. the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
  5060. contain:
  5061. @smallexample
  5062. @group
  5063. $ @kbd{tar tf foo.tar}
  5064. passwd
  5065. hosts
  5066. libc.a
  5067. @end group
  5068. @end smallexample
  5069. @noindent
  5070. @xopindex{directory, using in @option{--files-from} argument}
  5071. Notice that the option parsing algorithm used with @option{-T} is
  5072. stricter than the one used by shell. Namely, when specifying option
  5073. arguments, you should observe the following rules:
  5074. @itemize @bullet
  5075. @item
  5076. When using short (single-letter) option form, its argument must
  5077. immediately follow the option letter, without any intervening
  5078. whitespace. For example: @code{-Cdir}.
  5079. @item
  5080. When using long option form, the option argument must be separated
  5081. from the option by a single equal sign. No whitespace is allowed on
  5082. any side of the equal sign. For example: @code{--directory=dir}.
  5083. @item
  5084. For both short and long option forms, the option argument can be given
  5085. on the next line after the option name, e.g.:
  5086. @smallexample
  5087. @group
  5088. --directory
  5089. dir
  5090. @end group
  5091. @end smallexample
  5092. @noindent
  5093. and
  5094. @smallexample
  5095. @group
  5096. -C
  5097. dir
  5098. @end group
  5099. @end smallexample
  5100. @end itemize
  5101. @opindex add-file
  5102. If you happen to have a file whose name starts with @samp{-},
  5103. precede it with @option{--add-file} option to prevent it from
  5104. being recognized as an option. For example: @code{--add-file=--my-file}.
  5105. @menu
  5106. * nul::
  5107. @end menu
  5108. @node nul
  5109. @subsection @code{NUL} Terminated File Names
  5110. @cindex File names, terminated by @code{NUL}
  5111. @cindex @code{NUL} terminated file names
  5112. The @option{--null} option causes
  5113. @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
  5114. to read file names terminated by a @code{NUL} instead of a newline, so
  5115. files whose names contain newlines can be archived using
  5116. @option{--files-from}.
  5117. @table @option
  5118. @opindex null
  5119. @item --null
  5120. Only consider @code{NUL} terminated file names, instead of files that
  5121. terminate in a newline.
  5122. @end table
  5123. The @option{--null} option is just like the one in @acronym{GNU}
  5124. @command{xargs} and @command{cpio}, and is useful with the
  5125. @option{-print0} predicate of @acronym{GNU} @command{find}. In
  5126. @command{tar}, @option{--null} also disables special handling for
  5127. file names that begin with dash.
  5128. This example shows how to use @command{find} to generate a list of files
  5129. larger than 800K in length and put that list into a file called
  5130. @file{long-files}. The @option{-print0} option to @command{find} is just
  5131. like @option{-print}, except that it separates files with a @code{NUL}
  5132. rather than with a newline. You can then run @command{tar} with both the
  5133. @option{--null} and @option{-T} options to specify that @command{tar} get the
  5134. files from that file, @file{long-files}, to create the archive
  5135. @file{big.tgz}. The @option{--null} option to @command{tar} will cause
  5136. @command{tar} to recognize the @code{NUL} separator between files.
  5137. @smallexample
  5138. $ @kbd{find . -size +800 -print0 > long-files}
  5139. $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
  5140. @end smallexample
  5141. @FIXME{say anything else here to conclude the section?}
  5142. @node exclude
  5143. @section Excluding Some Files
  5144. @UNREVISED
  5145. @cindex File names, excluding files by
  5146. @cindex Excluding files by name and pattern
  5147. @cindex Excluding files by file system
  5148. To avoid operating on files whose names match a particular pattern,
  5149. use the @option{--exclude} or @option{--exclude-from} options.
  5150. @table @option
  5151. @opindex exclude
  5152. @item --exclude=@var{pattern}
  5153. Causes @command{tar} to ignore files that match the @var{pattern}.
  5154. @end table
  5155. @findex exclude
  5156. The @option{--exclude=@var{pattern}} option prevents any file or
  5157. member whose name matches the shell wildcard (@var{pattern}) from
  5158. being operated on.
  5159. For example, to create an archive with all the contents of the directory
  5160. @file{src} except for files whose names end in @file{.o}, use the
  5161. command @samp{tar -cf src.tar --exclude='*.o' src}.
  5162. You may give multiple @option{--exclude} options.
  5163. @table @option
  5164. @opindex exclude-from
  5165. @item --exclude-from=@var{file}
  5166. @itemx -X @var{file}
  5167. Causes @command{tar} to ignore files that match the patterns listed in
  5168. @var{file}.
  5169. @end table
  5170. @findex exclude-from
  5171. Use the @option{--exclude-from} option to read a
  5172. list of patterns, one per line, from @var{file}; @command{tar} will
  5173. ignore files matching those patterns. Thus if @command{tar} is
  5174. called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
  5175. single line @file{*.o}, no files whose names end in @file{.o} will be
  5176. added to the archive.
  5177. @table @option
  5178. @opindex exclude-caches
  5179. @item --exclude-caches
  5180. Causes @command{tar} to ignore directories containing a cache directory tag.
  5181. @end table
  5182. @findex exclude-caches
  5183. When creating an archive, the @option{--exclude-caches} option causes
  5184. @command{tar} to exclude all directories that contain a @dfn{cache
  5185. directory tag}. A cache directory tag is a short file with the
  5186. well-known name @file{CACHEDIR.TAG} and having a standard header
  5187. specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
  5188. Various applications write cache directory tags into directories they
  5189. use to hold regenerable, non-precious data, so that such data can be
  5190. more easily excluded from backups.
  5191. @menu
  5192. * problems with exclude::
  5193. @end menu
  5194. @node problems with exclude
  5195. @unnumberedsubsec Problems with Using the @code{exclude} Options
  5196. @xopindex{exclude, potential problems with}
  5197. Some users find @samp{exclude} options confusing. Here are some common
  5198. pitfalls:
  5199. @itemize @bullet
  5200. @item
  5201. The main operating mode of @command{tar} does not act on a path name
  5202. explicitly listed on the command line if one of its file name
  5203. components is excluded. In the example above, if
  5204. you create an archive and exclude files that end with @samp{*.o}, but
  5205. explicitly name the file @samp{dir.o/foo} after all the options have been
  5206. listed, @samp{dir.o/foo} will be excluded from the archive.
  5207. @item
  5208. You can sometimes confuse the meanings of @option{--exclude} and
  5209. @option{--exclude-from}. Be careful: use @option{--exclude} when files
  5210. to be excluded are given as a pattern on the command line. Use
  5211. @option{--exclude-from} to introduce the name of a file which contains
  5212. a list of patterns, one per line; each of these patterns can exclude
  5213. zero, one, or many files.
  5214. @item
  5215. When you use @option{--exclude=@var{pattern}}, be sure to quote the
  5216. @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
  5217. like @samp{*}. If you do not do this, the shell might expand the
  5218. @samp{*} itself using files at hand, so @command{tar} might receive a
  5219. list of files instead of one pattern, or none at all, making the
  5220. command somewhat illegal. This might not correspond to what you want.
  5221. For example, write:
  5222. @smallexample
  5223. $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
  5224. @end smallexample
  5225. @noindent
  5226. rather than:
  5227. @smallexample
  5228. # @emph{Wrong!}
  5229. $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
  5230. @end smallexample
  5231. @item
  5232. You must use use shell syntax, or globbing, rather than @code{regexp}
  5233. syntax, when using exclude options in @command{tar}. If you try to use
  5234. @code{regexp} syntax to describe files to be excluded, your command
  5235. might fail.
  5236. @item
  5237. @FIXME{The change in semantics must have occurred before 1.11,
  5238. so I doubt if it is worth mentioning at all. Anyway, should at
  5239. least specify in which version the semantics changed.}
  5240. In earlier versions of @command{tar}, what is now the
  5241. @option{--exclude-from} option was called @option{--exclude} instead.
  5242. Now, @option{--exclude} applies to patterns listed on the command
  5243. line and @option{--exclude-from} applies to patterns listed in a
  5244. file.
  5245. @end itemize
  5246. @node wildcards
  5247. @section Wildcards Patterns and Matching
  5248. @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
  5249. @samp{*} or @samp{?} for example, are replaced and expanded into all
  5250. existing files matching the given pattern. @GNUTAR{} can use wildcard
  5251. patterns for matching (or globbing) archive members when extracting
  5252. from or listing an archive. Wildcard patterns are also used for
  5253. verifying volume labels of @command{tar} archives. This section has the
  5254. purpose of explaining wildcard syntax for @command{tar}.
  5255. @FIXME{the next few paragraphs need work.}
  5256. A @var{pattern} should be written according to shell syntax, using wildcard
  5257. characters to effect globbing. Most characters in the pattern stand
  5258. for themselves in the matched string, and case is significant: @samp{a}
  5259. will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
  5260. pattern matches any single character in the matched string. The character
  5261. @samp{*} in the pattern matches zero, one, or more single characters in
  5262. the matched string. The character @samp{\} says to take the following
  5263. character of the pattern @emph{literally}; it is useful when one needs to
  5264. match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
  5265. The character @samp{[}, up to the matching @samp{]}, introduces a character
  5266. class. A @dfn{character class} is a list of acceptable characters
  5267. for the next single character of the matched string. For example,
  5268. @samp{[abcde]} would match any of the first five letters of the alphabet.
  5269. Note that within a character class, all of the ``special characters''
  5270. listed above other than @samp{\} lose their special meaning; for example,
  5271. @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
  5272. @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
  5273. the characters @samp{-} and @samp{]} must either come @emph{first} or
  5274. @emph{last} in a character class.)
  5275. @cindex Excluding characters from a character class
  5276. @cindex Character class, excluding characters from
  5277. If the first character of the class after the opening @samp{[}
  5278. is @samp{!} or @samp{^}, then the meaning of the class is reversed.
  5279. Rather than listing character to match, it lists those characters which
  5280. are @emph{forbidden} as the next single character of the matched string.
  5281. Other characters of the class stand for themselves. The special
  5282. construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
  5283. letters, is meant to represent all characters between @var{a} and
  5284. @var{e}, inclusive.
  5285. @FIXME{need to add a sentence or so here to make this clear for those
  5286. who don't have dan around.}
  5287. Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
  5288. special for wildcard matches. However, if a pattern completely matches
  5289. a directory prefix of a matched string, then it matches the full matched
  5290. string: thus, excluding a directory also excludes all the files beneath it.
  5291. @menu
  5292. * controlling pattern-matching::
  5293. @end menu
  5294. @node controlling pattern-matching
  5295. @unnumberedsubsec Controlling Pattern-Matching
  5296. For the purposes of this section, we call @dfn{exclusion members} all
  5297. member names obtained while processing @option{--exclude} and
  5298. @option{--exclude-from} options, and @dfn{inclusion members} those
  5299. member names that were given in the command line or read from the file
  5300. specified with @option{--files-from} option.
  5301. These two pairs of member lists are used in the following operations:
  5302. @option{--diff}, @option{--extract}, @option{--list},
  5303. @option{--update}.
  5304. There are no inclusion members in create mode (@option{--create} and
  5305. @option{--append}), since in this mode the names obtained from the
  5306. command line refer to @emph{files}, not archive members.
  5307. By default, inclusion members are compared with archive members
  5308. literally @footnote{Notice that earlier @GNUTAR{} versions used
  5309. globbing for inclusion members, which contradicted to UNIX98
  5310. specification and was not documented. @xref{Changes}, for more
  5311. information on this and other changes.} and exclusion members are
  5312. treated as globbing patterns. For example:
  5313. @smallexample
  5314. @group
  5315. $ @kbd{tar tf foo.tar}
  5316. a.c
  5317. b.c
  5318. a.txt
  5319. [remarks]
  5320. # @i{Member names are used verbatim:}
  5321. $ @kbd{tar -xf foo.tar -v '[remarks]'}
  5322. [remarks]
  5323. # @i{Exclude member names are globbed:}
  5324. $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
  5325. a.txt
  5326. [remarks]
  5327. @end group
  5328. @end smallexample
  5329. This behavior can be altered by using the following options:
  5330. @table @option
  5331. @opindex wildcards
  5332. @item --wildcards
  5333. Treat all member names as wildcards.
  5334. @opindex no-wildcards
  5335. @item --no-wildcards
  5336. Treat all member names as literal strings.
  5337. @end table
  5338. Thus, to extract files whose names end in @samp{.c}, you can use:
  5339. @smallexample
  5340. $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
  5341. a.c
  5342. b.c
  5343. @end smallexample
  5344. @noindent
  5345. Notice quoting of the pattern to prevent the shell from interpreting
  5346. it.
  5347. The effect of @option{--wildcards} option is cancelled by
  5348. @option{--no-wildcards}. This can be used to pass part of
  5349. the command line arguments verbatim and other part as globbing
  5350. patterns. For example, the following invocation:
  5351. @smallexample
  5352. $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
  5353. @end smallexample
  5354. @noindent
  5355. instructs @command{tar} to extract from @file{foo.tar} all files whose
  5356. names end in @samp{.txt} and the file named @file{[remarks]}.
  5357. Normally, a pattern matches a name if an initial subsequence of the
  5358. name's components matches the pattern, where @samp{*}, @samp{?}, and
  5359. @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
  5360. and wildcards can match @samp{/}.
  5361. Other than optionally stripping leading @samp{/} from names
  5362. (@pxref{absolute}), patterns and names are used as-is. For
  5363. example, trailing @samp{/} is not trimmed from a user-specified name
  5364. before deciding whether to exclude it.
  5365. However, this matching procedure can be altered by the options listed
  5366. below. These options accumulate. For example:
  5367. @smallexample
  5368. --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
  5369. @end smallexample
  5370. @noindent
  5371. ignores case when excluding @samp{makefile}, but not when excluding
  5372. @samp{readme}.
  5373. @table @option
  5374. @opindex anchored
  5375. @opindex no-anchored
  5376. @item --anchored
  5377. @itemx --no-anchored
  5378. If anchored, a pattern must match an initial subsequence
  5379. of the name's components. Otherwise, the pattern can match any
  5380. subsequence. Default is @option{--no-anchored} for exclusion members
  5381. and @option{--anchored} inclusion members.
  5382. @opindex ignore-case
  5383. @opindex no-ignore-case
  5384. @item --ignore-case
  5385. @itemx --no-ignore-case
  5386. When ignoring case, upper-case patterns match lower-case names and vice versa.
  5387. When not ignoring case (the default), matching is case-sensitive.
  5388. @opindex wildcards-match-slash
  5389. @opindex no-wildcards-match-slash
  5390. @item --wildcards-match-slash
  5391. @itemx --no-wildcards-match-slash
  5392. When wildcards match slash (the default for exclusion members), a
  5393. wildcard like @samp{*} in the pattern can match a @samp{/} in the
  5394. name. Otherwise, @samp{/} is matched only by @samp{/}.
  5395. @end table
  5396. The @option{--recursion} and @option{--no-recursion} options
  5397. (@pxref{recurse}) also affect how member patterns are interpreted. If
  5398. recursion is in effect, a pattern matches a name if it matches any of
  5399. the name's parent directories.
  5400. The following table summarizes pattern-matching default values:
  5401. @multitable @columnfractions .3 .7
  5402. @headitem Members @tab Default settings
  5403. @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
  5404. @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
  5405. @end multitable
  5406. @node quoting styles
  5407. @section Quoting Member Names
  5408. When displaying member names, @command{tar} takes care to avoid
  5409. ambiguities caused by certain characters. This is called @dfn{name
  5410. quoting}. The characters in question are:
  5411. @itemize @bullet
  5412. @item Non-printable control characters:
  5413. @multitable @columnfractions 0.20 0.10 0.60
  5414. @headitem Character @tab ASCII @tab Character name
  5415. @item \a @tab 7 @tab Audible bell
  5416. @item \b @tab 8 @tab Backspace
  5417. @item \f @tab 12 @tab Form feed
  5418. @item \n @tab 10 @tab New line
  5419. @item \r @tab 13 @tab Carriage return
  5420. @item \t @tab 9 @tab Horizontal tabulation
  5421. @item \v @tab 11 @tab Vertical tabulation
  5422. @end multitable
  5423. @item Space (ASCII 32)
  5424. @item Single and double quotes (@samp{'} and @samp{"})
  5425. @item Backslash (@samp{\})
  5426. @end itemize
  5427. The exact way @command{tar} uses to quote these characters depends on
  5428. the @dfn{quoting style}. The default quoting style, called
  5429. @dfn{escape} (see below), uses backslash notation to represent control
  5430. characters, space and backslash. Using this quoting style, control
  5431. characters are represented as listed in column @samp{Character} in the
  5432. above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
  5433. @GNUTAR{} offers seven distinct quoting styles, which can be selected
  5434. using @option{--quoting-style} option:
  5435. @table @option
  5436. @item --quoting-style=@var{style}
  5437. @opindex quoting-style
  5438. Sets quoting style. Valid values for @var{style} argument are:
  5439. literal, shell, shell-always, c, escape, locale, clocale.
  5440. @end table
  5441. These styles are described in detail below. To illustrate their
  5442. effect, we will use an imaginary tar archive @file{arch.tar}
  5443. containing the following members:
  5444. @smallexample
  5445. @group
  5446. # 1. Contains horizontal tabulation character.
  5447. a tab
  5448. # 2. Contains newline character
  5449. a
  5450. newline
  5451. # 3. Contains a space
  5452. a space
  5453. # 4. Contains double quotes
  5454. a"double"quote
  5455. # 5. Contains single quotes
  5456. a'single'quote
  5457. # 6. Contains a backslash character:
  5458. a\backslash
  5459. @end group
  5460. @end smallexample
  5461. Here is how usual @command{ls} command would have listed them, if they
  5462. had existed in the current working directory:
  5463. @smallexample
  5464. @group
  5465. $ @kbd{ls}
  5466. a\ttab
  5467. a\nnewline
  5468. a\ space
  5469. a"double"quote
  5470. a'single'quote
  5471. a\\backslash
  5472. @end group
  5473. @end smallexample
  5474. Quoting styles:
  5475. @table @samp
  5476. @item literal
  5477. No quoting, display each character as is:
  5478. @smallexample
  5479. @group
  5480. $ @kbd{tar tf arch.tar --quoting-style=literal}
  5481. ./
  5482. ./a space
  5483. ./a'single'quote
  5484. ./a"double"quote
  5485. ./a\backslash
  5486. ./a tab
  5487. ./a
  5488. newline
  5489. @end group
  5490. @end smallexample
  5491. @item shell
  5492. Display characters the same way Bourne shell does:
  5493. control characters, except @samp{\t} and @samp{\n}, are printed using
  5494. backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
  5495. single quote is printed as @samp{\'}. If a name contains any quoted
  5496. characters, it is enclosed in single quotes. In particular, if a name
  5497. contains single quotes, it is printed as several single-quoted strings:
  5498. @smallexample
  5499. @group
  5500. $ @kbd{tar tf arch.tar --quoting-style=shell}
  5501. ./
  5502. './a space'
  5503. './a'\''single'\''quote'
  5504. './a"double"quote'
  5505. './a\backslash'
  5506. './a tab'
  5507. './a
  5508. newline'
  5509. @end group
  5510. @end smallexample
  5511. @item shell-always
  5512. Same as @samp{shell}, but the names are always enclosed in single
  5513. quotes:
  5514. @smallexample
  5515. @group
  5516. $ @kbd{tar tf arch.tar --quoting-style=shell-always}
  5517. './'
  5518. './a space'
  5519. './a'\''single'\''quote'
  5520. './a"double"quote'
  5521. './a\backslash'
  5522. './a tab'
  5523. './a
  5524. newline'
  5525. @end group
  5526. @end smallexample
  5527. @item c
  5528. Use the notation of the C programming language. All names are
  5529. enclosed in double quotes. Control characters are quoted using
  5530. backslash notations, double quotes are represented as @samp{\"},
  5531. backslash characters are represented as @samp{\\}. Single quotes and
  5532. spaces are not quoted:
  5533. @smallexample
  5534. @group
  5535. $ @kbd{tar tf arch.tar --quoting-style=c}
  5536. "./"
  5537. "./a space"
  5538. "./a'single'quote"
  5539. "./a\"double\"quote"
  5540. "./a\\backslash"
  5541. "./a\ttab"
  5542. "./a\nnewline"
  5543. @end group
  5544. @end smallexample
  5545. @item escape
  5546. Control characters are printed using backslash notation, a space is
  5547. printed as @samp{\ } and a backslash as @samp{\\}. This is the
  5548. default quoting style, unless it was changed when configured the
  5549. package.
  5550. @smallexample
  5551. @group
  5552. $ @kbd{tar tf arch.tar --quoting-style=escape}
  5553. ./
  5554. ./a space
  5555. ./a'single'quote
  5556. ./a"double"quote
  5557. ./a\\backslash
  5558. ./a\ttab
  5559. ./a\nnewline
  5560. @end group
  5561. @end smallexample
  5562. @item locale
  5563. Control characters, single quote and backslash are printed using
  5564. backslash notation. All names are quoted using left and right
  5565. quotation marks, appropriate to the current locale. If it does not
  5566. define quotation marks, use @samp{`} as left and @samp{'} as right
  5567. quotation marks. Any occurrences of the right quotation mark in a
  5568. name are escaped with @samp{\}, for example:
  5569. For example:
  5570. @smallexample
  5571. @group
  5572. $ @kbd{tar tf arch.tar --quoting-style=locale}
  5573. `./'
  5574. `./a space'
  5575. `./a\'single\'quote'
  5576. `./a"double"quote'
  5577. `./a\\backslash'
  5578. `./a\ttab'
  5579. `./a\nnewline'
  5580. @end group
  5581. @end smallexample
  5582. @item clocale
  5583. Same as @samp{locale}, but @samp{"} is used for both left and right
  5584. quotation marks, if not provided by the currently selected locale:
  5585. @smallexample
  5586. @group
  5587. $ @kbd{tar tf arch.tar --quoting-style=clocale}
  5588. "./"
  5589. "./a space"
  5590. "./a'single'quote"
  5591. "./a\"double\"quote"
  5592. "./a\\backslash"
  5593. "./a\ttab"
  5594. "./a\nnewline"
  5595. @end group
  5596. @end smallexample
  5597. @end table
  5598. You can specify which characters should be quoted in addition to those
  5599. implied by the current quoting style:
  5600. @table @option
  5601. @item --quote-chars=@var{string}
  5602. Always quote characters from @var{string}, even if the selected
  5603. quoting style would not quote them.
  5604. @end table
  5605. For example, using @samp{escape} quoting (compare with the usual
  5606. escape listing above):
  5607. @smallexample
  5608. @group
  5609. $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
  5610. ./
  5611. ./a\ space
  5612. ./a'single'quote
  5613. ./a\"double\"quote
  5614. ./a\\backslash
  5615. ./a\ttab
  5616. ./a\nnewline
  5617. @end group
  5618. @end smallexample
  5619. To disable quoting of such additional characters, use the following
  5620. option:
  5621. @table @option
  5622. @item --no-quote-chars=@var{string}
  5623. Remove characters listed in @var{string} from the list of quoted
  5624. characters set by the previous @option{--quote-chars} option.
  5625. @end table
  5626. This option is particularly useful if you have added
  5627. @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
  5628. and wish to disable it for the current invocation.
  5629. Note, that @option{--no-quote-chars} does @emph{not} disable those
  5630. characters that are quoted by default in the selected quoting style.
  5631. @node transform
  5632. @section Modifying File and Member Names
  5633. @command{Tar} archives contain detailed information about files stored
  5634. in them and full file names are part of that information. When
  5635. storing file to an archive, its file name is recorded in the archive
  5636. along with the actual file contents. When restoring from an archive,
  5637. a file is created on disk with exactly the same name as that stored
  5638. in the archive. In the majority of cases this is the desired behavior
  5639. of a file archiver. However, there are some cases when it is not.
  5640. First of all, it is often unsafe to extract archive members with
  5641. absolute file names or those that begin with a @file{../}. @GNUTAR{}
  5642. takes special precautions when extracting such names and provides a
  5643. special option for handling them, which is described in
  5644. @ref{absolute}.
  5645. Secondly, you may wish to extract file names without some leading
  5646. directory components, or with otherwise modified names. In other
  5647. cases it is desirable to store files under differing names in the
  5648. archive.
  5649. @GNUTAR{} provides two options for these needs.
  5650. @table @option
  5651. @opindex strip-components
  5652. @item --strip-components=@var{number}
  5653. Strip given @var{number} of leading components from file names before
  5654. extraction.
  5655. @end table
  5656. For example, suppose you have archived whole @file{/usr} hierarchy to
  5657. a tar archive named @file{usr.tar}. Among other files, this archive
  5658. contains @file{usr/include/stdlib.h}, which you wish to extract to
  5659. the current working directory. To do so, you type:
  5660. @smallexample
  5661. $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
  5662. @end smallexample
  5663. The option @option{--strip=2} instructs @command{tar} to strip the
  5664. two leading components (@file{usr/} and @file{include/}) off the file
  5665. name.
  5666. If you add to the above invocation @option{--verbose} (@option{-v})
  5667. option, you will note that the verbose listing still contains the
  5668. full file name, with the two removed components still in place. This
  5669. can be inconvenient, so @command{tar} provides a special option for
  5670. altering this behavior:
  5671. @anchor{show-transformed-names}
  5672. @table @option
  5673. @opindex show-transformed-names
  5674. @item --show-transformed-names
  5675. Display file or member names with all requested transformations
  5676. applied.
  5677. @end table
  5678. @noindent
  5679. For example:
  5680. @smallexample
  5681. @group
  5682. $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
  5683. usr/include/stdlib.h
  5684. $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
  5685. stdlib.h
  5686. @end group
  5687. @end smallexample
  5688. Notice that in both cases the file is @file{stdlib.h} extracted to the
  5689. current working directory, @option{--show-transformed-names} affects
  5690. only the way its name is displayed.
  5691. This option is especially useful for verifying whether the invocation
  5692. will have the desired effect. Thus, before running
  5693. @smallexample
  5694. $ @kbd{tar -x --strip=@var{n}}
  5695. @end smallexample
  5696. @noindent
  5697. it is often advisable to run
  5698. @smallexample
  5699. $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
  5700. @end smallexample
  5701. @noindent
  5702. to make sure the command will produce the intended results.
  5703. In case you need to apply more complex modifications to the file name,
  5704. @GNUTAR{} provides a general-purpose transformation option:
  5705. @table @option
  5706. @opindex transform
  5707. @item --transform=@var{expression}
  5708. Modify file names using supplied @var{expression}.
  5709. @end table
  5710. @noindent
  5711. The @var{expression} is a @command{sed}-like replace expression of the
  5712. form:
  5713. @smallexample
  5714. s/@var{regexp}/@var{replace}/[@var{flags}]
  5715. @end smallexample
  5716. @noindent
  5717. where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
  5718. replacement for each file name part that matches @var{regexp}. Both
  5719. @var{regexp} and @var{replace} are described in detail in
  5720. @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
  5721. Supported @var{flags} are:
  5722. @table @samp
  5723. @item g
  5724. Apply the replacement to @emph{all} matches to the @var{regexp}, not
  5725. just the first.
  5726. @item i
  5727. Use case-insensitive matching
  5728. @item x
  5729. @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
  5730. regexps, Extended regular expressions, Extended regular expressions,
  5731. sed, GNU sed}).
  5732. @item @var{number}
  5733. Only replace the @var{number}th match of the @var{regexp}.
  5734. Note: the @var{posix} standard does not specify what should happen
  5735. when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
  5736. follows the GNU @command{sed} implementation in this regard, so
  5737. the the interaction is defined to be: ignore matches before the
  5738. @var{number}th, and then match and replace all matches from the
  5739. @var{number}th on.
  5740. @end table
  5741. Any delimiter can be used in lieue of @samp{/}, the only requirement being
  5742. that it be used consistently throughout the expression. For example,
  5743. the following two expressions are equivalent:
  5744. @smallexample
  5745. @group
  5746. s/one/two/
  5747. s,one,two,
  5748. @end group
  5749. @end smallexample
  5750. Changing delimiters is often useful when the @var{regex} contains
  5751. slashes. For example, it is more convenient to write @code{s,/,-,} than
  5752. @code{s/\//-/}.
  5753. Here are several examples of @option{--transform} usage:
  5754. @enumerate
  5755. @item Extract @file{usr/} hierarchy into @file{usr/local/}:
  5756. @smallexample
  5757. $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
  5758. @end smallexample
  5759. @item Strip two leading directory components (equivalent to
  5760. @option{--strip-components=2}):
  5761. @smallexample
  5762. $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
  5763. @end smallexample
  5764. @item Prepend @file{/prefix/} to each file name:
  5765. @smallexample
  5766. $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
  5767. @end smallexample
  5768. @item Convert each file name to lower case:
  5769. @smallexample
  5770. $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
  5771. @end smallexample
  5772. @end enumerate
  5773. Unlike @option{--strip-components}, @option{--transform} can be used
  5774. in any @GNUTAR{} operation mode. For example, the following command
  5775. adds files to the archive while replacing the leading @file{usr/}
  5776. component with @file{var/}:
  5777. @smallexample
  5778. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
  5779. @end smallexample
  5780. To test @option{--transform} effect we suggest using
  5781. @option{--show-transformed-names} option:
  5782. @smallexample
  5783. $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
  5784. --verbose --show-transformed-names /}
  5785. @end smallexample
  5786. If both @option{--strip-components} and @option{--transform} are used
  5787. together, then @option{--transform} is applied first, and the required
  5788. number of components is then stripped from its result.
  5789. @node after
  5790. @section Operating Only on New Files
  5791. @UNREVISED
  5792. @cindex Excluding file by age
  5793. @cindex Data Modification time, excluding files by
  5794. @cindex Modification time, excluding files by
  5795. @cindex Age, excluding files by
  5796. The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
  5797. @option{-N @var{date}}) option causes @command{tar} to only work on
  5798. files whose data modification or status change times are newer than
  5799. the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
  5800. it is taken to be a file name; the data modification time of that file
  5801. is used as the date. If you use this option when creating or appending
  5802. to an archive, the archive will only include new files. If you use
  5803. @option{--after-date} when extracting an archive, @command{tar} will
  5804. only extract files newer than the @var{date} you specify.
  5805. If you only want @command{tar} to make the date comparison based on
  5806. modification of the file's data (rather than status
  5807. changes), then use the @option{--newer-mtime=@var{date}} option.
  5808. You may use these options with any operation. Note that these options
  5809. differ from the @option{--update} (@option{-u}) operation in that they
  5810. allow you to specify a particular date against which @command{tar} can
  5811. compare when deciding whether or not to archive the files.
  5812. @table @option
  5813. @opindex after-date
  5814. @opindex newer
  5815. @item --after-date=@var{date}
  5816. @itemx --newer=@var{date}
  5817. @itemx -N @var{date}
  5818. Only store files newer than @var{date}.
  5819. Acts on files only if their data modification or status change times are
  5820. later than @var{date}. Use in conjunction with any operation.
  5821. If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
  5822. name; the data modification time of that file is used as the date.
  5823. @opindex newer-mtime
  5824. @item --newer-mtime=@var{date}
  5825. Acts like @option{--after-date}, but only looks at data modification times.
  5826. @end table
  5827. These options limit @command{tar} to operate only on files which have
  5828. been modified after the date specified. A file's status is considered to have
  5829. changed if its contents have been modified, or if its owner,
  5830. permissions, and so forth, have been changed. (For more information on
  5831. how to specify a date, see @ref{Date input formats}; remember that the
  5832. entire date argument must be quoted if it contains any spaces.)
  5833. Gurus would say that @option{--after-date} tests both the data
  5834. modification time (@code{mtime}, the time the contents of the file
  5835. were last modified) and the status change time (@code{ctime}, the time
  5836. the file's status was last changed: owner, permissions, etc.@:)
  5837. fields, while @option{--newer-mtime} tests only the @code{mtime}
  5838. field.
  5839. To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
  5840. @code{ctime} and processes the file if either one is more recent than
  5841. @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
  5842. disregards @code{ctime}. Neither does it use @code{atime} (the last time the
  5843. contents of the file were looked at).
  5844. Date specifiers can have embedded spaces. Because of this, you may need
  5845. to quote date arguments to keep the shell from parsing them as separate
  5846. arguments. For example, the following command will add to the archive
  5847. all the files modified less than two days ago:
  5848. @smallexample
  5849. $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
  5850. @end smallexample
  5851. When any of these options is used with the option @option{--verbose}
  5852. (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
  5853. date back to its textual representation and compare that with the
  5854. one given with the option. If the two dates differ, @command{tar} will
  5855. print a warning saying what date it will use. This is to help user
  5856. ensure he is using the right date. For example:
  5857. @smallexample
  5858. @group
  5859. $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
  5860. tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
  5861. 13:19:37.232434
  5862. @end group
  5863. @end smallexample
  5864. @quotation
  5865. @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
  5866. should not be used for incremental backups. @xref{Incremental Dumps},
  5867. for proper way of creating incremental backups.
  5868. @end quotation
  5869. @node recurse
  5870. @section Descending into Directories
  5871. @UNREVISED
  5872. @cindex Avoiding recursion in directories
  5873. @cindex Descending directories, avoiding
  5874. @cindex Directories, avoiding recursion
  5875. @cindex Recursion in directories, avoiding
  5876. @FIXME{arrggh! this is still somewhat confusing to me. :-< }
  5877. Usually, @command{tar} will recursively explore all directories (either
  5878. those given on the command line or through the @option{--files-from}
  5879. option) for the various files they contain. However, you may not always
  5880. want @command{tar} to act this way.
  5881. @opindex no-recursion
  5882. The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
  5883. into specified directories. If you specify @option{--no-recursion}, you can
  5884. use the @command{find} utility for hunting through levels of directories to
  5885. construct a list of file names which you could then pass to @command{tar}.
  5886. @command{find} allows you to be more selective when choosing which files to
  5887. archive; see @ref{files}, for more information on using @command{find} with
  5888. @command{tar}, or look.
  5889. @table @option
  5890. @item --no-recursion
  5891. Prevents @command{tar} from recursively descending directories.
  5892. @opindex recursion
  5893. @item --recursion
  5894. Requires @command{tar} to recursively descend directories.
  5895. This is the default.
  5896. @end table
  5897. When you use @option{--no-recursion}, @GNUTAR{} grabs
  5898. directory entries themselves, but does not descend on them
  5899. recursively. Many people use @command{find} for locating files they
  5900. want to back up, and since @command{tar} @emph{usually} recursively
  5901. descends on directories, they have to use the @samp{@w{-not -type d}}
  5902. test in their @command{find} invocation (@pxref{Type, Type, Type test,
  5903. find, Finding Files}), as they usually do not want all the files in a
  5904. directory. They then use the @option{--files-from} option to archive
  5905. the files located via @command{find}.
  5906. The problem when restoring files archived in this manner is that the
  5907. directories themselves are not in the archive; so the
  5908. @option{--same-permissions} (@option{--preserve-permissions},
  5909. @option{-p}) option does not affect them---while users might really
  5910. like it to. Specifying @option{--no-recursion} is a way to tell
  5911. @command{tar} to grab only the directory entries given to it, adding
  5912. no new files on its own. To summarize, if you use @command{find} to
  5913. create a list of files to be stored in an archive, use it as follows:
  5914. @smallexample
  5915. @group
  5916. $ @kbd{find @var{dir} @var{tests} | \
  5917. tar -cf @var{archive} -T - --no-recursion}
  5918. @end group
  5919. @end smallexample
  5920. The @option{--no-recursion} option also applies when extracting: it
  5921. causes @command{tar} to extract only the matched directory entries, not
  5922. the files under those directories.
  5923. The @option{--no-recursion} option also affects how globbing patterns
  5924. are interpreted (@pxref{controlling pattern-matching}).
  5925. The @option{--no-recursion} and @option{--recursion} options apply to
  5926. later options and operands, and can be overridden by later occurrences
  5927. of @option{--no-recursion} and @option{--recursion}. For example:
  5928. @smallexample
  5929. $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
  5930. @end smallexample
  5931. @noindent
  5932. creates an archive with one entry for @file{grape}, and the recursive
  5933. contents of @file{grape/concord}, but no entries under @file{grape}
  5934. other than @file{grape/concord}.
  5935. @node one
  5936. @section Crossing File System Boundaries
  5937. @cindex File system boundaries, not crossing
  5938. @UNREVISED
  5939. @command{tar} will normally automatically cross file system boundaries in
  5940. order to archive files which are part of a directory tree. You can
  5941. change this behavior by running @command{tar} and specifying
  5942. @option{--one-file-system}. This option only affects files that are
  5943. archived because they are in a directory that is being archived;
  5944. @command{tar} will still archive files explicitly named on the command line
  5945. or through @option{--files-from}, regardless of where they reside.
  5946. @table @option
  5947. @opindex one-file-system
  5948. @item --one-file-system
  5949. Prevents @command{tar} from crossing file system boundaries when
  5950. archiving. Use in conjunction with any write operation.
  5951. @end table
  5952. The @option{--one-file-system} option causes @command{tar} to modify its
  5953. normal behavior in archiving the contents of directories. If a file in
  5954. a directory is not on the same file system as the directory itself, then
  5955. @command{tar} will not archive that file. If the file is a directory
  5956. itself, @command{tar} will not archive anything beneath it; in other words,
  5957. @command{tar} will not cross mount points.
  5958. This option is useful for making full or incremental archival backups of
  5959. a file system. If this option is used in conjunction with
  5960. @option{--verbose} (@option{-v}), files that are excluded are
  5961. mentioned by name on the standard error.
  5962. @menu
  5963. * directory:: Changing Directory
  5964. * absolute:: Absolute File Names
  5965. @end menu
  5966. @node directory
  5967. @subsection Changing the Working Directory
  5968. @UNREVISED
  5969. @FIXME{need to read over this node now for continuity; i've switched
  5970. things around some.}
  5971. @cindex Changing directory mid-stream
  5972. @cindex Directory, changing mid-stream
  5973. @cindex Working directory, specifying
  5974. To change the working directory in the middle of a list of file names,
  5975. either on the command line or in a file specified using
  5976. @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
  5977. This will change the working directory to the specified directory
  5978. after that point in the list.
  5979. @table @option
  5980. @opindex directory
  5981. @item --directory=@var{directory}
  5982. @itemx -C @var{directory}
  5983. Changes the working directory in the middle of a command line.
  5984. @end table
  5985. For example,
  5986. @smallexample
  5987. $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
  5988. @end smallexample
  5989. @noindent
  5990. will place the files @file{grape} and @file{prune} from the current
  5991. directory into the archive @file{jams.tar}, followed by the file
  5992. @file{cherry} from the directory @file{food}. This option is especially
  5993. useful when you have several widely separated files that you want to
  5994. store in the same archive.
  5995. Note that the file @file{cherry} is recorded in the archive under the
  5996. precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
  5997. archive will contain three files that all appear to have come from the
  5998. same directory; if the archive is extracted with plain @samp{tar
  5999. --extract}, all three files will be written in the current directory.
  6000. Contrast this with the command,
  6001. @smallexample
  6002. $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
  6003. @end smallexample
  6004. @noindent
  6005. which records the third file in the archive under the name
  6006. @file{red/cherry} so that, if the archive is extracted using
  6007. @samp{tar --extract}, the third file will be written in a subdirectory
  6008. named @file{orange-colored}.
  6009. You can use the @option{--directory} option to make the archive
  6010. independent of the original name of the directory holding the files.
  6011. The following command places the files @file{/etc/passwd},
  6012. @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
  6013. @file{foo.tar}:
  6014. @smallexample
  6015. $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
  6016. @end smallexample
  6017. @noindent
  6018. However, the names of the archive members will be exactly what they were
  6019. on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
  6020. They will not appear to be related by file name to the original
  6021. directories where those files were located.
  6022. Note that @option{--directory} options are interpreted consecutively. If
  6023. @option{--directory} specifies a relative file name, it is interpreted
  6024. relative to the then current directory, which might not be the same as
  6025. the original current working directory of @command{tar}, due to a previous
  6026. @option{--directory} option.
  6027. When using @option{--files-from} (@pxref{files}), you can put various
  6028. @command{tar} options (including @option{-C}) in the file list. Notice,
  6029. however, that in this case the option and its argument may not be
  6030. separated by whitespace. If you use short option, its argument must
  6031. either follow the option letter immediately, without any intervening
  6032. whitespace, or occupy the next line. Otherwise, if you use long
  6033. option, separate its argument by an equal sign.
  6034. For instance, the file list for the above example will be:
  6035. @smallexample
  6036. @group
  6037. -C
  6038. /etc
  6039. passwd
  6040. hosts
  6041. -C
  6042. /lib
  6043. libc.a
  6044. @end group
  6045. @end smallexample
  6046. @noindent
  6047. To use it, you would invoke @command{tar} as follows:
  6048. @smallexample
  6049. $ @kbd{tar -c -f foo.tar --files-from list}
  6050. @end smallexample
  6051. Notice also that you can only use the short option variant in the file
  6052. list, i.e., always use @option{-C}, not @option{--directory}.
  6053. The interpretation of @option{--directory} is disabled by
  6054. @option{--null} option.
  6055. @node absolute
  6056. @subsection Absolute File Names
  6057. @UNREVISED
  6058. @table @option
  6059. @opindex absolute-names
  6060. @item --absolute-names
  6061. @itemx -P
  6062. Do not strip leading slashes from file names, and permit file names
  6063. containing a @file{..} file name component.
  6064. @end table
  6065. By default, @GNUTAR{} drops a leading @samp{/} on
  6066. input or output, and complains about file names containing a @file{..}
  6067. component. This option turns off this behavior.
  6068. When @command{tar} extracts archive members from an archive, it strips any
  6069. leading slashes (@samp{/}) from the member name. This causes absolute
  6070. member names in the archive to be treated as relative file names. This
  6071. allows you to have such members extracted wherever you want, instead of
  6072. being restricted to extracting the member in the exact directory named
  6073. in the archive. For example, if the archive member has the name
  6074. @file{/etc/passwd}, @command{tar} will extract it as if the name were
  6075. really @file{etc/passwd}.
  6076. File names containing @file{..} can cause problems when extracting, so
  6077. @command{tar} normally warns you about such files when creating an
  6078. archive, and rejects attempts to extracts such files.
  6079. Other @command{tar} programs do not do this. As a result, if you
  6080. create an archive whose member names start with a slash, they will be
  6081. difficult for other people with a non-@GNUTAR{}
  6082. program to use. Therefore, @GNUTAR{} also strips
  6083. leading slashes from member names when putting members into the
  6084. archive. For example, if you ask @command{tar} to add the file
  6085. @file{/bin/ls} to an archive, it will do so, but the member name will
  6086. be @file{bin/ls}.@footnote{A side effect of this is that when
  6087. @option{--create} is used with @option{--verbose} the resulting output
  6088. is not, generally speaking, the same as the one you'd get running
  6089. @kbd{tar --list} command. This may be important if you use some
  6090. scripts for comparing both outputs. @xref{listing member and file names},
  6091. for the information on how to handle this case.}
  6092. If you use the @option{--absolute-names} (@option{-P}) option,
  6093. @command{tar} will do none of these transformations.
  6094. To archive or extract files relative to the root directory, specify
  6095. the @option{--absolute-names} (@option{-P}) option.
  6096. Normally, @command{tar} acts on files relative to the working
  6097. directory---ignoring superior directory names when archiving, and
  6098. ignoring leading slashes when extracting.
  6099. When you specify @option{--absolute-names} (@option{-P}),
  6100. @command{tar} stores file names including all superior directory
  6101. names, and preserves leading slashes. If you only invoked
  6102. @command{tar} from the root directory you would never need the
  6103. @option{--absolute-names} option, but using this option
  6104. may be more convenient than switching to root.
  6105. @FIXME{Should be an example in the tutorial/wizardry section using this
  6106. to transfer files between systems.}
  6107. @FIXME{Is write access an issue?}
  6108. @table @option
  6109. @item --absolute-names
  6110. Preserves full file names (including superior directory names) when
  6111. archiving files. Preserves leading slash when extracting files.
  6112. @end table
  6113. @FIXME{this is still horrible; need to talk with dan on monday.}
  6114. @command{tar} prints out a message about removing the @samp{/} from
  6115. file names. This message appears once per @GNUTAR{}
  6116. invocation. It represents something which ought to be told; ignoring
  6117. what it means can cause very serious surprises, later.
  6118. Some people, nevertheless, do not want to see this message. Wanting to
  6119. play really dangerously, one may of course redirect @command{tar} standard
  6120. error to the sink. For example, under @command{sh}:
  6121. @smallexample
  6122. $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
  6123. @end smallexample
  6124. @noindent
  6125. Another solution, both nicer and simpler, would be to change to
  6126. the @file{/} directory first, and then avoid absolute notation.
  6127. For example:
  6128. @smallexample
  6129. $ @kbd{(cd / && tar -c -f archive.tar home)}
  6130. # @i{or}:
  6131. $ @kbd{tar -c -f archive.tar -C / home}
  6132. @end smallexample
  6133. @include getdate.texi
  6134. @node Formats
  6135. @chapter Controlling the Archive Format
  6136. @cindex Tar archive formats
  6137. Due to historical reasons, there are several formats of tar archives.
  6138. All of them are based on the same principles, but have some subtle
  6139. differences that often make them incompatible with each other.
  6140. GNU tar is able to create and handle archives in a variety of formats.
  6141. The most frequently used formats are (in alphabetical order):
  6142. @table @asis
  6143. @item gnu
  6144. Format used by @GNUTAR{} versions up to 1.13.25. This format derived
  6145. from an early @acronym{POSIX} standard, adding some improvements such as
  6146. sparse file handling and incremental archives. Unfortunately these
  6147. features were implemented in a way incompatible with other archive
  6148. formats.
  6149. Archives in @samp{gnu} format are able to hold pathnames of unlimited
  6150. length.
  6151. @item oldgnu
  6152. Format used by @GNUTAR{} of versions prior to 1.12.
  6153. @item v7
  6154. Archive format, compatible with the V7 implementation of tar. This
  6155. format imposes a number of limitations. The most important of them
  6156. are:
  6157. @enumerate
  6158. @item The maximum length of a file name is limited to 99 characters.
  6159. @item The maximum length of a symbolic link is limited to 99 characters.
  6160. @item It is impossible to store special files (block and character
  6161. devices, fifos etc.)
  6162. @item Maximum value of user or group ID is limited to 2097151 (7777777
  6163. octal)
  6164. @item V7 archives do not contain symbolic ownership information (user
  6165. and group name of the file owner).
  6166. @end enumerate
  6167. This format has traditionally been used by Automake when producing
  6168. Makefiles. This practice will change in the future, in the meantime,
  6169. however this means that projects containing filenames more than 99
  6170. characters long will not be able to use @GNUTAR{} @value{VERSION} and
  6171. Automake prior to 1.9.
  6172. @item ustar
  6173. Archive format defined by @acronym{POSIX.1-1988} specification. It stores
  6174. symbolic ownership information. It is also able to store
  6175. special files. However, it imposes several restrictions as well:
  6176. @enumerate
  6177. @item The maximum length of a file name is limited to 256 characters,
  6178. provided that the filename can be split at directory separator in
  6179. two parts, first of them being at most 155 bytes long. So, in most
  6180. cases the maximum file name length will be shorter than 256
  6181. characters.
  6182. @item The maximum length of a symbolic link name is limited to
  6183. 100 characters.
  6184. @item Maximum size of a file the archive is able to accomodate
  6185. is 8GB
  6186. @item Maximum value of UID/GID is 2097151.
  6187. @item Maximum number of bits in device major and minor numbers is 21.
  6188. @end enumerate
  6189. @item star
  6190. Format used by J@"org Schilling @command{star}
  6191. implementation. @GNUTAR{} is able to read @samp{star} archives but
  6192. currently does not produce them.
  6193. @item posix
  6194. Archive format defined by @acronym{POSIX.1-2001} specification. This is the
  6195. most flexible and feature-rich format. It does not impose any
  6196. restrictions on file sizes or filename lengths. This format is quite
  6197. recent, so not all tar implementations are able to handle it properly.
  6198. However, this format is designed in such a way that any tar
  6199. implementation able to read @samp{ustar} archives will be able to read
  6200. most @samp{posix} archives as well, with the only exception that any
  6201. additional information (such as long file names etc.) will in such
  6202. case be extracted as plain text files along with the files it refers to.
  6203. This archive format will be the default format for future versions
  6204. of @GNUTAR{}.
  6205. @end table
  6206. The following table summarizes the limitations of each of these
  6207. formats:
  6208. @multitable @columnfractions .10 .20 .20 .20 .20
  6209. @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
  6210. @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  6211. @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
  6212. @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
  6213. @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
  6214. @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
  6215. @end multitable
  6216. The default format for @GNUTAR{} is defined at compilation
  6217. time. You may check it by running @command{tar --help}, and examining
  6218. the last lines of its output. Usually, @GNUTAR{} is configured
  6219. to create archives in @samp{gnu} format, however, future version will
  6220. switch to @samp{posix}.
  6221. @menu
  6222. * Portability:: Making @command{tar} Archives More Portable
  6223. * Compression:: Using Less Space through Compression
  6224. * Attributes:: Handling File Attributes
  6225. * cpio:: Comparison of @command{tar} and @command{cpio}
  6226. @end menu
  6227. @node Portability
  6228. @section Making @command{tar} Archives More Portable
  6229. Creating a @command{tar} archive on a particular system that is meant to be
  6230. useful later on many other machines and with other versions of @command{tar}
  6231. is more challenging than you might think. @command{tar} archive formats
  6232. have been evolving since the first versions of Unix. Many such formats
  6233. are around, and are not always compatible with each other. This section
  6234. discusses a few problems, and gives some advice about making @command{tar}
  6235. archives more portable.
  6236. One golden rule is simplicity. For example, limit your @command{tar}
  6237. archives to contain only regular files and directories, avoiding
  6238. other kind of special files. Do not attempt to save sparse files or
  6239. contiguous files as such. Let's discuss a few more problems, in turn.
  6240. @FIXME{Discuss GNU extensions (incremental backups, multi-volume
  6241. archives and archive labels) in GNU and PAX formats.}
  6242. @menu
  6243. * Portable Names:: Portable Names
  6244. * dereference:: Symbolic Links
  6245. * old:: Old V7 Archives
  6246. * ustar:: Ustar Archives
  6247. * gnu:: GNU and old GNU format archives.
  6248. * posix:: @acronym{POSIX} archives
  6249. * Checksumming:: Checksumming Problems
  6250. * Large or Negative Values:: Large files, negative time stamps, etc.
  6251. * Other Tars:: How to Extract GNU-Specific Data Using
  6252. Other @command{tar} Implementations
  6253. @end menu
  6254. @node Portable Names
  6255. @subsection Portable Names
  6256. Use portable file and member names. A name is portable if it contains
  6257. only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
  6258. @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
  6259. contain @samp{/-}. Avoid deep directory nesting. For portability to
  6260. old Unix hosts, limit your file name components to 14 characters or
  6261. less.
  6262. If you intend to have your @command{tar} archives to be read under
  6263. MSDOS, you should not rely on case distinction for file names, and you
  6264. might use the @acronym{GNU} @command{doschk} program for helping you
  6265. further diagnosing illegal MSDOS names, which are even more limited
  6266. than System V's.
  6267. @node dereference
  6268. @subsection Symbolic Links
  6269. @cindex File names, using symbolic links
  6270. @cindex Symbolic link as file name
  6271. @opindex dereference
  6272. Normally, when @command{tar} archives a symbolic link, it writes a
  6273. block to the archive naming the target of the link. In that way, the
  6274. @command{tar} archive is a faithful record of the file system contents.
  6275. @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
  6276. @command{tar} to archive the files symbolic links point to, instead of
  6277. the links themselves. When this option is used, when @command{tar}
  6278. encounters a symbolic link, it will archive the linked-to file,
  6279. instead of simply recording the presence of a symbolic link.
  6280. The name under which the file is stored in the file system is not
  6281. recorded in the archive. To record both the symbolic link name and
  6282. the file name in the system, archive the file under both names. If
  6283. all links were recorded automatically by @command{tar}, an extracted file
  6284. might be linked to a file name that no longer exists in the file
  6285. system.
  6286. If a linked-to file is encountered again by @command{tar} while creating
  6287. the same archive, an entire second copy of it will be stored. (This
  6288. @emph{might} be considered a bug.)
  6289. So, for portable archives, do not archive symbolic links as such,
  6290. and use @option{--dereference} (@option{-h}): many systems do not support
  6291. symbolic links, and moreover, your distribution might be unusable if
  6292. it contains unresolved symbolic links.
  6293. @node old
  6294. @subsection Old V7 Archives
  6295. @cindex Format, old style
  6296. @cindex Old style format
  6297. @cindex Old style archives
  6298. @cindex v7 archive format
  6299. Certain old versions of @command{tar} cannot handle additional
  6300. information recorded by newer @command{tar} programs. To create an
  6301. archive in V7 format (not ANSI), which can be read by these old
  6302. versions, specify the @option{--format=v7} option in
  6303. conjunction with the @option{--create} (@option{-c}) (@command{tar} also
  6304. accepts @option{--portability} or @samp{op-old-archive} for this
  6305. option). When you specify it,
  6306. @command{tar} leaves out information about directories, pipes, fifos,
  6307. contiguous files, and device files, and specifies file ownership by
  6308. group and user IDs instead of group and user names.
  6309. When updating an archive, do not use @option{--format=v7}
  6310. unless the archive was created using this option.
  6311. In most cases, a @emph{new} format archive can be read by an @emph{old}
  6312. @command{tar} program without serious trouble, so this option should
  6313. seldom be needed. On the other hand, most modern @command{tar}s are
  6314. able to read old format archives, so it might be safer for you to
  6315. always use @option{--format=v7} for your distributions.
  6316. @node ustar
  6317. @subsection Ustar Archive Format
  6318. @cindex ustar archive format
  6319. Archive format defined by @acronym{POSIX}.1-1988 specification is called
  6320. @code{ustar}. Although it is more flexible than the V7 format, it
  6321. still has many restrictions (@xref{Formats,ustar}, for the detailed
  6322. description of @code{ustar} format). Along with V7 format,
  6323. @code{ustar} format is a good choice for archives intended to be read
  6324. with other implementations of @command{tar}.
  6325. To create archive in @code{ustar} format, use @option{--format=ustar}
  6326. option in conjunction with the @option{--create} (@option{-c}).
  6327. @node gnu
  6328. @subsection @acronym{GNU} and old @GNUTAR{} format
  6329. @cindex GNU archive format
  6330. @cindex Old GNU archive format
  6331. @GNUTAR{} was based on an early draft of the
  6332. @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
  6333. @command{tar}, such as the support for file names longer than 100
  6334. characters, use portions of the @command{tar} header record which were
  6335. specified in that @acronym{POSIX} draft as unused. Subsequent changes in
  6336. @acronym{POSIX} have allocated the same parts of the header record for
  6337. other purposes. As a result, @GNUTAR{} format is
  6338. incompatible with the current @acronym{POSIX} specification, and with
  6339. @command{tar} programs that follow it.
  6340. In the majority of cases, @command{tar} will be configured to create
  6341. this format by default. This will change in the future releases, since
  6342. we plan to make @samp{posix} format the default.
  6343. To force creation a @GNUTAR{} archive, use option
  6344. @option{--format=gnu}.
  6345. @node posix
  6346. @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
  6347. @cindex POSIX archive format
  6348. @cindex PAX archive format
  6349. Starting from version 1.14 @GNUTAR{} features full support for
  6350. @acronym{POSIX.1-2001} archives.
  6351. A @acronym{POSIX} conformant archive will be created if @command{tar}
  6352. was given @option{--format=posix} (@option{--format=pax}) option. No
  6353. special option is required to read and extract from a @acronym{POSIX}
  6354. archive.
  6355. @menu
  6356. * PAX keywords:: Controlling Extended Header Keywords.
  6357. @end menu
  6358. @node PAX keywords
  6359. @subsubsection Controlling Extended Header Keywords
  6360. @table @option
  6361. @opindex pax-option
  6362. @item --pax-option=@var{keyword-list}
  6363. Handle keywords in @acronym{PAX} extended headers. This option is
  6364. equivalent to @option{-o} option of the @command{pax} utility.
  6365. @end table
  6366. @var{Keyword-list} is a comma-separated
  6367. list of keyword options, each keyword option taking one of
  6368. the following forms:
  6369. @table @code
  6370. @item delete=@var{pattern}
  6371. When used with one of archive-creation commands,
  6372. this option instructs @command{tar} to omit from extended header records
  6373. that it produces any keywords matching the string @var{pattern}.
  6374. When used in extract or list mode, this option instructs tar
  6375. to ignore any keywords matching the given @var{pattern} in the extended
  6376. header records. In both cases, matching is performed using the pattern
  6377. matching notation described in @acronym{POSIX 1003.2}, 3.13
  6378. (@pxref{wildcards}). For example:
  6379. @smallexample
  6380. --pax-option delete=security.*
  6381. @end smallexample
  6382. would suppress security-related information.
  6383. @item exthdr.name=@var{string}
  6384. This keyword allows user control over the name that is written into the
  6385. ustar header blocks for the extended headers. The name is obtained
  6386. from @var{string} after making the following substitutions:
  6387. @multitable @columnfractions .25 .55
  6388. @headitem Meta-character @tab Replaced By
  6389. @item %d @tab The directory name of the file, equivalent to the
  6390. result of the @command{dirname} utility on the translated pathname.
  6391. @item %f @tab The filename of the file, equivalent to the result
  6392. of the @command{basename} utility on the translated pathname.
  6393. @item %p @tab The process ID of the @command{tar} process.
  6394. @item %% @tab A @samp{%} character.
  6395. @end multitable
  6396. Any other @samp{%} characters in @var{string} produce undefined
  6397. results.
  6398. If no option @samp{exthdr.name=string} is specified, @command{tar}
  6399. will use the following default value:
  6400. @smallexample
  6401. %d/PaxHeaders.%p/%f
  6402. @end smallexample
  6403. @item globexthdr.name=@var{string}
  6404. This keyword allows user control over the name that is written into
  6405. the ustar header blocks for global extended header records. The name
  6406. is obtained from the contents of @var{string}, after making
  6407. the following substitutions:
  6408. @multitable @columnfractions .25 .55
  6409. @headitem Meta-character @tab Replaced By
  6410. @item %n @tab An integer that represents the
  6411. sequence number of the global extended header record in the archive,
  6412. starting at 1.
  6413. @item %p @tab The process ID of the @command{tar} process.
  6414. @item %% @tab A @samp{%} character.
  6415. @end multitable
  6416. Any other @samp{%} characters in @var{string} produce undefined results.
  6417. If no option @samp{globexthdr.name=string} is specified, @command{tar}
  6418. will use the following default value:
  6419. @smallexample
  6420. $TMPDIR/GlobalHead.%p.%n
  6421. @end smallexample
  6422. @noindent
  6423. where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
  6424. environment variable. If @var{TMPDIR} is not set, @command{tar}
  6425. uses @samp{/tmp}.
  6426. @item @var{keyword}=@var{value}
  6427. When used with one of archive-creation commands, these keyword/value pairs
  6428. will be included at the beginning of the archive in a global extended
  6429. header record. When used with one of archive-reading commands,
  6430. @command{tar} will behave as if it has encountered these keyword/value
  6431. pairs at the beginning of the archive in a global extended header
  6432. record.
  6433. @item @var{keyword}:=@var{value}
  6434. When used with one of archive-creation commands, these keyword/value pairs
  6435. will be included as records at the beginning of an extended header for
  6436. each file. This is effectively equivalent to @var{keyword}=@var{value}
  6437. form except that it creates no global extended header records.
  6438. When used with one of archive-reading commands, @command{tar} will
  6439. behave as if these keyword/value pairs were included as records at the
  6440. end of each extended header; thus, they will override any global or
  6441. file-specific extended header record keywords of the same names.
  6442. For example, in the command:
  6443. @smallexample
  6444. tar --format=posix --create \
  6445. --file archive --pax-option gname:=user .
  6446. @end smallexample
  6447. the group name will be forced to a new value for all files
  6448. stored in the archive.
  6449. @end table
  6450. @node Checksumming
  6451. @subsection Checksumming Problems
  6452. SunOS and HP-UX @command{tar} fail to accept archives created using
  6453. @GNUTAR{} and containing non-ASCII file names, that
  6454. is, file names having characters with the eight bit set, because they
  6455. use signed checksums, while @GNUTAR{} uses unsigned
  6456. checksums while creating archives, as per @acronym{POSIX} standards. On
  6457. reading, @GNUTAR{} computes both checksums and
  6458. accept any. It is somewhat worrying that a lot of people may go
  6459. around doing backup of their files using faulty (or at least
  6460. non-standard) software, not learning about it until it's time to
  6461. restore their missing files with an incompatible file extractor, or
  6462. vice versa.
  6463. @GNUTAR{} compute checksums both ways, and accept
  6464. any on read, so @acronym{GNU} tar can read Sun tapes even with their
  6465. wrong checksums. @GNUTAR{} produces the standard
  6466. checksum, however, raising incompatibilities with Sun. That is to
  6467. say, @GNUTAR{} has not been modified to
  6468. @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
  6469. I've been told that more recent Sun @command{tar} now read standard
  6470. archives, so maybe Sun did a similar patch, after all?
  6471. The story seems to be that when Sun first imported @command{tar}
  6472. sources on their system, they recompiled it without realizing that
  6473. the checksums were computed differently, because of a change in
  6474. the default signing of @code{char}'s in their compiler. So they
  6475. started computing checksums wrongly. When they later realized their
  6476. mistake, they merely decided to stay compatible with it, and with
  6477. themselves afterwards. Presumably, but I do not really know, HP-UX
  6478. has chosen that their @command{tar} archives to be compatible with Sun's.
  6479. The current standards do not favor Sun @command{tar} format. In any
  6480. case, it now falls on the shoulders of SunOS and HP-UX users to get
  6481. a @command{tar} able to read the good archives they receive.
  6482. @node Large or Negative Values
  6483. @subsection Large or Negative Values
  6484. @cindex large values
  6485. @cindex future time stamps
  6486. @cindex negative time stamps
  6487. @UNREVISED{}
  6488. The above sections suggest to use @samp{oldest possible} archive
  6489. format if in doubt. However, sometimes it is not possible. If you
  6490. attempt to archive a file whose metadata cannot be represented using
  6491. required format, @GNUTAR{} will print error message and ignore such a
  6492. file. You will than have to switch to a format that is able to
  6493. handle such values. The format summary table (@pxref{Formats}) will
  6494. help you to do so.
  6495. In particular, when trying to archive files larger than 8GB or with
  6496. timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
  6497. 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
  6498. @acronym{POSIX} archive formats. When considering which format to
  6499. choose, bear in mind that the @acronym{GNU} format uses
  6500. two's-complement base-256 notation to store values that do not fit
  6501. into standard @acronym{ustar} range. Such archives can generally be
  6502. read only by a @GNUTAR{} implementation. Moreover, they sometimes
  6503. cannot be correctly restored on another hosts even by @GNUTAR{}. For
  6504. example, using two's complement representation for negative time
  6505. stamps that assumes a signed 32-bit @code{time_t} generates archives
  6506. that are not portable to hosts with differing @code{time_t}
  6507. representations.
  6508. On the other hand, @acronym{POSIX} archives, generally speaking, can
  6509. be extracted by any tar implementation that understands older
  6510. @acronym{ustar} format. The only exception are files larger than 8GB.
  6511. @FIXME{Describe how @acronym{POSIX} archives are extracted by non
  6512. POSIX-aware tars.}
  6513. @node Other Tars
  6514. @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
  6515. In previous sections you became acquainted with various quircks
  6516. necessary to make your archives portable. Sometimes you may need to
  6517. extract archives containing GNU-specific members using some
  6518. third-party @command{tar} implementation or an older version of
  6519. @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
  6520. but if it is for some reason impossible, this section will explain
  6521. how to cope without it.
  6522. When we speak about @dfn{GNU-specific} members we mean two classes of
  6523. them: members split between the volumes of a multi-volume archive and
  6524. sparse members. You will be able to always recover such members if
  6525. the archive is in PAX format. In addition split members can be
  6526. recovered from archives in old GNU format. The following subsections
  6527. describe the required procedures in detail.
  6528. @menu
  6529. * Split Recovery:: Members Split Between Volumes
  6530. * Sparse Recovery:: Sparse Members
  6531. @end menu
  6532. @node Split Recovery
  6533. @subsubsection Extracting Members Split Between Volumes
  6534. If a member is split between several volumes of an old GNU format archive
  6535. most third party @command{tar} implementation will fail to extract
  6536. it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
  6537. This program is available from
  6538. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat, @GNUTAR{}
  6539. home page}. It concatenates several archive volumes into a single
  6540. valid archive. For example, if you have three volumes named from
  6541. @file{vol-1.tar} to @file{vol-2.tar}, you can do the following to
  6542. extract them using a third-party @command{tar}:
  6543. @smallexample
  6544. $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
  6545. @end smallexample
  6546. You could use this approach for many (although not all) PAX
  6547. format archives as well. However, extracting split members from a PAX
  6548. archive is a much easier task, because PAX volumes are constructed in
  6549. such a way that each part of a split member is extracted as a
  6550. different file by @command{tar} implementations that are not aware of
  6551. GNU extensions. More specifically, the very first part retains its
  6552. original name, and all subsequent parts are named using the pattern:
  6553. @smallexample
  6554. %d/GNUFileParts.%p/%f.%n
  6555. @end smallexample
  6556. @noindent
  6557. where symbols preceeded by @samp{%} are @dfn{macro characters} that
  6558. have the following meaning:
  6559. @multitable @columnfractions .25 .55
  6560. @headitem Meta-character @tab Replaced By
  6561. @item %d @tab The directory name of the file, equivalent to the
  6562. result of the @command{dirname} utility on its full name.
  6563. @item %f @tab The file name of the file, equivalent to the result
  6564. of the @command{basename} utility on its full name.
  6565. @item %p @tab The process ID of the @command{tar} process that
  6566. created the archive.
  6567. @item %n @tab Ordinal number of this particular part.
  6568. @end multitable
  6569. For example, if, a file @file{var/longfile} was split during archive
  6570. creation between three volumes, and the creator @command{tar} process
  6571. had process ID @samp{27962}, then the member names will be:
  6572. @smallexample
  6573. var/longfile
  6574. var/GNUFileParts.27962/longfile.1
  6575. var/GNUFileParts.27962/longfile.2
  6576. @end smallexample
  6577. When you extract your archive using a third-party @command{tar}, these
  6578. files will be created on your disk, and the only thing you will need
  6579. to do to restore your file in its original form is concatenate them in
  6580. the proper order, for example:
  6581. @smallexample
  6582. @group
  6583. $ @kbd{cd var}
  6584. $ @kbd{cat GNUFileParts.27962/longfile.1 \
  6585. GNUFileParts.27962/longfile.2 >> longfile}
  6586. $ rm -f GNUFileParts.27962
  6587. @end group
  6588. @end smallexample
  6589. Notice, that if the @command{tar} implementation you use supports PAX
  6590. format archives, it will probably emit warnings about unknown keywords
  6591. during extraction. They will lool like this:
  6592. @smallexample
  6593. @group
  6594. Tar file too small
  6595. Unknown extended header keyword 'GNU.volume.filename' ignored.
  6596. Unknown extended header keyword 'GNU.volume.size' ignored.
  6597. Unknown extended header keyword 'GNU.volume.offset' ignored.
  6598. @end group
  6599. @end smallexample
  6600. @noindent
  6601. You can safely ignore these warnings.
  6602. If your @command{tar} implementation is not PAX-aware, you will get
  6603. more warnigns and more files generated on your disk, e.g.:
  6604. @smallexample
  6605. @group
  6606. $ @kbd{tar xf vol-1.tar}
  6607. var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
  6608. normal file
  6609. Unexpected EOF in archive
  6610. $ @kbd{tar xf vol-2.tar}
  6611. tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
  6612. GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
  6613. 'x', extracted as normal file
  6614. @end group
  6615. @end smallexample
  6616. Ignore these warnings. The @file{PaxHeaders.*} directories created
  6617. will contain files with @dfn{extended header keywords} describing the
  6618. extracted files. You can delete them, unless they describe sparse
  6619. members. Read further to learn more about them.
  6620. @node Sparse Recovery
  6621. @subsubsection Extracting Sparse Members
  6622. Any @command{tar} implementation will be able to extract sparse members from a
  6623. PAX archive. However, the extracted files will be @dfn{condensed},
  6624. i.e. any zero blocks will be removed from them. When we restore such
  6625. a condensed file to its original form, by adding zero bloks (or
  6626. @dfn{holes}) back to their original locations, we call this process
  6627. @dfn{expanding} a compressed sparse file.
  6628. To expand a file, you will need a simple auxiliary program called
  6629. @command{xsparse}. It is available in source form from
  6630. @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse, @GNUTAR{}
  6631. home page}.
  6632. Let's begin with archive members in @dfn{sparse format
  6633. version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
  6634. The condensed file will contain both file map and file data, so no
  6635. additional data will be needed to restore it. If the original file
  6636. name was @file{@var{dir}/@var{name}}, then the condensed file will be
  6637. named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
  6638. @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
  6639. @dfn{process ID} of the @command{tar} process which created the
  6640. archive (@pxref{PAX keywords}).}.
  6641. To expand a version 1.0 file, run @command{xsparse} as follows:
  6642. @smallexample
  6643. $ @kbd{xsparse @file{cond-file}}
  6644. @end smallexample
  6645. @noindent
  6646. where @file{cond-file} is the name of the condensed file. The utility
  6647. will deduce the name for the resulting expanded file using the
  6648. following algorithm:
  6649. @enumerate 1
  6650. @item If @file{cond-file} does not contain any directories,
  6651. @file{../cond-file} will be used;
  6652. @item If @file{cond-file} has the form
  6653. @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
  6654. are simple names, with no @samp{/} characters in them, the output file
  6655. name will be @file{@var{dir}/@var{name}}.
  6656. @item Otherwise, if @file{cond-file} has the form
  6657. @file{@var{dir}/@var{name}}, the output file name will be
  6658. @file{@var{name}}.
  6659. @end enumerate
  6660. In the unlikely case when this algorithm does not suite your needs,
  6661. you can explicitely specify output file name as a second argument to
  6662. the command:
  6663. @smallexample
  6664. $ @kbd{xsparse @file{cond-file}}
  6665. @end smallexample
  6666. It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
  6667. first. In this mode, the command does not actually expand the file,
  6668. but verbosely lists all actions it would be taking to do so. The dry
  6669. run mode is enabled by @option{-n} command line argument:
  6670. @smallexample
  6671. @group
  6672. $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
  6673. Reading v.1.0 sparse map
  6674. Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
  6675. `/home/gray/sparsefile'
  6676. Finished dry run
  6677. @end group
  6678. @end smallexample
  6679. To actually expand the file, you would run:
  6680. @smallexample
  6681. $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
  6682. @end smallexample
  6683. @noindent
  6684. The program behaves the same way all UNIX utilities do: it will keep
  6685. quiet unless it has simething important to tell you (e.g. an error
  6686. condition or something). If you wish it to produce verbose output,
  6687. similar to that from the dry run mode, give it @option{-v} option:
  6688. @smallexample
  6689. @group
  6690. $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
  6691. Reading v.1.0 sparse map
  6692. Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
  6693. `/home/gray/sparsefile'
  6694. Done
  6695. @end group
  6696. @end smallexample
  6697. Additionally, if your @command{tar} implementation has extracted the
  6698. @dfn{extended headers} for this file, you can instruct @command{xstar}
  6699. to use them in order to verify the integrity of the expanded file.
  6700. The option @option{-x} sets the name of the extended header file to
  6701. use. Continuing our example:
  6702. @smallexample
  6703. @group
  6704. $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
  6705. /home/gray/GNUSparseFile.6058/sparsefile}
  6706. Reading extended header file
  6707. Found variable GNU.sparse.major = 1
  6708. Found variable GNU.sparse.minor = 0
  6709. Found variable GNU.sparse.name = sparsefile
  6710. Found variable GNU.sparse.realsize = 217481216
  6711. Reading v.1.0 sparse map
  6712. Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
  6713. `/home/gray/sparsefile'
  6714. Done
  6715. @end group
  6716. @end smallexample
  6717. An @dfn{extended header} is a special @command{tar} archive header
  6718. that precedes an archive member and contains a set of
  6719. @dfn{variables}, describing the member properties that cannot be
  6720. stored in the standard @code{ustar} header. While optional for
  6721. expanding sparse version 1.0 members, use of extended headers is
  6722. mandatory when expanding sparse members in older sparse formats: v.0.0
  6723. and v.0.1 (The sparse formats are described in detail in @pxref{Sparse
  6724. Formats}). So, for this format, the question is: how to obtain
  6725. extended headers from the archive?
  6726. If you use a @command{tar} implementation that does not support PAX
  6727. format, extended headers for each member will be extracted as a
  6728. separate file. If we represent the member name as
  6729. @file{@var{dir}/@var{name}}, then the extended header file will be
  6730. named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
  6731. @var{n} is an integer number.
  6732. Things become more difficult if your @command{tar} implementation
  6733. does support PAX headers, because in this case you will have to
  6734. manually extract the headers. We recommend the following algorithm:
  6735. @enumerate 1
  6736. @item
  6737. Consult the documentation for your @command{tar} implementation for an
  6738. option that will print @dfn{block numbers} along with the archive
  6739. listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
  6740. @command{star} has @option{-block-number}.
  6741. @item
  6742. Obtain the verbose listing using the @samp{block number} option, and
  6743. find the position of the sparse member in question and the member
  6744. immediately following it. For example, running @command{star} on our
  6745. archive we obtain:
  6746. @smallexample
  6747. @group
  6748. $ @kbd{star -t -v -block-number -f arc.tar}
  6749. @dots{}
  6750. star: Unknown extended header keyword 'GNU.sparse.size' ignored.
  6751. star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
  6752. star: Unknown extended header keyword 'GNU.sparse.name' ignored.
  6753. star: Unknown extended header keyword 'GNU.sparse.map' ignored.
  6754. block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
  6755. block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
  6756. @dots{}
  6757. @end group
  6758. @end smallexample
  6759. @noindent
  6760. (as usual, ignore the warnings about unknown keywords.)
  6761. @item
  6762. Let the size of the sparse member be @var{size}, its block number be
  6763. @var{Bs} and the block number of the next member be @var{Bn}.
  6764. Compute:
  6765. @smallexample
  6766. @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
  6767. @end smallexample
  6768. @noindent
  6769. This number gives the size of the extended header part in tar @dfn{blocks}.
  6770. In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
  6771. = 7}.
  6772. @item
  6773. Use @command{dd} to extract the headers:
  6774. @smallexample
  6775. @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
  6776. @end smallexample
  6777. @noindent
  6778. where @var{archive} is the archive name, @var{hname} is a name of the
  6779. file to store the extended header in, @var{Bs} and @var{N} are
  6780. computed in previous steps.
  6781. In our example, this command will be
  6782. @smallexample
  6783. $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
  6784. @end smallexample
  6785. @end enumerate
  6786. Finally, you can expand the condensed file, using the obtained header:
  6787. @smallexample
  6788. @group
  6789. $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
  6790. Reading extended header file
  6791. Found variable GNU.sparse.size = 217481216
  6792. Found variable GNU.sparse.numblocks = 208
  6793. Found variable GNU.sparse.name = sparsefile
  6794. Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
  6795. Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
  6796. Done
  6797. @end group
  6798. @end smallexample
  6799. @node Compression
  6800. @section Using Less Space through Compression
  6801. @menu
  6802. * gzip:: Creating and Reading Compressed Archives
  6803. * sparse:: Archiving Sparse Files
  6804. @end menu
  6805. @node gzip
  6806. @subsection Creating and Reading Compressed Archives
  6807. @cindex Compressed archives
  6808. @cindex Storing archives in compressed format
  6809. @GNUTAR{} is able to create and read compressed archives. It supports
  6810. @command{gzip} and @command{bzip2} compression programs. For backward
  6811. compatibilty, it also supports @command{compress} command, although
  6812. we strongly recommend against using it, since there is a patent
  6813. covering the algorithm it uses and you could be sued for patent
  6814. infringement merely by running @command{compress}! Besides, it is less
  6815. effective than @command{gzip} and @command{bzip2}.
  6816. Creating a compressed archive is simple: you just specify a
  6817. @dfn{compression option} along with the usual archive creation
  6818. commands. The compression option is @option{-z} (@option{--gzip}) to
  6819. create a @command{gzip} compressed archive, @option{-j}
  6820. (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
  6821. @option{-Z} (@option{--compress}) to use @command{compress} program.
  6822. For example:
  6823. @smallexample
  6824. $ @kbd{tar cfz archive.tar.gz .}
  6825. @end smallexample
  6826. Reading compressed archive is even simpler: you don't need to specify
  6827. any additional options as @GNUTAR{} recognizes its format
  6828. automatically. Thus, the following commands will list and extract the
  6829. archive created in previous example:
  6830. @smallexample
  6831. # List the compressed archive
  6832. $ @kbd{tar tf archive.tar.gz}
  6833. # Extract the compressed archive
  6834. $ @kbd{tar xf archive.tar.gz}
  6835. @end smallexample
  6836. The only case when you have to specify a decompression option while
  6837. reading the archive is when reading from a pipe or from a tape drive
  6838. that does not support random access. However, in this case @GNUTAR{}
  6839. will indicate which option you should use. For example:
  6840. @smallexample
  6841. $ @kbd{cat archive.tar.gz | tar tf -}
  6842. tar: Archive is compressed. Use -z option
  6843. tar: Error is not recoverable: exiting now
  6844. @end smallexample
  6845. If you see such diagnostics, just add the suggested option to the
  6846. invocation of @GNUTAR{}:
  6847. @smallexample
  6848. $ @kbd{cat archive.tar.gz | tar tfz -}
  6849. @end smallexample
  6850. Notice also, that there are several restrictions on operations on
  6851. compressed archives. First of all, compressed archives cannot be
  6852. modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
  6853. (@option{--delete}) members from them. Likewise, you cannot append
  6854. another @command{tar} archive to a compressed archive using
  6855. @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
  6856. compressed.
  6857. The following table summarizes compression options used by @GNUTAR{}.
  6858. @table @option
  6859. @opindex gzip
  6860. @opindex ungzip
  6861. @item -z
  6862. @itemx --gzip
  6863. @itemx --ungzip
  6864. Filter the archive through @command{gzip}.
  6865. You can use @option{--gzip} and @option{--gunzip} on physical devices
  6866. (tape drives, etc.) and remote files as well as on normal files; data
  6867. to or from such devices or remote files is reblocked by another copy
  6868. of the @command{tar} program to enforce the specified (or default) record
  6869. size. The default compression parameters are used; if you need to
  6870. override them, set @env{GZIP} environment variable, e.g.:
  6871. @smallexample
  6872. $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
  6873. @end smallexample
  6874. @noindent
  6875. Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
  6876. @command{gzip} explicitly:
  6877. @smallexample
  6878. $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
  6879. @end smallexample
  6880. @cindex corrupted archives
  6881. About corrupted compressed archives: @command{gzip}'ed files have no
  6882. redundancy, for maximum compression. The adaptive nature of the
  6883. compression scheme means that the compression tables are implicitly
  6884. spread all over the archive. If you lose a few blocks, the dynamic
  6885. construction of the compression tables becomes unsynchronized, and there
  6886. is little chance that you could recover later in the archive.
  6887. There are pending suggestions for having a per-volume or per-file
  6888. compression in @GNUTAR{}. This would allow for viewing the
  6889. contents without decompression, and for resynchronizing decompression at
  6890. every volume or file, in case of corrupted archives. Doing so, we might
  6891. lose some compressibility. But this would have make recovering easier.
  6892. So, there are pros and cons. We'll see!
  6893. @opindex bzip2
  6894. @item -j
  6895. @itemx --bzip2
  6896. Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
  6897. @opindex compress
  6898. @opindex uncompress
  6899. @item -Z
  6900. @itemx --compress
  6901. @itemx --uncompress
  6902. Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
  6903. The @acronym{GNU} Project recommends you not use
  6904. @command{compress}, because there is a patent covering the algorithm it
  6905. uses. You could be sued for patent infringement merely by running
  6906. @command{compress}.
  6907. @opindex use-compress-program
  6908. @item --use-compress-program=@var{prog}
  6909. Use external compression program @var{prog}. Use this option if you
  6910. have a compression program that @GNUTAR{} does not support. There
  6911. are two requirements to which @var{prog} should comply:
  6912. First, when called without options, it should read data from standard
  6913. input, compress it and output it on standard output.
  6914. Secondly, if called with @option{-d} argument, it should do exactly
  6915. the opposite, i.e., read the compressed data from the standard input
  6916. and produce uncompressed data on the standard output.
  6917. @end table
  6918. @cindex gpg, using with tar
  6919. @cindex gnupg, using with tar
  6920. @cindex Using encrypted archives
  6921. The @option{--use-compress-program} option, in particular, lets you
  6922. implement your own filters, not necessarily dealing with
  6923. compression/decomression. For example, suppose you wish to implement
  6924. PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
  6925. gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
  6926. Manual}). The following script does that:
  6927. @smallexample
  6928. @group
  6929. #! /bin/sh
  6930. case $1 in
  6931. -d) gpg --decrypt - | gzip -d -c;;
  6932. '') gzip -c | gpg -s ;;
  6933. *) echo "Unknown option $1">&2; exit 1;;
  6934. esac
  6935. @end group
  6936. @end smallexample
  6937. Suppose you name it @file{gpgz} and save it somewhere in your
  6938. @env{PATH}. Then the following command will create a commpressed
  6939. archive signed with your private key:
  6940. @smallexample
  6941. $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
  6942. @end smallexample
  6943. @noindent
  6944. Likewise, the following command will list its contents:
  6945. @smallexample
  6946. $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
  6947. @end smallexample
  6948. @ignore
  6949. The above is based on the following discussion:
  6950. I have one question, or maybe it's a suggestion if there isn't a way
  6951. to do it now. I would like to use @option{--gzip}, but I'd also like
  6952. the output to be fed through a program like @acronym{GNU}
  6953. @command{ecc} (actually, right now that's @samp{exactly} what I'd like
  6954. to use :-)), basically adding ECC protection on top of compression.
  6955. It seems as if this should be quite easy to do, but I can't work out
  6956. exactly how to go about it. Of course, I can pipe the standard output
  6957. of @command{tar} through @command{ecc}, but then I lose (though I
  6958. haven't started using it yet, I confess) the ability to have
  6959. @command{tar} use @command{rmt} for it's I/O (I think).
  6960. I think the most straightforward thing would be to let me specify a
  6961. general set of filters outboard of compression (preferably ordered,
  6962. so the order can be automatically reversed on input operations, and
  6963. with the options they require specifiable), but beggars shouldn't be
  6964. choosers and anything you decide on would be fine with me.
  6965. By the way, I like @command{ecc} but if (as the comments say) it can't
  6966. deal with loss of block sync, I'm tempted to throw some time at adding
  6967. that capability. Supposing I were to actually do such a thing and
  6968. get it (apparently) working, do you accept contributed changes to
  6969. utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
  6970. Isn't that exactly the role of the
  6971. @option{--use-compress-prog=@var{program}} option?
  6972. I never tried it myself, but I suspect you may want to write a
  6973. @var{prog} script or program able to filter stdin to stdout to
  6974. way you want. It should recognize the @option{-d} option, for when
  6975. extraction is needed rather than creation.
  6976. It has been reported that if one writes compressed data (through the
  6977. @option{--gzip} or @option{--compress} options) to a DLT and tries to use
  6978. the DLT compression mode, the data will actually get bigger and one will
  6979. end up with less space on the tape.
  6980. @end ignore
  6981. @node sparse
  6982. @subsection Archiving Sparse Files
  6983. @cindex Sparse Files
  6984. @UNREVISED
  6985. @table @option
  6986. @opindex sparse
  6987. @item -S
  6988. @itemx --sparse
  6989. Handle sparse files efficiently.
  6990. @end table
  6991. This option causes all files to be put in the archive to be tested for
  6992. sparseness, and handled specially if they are. The @option{--sparse}
  6993. (@option{-S}) option is useful when many @code{dbm} files, for example, are being
  6994. backed up. Using this option dramatically decreases the amount of
  6995. space needed to store such a file.
  6996. In later versions, this option may be removed, and the testing and
  6997. treatment of sparse files may be done automatically with any special
  6998. @acronym{GNU} options. For now, it is an option needing to be specified on
  6999. the command line with the creation or updating of an archive.
  7000. Files in the file system occasionally have @dfn{holes}. A @dfn{hole} in a file
  7001. is a section of the file's contents which was never written. The
  7002. contents of a hole read as all zeros. On many operating systems,
  7003. actual disk storage is not allocated for holes, but they are counted
  7004. in the length of the file. If you archive such a file, @command{tar}
  7005. could create an archive longer than the original. To have @command{tar}
  7006. attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
  7007. you use this option, then, for any file using less disk space than
  7008. would be expected from its length, @command{tar} searches the file for
  7009. consecutive stretches of zeros. It then records in the archive for
  7010. the file where the consecutive stretches of zeros are, and only
  7011. archives the ``real contents'' of the file. On extraction (using
  7012. @option{--sparse} is not needed on extraction) any such
  7013. files have holes created wherever the continuous stretches of zeros
  7014. were found. Thus, if you use @option{--sparse}, @command{tar} archives
  7015. won't take more space than the original.
  7016. A file is sparse if it contains blocks of zeros whose existence is
  7017. recorded, but that have no space allocated on disk. When you specify
  7018. the @option{--sparse} option in conjunction with the @option{--create}
  7019. (@option{-c}) operation, @command{tar} tests all files for sparseness
  7020. while archiving. If @command{tar} finds a file to be sparse, it uses a
  7021. sparse representation of the file in the archive. @xref{create}, for
  7022. more information about creating archives.
  7023. @option{--sparse} is useful when archiving files, such as dbm files,
  7024. likely to contain many nulls. This option dramatically
  7025. decreases the amount of space needed to store such an archive.
  7026. @quotation
  7027. @strong{Please Note:} Always use @option{--sparse} when performing file
  7028. system backups, to avoid archiving the expanded forms of files stored
  7029. sparsely in the system.
  7030. Even if your system has no sparse files currently, some may be
  7031. created in the future. If you use @option{--sparse} while making file
  7032. system backups as a matter of course, you can be assured the archive
  7033. will never take more space on the media than the files take on disk
  7034. (otherwise, archiving a disk filled with sparse files might take
  7035. hundreds of tapes). @xref{Incremental Dumps}.
  7036. @end quotation
  7037. @command{tar} ignores the @option{--sparse} option when reading an archive.
  7038. @table @option
  7039. @item --sparse
  7040. @itemx -S
  7041. Files stored sparsely in the file system are represented sparsely in
  7042. the archive. Use in conjunction with write operations.
  7043. @end table
  7044. However, users should be well aware that at archive creation time,
  7045. @GNUTAR{} still has to read whole disk file to
  7046. locate the @dfn{holes}, and so, even if sparse files use little space
  7047. on disk and in the archive, they may sometimes require inordinate
  7048. amount of time for reading and examining all-zero blocks of a file.
  7049. Although it works, it's painfully slow for a large (sparse) file, even
  7050. though the resulting tar archive may be small. (One user reports that
  7051. dumping a @file{core} file of over 400 megabytes, but with only about
  7052. 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
  7053. ELC, with full CPU utilization.)
  7054. This reading is required in all cases and is not related to the fact
  7055. the @option{--sparse} option is used or not, so by merely @emph{not}
  7056. using the option, you are not saving time@footnote{Well! We should say
  7057. the whole truth, here. When @option{--sparse} is selected while creating
  7058. an archive, the current @command{tar} algorithm requires sparse files to be
  7059. read twice, not once. We hope to develop a new archive format for saving
  7060. sparse files in which one pass will be sufficient.}.
  7061. Programs like @command{dump} do not have to read the entire file; by
  7062. examining the file system directly, they can determine in advance
  7063. exactly where the holes are and thus avoid reading through them. The
  7064. only data it need read are the actual allocated data blocks.
  7065. @GNUTAR{} uses a more portable and straightforward
  7066. archiving approach, it would be fairly difficult that it does
  7067. otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
  7068. 1990-12-10:
  7069. @quotation
  7070. What I did say is that you cannot tell the difference between a hole and an
  7071. equivalent number of nulls without reading raw blocks. @code{st_blocks} at
  7072. best tells you how many holes there are; it doesn't tell you @emph{where}.
  7073. Just as programs may, conceivably, care what @code{st_blocks} is (care
  7074. to name one that does?), they may also care where the holes are (I have
  7075. no examples of this one either, but it's equally imaginable).
  7076. I conclude from this that good archivers are not portable. One can
  7077. arguably conclude that if you want a portable program, you can in good
  7078. conscience restore files with as many holes as possible, since you can't
  7079. get it right.
  7080. @end quotation
  7081. @node Attributes
  7082. @section Handling File Attributes
  7083. @UNREVISED
  7084. When @command{tar} reads files, it updates their access times. To
  7085. avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
  7086. reset the access time retroactively or avoid changing it in the first
  7087. place.
  7088. Handling of file attributes
  7089. @table @option
  7090. @opindex atime-preserve
  7091. @item --atime-preserve
  7092. @itemx --atime-preserve=replace
  7093. @itemx --atime-preserve=system
  7094. Preserve the access times of files that are read. This works only for
  7095. files that you own, unless you have superuser privileges.
  7096. @option{--atime-preserve=replace} works on most systems, but it also
  7097. restores the data modification time and updates the status change
  7098. time. Hence it doesn't interact with incremental dumps nicely
  7099. (@pxref{Backups}), and it can set access or data modification times
  7100. incorrectly if other programs access the file while @command{tar} is
  7101. running.
  7102. @option{--atime-preserve=system} avoids changing the access time in
  7103. the first place, if the operating system supports this.
  7104. Unfortunately, this may or may not work on any given operating system
  7105. or file system. If @command{tar} knows for sure it won't work, it
  7106. complains right away.
  7107. Currently @option{--atime-preserve} with no operand defaults to
  7108. @option{--atime-preserve=replace}, but this is intended to change to
  7109. @option{--atime-preserve=system} when the latter is better-supported.
  7110. @opindex touch
  7111. @item -m
  7112. @itemx --touch
  7113. Do not extract data modification time.
  7114. When this option is used, @command{tar} leaves the data modification times
  7115. of the files it extracts as the times when the files were extracted,
  7116. instead of setting it to the times recorded in the archive.
  7117. This option is meaningless with @option{--list} (@option{-t}).
  7118. @opindex same-owner
  7119. @item --same-owner
  7120. Create extracted files with the same ownership they have in the
  7121. archive.
  7122. This is the default behavior for the superuser,
  7123. so this option is meaningful only for non-root users, when @command{tar}
  7124. is executed on those systems able to give files away. This is
  7125. considered as a security flaw by many people, at least because it
  7126. makes quite difficult to correctly account users for the disk space
  7127. they occupy. Also, the @code{suid} or @code{sgid} attributes of
  7128. files are easily and silently lost when files are given away.
  7129. When writing an archive, @command{tar} writes the user id and user name
  7130. separately. If it can't find a user name (because the user id is not
  7131. in @file{/etc/passwd}), then it does not write one. When restoring,
  7132. it tries to look the name (if one was written) up in
  7133. @file{/etc/passwd}. If it fails, then it uses the user id stored in
  7134. the archive instead.
  7135. @opindex no-same-owner
  7136. @item --no-same-owner
  7137. @itemx -o
  7138. Do not attempt to restore ownership when extracting. This is the
  7139. default behavior for ordinary users, so this option has an effect
  7140. only for the superuser.
  7141. @opindex numeric-owner
  7142. @item --numeric-owner
  7143. The @option{--numeric-owner} option allows (ANSI) archives to be written
  7144. without user/group name information or such information to be ignored
  7145. when extracting. It effectively disables the generation and/or use
  7146. of user/group name information. This option forces extraction using
  7147. the numeric ids from the archive, ignoring the names.
  7148. This is useful in certain circumstances, when restoring a backup from
  7149. an emergency floppy with different passwd/group files for example.
  7150. It is otherwise impossible to extract files with the right ownerships
  7151. if the password file in use during the extraction does not match the
  7152. one belonging to the file system(s) being extracted. This occurs,
  7153. for example, if you are restoring your files after a major crash and
  7154. had booted from an emergency floppy with no password file or put your
  7155. disk into another machine to do the restore.
  7156. The numeric ids are @emph{always} saved into @command{tar} archives.
  7157. The identifying names are added at create time when provided by the
  7158. system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
  7159. used when moving archives between a collection of machines using
  7160. a centralized management for attribution of numeric ids to users
  7161. and groups. This is often made through using the NIS capabilities.
  7162. When making a @command{tar} file for distribution to other sites, it
  7163. is sometimes cleaner to use a single owner for all files in the
  7164. distribution, and nicer to specify the write permission bits of the
  7165. files as stored in the archive independently of their actual value on
  7166. the file system. The way to prepare a clean distribution is usually
  7167. to have some Makefile rule creating a directory, copying all needed
  7168. files in that directory, then setting ownership and permissions as
  7169. wanted (there are a lot of possible schemes), and only then making a
  7170. @command{tar} archive out of this directory, before cleaning
  7171. everything out. Of course, we could add a lot of options to
  7172. @GNUTAR{} for fine tuning permissions and ownership.
  7173. This is not the good way, I think. @GNUTAR{} is
  7174. already crowded with options and moreover, the approach just explained
  7175. gives you a great deal of control already.
  7176. @xopindex{same-permissions, short description}
  7177. @xopindex{preserve-permissions, short description}
  7178. @item -p
  7179. @itemx --same-permissions
  7180. @itemx --preserve-permissions
  7181. Extract all protection information.
  7182. This option causes @command{tar} to set the modes (access permissions) of
  7183. extracted files exactly as recorded in the archive. If this option
  7184. is not used, the current @code{umask} setting limits the permissions
  7185. on extracted files. This option is by default enabled when
  7186. @command{tar} is executed by a superuser.
  7187. This option is meaningless with @option{--list} (@option{-t}).
  7188. @opindex preserve
  7189. @item --preserve
  7190. Same as both @option{--same-permissions} and @option{--same-order}.
  7191. The @option{--preserve} option has no equivalent short option name.
  7192. It is equivalent to @option{--same-permissions} plus @option{--same-order}.
  7193. @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
  7194. Neither do I. --Sergey}
  7195. @end table
  7196. @node cpio
  7197. @section Comparison of @command{tar} and @command{cpio}
  7198. @UNREVISED
  7199. @FIXME{Reorganize the following material}
  7200. The @command{cpio} archive formats, like @command{tar}, do have maximum
  7201. pathname lengths. The binary and old ASCII formats have a max path
  7202. length of 256, and the new ASCII and CRC ASCII formats have a max
  7203. path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
  7204. with arbitrary pathname lengths, but other @command{cpio} implementations
  7205. may crash unexplainedly trying to read them.
  7206. @command{tar} handles symbolic links in the form in which it comes in BSD;
  7207. @command{cpio} doesn't handle symbolic links in the form in which it comes
  7208. in System V prior to SVR4, and some vendors may have added symlinks
  7209. to their system without enhancing @command{cpio} to know about them.
  7210. Others may have enhanced it in a way other than the way I did it
  7211. at Sun, and which was adopted by AT&T (and which is, I think, also
  7212. present in the @command{cpio} that Berkeley picked up from AT&T and put
  7213. into a later BSD release---I think I gave them my changes).
  7214. (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
  7215. can handle @command{tar} format input, and write it on output, and it
  7216. probably handles symbolic links. They may not have bothered doing
  7217. anything to enhance @command{tar} as a result.)
  7218. @command{cpio} handles special files; traditional @command{tar} doesn't.
  7219. @command{tar} comes with V7, System III, System V, and BSD source;
  7220. @command{cpio} comes only with System III, System V, and later BSD
  7221. (4.3-tahoe and later).
  7222. @command{tar}'s way of handling multiple hard links to a file can handle
  7223. file systems that support 32-bit inumbers (e.g., the BSD file system);
  7224. @command{cpio}s way requires you to play some games (in its "binary"
  7225. format, i-numbers are only 16 bits, and in its "portable ASCII" format,
  7226. they're 18 bits---it would have to play games with the "file system ID"
  7227. field of the header to make sure that the file system ID/i-number pairs
  7228. of different files were always different), and I don't know which
  7229. @command{cpio}s, if any, play those games. Those that don't might get
  7230. confused and think two files are the same file when they're not, and
  7231. make hard links between them.
  7232. @command{tar}s way of handling multiple hard links to a file places only
  7233. one copy of the link on the tape, but the name attached to that copy
  7234. is the @emph{only} one you can use to retrieve the file; @command{cpio}s
  7235. way puts one copy for every link, but you can retrieve it using any
  7236. of the names.
  7237. @quotation
  7238. What type of check sum (if any) is used, and how is this calculated.
  7239. @end quotation
  7240. See the attached manual pages for @command{tar} and @command{cpio} format.
  7241. @command{tar} uses a checksum which is the sum of all the bytes in the
  7242. @command{tar} header for a file; @command{cpio} uses no checksum.
  7243. @quotation
  7244. If anyone knows why @command{cpio} was made when @command{tar} was present
  7245. at the unix scene,
  7246. @end quotation
  7247. It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
  7248. generally-available version of UNIX had @command{tar} at the time. I don't
  7249. know whether any version that was generally available @emph{within AT&T}
  7250. had @command{tar}, or, if so, whether the people within AT&T who did
  7251. @command{cpio} knew about it.
  7252. On restore, if there is a corruption on a tape @command{tar} will stop at
  7253. that point, while @command{cpio} will skip over it and try to restore the
  7254. rest of the files.
  7255. The main difference is just in the command syntax and header format.
  7256. @command{tar} is a little more tape-oriented in that everything is blocked
  7257. to start on a record boundary.
  7258. @quotation
  7259. Is there any differences between the ability to recover crashed
  7260. archives between the two of them. (Is there any chance of recovering
  7261. crashed archives at all.)
  7262. @end quotation
  7263. Theoretically it should be easier under @command{tar} since the blocking
  7264. lets you find a header with some variation of @samp{dd skip=@var{nn}}.
  7265. However, modern @command{cpio}'s and variations have an option to just
  7266. search for the next file header after an error with a reasonable chance
  7267. of resyncing. However, lots of tape driver software won't allow you to
  7268. continue past a media error which should be the only reason for getting
  7269. out of sync unless a file changed sizes while you were writing the
  7270. archive.
  7271. @quotation
  7272. If anyone knows why @command{cpio} was made when @command{tar} was present
  7273. at the unix scene, please tell me about this too.
  7274. @end quotation
  7275. Probably because it is more media efficient (by not blocking everything
  7276. and using only the space needed for the headers where @command{tar}
  7277. always uses 512 bytes per file header) and it knows how to archive
  7278. special files.
  7279. You might want to look at the freely available alternatives. The
  7280. major ones are @command{afio}, @GNUTAR{}, and
  7281. @command{pax}, each of which have their own extensions with some
  7282. backwards compatibility.
  7283. Sparse files were @command{tar}red as sparse files (which you can
  7284. easily test, because the resulting archive gets smaller, and
  7285. @acronym{GNU} @command{cpio} can no longer read it).
  7286. @node Media
  7287. @chapter Tapes and Other Archive Media
  7288. @UNREVISED
  7289. A few special cases about tape handling warrant more detailed
  7290. description. These special cases are discussed below.
  7291. Many complexities surround the use of @command{tar} on tape drives. Since
  7292. the creation and manipulation of archives located on magnetic tape was
  7293. the original purpose of @command{tar}, it contains many features making
  7294. such manipulation easier.
  7295. Archives are usually written on dismountable media---tape cartridges,
  7296. mag tapes, or floppy disks.
  7297. The amount of data a tape or disk holds depends not only on its size,
  7298. but also on how it is formatted. A 2400 foot long reel of mag tape
  7299. holds 40 megabytes of data when formatted at 1600 bits per inch. The
  7300. physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
  7301. Magnetic media are re-usable---once the archive on a tape is no longer
  7302. needed, the archive can be erased and the tape or disk used over.
  7303. Media quality does deteriorate with use, however. Most tapes or disks
  7304. should be discarded when they begin to produce data errors. EXABYTE
  7305. tape cartridges should be discarded when they generate an @dfn{error
  7306. count} (number of non-usable bits) of more than 10k.
  7307. Magnetic media are written and erased using magnetic fields, and
  7308. should be protected from such fields to avoid damage to stored data.
  7309. Sticking a floppy disk to a filing cabinet using a magnet is probably
  7310. not a good idea.
  7311. @menu
  7312. * Device:: Device selection and switching
  7313. * Remote Tape Server::
  7314. * Common Problems and Solutions::
  7315. * Blocking:: Blocking
  7316. * Many:: Many archives on one tape
  7317. * Using Multiple Tapes:: Using Multiple Tapes
  7318. * label:: Including a Label in the Archive
  7319. * verify::
  7320. * Write Protection::
  7321. @end menu
  7322. @node Device
  7323. @section Device Selection and Switching
  7324. @UNREVISED
  7325. @table @option
  7326. @item -f [@var{hostname}:]@var{file}
  7327. @itemx --file=[@var{hostname}:]@var{file}
  7328. Use archive file or device @var{file} on @var{hostname}.
  7329. @end table
  7330. This option is used to specify the file name of the archive @command{tar}
  7331. works on.
  7332. If the file name is @samp{-}, @command{tar} reads the archive from standard
  7333. input (when listing or extracting), or writes it to standard output
  7334. (when creating). If the @samp{-} file name is given when updating an
  7335. archive, @command{tar} will read the original archive from its standard
  7336. input, and will write the entire new archive to its standard output.
  7337. If the file name contains a @samp{:}, it is interpreted as
  7338. @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
  7339. sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
  7340. either case, @command{tar} will invoke the command @command{rsh} (or
  7341. @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
  7342. machine. If you give an alternate login name, it will be given to the
  7343. @command{rsh}.
  7344. Naturally, the remote machine must have an executable
  7345. @command{/usr/libexec/rmt}. This program is free software from the
  7346. University of California, and a copy of the source code can be found
  7347. with the sources for @command{tar}; it's compiled and installed by default.
  7348. The exact path to this utility is determined when configuring the package.
  7349. It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
  7350. your installation prefix. This location may also be overridden at
  7351. runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
  7352. ---rmt-command}, for detailed description of this option. @xref{Remote
  7353. Tape Server}, for the description of @command{rmt} command).
  7354. If this option is not given, but the environment variable @env{TAPE}
  7355. is set, its value is used; otherwise, old versions of @command{tar}
  7356. used a default archive name (which was picked when @command{tar} was
  7357. compiled). The default is normally set up to be the @dfn{first} tape
  7358. drive or other transportable I/O medium on the system.
  7359. Starting with version 1.11.5, @GNUTAR{} uses
  7360. standard input and standard output as the default device, and I will
  7361. not try anymore supporting automatic device detection at installation
  7362. time. This was failing really in too many cases, it was hopeless.
  7363. This is now completely left to the installer to override standard
  7364. input and standard output for default device, if this seems
  7365. preferable. Further, I think @emph{most} actual usages of
  7366. @command{tar} are done with pipes or disks, not really tapes,
  7367. cartridges or diskettes.
  7368. Some users think that using standard input and output is running
  7369. after trouble. This could lead to a nasty surprise on your screen if
  7370. you forget to specify an output file name---especially if you are going
  7371. through a network or terminal server capable of buffering large amounts
  7372. of output. We had so many bug reports in that area of configuring
  7373. default tapes automatically, and so many contradicting requests, that
  7374. we finally consider the problem to be portably intractable. We could
  7375. of course use something like @samp{/dev/tape} as a default, but this
  7376. is @emph{also} running after various kind of trouble, going from hung
  7377. processes to accidental destruction of real tapes. After having seen
  7378. all this mess, using standard input and output as a default really
  7379. sounds like the only clean choice left, and a very useful one too.
  7380. @GNUTAR{} reads and writes archive in records, I
  7381. suspect this is the main reason why block devices are preferred over
  7382. character devices. Most probably, block devices are more efficient
  7383. too. The installer could also check for @samp{DEFTAPE} in
  7384. @file{<sys/mtio.h>}.
  7385. @table @option
  7386. @xopindex{force-local, short description}
  7387. @item --force-local
  7388. Archive file is local even if it contains a colon.
  7389. @opindex rsh-command
  7390. @item --rsh-command=@var{command}
  7391. Use remote @var{command} instead of @command{rsh}. This option exists
  7392. so that people who use something other than the standard @command{rsh}
  7393. (e.g., a Kerberized @command{rsh}) can access a remote device.
  7394. When this command is not used, the shell command found when
  7395. the @command{tar} program was installed is used instead. This is
  7396. the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
  7397. @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
  7398. The installer may have overridden this by defining the environment
  7399. variable @env{RSH} @emph{at installation time}.
  7400. @item -[0-7][lmh]
  7401. Specify drive and density.
  7402. @xopindex{multi-volume, short description}
  7403. @item -M
  7404. @itemx --multi-volume
  7405. Create/list/extract multi-volume archive.
  7406. This option causes @command{tar} to write a @dfn{multi-volume} archive---one
  7407. that may be larger than will fit on the medium used to hold it.
  7408. @xref{Multi-Volume Archives}.
  7409. @xopindex{tape-length, short description}
  7410. @item -L @var{num}
  7411. @itemx --tape-length=@var{num}
  7412. Change tape after writing @var{num} x 1024 bytes.
  7413. This option might be useful when your tape drivers do not properly
  7414. detect end of physical tapes. By being slightly conservative on the
  7415. maximum tape length, you might avoid the problem entirely.
  7416. @xopindex{info-script, short description}
  7417. @xopindex{new-volume-script, short description}
  7418. @item -F @var{file}
  7419. @itemx --info-script=@var{file}
  7420. @itemx --new-volume-script=@var{file}
  7421. Execute @file{file} at end of each tape. This implies
  7422. @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
  7423. description of this option.
  7424. @end table
  7425. @node Remote Tape Server
  7426. @section The Remote Tape Server
  7427. @cindex remote tape drive
  7428. @pindex rmt
  7429. In order to access the tape drive on a remote machine, @command{tar}
  7430. uses the remote tape server written at the University of California at
  7431. Berkeley. The remote tape server must be installed as
  7432. @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
  7433. want to use. @command{tar} calls @command{rmt} by running an
  7434. @command{rsh} or @command{remsh} to the remote machine, optionally
  7435. using a different login name if one is supplied.
  7436. A copy of the source for the remote tape server is provided. It is
  7437. Copyright @copyright{} 1983 by the Regents of the University of
  7438. California, but can be freely distributed. It is compiled and
  7439. installed by default.
  7440. @cindex absolute file names
  7441. Unless you use the @option{--absolute-names} (@option{-P}) option,
  7442. @GNUTAR{} will not allow you to create an archive that contains
  7443. absolute file names (a file name beginning with @samp{/}.) If you try,
  7444. @command{tar} will automatically remove the leading @samp{/} from the
  7445. file names it stores in the archive. It will also type a warning
  7446. message telling you what it is doing.
  7447. When reading an archive that was created with a different
  7448. @command{tar} program, @GNUTAR{} automatically
  7449. extracts entries in the archive which have absolute file names as if
  7450. the file names were not absolute. This is an important feature. A
  7451. visitor here once gave a @command{tar} tape to an operator to restore;
  7452. the operator used Sun @command{tar} instead of @GNUTAR{},
  7453. and the result was that it replaced large portions of
  7454. our @file{/bin} and friends with versions from the tape; needless to
  7455. say, we were unhappy about having to recover the file system from
  7456. backup tapes.
  7457. For example, if the archive contained a file @file{/usr/bin/computoy},
  7458. @GNUTAR{} would extract the file to @file{usr/bin/computoy},
  7459. relative to the current directory. If you want to extract the files in
  7460. an archive to the same absolute names that they had when the archive
  7461. was created, you should do a @samp{cd /} before extracting the files
  7462. from the archive, or you should either use the @option{--absolute-names}
  7463. option, or use the command @samp{tar -C / @dots{}}.
  7464. @cindex Ultrix 3.1 and write failure
  7465. Some versions of Unix (Ultrix 3.1 is known to have this problem),
  7466. can claim that a short write near the end of a tape succeeded,
  7467. when it actually failed. This will result in the -M option not
  7468. working correctly. The best workaround at the moment is to use a
  7469. significantly larger blocking factor than the default 20.
  7470. In order to update an archive, @command{tar} must be able to backspace the
  7471. archive in order to reread or rewrite a record that was just read (or
  7472. written). This is currently possible only on two kinds of files: normal
  7473. disk files (or any other file that can be backspaced with @samp{lseek}),
  7474. and industry-standard 9-track magnetic tape (or any other kind of tape
  7475. that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
  7476. This means that the @option{--append}, @option{--concatenate}, and
  7477. @option{--delete} commands will not work on any other kind of file.
  7478. Some media simply cannot be backspaced, which means these commands and
  7479. options will never be able to work on them. These non-backspacing
  7480. media include pipes and cartridge tape drives.
  7481. Some other media can be backspaced, and @command{tar} will work on them
  7482. once @command{tar} is modified to do so.
  7483. Archives created with the @option{--multi-volume}, @option{--label}, and
  7484. @option{--incremental} (@option{-G}) options may not be readable by other version
  7485. of @command{tar}. In particular, restoring a file that was split over
  7486. a volume boundary will require some careful work with @command{dd}, if
  7487. it can be done at all. Other versions of @command{tar} may also create
  7488. an empty file whose name is that of the volume header. Some versions
  7489. of @command{tar} may create normal files instead of directories archived
  7490. with the @option{--incremental} (@option{-G}) option.
  7491. @node Common Problems and Solutions
  7492. @section Some Common Problems and their Solutions
  7493. @ifclear PUBLISH
  7494. @format
  7495. errors from system:
  7496. permission denied
  7497. no such file or directory
  7498. not owner
  7499. errors from @command{tar}:
  7500. directory checksum error
  7501. header format error
  7502. errors from media/system:
  7503. i/o error
  7504. device busy
  7505. @end format
  7506. @end ifclear
  7507. @node Blocking
  7508. @section Blocking
  7509. @UNREVISED
  7510. @dfn{Block} and @dfn{record} terminology is rather confused, and it
  7511. is also confusing to the expert reader. On the other hand, readers
  7512. who are new to the field have a fresh mind, and they may safely skip
  7513. the next two paragraphs, as the remainder of this manual uses those
  7514. two terms in a quite consistent way.
  7515. John Gilmore, the writer of the public domain @command{tar} from which
  7516. @GNUTAR{} was originally derived, wrote (June 1995):
  7517. @quotation
  7518. The nomenclature of tape drives comes from IBM, where I believe
  7519. they were invented for the IBM 650 or so. On IBM mainframes, what
  7520. is recorded on tape are tape blocks. The logical organization of
  7521. data is into records. There are various ways of putting records into
  7522. blocks, including @code{F} (fixed sized records), @code{V} (variable
  7523. sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
  7524. to a block), @code{VB} (variable size records, @var{n} to a block),
  7525. @code{VSB} (variable spanned blocked: variable sized records that can
  7526. occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
  7527. parameter specified this to the operating system.
  7528. The Unix man page on @command{tar} was totally confused about this.
  7529. When I wrote @code{PD TAR}, I used the historically correct terminology
  7530. (@command{tar} writes data records, which are grouped into blocks).
  7531. It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
  7532. here), and now Fran@,{c}ois has migrated that terminology back
  7533. into the source code too.
  7534. @end quotation
  7535. The term @dfn{physical block} means the basic transfer chunk from or
  7536. to a device, after which reading or writing may stop without anything
  7537. being lost. In this manual, the term @dfn{block} usually refers to
  7538. a disk physical block, @emph{assuming} that each disk block is 512
  7539. bytes in length. It is true that some disk devices have different
  7540. physical blocks, but @command{tar} ignore these differences in its own
  7541. format, which is meant to be portable, so a @command{tar} block is always
  7542. 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
  7543. The term @dfn{logical block} often represents the basic chunk of
  7544. allocation of many disk blocks as a single entity, which the operating
  7545. system treats somewhat atomically; this concept is only barely used
  7546. in @GNUTAR{}.
  7547. The term @dfn{physical record} is another way to speak of a physical
  7548. block, those two terms are somewhat interchangeable. In this manual,
  7549. the term @dfn{record} usually refers to a tape physical block,
  7550. @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
  7551. It is true that archives may be put on disk or used with pipes,
  7552. but nevertheless, @command{tar} tries to read and write the archive one
  7553. @dfn{record} at a time, whatever the medium in use. One record is made
  7554. up of an integral number of blocks, and this operation of putting many
  7555. disk blocks into a single tape block is called @dfn{reblocking}, or
  7556. more simply, @dfn{blocking}. The term @dfn{logical record} refers to
  7557. the logical organization of many characters into something meaningful
  7558. to the application. The term @dfn{unit record} describes a small set
  7559. of characters which are transmitted whole to or by the application,
  7560. and often refers to a line of text. Those two last terms are unrelated
  7561. to what we call a @dfn{record} in @GNUTAR{}.
  7562. When writing to tapes, @command{tar} writes the contents of the archive
  7563. in chunks known as @dfn{records}. To change the default blocking
  7564. factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
  7565. @var{512-size}}) option. Each record will then be composed of
  7566. @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
  7567. @xref{Standard}.) Each file written to the archive uses at least one
  7568. full record. As a result, using a larger record size can result in
  7569. more wasted space for small files. On the other hand, a larger record
  7570. size can often be read and written much more efficiently.
  7571. Further complicating the problem is that some tape drives ignore the
  7572. blocking entirely. For these, a larger record size can still improve
  7573. performance (because the software layers above the tape drive still
  7574. honor the blocking), but not as dramatically as on tape drives that
  7575. honor blocking.
  7576. When reading an archive, @command{tar} can usually figure out the
  7577. record size on itself. When this is the case, and a non-standard
  7578. record size was used when the archive was created, @command{tar} will
  7579. print a message about a non-standard blocking factor, and then operate
  7580. normally. On some tape devices, however, @command{tar} cannot figure
  7581. out the record size itself. On most of those, you can specify a
  7582. blocking factor (with @option{--blocking-factor}) larger than the
  7583. actual blocking factor, and then use the @option{--read-full-records}
  7584. (@option{-B}) option. (If you specify a blocking factor with
  7585. @option{--blocking-factor} and don't use the
  7586. @option{--read-full-records} option, then @command{tar} will not
  7587. attempt to figure out the recording size itself.) On some devices,
  7588. you must always specify the record size exactly with
  7589. @option{--blocking-factor} when reading, because @command{tar} cannot
  7590. figure it out. In any case, use @option{--list} (@option{-t}) before
  7591. doing any extractions to see whether @command{tar} is reading the archive
  7592. correctly.
  7593. @command{tar} blocks are all fixed size (512 bytes), and its scheme for
  7594. putting them into records is to put a whole number of them (one or
  7595. more) into each record. @command{tar} records are all the same size;
  7596. at the end of the file there's a block containing all zeros, which
  7597. is how you tell that the remainder of the last record(s) are garbage.
  7598. In a standard @command{tar} file (no options), the block size is 512
  7599. and the record size is 10240, for a blocking factor of 20. What the
  7600. @option{--blocking-factor} option does is sets the blocking factor,
  7601. changing the record size while leaving the block size at 512 bytes.
  7602. 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
  7603. most tape drives these days prefer much bigger records in order to
  7604. stream and not waste tape. When writing tapes for myself, some tend
  7605. to use a factor of the order of 2048, say, giving a record size of
  7606. around one megabyte.
  7607. If you use a blocking factor larger than 20, older @command{tar}
  7608. programs might not be able to read the archive, so we recommend this
  7609. as a limit to use in practice. @GNUTAR{}, however,
  7610. will support arbitrarily large record sizes, limited only by the
  7611. amount of virtual memory or the physical characteristics of the tape
  7612. device.
  7613. @menu
  7614. * Format Variations:: Format Variations
  7615. * Blocking Factor:: The Blocking Factor of an Archive
  7616. @end menu
  7617. @node Format Variations
  7618. @subsection Format Variations
  7619. @cindex Format Parameters
  7620. @cindex Format Options
  7621. @cindex Options, archive format specifying
  7622. @cindex Options, format specifying
  7623. @UNREVISED
  7624. Format parameters specify how an archive is written on the archive
  7625. media. The best choice of format parameters will vary depending on
  7626. the type and number of files being archived, and on the media used to
  7627. store the archive.
  7628. To specify format parameters when accessing or creating an archive,
  7629. you can use the options described in the following sections.
  7630. If you do not specify any format parameters, @command{tar} uses
  7631. default parameters. You cannot modify a compressed archive.
  7632. If you create an archive with the @option{--blocking-factor} option
  7633. specified (@pxref{Blocking Factor}), you must specify that
  7634. blocking-factor when operating on the archive. @xref{Formats}, for other
  7635. examples of format parameter considerations.
  7636. @node Blocking Factor
  7637. @subsection The Blocking Factor of an Archive
  7638. @cindex Blocking Factor
  7639. @cindex Record Size
  7640. @cindex Number of blocks per record
  7641. @cindex Number of bytes per record
  7642. @cindex Bytes per record
  7643. @cindex Blocks per record
  7644. @UNREVISED
  7645. @opindex blocking-factor
  7646. The data in an archive is grouped into blocks, which are 512 bytes.
  7647. Blocks are read and written in whole number multiples called
  7648. @dfn{records}. The number of blocks in a record (i.e. the size of a
  7649. record in units of 512 bytes) is called the @dfn{blocking factor}.
  7650. The @option{--blocking-factor=@var{512-size}} (@option{-b
  7651. @var{512-size}}) option specifies the blocking factor of an archive.
  7652. The default blocking factor is typically 20 (i.e., 10240 bytes), but
  7653. can be specified at installation. To find out the blocking factor of
  7654. an existing archive, use @samp{tar --list --file=@var{archive-name}}.
  7655. This may not work on some devices.
  7656. Records are separated by gaps, which waste space on the archive media.
  7657. If you are archiving on magnetic tape, using a larger blocking factor
  7658. (and therefore larger records) provides faster throughput and allows you
  7659. to fit more data on a tape (because there are fewer gaps). If you are
  7660. archiving on cartridge, a very large blocking factor (say 126 or more)
  7661. greatly increases performance. A smaller blocking factor, on the other
  7662. hand, may be useful when archiving small files, to avoid archiving lots
  7663. of nulls as @command{tar} fills out the archive to the end of the record.
  7664. In general, the ideal record size depends on the size of the
  7665. inter-record gaps on the tape you are using, and the average size of the
  7666. files you are archiving. @xref{create}, for information on
  7667. writing archives.
  7668. @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
  7669. Archives with blocking factors larger than 20 cannot be read
  7670. by very old versions of @command{tar}, or by some newer versions
  7671. of @command{tar} running on old machines with small address spaces.
  7672. With @GNUTAR{}, the blocking factor of an archive is limited
  7673. only by the maximum record size of the device containing the archive,
  7674. or by the amount of available virtual memory.
  7675. Also, on some systems, not using adequate blocking factors, as sometimes
  7676. imposed by the device drivers, may yield unexpected diagnostics. For
  7677. example, this has been reported:
  7678. @smallexample
  7679. Cannot write to /dev/dlt: Invalid argument
  7680. @end smallexample
  7681. @noindent
  7682. In such cases, it sometimes happen that the @command{tar} bundled by
  7683. the system is aware of block size idiosyncrasies, while @GNUTAR{}
  7684. requires an explicit specification for the block size,
  7685. which it cannot guess. This yields some people to consider
  7686. @GNUTAR{} is misbehaving, because by comparison,
  7687. @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
  7688. for example, might resolve the problem.
  7689. If you use a non-default blocking factor when you create an archive, you
  7690. must specify the same blocking factor when you modify that archive. Some
  7691. archive devices will also require you to specify the blocking factor when
  7692. reading that archive, however this is not typically the case. Usually, you
  7693. can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
  7694. reports a non-default record size and then lists the archive members as
  7695. it would normally. To extract files from an archive with a non-standard
  7696. blocking factor (particularly if you're not sure what the blocking factor
  7697. is), you can usually use the @option{--read-full-records} (@option{-B}) option while
  7698. specifying a blocking factor larger then the blocking factor of the archive
  7699. (i.e. @samp{tar --extract --read-full-records --blocking-factor=300}.
  7700. @xref{list}, for more information on the @option{--list} (@option{-t})
  7701. operation. @xref{Reading}, for a more detailed explanation of that option.
  7702. @table @option
  7703. @item --blocking-factor=@var{number}
  7704. @itemx -b @var{number}
  7705. Specifies the blocking factor of an archive. Can be used with any
  7706. operation, but is usually not necessary with @option{--list} (@option{-t}).
  7707. @end table
  7708. Device blocking
  7709. @table @option
  7710. @item -b @var{blocks}
  7711. @itemx --blocking-factor=@var{blocks}
  7712. Set record size to @math{@var{blocks} * 512} bytes.
  7713. This option is used to specify a @dfn{blocking factor} for the archive.
  7714. When reading or writing the archive, @command{tar}, will do reads and writes
  7715. of the archive in records of @math{@var{block}*512} bytes. This is true
  7716. even when the archive is compressed. Some devices requires that all
  7717. write operations be a multiple of a certain size, and so, @command{tar}
  7718. pads the archive out to the next record boundary.
  7719. The default blocking factor is set when @command{tar} is compiled, and is
  7720. typically 20. Blocking factors larger than 20 cannot be read by very
  7721. old versions of @command{tar}, or by some newer versions of @command{tar}
  7722. running on old machines with small address spaces.
  7723. With a magnetic tape, larger records give faster throughput and fit
  7724. more data on a tape (because there are fewer inter-record gaps).
  7725. If the archive is in a disk file or a pipe, you may want to specify
  7726. a smaller blocking factor, since a large one will result in a large
  7727. number of null bytes at the end of the archive.
  7728. When writing cartridge or other streaming tapes, a much larger
  7729. blocking factor (say 126 or more) will greatly increase performance.
  7730. However, you must specify the same blocking factor when reading or
  7731. updating the archive.
  7732. Apparently, Exabyte drives have a physical block size of 8K bytes.
  7733. If we choose our blocksize as a multiple of 8k bytes, then the problem
  7734. seems to disappear. Id est, we are using block size of 112 right
  7735. now, and we haven't had the problem since we switched@dots{}
  7736. With @GNUTAR{} the blocking factor is limited only
  7737. by the maximum record size of the device containing the archive, or by
  7738. the amount of available virtual memory.
  7739. However, deblocking or reblocking is virtually avoided in a special
  7740. case which often occurs in practice, but which requires all the
  7741. following conditions to be simultaneously true:
  7742. @itemize @bullet
  7743. @item
  7744. the archive is subject to a compression option,
  7745. @item
  7746. the archive is not handled through standard input or output, nor
  7747. redirected nor piped,
  7748. @item
  7749. the archive is directly handled to a local disk, instead of any special
  7750. device,
  7751. @item
  7752. @option{--blocking-factor} is not explicitly specified on the @command{tar}
  7753. invocation.
  7754. @end itemize
  7755. If the output goes directly to a local disk, and not through
  7756. stdout, then the last write is not extended to a full record size.
  7757. Otherwise, reblocking occurs. Here are a few other remarks on this
  7758. topic:
  7759. @itemize @bullet
  7760. @item
  7761. @command{gzip} will complain about trailing garbage if asked to
  7762. uncompress a compressed archive on tape, there is an option to turn
  7763. the message off, but it breaks the regularity of simply having to use
  7764. @samp{@var{prog} -d} for decompression. It would be nice if gzip was
  7765. silently ignoring any number of trailing zeros. I'll ask Jean-loup
  7766. Gailly, by sending a copy of this message to him.
  7767. @item
  7768. @command{compress} does not show this problem, but as Jean-loup pointed
  7769. out to Michael, @samp{compress -d} silently adds garbage after
  7770. the result of decompression, which tar ignores because it already
  7771. recognized its end-of-file indicator. So this bug may be safely
  7772. ignored.
  7773. @item
  7774. @samp{gzip -d -q} will be silent about the trailing zeros indeed,
  7775. but will still return an exit status of 2 which tar reports in turn.
  7776. @command{tar} might ignore the exit status returned, but I hate doing
  7777. that, as it weakens the protection @command{tar} offers users against
  7778. other possible problems at decompression time. If @command{gzip} was
  7779. silently skipping trailing zeros @emph{and} also avoiding setting the
  7780. exit status in this innocuous case, that would solve this situation.
  7781. @item
  7782. @command{tar} should become more solid at not stopping to read a pipe at
  7783. the first null block encountered. This inelegantly breaks the pipe.
  7784. @command{tar} should rather drain the pipe out before exiting itself.
  7785. @end itemize
  7786. @xopindex{ignore-zeros, short description}
  7787. @item -i
  7788. @itemx --ignore-zeros
  7789. Ignore blocks of zeros in archive (means EOF).
  7790. The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
  7791. of zeros in the archive. Normally a block of zeros indicates the
  7792. end of the archive, but when reading a damaged archive, or one which
  7793. was created by concatenating several archives together, this option
  7794. allows @command{tar} to read the entire archive. This option is not on
  7795. by default because many versions of @command{tar} write garbage after
  7796. the zeroed blocks.
  7797. Note that this option causes @command{tar} to read to the end of the
  7798. archive file, which may sometimes avoid problems when multiple files
  7799. are stored on a single physical tape.
  7800. @xopindex{read-full-records, short description}
  7801. @item -B
  7802. @itemx --read-full-records
  7803. Reblock as we read (for reading 4.2BSD pipes).
  7804. If @option{--read-full-records} is used, @command{tar}
  7805. will not panic if an attempt to read a record from the archive does
  7806. not return a full record. Instead, @command{tar} will keep reading
  7807. until it has obtained a full
  7808. record.
  7809. This option is turned on by default when @command{tar} is reading
  7810. an archive from standard input, or from a remote machine. This is
  7811. because on BSD Unix systems, a read of a pipe will return however
  7812. much happens to be in the pipe, even if it is less than @command{tar}
  7813. requested. If this option was not used, @command{tar} would fail as
  7814. soon as it read an incomplete record from the pipe.
  7815. This option is also useful with the commands for updating an archive.
  7816. @end table
  7817. Tape blocking
  7818. @FIXME{Appropriate options should be moved here from elsewhere.}
  7819. @cindex blocking factor
  7820. @cindex tape blocking
  7821. When handling various tapes or cartridges, you have to take care of
  7822. selecting a proper blocking, that is, the number of disk blocks you
  7823. put together as a single tape block on the tape, without intervening
  7824. tape gaps. A @dfn{tape gap} is a small landing area on the tape
  7825. with no information on it, used for decelerating the tape to a
  7826. full stop, and for later regaining the reading or writing speed.
  7827. When the tape driver starts reading a record, the record has to
  7828. be read whole without stopping, as a tape gap is needed to stop the
  7829. tape motion without loosing information.
  7830. @cindex Exabyte blocking
  7831. @cindex DAT blocking
  7832. Using higher blocking (putting more disk blocks per tape block) will use
  7833. the tape more efficiently as there will be less tape gaps. But reading
  7834. such tapes may be more difficult for the system, as more memory will be
  7835. required to receive at once the whole record. Further, if there is a
  7836. reading error on a huge record, this is less likely that the system will
  7837. succeed in recovering the information. So, blocking should not be too
  7838. low, nor it should be too high. @command{tar} uses by default a blocking of
  7839. 20 for historical reasons, and it does not really matter when reading or
  7840. writing to disk. Current tape technology would easily accommodate higher
  7841. blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
  7842. We were told that for some DLT drives, the blocking should be a multiple
  7843. of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
  7844. Other manufacturers may use different recommendations for the same tapes.
  7845. This might also depends of the buffering techniques used inside modern
  7846. tape controllers. Some imposes a minimum blocking, or a maximum blocking.
  7847. Others request blocking to be some exponent of two.
  7848. So, there is no fixed rule for blocking. But blocking at read time
  7849. should ideally be the same as blocking used at write time. At one place
  7850. I know, with a wide variety of equipment, they found it best to use a
  7851. blocking of 32 to guarantee that their tapes are fully interchangeable.
  7852. I was also told that, for recycled tapes, prior erasure (by the same
  7853. drive unit that will be used to create the archives) sometimes lowers
  7854. the error rates observed at rewriting time.
  7855. I might also use @option{--number-blocks} instead of
  7856. @option{--block-number}, so @option{--block} will then expand to
  7857. @option{--blocking-factor} unambiguously.
  7858. @node Many
  7859. @section Many Archives on One Tape
  7860. @FIXME{Appropriate options should be moved here from elsewhere.}
  7861. @findex ntape @r{device}
  7862. Most tape devices have two entries in the @file{/dev} directory, or
  7863. entries that come in pairs, which differ only in the minor number for
  7864. this device. Let's take for example @file{/dev/tape}, which often
  7865. points to the only or usual tape device of a given system. There might
  7866. be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
  7867. name is the @emph{rewinding} version of the device, while the name
  7868. having @samp{nr} in it is the @emph{no rewinding} version of the same
  7869. device.
  7870. A rewinding tape device will bring back the tape to its beginning point
  7871. automatically when this device is opened or closed. Since @command{tar}
  7872. opens the archive file before using it and closes it afterwards, this
  7873. means that a simple:
  7874. @smallexample
  7875. $ @kbd{tar cf /dev/tape @var{directory}}
  7876. @end smallexample
  7877. @noindent
  7878. will reposition the tape to its beginning both prior and after saving
  7879. @var{directory} contents to it, thus erasing prior tape contents and
  7880. making it so that any subsequent write operation will destroy what has
  7881. just been saved.
  7882. @cindex tape positioning
  7883. So, a rewinding device is normally meant to hold one and only one file.
  7884. If you want to put more than one @command{tar} archive on a given tape, you
  7885. will need to avoid using the rewinding version of the tape device. You
  7886. will also have to pay special attention to tape positioning. Errors in
  7887. positioning may overwrite the valuable data already on your tape. Many
  7888. people, burnt by past experiences, will only use rewinding devices and
  7889. limit themselves to one file per tape, precisely to avoid the risk of
  7890. such errors. Be fully aware that writing at the wrong position on a
  7891. tape loses all information past this point and most probably until the
  7892. end of the tape, and this destroyed information @emph{cannot} be
  7893. recovered.
  7894. To save @var{directory-1} as a first archive at the beginning of a
  7895. tape, and leave that tape ready for a second archive, you should use:
  7896. @smallexample
  7897. $ @kbd{mt -f /dev/nrtape rewind}
  7898. $ @kbd{tar cf /dev/nrtape @var{directory-1}}
  7899. @end smallexample
  7900. @cindex tape marks
  7901. @dfn{Tape marks} are special magnetic patterns written on the tape
  7902. media, which are later recognizable by the reading hardware. These
  7903. marks are used after each file, when there are many on a single tape.
  7904. An empty file (that is to say, two tape marks in a row) signal the
  7905. logical end of the tape, after which no file exist. Usually,
  7906. non-rewinding tape device drivers will react to the close request issued
  7907. by @command{tar} by first writing two tape marks after your archive, and by
  7908. backspacing over one of these. So, if you remove the tape at that time
  7909. from the tape drive, it is properly terminated. But if you write
  7910. another file at the current position, the second tape mark will be
  7911. erased by the new information, leaving only one tape mark between files.
  7912. So, you may now save @var{directory-2} as a second archive after the
  7913. first on the same tape by issuing the command:
  7914. @smallexample
  7915. $ @kbd{tar cf /dev/nrtape @var{directory-2}}
  7916. @end smallexample
  7917. @noindent
  7918. and so on for all the archives you want to put on the same tape.
  7919. Another usual case is that you do not write all the archives the same
  7920. day, and you need to remove and store the tape between two archive
  7921. sessions. In general, you must remember how many files are already
  7922. saved on your tape. Suppose your tape already has 16 files on it, and
  7923. that you are ready to write the 17th. You have to take care of skipping
  7924. the first 16 tape marks before saving @var{directory-17}, say, by using
  7925. these commands:
  7926. @smallexample
  7927. $ @kbd{mt -f /dev/nrtape rewind}
  7928. $ @kbd{mt -f /dev/nrtape fsf 16}
  7929. $ @kbd{tar cf /dev/nrtape @var{directory-17}}
  7930. @end smallexample
  7931. In all the previous examples, we put aside blocking considerations, but
  7932. you should do the proper things for that as well. @xref{Blocking}.
  7933. @menu
  7934. * Tape Positioning:: Tape Positions and Tape Marks
  7935. * mt:: The @command{mt} Utility
  7936. @end menu
  7937. @node Tape Positioning
  7938. @subsection Tape Positions and Tape Marks
  7939. @UNREVISED
  7940. Just as archives can store more than one file from the file system,
  7941. tapes can store more than one archive file. To keep track of where
  7942. archive files (or any other type of file stored on tape) begin and
  7943. end, tape archive devices write magnetic @dfn{tape marks} on the
  7944. archive media. Tape drives write one tape mark between files,
  7945. two at the end of all the file entries.
  7946. If you think of data as a series of records "rrrr"'s, and tape marks as
  7947. "*"'s, a tape might look like the following:
  7948. @smallexample
  7949. rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
  7950. @end smallexample
  7951. Tape devices read and write tapes using a read/write @dfn{tape
  7952. head}---a physical part of the device which can only access one
  7953. point on the tape at a time. When you use @command{tar} to read or
  7954. write archive data from a tape device, the device will begin reading
  7955. or writing from wherever on the tape the tape head happens to be,
  7956. regardless of which archive or what part of the archive the tape
  7957. head is on. Before writing an archive, you should make sure that no
  7958. data on the tape will be overwritten (unless it is no longer needed).
  7959. Before reading an archive, you should make sure the tape head is at
  7960. the beginning of the archive you want to read. You can do it manually
  7961. via @code{mt} utility (@pxref{mt}). The @code{restore} script does
  7962. that automatically (@pxref{Scripted Restoration}).
  7963. If you want to add new archive file entries to a tape, you should
  7964. advance the tape to the end of the existing file entries, backspace
  7965. over the last tape mark, and write the new archive file. If you were
  7966. to add two archives to the example above, the tape might look like the
  7967. following:
  7968. @smallexample
  7969. rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
  7970. @end smallexample
  7971. @node mt
  7972. @subsection The @command{mt} Utility
  7973. @UNREVISED
  7974. @FIXME{Is it true that this only works on non-block devices?
  7975. should explain the difference, (fixed or variable).}
  7976. @xref{Blocking Factor}.
  7977. You can use the @command{mt} utility to advance or rewind a tape past a
  7978. specified number of archive files on the tape. This will allow you
  7979. to move to the beginning of an archive before extracting or reading
  7980. it, or to the end of all the archives before writing a new one.
  7981. @FIXME{Why isn't there an "advance 'til you find two tape marks
  7982. together"?}
  7983. The syntax of the @command{mt} command is:
  7984. @smallexample
  7985. @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
  7986. @end smallexample
  7987. where @var{tapename} is the name of the tape device, @var{number} is
  7988. the number of times an operation is performed (with a default of one),
  7989. and @var{operation} is one of the following:
  7990. @FIXME{is there any use for record operations?}
  7991. @table @option
  7992. @item eof
  7993. @itemx weof
  7994. Writes @var{number} tape marks at the current position on the tape.
  7995. @item fsf
  7996. Moves tape position forward @var{number} files.
  7997. @item bsf
  7998. Moves tape position back @var{number} files.
  7999. @item rewind
  8000. Rewinds the tape. (Ignores @var{number}).
  8001. @item offline
  8002. @itemx rewoff1
  8003. Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
  8004. @item status
  8005. Prints status information about the tape unit.
  8006. @end table
  8007. @FIXME{Is there a better way to frob the spacing on the list?}
  8008. If you don't specify a @var{tapename}, @command{mt} uses the environment
  8009. variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
  8010. the default device specified in your @file{sys/mtio.h} file
  8011. (@code{DEFTAPE} variable). If this is not defined, the program will
  8012. display a descriptive error message and exit with code 1.
  8013. @command{mt} returns a 0 exit status when the operation(s) were
  8014. successful, 1 if the command was unrecognized, and 2 if an operation
  8015. failed.
  8016. @node Using Multiple Tapes
  8017. @section Using Multiple Tapes
  8018. Often you might want to write a large archive, one larger than will fit
  8019. on the actual tape you are using. In such a case, you can run multiple
  8020. @command{tar} commands, but this can be inconvenient, particularly if you
  8021. are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
  8022. Therefore, @command{tar} provides a special mode for creating
  8023. multi-volume archives.
  8024. @dfn{Multi-volume} archive is a single @command{tar} archive, stored
  8025. on several media volumes of fixed size. Although in this section we will
  8026. often call @samp{volume} a @dfn{tape}, there is absolutely no
  8027. requirement for multi-volume archives to be stored on tapes. Instead,
  8028. they can use whatever media type the user finds convenient, they can
  8029. even be located on files.
  8030. When creating a multi-volume arvhive, @GNUTAR{} continues to fill
  8031. current volume until it runs out of space, then it switches to
  8032. next volume (usually the operator is queried to replace the tape on
  8033. this point), and continues working on the new volume. This operation
  8034. continues untill all requested files are dumped. If @GNUTAR{} detects
  8035. end of media while dumping a file, such a file is archived in split
  8036. form. Some very big files can even be split across several volumes.
  8037. Each volume is itself a valid @GNUTAR{} archive, so it can be read
  8038. without any special options. Consequently any file member residing
  8039. entirely on one volume can be extracted or otherwise operated upon
  8040. without needing the other volume. Sure enough, to extract a split
  8041. member you would need all volumes its parts reside on.
  8042. Multi-volume archives suffer from several limitations. In particular,
  8043. they cannot be compressed.
  8044. @GNUTAR{} is able to create multi-volume archives of two formats
  8045. (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
  8046. @menu
  8047. * Multi-Volume Archives:: Archives Longer than One Tape or Disk
  8048. * Tape Files:: Tape Files
  8049. * Tarcat:: Concatenate Volumes into a Single Archive
  8050. @end menu
  8051. @node Multi-Volume Archives
  8052. @subsection Archives Longer than One Tape or Disk
  8053. @cindex Multi-volume archives
  8054. @opindex multi-volume
  8055. To create an archive that is larger than will fit on a single unit of
  8056. the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
  8057. the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
  8058. archive can be manipulated like any other archive (provided the
  8059. @option{--multi-volume} option is specified), but is stored on more
  8060. than one tape or disk.
  8061. When you specify @option{--multi-volume}, @command{tar} does not report an
  8062. error when it comes to the end of an archive volume (when reading), or
  8063. the end of the media (when writing). Instead, it prompts you to load
  8064. a new storage volume. If the archive is on a magnetic tape, you
  8065. should change tapes when you see the prompt; if the archive is on a
  8066. floppy disk, you should change disks; etc.
  8067. @table @option
  8068. @item --multi-volume
  8069. @itemx -M
  8070. Creates a multi-volume archive, when used in conjunction with
  8071. @option{--create} (@option{-c}). To perform any other operation on a multi-volume
  8072. archive, specify @option{--multi-volume} in conjunction with that
  8073. operation.
  8074. For example:
  8075. @smallexample
  8076. $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
  8077. @end smallexample
  8078. @end table
  8079. The method @command{tar} uses to detect end of tape is not perfect, and
  8080. fails on some operating systems or on some devices. If @command{tar}
  8081. cannot detect the end of the tape itself, you can use
  8082. @option{--tape-length} option to inform it about the capacity of the
  8083. tape:
  8084. @anchor{tape-length}
  8085. @table @option
  8086. @opindex tape-length
  8087. @item --tape-length=@var{size}
  8088. @itemx -L @var{size}
  8089. Set maximum length of a volume. The @var{size} argument should then
  8090. be the usable size of the tape in units of 1024 bytes. This option
  8091. selects @option{--multi-volume} automatically. For example:
  8092. @smallexample
  8093. $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
  8094. @end smallexample
  8095. @end table
  8096. @anchor{change volume prompt}
  8097. When @GNUTAR{} comes to the end of a storage media, it asks you to
  8098. change the volume. The built-in prompt for POSIX locale
  8099. is@footnote{If you run @GNUTAR{} under a different locale, the
  8100. translation to the locale's language will be used.}:
  8101. @smallexample
  8102. Prepare volume #@var{n} for `@var{archive}' and hit return:
  8103. @end smallexample
  8104. @noindent
  8105. where @var{n} is the ordinal number of the volume to be created and
  8106. @var{archive} is archive file or device name.
  8107. When prompting for a new tape, @command{tar} accepts any of the following
  8108. responses:
  8109. @table @kbd
  8110. @item ?
  8111. Request @command{tar} to explain possible responses
  8112. @item q
  8113. Request @command{tar} to exit immediately.
  8114. @item n @var{file-name}
  8115. Request @command{tar} to write the next volume on the file @var{file-name}.
  8116. @item !
  8117. Request @command{tar} to run a subshell. This option can be disabled
  8118. by giving @option{--restrict} command line option to
  8119. @command{tar}@footnote{@xref{--restrict}, for more information about
  8120. this option}.
  8121. @item y
  8122. Request @command{tar} to begin writing the next volume.
  8123. @end table
  8124. (You should only type @samp{y} after you have changed the tape;
  8125. otherwise @command{tar} will write over the volume it just finished.)
  8126. @cindex Volume number file
  8127. @cindex volno file
  8128. @anchor{volno-file}
  8129. @opindex volno-file
  8130. The volume number used by @command{tar} in its tape-changing prompt
  8131. can be changed; if you give the
  8132. @option{--volno-file=@var{file-of-number}} option, then
  8133. @var{file-of-number} should be an unexisting file to be created, or
  8134. else, a file already containing a decimal number. That number will be
  8135. used as the volume number of the first volume written. When
  8136. @command{tar} is finished, it will rewrite the file with the
  8137. now-current volume number. (This does not change the volume number
  8138. written on a tape label, as per @ref{label}, it @emph{only} affects
  8139. the number used in the prompt.)
  8140. @cindex End-of-archive info script
  8141. @cindex Info script
  8142. @anchor{info-script}
  8143. @opindex info-script
  8144. @opindex new-volume-script
  8145. If you want more elaborate behavior than this, you can write a special
  8146. @dfn{new volume script}, that will be responsible for changing the
  8147. volume, and instruct @command{tar} to use it instead of its normal
  8148. prompting procedure:
  8149. @table @option
  8150. @item --info-script=@var{script-name}
  8151. @itemx --new-volume-script=@var{script-name}
  8152. @itemx -F @var{script-name}
  8153. Specify the full name of the volume script to use. The script can be
  8154. used to eject cassettes, or to broadcast messages such as
  8155. @samp{Someone please come change my tape} when performing unattended
  8156. backups.
  8157. @end table
  8158. The @var{script-name} is executed without any command line
  8159. arguments. It inherits @command{tar}'s shell environment.
  8160. Additional data is passed to it via the following
  8161. environment variables:
  8162. @table @env
  8163. @vrindex TAR_VERSION, info script environment variable
  8164. @item TAR_VERSION
  8165. @GNUTAR{} version number.
  8166. @vrindex TAR_ARCHIVE, info script environment variable
  8167. @item TAR_ARCHIVE
  8168. The name of the archive @command{tar} is processing.
  8169. @vrindex TAR_VOLUME, info script environment variable
  8170. @item TAR_VOLUME
  8171. Ordinal number of the volume @command{tar} is about to start.
  8172. @vrindex TAR_SUBCOMMAND, info script environment variable
  8173. @item TAR_SUBCOMMAND
  8174. Short option describing the operation @command{tar} is executing
  8175. @xref{Operations}, for a complete list of subcommand options.
  8176. @vrindex TAR_FORMAT, info script environment variable
  8177. @item TAR_FORMAT
  8178. Format of the archive being processed. @xref{Formats}, for a complete
  8179. list of archive format names.
  8180. @end table
  8181. The volume script can instruct @command{tar} to use new archive name,
  8182. by writing in to file descriptor 3 (see below for an example).
  8183. If the info script fails, @command{tar} exits; otherwise, it begins
  8184. writing the next volume.
  8185. If you want @command{tar} to cycle through a series of files or tape
  8186. drives, there are three approaches to choose from. First of all, you
  8187. can give @command{tar} multiple @option{--file} options. In this case
  8188. the specified files will be used, in sequence, as the successive
  8189. volumes of the archive. Only when the first one in the sequence needs
  8190. to be used again will @command{tar} prompt for a tape change (or run
  8191. the info script). For example, suppose someone has two tape drives on
  8192. a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
  8193. @GNUTAR{} to switch to the second drive when it needs to write the
  8194. second tape, and then back to the first tape, etc., just do either of:
  8195. @smallexample
  8196. $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
  8197. $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
  8198. @end smallexample
  8199. The second method is to use the @samp{n} response to the tape-change
  8200. prompt.
  8201. Finally, the most flexible approach is to use a volume script, that
  8202. writes new archive name to the file descriptor #3. For example, the
  8203. following volume script will create a series of archive files, named
  8204. @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
  8205. archive being created (as given by @option{--file} option) and
  8206. @var{vol} is the ordinal number of the archive being created:
  8207. @smallexample
  8208. @group
  8209. #! /bin/sh
  8210. echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
  8211. name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
  8212. case $TAR_SUBCOMMAND in
  8213. -c) ;;
  8214. -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
  8215. ;;
  8216. *) exit 1
  8217. esac
  8218. echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
  8219. @end group
  8220. @end smallexample
  8221. The same script cant be used while listing, comparing or extracting
  8222. from the created archive. For example:
  8223. @smallexample
  8224. @group
  8225. # @r{Create a multi-volume archive:}
  8226. $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
  8227. # @r{Extract from the created archive:}
  8228. $ @kbd{tar -x -f archive.tar -F new-volume .}
  8229. @end group
  8230. @end smallexample
  8231. @noindent
  8232. Notice, that the first command had to use @option{-L} option, since
  8233. otherwise @GNUTAR{} will end up writing everything to file
  8234. @file{archive.tar}.
  8235. You can read each individual volume of a multi-volume archive as if it
  8236. were an archive by itself. For example, to list the contents of one
  8237. volume, use @option{--list}, without @option{--multi-volume} specified.
  8238. To extract an archive member from one volume (assuming it is described
  8239. that volume), use @option{--extract}, again without
  8240. @option{--multi-volume}.
  8241. If an archive member is split across volumes (i.e. its entry begins on
  8242. one volume of the media and ends on another), you need to specify
  8243. @option{--multi-volume} to extract it successfully. In this case, you
  8244. should load the volume where the archive member starts, and use
  8245. @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
  8246. volumes as it needs them. @xref{extracting archives}, for more
  8247. information about extracting archives.
  8248. Multi-volume archives can be modified like any other archive. To add
  8249. files to a multi-volume archive, you need to only mount the last
  8250. volume of the archive media (and new volumes, if needed). For all
  8251. other operations, you need to use the entire archive.
  8252. If a multi-volume archive was labeled using
  8253. @option{--label=@var{archive-label}} (@pxref{label}) when it was
  8254. created, @command{tar} will not automatically label volumes which are
  8255. added later. To label subsequent volumes, specify
  8256. @option{--label=@var{archive-label}} again in conjunction with the
  8257. @option{--append}, @option{--update} or @option{--concatenate} operation.
  8258. @FIXME{This is no longer true: Multivolume archives in @samp{POSIX}
  8259. format can be extracted using any posix-compliant tar
  8260. implementation. The split members can then be recreated from parts
  8261. using a simple shell script. Provide more information about it:}
  8262. Beware that there is @emph{no} real standard about the proper way, for
  8263. a @command{tar} archive, to span volume boundaries. If you have a
  8264. multi-volume created by some vendor's @command{tar}, there is almost
  8265. no chance you could read all the volumes with @GNUTAR{}.
  8266. The converse is also true: you may not expect
  8267. multi-volume archives created by @GNUTAR{} to be
  8268. fully recovered by vendor's @command{tar}. Since there is little
  8269. chance that, in mixed system configurations, some vendor's
  8270. @command{tar} will work on another vendor's machine, and there is a
  8271. great chance that @GNUTAR{} will work on most of
  8272. them, your best bet is to install @GNUTAR{} on all
  8273. machines between which you know exchange of files is possible.
  8274. @node Tape Files
  8275. @subsection Tape Files
  8276. @UNREVISED
  8277. To give the archive a name which will be recorded in it, use the
  8278. @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
  8279. option. This will write a special block identifying
  8280. @var{volume-label} as the name of the archive to the front of the
  8281. archive which will be displayed when the archive is listed with
  8282. @option{--list}. If you are creating a multi-volume archive with
  8283. @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
  8284. volume label will have @samp{Volume @var{nnn}} appended to the name
  8285. you give, where @var{nnn} is the number of the volume of the archive.
  8286. (If you use the @option{--label=@var{volume-label}}) option when
  8287. reading an archive, it checks to make sure the label on the tape
  8288. matches the one you give. @xref{label}.
  8289. When @command{tar} writes an archive to tape, it creates a single
  8290. tape file. If multiple archives are written to the same tape, one
  8291. after the other, they each get written as separate tape files. When
  8292. extracting, it is necessary to position the tape at the right place
  8293. before running @command{tar}. To do this, use the @command{mt} command.
  8294. For more information on the @command{mt} command and on the organization
  8295. of tapes into a sequence of tape files, see @ref{mt}.
  8296. People seem to often do:
  8297. @smallexample
  8298. @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
  8299. @end smallexample
  8300. or such, for pushing a common date in all volumes or an archive set.
  8301. @node Tarcat
  8302. @subsection Concatenate Volumes into a Single Archive
  8303. @pindex tarcat
  8304. Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
  8305. archive to a single @command{tar} archive. Simply concatenating all
  8306. volumes into one will not work, since each volume carries an additional
  8307. information at the beginning. @GNUTAR{} is shipped with the shell
  8308. script @command{tarcat} designed for this purpose.
  8309. The script takes a list of files comprising a multi-volume archive
  8310. and creates the resulting archive at the standard output. For example:
  8311. @smallexample
  8312. @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
  8313. @end smallexample
  8314. The script implements a simple heuristics to determine the format of
  8315. the first volume file and to decide how to process the rest of the
  8316. files. However, it makes no attempt to verify whether the files are
  8317. given in order or even if they are valid @command{tar} archives.
  8318. It uses @command{dd} and does not filter its standard error, so you
  8319. will usually see lots of spurious messages.
  8320. @FIXME{The script is not installed. Should we install it?}
  8321. @node label
  8322. @section Including a Label in the Archive
  8323. @cindex Labeling an archive
  8324. @cindex Labels on the archive media
  8325. @cindex Labeling multi-volume archives
  8326. @UNREVISED
  8327. @opindex label
  8328. To avoid problems caused by misplaced paper labels on the archive
  8329. media, you can include a @dfn{label} entry---an archive member which
  8330. contains the name of the archive---in the archive itself. Use the
  8331. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  8332. option in conjunction with the @option{--create} operation to include
  8333. a label entry in the archive as it is being created.
  8334. @table @option
  8335. @item --label=@var{archive-label}
  8336. @itemx -V @var{archive-label}
  8337. Includes an @dfn{archive-label} at the beginning of the archive when
  8338. the archive is being created, when used in conjunction with the
  8339. @option{--create} operation. Checks to make sure the archive label
  8340. matches the one specified (when used in conjunction with any other
  8341. operation.
  8342. @end table
  8343. If you create an archive using both
  8344. @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
  8345. and @option{--multi-volume} (@option{-M}), each volume of the archive
  8346. will have an archive label of the form @samp{@var{archive-label}
  8347. Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
  8348. next, and so on. @xref{Using Multiple Tapes}, for information on
  8349. creating multiple volume archives.
  8350. @cindex Volume label, listing
  8351. @cindex Listing volume label
  8352. The volume label will be displayed by @option{--list} along with
  8353. the file contents. If verbose display is requested, it will also be
  8354. explicitely marked as in the example below:
  8355. @smallexample
  8356. @group
  8357. $ @kbd{tar --verbose --list --file=iamanarchive}
  8358. V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
  8359. -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
  8360. @end group
  8361. @end smallexample
  8362. @opindex test-label
  8363. @anchor{--test-label option}
  8364. However, @option{--list} option will cause listing entire
  8365. contents of the archive, which may be undesirable (for example, if the
  8366. archive is stored on a tape). You can request checking only the volume
  8367. by specifying @option{--test-label} option. This option reads only the
  8368. first block of an archive, so it can be used with slow storage
  8369. devices. For example:
  8370. @smallexample
  8371. @group
  8372. $ @kbd{tar --test-label --file=iamanarchive}
  8373. iamalabel
  8374. @end group
  8375. @end smallexample
  8376. If @option{--test-label} is used with a single command line
  8377. argument, @command{tar} compares the volume label with the
  8378. argument. It exits with code 0 if the two strings match, and with code
  8379. 2 otherwise. In this case no output is displayed. For example:
  8380. @smallexample
  8381. @group
  8382. $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
  8383. @result{} 0
  8384. $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
  8385. @result{} 1
  8386. @end group
  8387. @end smallexample
  8388. If you request any operation, other than @option{--create}, along
  8389. with using @option{--label} option, @command{tar} will first check if
  8390. the archive label matches the one specified and will refuse to proceed
  8391. if it does not. Use this as a safety precaution to avoid accidentally
  8392. overwriting existing archives. For example, if you wish to add files
  8393. to @file{archive}, presumably labelled with string @samp{My volume},
  8394. you will get:
  8395. @smallexample
  8396. @group
  8397. $ @kbd{tar -rf archive --label 'My volume' .}
  8398. tar: Archive not labeled to match `My volume'
  8399. @end group
  8400. @end smallexample
  8401. @noindent
  8402. in case its label does not match. This will work even if
  8403. @file{archive} is not labelled at all.
  8404. Similarly, @command{tar} will refuse to list or extract the
  8405. archive if its label doesn't match the @var{archive-label}
  8406. specified. In those cases, @var{archive-label} argument is interpreted
  8407. as a globbing-style pattern which must match the actual magnetic
  8408. volume label. @xref{exclude}, for a precise description of how match
  8409. is attempted@footnote{Previous versions of @command{tar} used full
  8410. regular expression matching, or before that, only exact string
  8411. matching, instead of wildcard matchers. We decided for the sake of
  8412. simplicity to use a uniform matching device through
  8413. @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
  8414. the volume label matcher will also suffix @var{archive-label} by
  8415. @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
  8416. up. Since the volume numbering is automatically added in labels at
  8417. creation time, it sounded logical to equally help the user taking care
  8418. of it when the archive is being read.
  8419. The @option{--label} was once called @option{--volume}, but is not
  8420. available under that name anymore.
  8421. You can also use @option{--label} to get a common information on
  8422. all tapes of a series. For having this information different in each
  8423. series created through a single script used on a regular basis, just
  8424. manage to get some date string as part of the label. For example:
  8425. @smallexample
  8426. @group
  8427. $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
  8428. $ @kbd{tar --create --file=/dev/tape --multi-volume \
  8429. --volume="Daily backup for `date +%Y-%m-%d`"}
  8430. @end group
  8431. @end smallexample
  8432. Also note that each label has its own date and time, which corresponds
  8433. to when @GNUTAR{} initially attempted to write it,
  8434. often soon after the operator launches @command{tar} or types the
  8435. carriage return telling that the next tape is ready. Comparing date
  8436. labels does give an idea of tape throughput only if the delays for
  8437. rewinding tapes and the operator switching them were negligible, which
  8438. is usually not the case.
  8439. @node verify
  8440. @section Verifying Data as It is Stored
  8441. @cindex Verifying a write operation
  8442. @cindex Double-checking a write operation
  8443. @table @option
  8444. @item -W
  8445. @itemx --verify
  8446. @opindex verify, short description
  8447. Attempt to verify the archive after writing.
  8448. @end table
  8449. This option causes @command{tar} to verify the archive after writing it.
  8450. Each volume is checked after it is written, and any discrepancies
  8451. are recorded on the standard error output.
  8452. Verification requires that the archive be on a back-space-able medium.
  8453. This means pipes, some cartridge tape drives, and some other devices
  8454. cannot be verified.
  8455. You can insure the accuracy of an archive by comparing files in the
  8456. system with archive members. @command{tar} can compare an archive to the
  8457. file system as the archive is being written, to verify a write
  8458. operation, or can compare a previously written archive, to insure that
  8459. it is up to date.
  8460. @xopindex{verify, using with @option{--create}}
  8461. @xopindex{create, using with @option{--verify}}
  8462. To check for discrepancies in an archive immediately after it is
  8463. written, use the @option{--verify} (@option{-W}) option in conjunction with
  8464. the @option{--create} operation. When this option is
  8465. specified, @command{tar} checks archive members against their counterparts
  8466. in the file system, and reports discrepancies on the standard error.
  8467. To verify an archive, you must be able to read it from before the end
  8468. of the last written entry. This option is useful for detecting data
  8469. errors on some tapes. Archives written to pipes, some cartridge tape
  8470. drives, and some other devices cannot be verified.
  8471. One can explicitly compare an already made archive with the file
  8472. system by using the @option{--compare} (@option{--diff}, @option{-d})
  8473. option, instead of using the more automatic @option{--verify} option.
  8474. @xref{compare}.
  8475. Note that these two options have a slightly different intent. The
  8476. @option{--compare} option checks how identical are the logical contents of some
  8477. archive with what is on your disks, while the @option{--verify} option is
  8478. really for checking if the physical contents agree and if the recording
  8479. media itself is of dependable quality. So, for the @option{--verify}
  8480. operation, @command{tar} tries to defeat all in-memory cache pertaining to
  8481. the archive, while it lets the speed optimization undisturbed for the
  8482. @option{--compare} option. If you nevertheless use @option{--compare} for
  8483. media verification, you may have to defeat the in-memory cache yourself,
  8484. maybe by opening and reclosing the door latch of your recording unit,
  8485. forcing some doubt in your operating system about the fact this is really
  8486. the same volume as the one just written or read.
  8487. The @option{--verify} option would not be necessary if drivers were indeed
  8488. able to detect dependably all write failures. This sometimes require many
  8489. magnetic heads, some able to read after the writes occurred. One would
  8490. not say that drivers unable to detect all cases are necessarily flawed,
  8491. as long as programming is concerned.
  8492. The @option{--verify} (@option{-W}) option will not work in
  8493. conjunction with the @option{--multi-volume} (@option{-M}) option or
  8494. the @option{--append} (@option{-r}), @option{--update} (@option{-u})
  8495. and @option{--delete} operations. @xref{Operations}, for more
  8496. information on these operations.
  8497. Also, since @command{tar} normally strips leading @samp{/} from file
  8498. names (@pxref{absolute}), a command like @samp{tar --verify -cf
  8499. /tmp/foo.tar /etc} will work as desired only if the working directory is
  8500. @file{/}, as @command{tar} uses the archive's relative member names
  8501. (e.g., @file{etc/motd}) when verifying the archive.
  8502. @node Write Protection
  8503. @section Write Protection
  8504. Almost all tapes and diskettes, and in a few rare cases, even disks can
  8505. be @dfn{write protected}, to protect data on them from being changed.
  8506. Once an archive is written, you should write protect the media to prevent
  8507. the archive from being accidentally overwritten or deleted. (This will
  8508. protect the archive from being changed with a tape or floppy drive---it
  8509. will not protect it from magnet fields or other physical hazards).
  8510. The write protection device itself is usually an integral part of the
  8511. physical media, and can be a two position (write enabled/write
  8512. disabled) switch, a notch which can be popped out or covered, a ring
  8513. which can be removed from the center of a tape reel, or some other
  8514. changeable feature.
  8515. @node Changes
  8516. @appendix Changes
  8517. This appendix lists some important user-visible changes between
  8518. version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
  8519. version of this document is available at
  8520. @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
  8521. @GNUTAR{} documentation page}.
  8522. @table @asis
  8523. @item Use of globbing patterns when listing and extracting.
  8524. Previous versions of GNU tar assumed shell-style globbing when
  8525. extracting from or listing an archive. For example:
  8526. @smallexample
  8527. $ @kbd{tar xf foo.tar '*.c'}
  8528. @end smallexample
  8529. would extract all files whose names end in @samp{.c}. This behavior
  8530. was not documented and was incompatible with traditional tar
  8531. implementations. Therefore, starting from version 1.15.91, GNU tar
  8532. no longer uses globbing by default. For example, the above invocation
  8533. is now interpreted as a request to extract from the archive the file
  8534. named @file{*.c}.
  8535. To facilitate transition to the new behavior for those users who got
  8536. used to the previous incorrect one, @command{tar} will print a warning
  8537. if it finds out that a requested member was not found in the archive
  8538. and its name looks like a globbing pattern. For example:
  8539. @smallexample
  8540. $ @kbd{tar xf foo.tar '*.c'}
  8541. tar: Pattern matching characters used in file names. Please,
  8542. tar: use --wildcards to enable pattern matching, or --no-wildcards to
  8543. tar: suppress this warning.
  8544. tar: *.c: Not found in archive
  8545. tar: Error exit delayed from previous errors
  8546. @end smallexample
  8547. To treat member names as globbing patterns, use --wildcards option.
  8548. If you want to tar to mimic the behavior of versions prior to 1.15.91,
  8549. add this option to your @env{TAR_OPTIONS} variable.
  8550. @xref{wildcards}, for the detailed discussion of the use of globbing
  8551. patterns by @GNUTAR{}.
  8552. @item Use of short option @option{-o}.
  8553. Earlier versions of @GNUTAR{} understood @option{-o} command line
  8554. option as a synonym for @option{--old-archive}.
  8555. @GNUTAR{} starting from version 1.13.90 understands this option as
  8556. a synonym for @option{--no-same-owner}. This is compatible with
  8557. UNIX98 @command{tar} implementations.
  8558. However, to facilitate transition, @option{-o} option retains its
  8559. old semantics when it is used with one of archive-creation commands.
  8560. Users are encouraged to use @option{--format=oldgnu} instead.
  8561. It is especially important, since versions of @acronym{GNU} Automake
  8562. up to and including 1.8.4 invoke tar with this option to produce
  8563. distribution tarballs. @xref{Formats,v7}, for the detailed discussion
  8564. of this issue and its implications.
  8565. @FIXME{Change the first argument to tar-formats when the new Automake is
  8566. out. The proposition to add @anchor{} to the appropriate place of its
  8567. docs was accepted by Automake people --Sergey 2006-05-25}.
  8568. @xref{Options, tar-v7, Changing Automake's Behavior,
  8569. automake, GNU Automake}, for a description on how to use various
  8570. archive formats with @command{automake}.
  8571. Future versions of @GNUTAR{} will understand @option{-o} only as a
  8572. synonym for @option{--no-same-owner}.
  8573. @item Use of short option @option{-l}
  8574. Earlier versions of @GNUTAR{} understood @option{-l} option as a
  8575. synonym for @option{--one-file-system}. Since such usage contradicted
  8576. to UNIX98 specification and harmed compatibility with other
  8577. implementation, it was declared deprecated in version 1.14. However,
  8578. to facilitate transition to its new semantics, it was supported by
  8579. versions 1.15 and 1.15.90. The present use of @option{-l} as a short
  8580. variant of @option{--check-links} was introduced in version 1.15.91.
  8581. @item Use of options @option{--portability} and @option{--old-archive}
  8582. These options are deprecated. Please use @option{--format=v7} instead.
  8583. @item Use of option @option{--posix}
  8584. This option is deprecated. Please use @option{--format=posix} instead.
  8585. @end table
  8586. @node Configuring Help Summary
  8587. @appendix Configuring Help Summary
  8588. Running @kbd{tar --help} displays the short @command{tar} option
  8589. summary (@pxref{help}). This summary is organised by @dfn{groups} of
  8590. semantically close options. The options within each group are printed
  8591. in the following order: a short option, eventually followed by a list
  8592. of corresponding long option names, followed by a short description of
  8593. the option. For example, here is an excerpt from the actual @kbd{tar
  8594. --help} output:
  8595. @verbatim
  8596. Main operation mode:
  8597. -A, --catenate, --concatenate append tar files to an archive
  8598. -c, --create create a new archive
  8599. -d, --diff, --compare find differences between archive and
  8600. file system
  8601. --delete delete from the archive
  8602. @end verbatim
  8603. @vrindex ARGP_HELP_FMT, environment variable
  8604. The exact visual representation of the help output is configurable via
  8605. @env{ARGP_HELP_FMT} environment variable. The value of this variable
  8606. is a comma-separated list of @dfn{format variable} assignments. There
  8607. are two kinds of format variables. An @dfn{offset variable} keeps the
  8608. offset of some part of help output text from the leftmost column on
  8609. the screen. A @dfn{boolean} variable is a flag that toggles some
  8610. output feature on or off. Depending on the type of the corresponding
  8611. variable, there are two kinds of assignments:
  8612. @table @asis
  8613. @item Offset assignment
  8614. The assignment to an offset variable has the following syntax:
  8615. @smallexample
  8616. @var{variable}=@var{value}
  8617. @end smallexample
  8618. @noindent
  8619. where @var{variable} is the variable name, and @var{value} is a
  8620. numeric value to be assigned to the variable.
  8621. @item Boolean assignment
  8622. To assign @code{true} value to a variable, simply put this variable name. To
  8623. assign @code{false} value, prefix the variable name with @samp{no-}. For
  8624. example:
  8625. @smallexample
  8626. @group
  8627. # Assign @code{true} value:
  8628. dup-args
  8629. # Assign @code{false} value:
  8630. no-dup-args
  8631. @end group
  8632. @end smallexample
  8633. @end table
  8634. Following variables are declared:
  8635. @deftypevr {Help Output} boolean dup-args
  8636. If true, arguments for an option are shown with both short and long
  8637. options, even when a given option has both forms, for example:
  8638. @smallexample
  8639. -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
  8640. @end smallexample
  8641. If false, then if an option has both short and long forms, the
  8642. argument is only shown with the long one, for example:
  8643. @smallexample
  8644. -f, --file=ARCHIVE use archive file or device ARCHIVE
  8645. @end smallexample
  8646. @noindent
  8647. and a message indicating that the argument is applicable to both
  8648. forms is printed below the options. This message can be disabled
  8649. using @code{dup-args-note} (see below).
  8650. The default is false.
  8651. @end deftypevr
  8652. @deftypevr {Help Output} boolean dup-args-note
  8653. If this variable is true, which is the default, the following notice
  8654. is displayed at the end of the help output:
  8655. @quotation
  8656. Mandatory or optional arguments to long options are also mandatory or
  8657. optional for any corresponding short options.
  8658. @end quotation
  8659. Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
  8660. variables @code{dup-args} or @code{dup-args-note} should be set.
  8661. @end deftypevr
  8662. @deftypevr {Help Output} offset short-opt-col
  8663. Column in which short options start. Default is 2.
  8664. @smallexample
  8665. @group
  8666. $ @kbd{tar --help|grep ARCHIVE}
  8667. -f, --file=ARCHIVE use archive file or device ARCHIVE
  8668. $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
  8669. -f, --file=ARCHIVE use archive file or device ARCHIVE
  8670. @end group
  8671. @end smallexample
  8672. @end deftypevr
  8673. @deftypevr {Help Output} offset long-opt-col
  8674. Column in which long options start. Default is 6. For example:
  8675. @smallexample
  8676. @group
  8677. $ @kbd{tar --help|grep ARCHIVE}
  8678. -f, --file=ARCHIVE use archive file or device ARCHIVE
  8679. $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
  8680. -f, --file=ARCHIVE use archive file or device ARCHIVE
  8681. @end group
  8682. @end smallexample
  8683. @end deftypevr
  8684. @deftypevr {Help Output} offset doc-opt-col
  8685. Column in which @dfn{doc options} start. A doc option isn't actually
  8686. an option, but rather an arbitrary piece of documentation that is
  8687. displayed in much the same manner as the options. For example, in
  8688. the description of @option{--format} option:
  8689. @smallexample
  8690. @group
  8691. -H, --format=FORMAT create archive of the given format.
  8692. FORMAT is one of the following:
  8693. gnu GNU tar 1.13.x format
  8694. oldgnu GNU format as per tar <= 1.12
  8695. pax POSIX 1003.1-2001 (pax) format
  8696. posix same as pax
  8697. ustar POSIX 1003.1-1988 (ustar) format
  8698. v7 old V7 tar format
  8699. @end group
  8700. @end smallexample
  8701. @noindent
  8702. the format names are doc options. Thus, if you set
  8703. @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
  8704. will look as follows:
  8705. @smallexample
  8706. @group
  8707. -H, --format=FORMAT create archive of the given format.
  8708. FORMAT is one of the following:
  8709. gnu GNU tar 1.13.x format
  8710. oldgnu GNU format as per tar <= 1.12
  8711. pax POSIX 1003.1-2001 (pax) format
  8712. posix same as pax
  8713. ustar POSIX 1003.1-1988 (ustar) format
  8714. v7 old V7 tar format
  8715. @end group
  8716. @end smallexample
  8717. @end deftypevr
  8718. @deftypevr {Help Output} offset opt-doc-col
  8719. Column in which option description starts. Default is 29.
  8720. @smallexample
  8721. @group
  8722. $ @kbd{tar --help|grep ARCHIVE}
  8723. -f, --file=ARCHIVE use archive file or device ARCHIVE
  8724. $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
  8725. -f, --file=ARCHIVE use archive file or device ARCHIVE
  8726. $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
  8727. -f, --file=ARCHIVE
  8728. use archive file or device ARCHIVE
  8729. @end group
  8730. @end smallexample
  8731. @noindent
  8732. Notice, that the description starts on a separate line if
  8733. @code{opt-doc-col} value is too small.
  8734. @end deftypevr
  8735. @deftypevr {Help Output} offset header-col
  8736. Column in which @dfn{group headers} are printed. A group header is a
  8737. descriptive text preceding an option group. For example, in the
  8738. following text:
  8739. @verbatim
  8740. Main operation mode:
  8741. -A, --catenate, --concatenate append tar files to
  8742. an archive
  8743. -c, --create create a new archive
  8744. @end verbatim
  8745. @noindent
  8746. @samp{Main operation mode:} is the group header.
  8747. The default value is 1.
  8748. @end deftypevr
  8749. @deftypevr {Help Output} offset usage-indent
  8750. Indentation of wrapped usage lines. Affects @option{--usage}
  8751. output. Default is 12.
  8752. @end deftypevr
  8753. @deftypevr {Help Output} offset rmargin
  8754. Right margin of the text output. Used for wrapping.
  8755. @end deftypevr
  8756. @node Tar Internals
  8757. @appendix Tar Internals
  8758. @include intern.texi
  8759. @node Genfile
  8760. @appendix Genfile
  8761. @include genfile.texi
  8762. @node Free Software Needs Free Documentation
  8763. @appendix Free Software Needs Free Documentation
  8764. @include freemanuals.texi
  8765. @node Copying This Manual
  8766. @appendix Copying This Manual
  8767. @menu
  8768. * GNU Free Documentation License:: License for copying this manual
  8769. @end menu
  8770. @include fdl.texi
  8771. @node Index of Command Line Options
  8772. @appendix Index of Command Line Options
  8773. This appendix contains an index of all @GNUTAR{} long command line
  8774. options. The options are listed without the preceeding double-dash.
  8775. For a cross-reference of short command line options, @ref{Short Option Summary}.
  8776. @printindex op
  8777. @node Index
  8778. @appendix Index
  8779. @printindex cp
  8780. @summarycontents
  8781. @contents
  8782. @bye
  8783. @c Local variables:
  8784. @c texinfo-column-for-description: 32
  8785. @c End: