]> Dogcows Code - chaz/tar/blob - doc/tar.texi
(Other Tars): New node describing how to extract
[chaz/tar] / doc / tar.texi
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
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @c Maintenance notes:
14 @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
15 @c 2. Before creating final variant:
16 @c 1.1. Run `make check-options' to make sure all options are properly
17 @c documented;
18 @c 2.1. Run `make master-menu' (see comment before the master menu).
19
20 @include rendition.texi
21 @include value.texi
22
23 @defcodeindex op
24
25 @c Put everything in one index (arbitrarily chosen to be the concept index).
26 @syncodeindex fn cp
27 @syncodeindex ky cp
28 @syncodeindex pg cp
29 @syncodeindex vr cp
30
31 @copying
32
33 This manual is for @acronym{GNU} @command{tar} (version
34 @value{VERSION}, @value{UPDATED}), which creates and extracts files
35 from archives.
36
37 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
38 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
39
40 @quotation
41 Permission is granted to copy, distribute and/or modify this document
42 under the terms of the GNU Free Documentation License, Version 1.1 or
43 any later version published by the Free Software Foundation; with no
44 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
45 and with the Back-Cover Texts as in (a) below. A copy of the license
46 is included in the section entitled "GNU Free Documentation License".
47
48 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
49 this GNU Manual. Buying copies from GNU Press supports the FSF in
50 developing GNU and promoting software freedom.''
51 @end quotation
52 @end copying
53
54 @dircategory Archiving
55 @direntry
56 * Tar: (tar). Making tape (or disk) archives.
57 @end direntry
58
59 @dircategory Individual utilities
60 @direntry
61 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
62 @end direntry
63
64 @shorttitlepage @acronym{GNU} @command{tar}
65
66 @titlepage
67 @title @acronym{GNU} tar: an archiver tool
68 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
69 @author John Gilmore, Jay Fenlason et al.
70
71 @page
72 @vskip 0pt plus 1filll
73 @insertcopying
74 @end titlepage
75
76 @ifnottex
77 @node Top
78 @top @acronym{GNU} tar: an archiver tool
79
80 @insertcopying
81
82 @cindex file archival
83 @cindex archiving files
84
85 The first part of this master menu lists the major nodes in this Info
86 document. The rest of the menu lists all the lower level nodes.
87 @end ifnottex
88
89 @c The master menu goes here.
90 @c
91 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
92 @c loaded and run texinfo-master-menu.
93 @c To update it from the command line, run
94 @c
95 @c make master-menu
96
97 @menu
98 * Introduction::
99 * Tutorial::
100 * tar invocation::
101 * operations::
102 * Backups::
103 * Choosing::
104 * Date input formats::
105 * Formats::
106 * Media::
107
108 Appendices
109
110 * Changes::
111 * Configuring Help Summary::
112 * Tar Internals::
113 * Genfile::
114 * Free Software Needs Free Documentation::
115 * Copying This Manual::
116 * Index of Command Line Options::
117 * Index::
118
119 @detailmenu
120 --- The Detailed Node Listing ---
121
122 Introduction
123
124 * Book Contents:: What this Book Contains
125 * Definitions:: Some Definitions
126 * What tar Does:: What @command{tar} Does
127 * Naming tar Archives:: How @command{tar} Archives are Named
128 * Authors:: @GNUTAR{} Authors
129 * Reports:: Reporting bugs or suggestions
130
131 Tutorial Introduction to @command{tar}
132
133 * assumptions::
134 * stylistic conventions::
135 * basic tar options:: Basic @command{tar} Operations and Options
136 * frequent operations::
137 * Two Frequent Options::
138 * create:: How to Create Archives
139 * list:: How to List Archives
140 * extract:: How to Extract Members from an Archive
141 * going further::
142
143 Two Frequently Used Options
144
145 * file tutorial::
146 * verbose tutorial::
147 * help tutorial::
148
149 How to Create Archives
150
151 * prepare for examples::
152 * Creating the archive::
153 * create verbose::
154 * short create::
155 * create dir::
156
157 How to List Archives
158
159 * list dir::
160
161 How to Extract Members from an Archive
162
163 * extracting archives::
164 * extracting files::
165 * extract dir::
166 * extracting untrusted archives::
167 * failing commands::
168
169 Invoking @GNUTAR{}
170
171 * Synopsis::
172 * using tar options::
173 * Styles::
174 * All Options::
175 * help::
176 * defaults::
177 * verbose::
178 * interactive::
179
180 The Three Option Styles
181
182 * Long Options:: Long Option Style
183 * Short Options:: Short Option Style
184 * Old Options:: Old Option Style
185 * Mixing:: Mixing Option Styles
186
187 All @command{tar} Options
188
189 * Operation Summary::
190 * Option Summary::
191 * Short Option Summary::
192
193 @GNUTAR{} Operations
194
195 * Basic tar::
196 * Advanced tar::
197 * create options::
198 * extract options::
199 * backup::
200 * Applications::
201 * looking ahead::
202
203 Advanced @GNUTAR{} Operations
204
205 * Operations::
206 * append::
207 * update::
208 * concatenate::
209 * delete::
210 * compare::
211
212 How to Add Files to Existing Archives: @option{--append}
213
214 * appending files:: Appending Files to an Archive
215 * multiple::
216
217 Updating an Archive
218
219 * how to update::
220
221 Options Used by @option{--create}
222
223 * override:: Overriding File Metadata.
224 * Ignore Failed Read::
225
226 Options Used by @option{--extract}
227
228 * Reading:: Options to Help Read Archives
229 * Writing:: Changing How @command{tar} Writes Files
230 * Scarce:: Coping with Scarce Resources
231
232 Options to Help Read Archives
233
234 * read full records::
235 * Ignore Zeros::
236
237 Changing How @command{tar} Writes Files
238
239 * Dealing with Old Files::
240 * Overwrite Old Files::
241 * Keep Old Files::
242 * Keep Newer Files::
243 * Unlink First::
244 * Recursive Unlink::
245 * Data Modification Times::
246 * Setting Access Permissions::
247 * Directory Modification Times and Permissions::
248 * Writing to Standard Output::
249 * Writing to an External Program::
250 * remove files::
251
252 Coping with Scarce Resources
253
254 * Starting File::
255 * Same Order::
256
257 Performing Backups and Restoring Files
258
259 * Full Dumps:: Using @command{tar} to Perform Full Dumps
260 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
261 * Backup Levels:: Levels of Backups
262 * Backup Parameters:: Setting Parameters for Backups and Restoration
263 * Scripted Backups:: Using the Backup Scripts
264 * Scripted Restoration:: Using the Restore Script
265
266 Setting Parameters for Backups and Restoration
267
268 * General-Purpose Variables::
269 * Magnetic Tape Control::
270 * User Hooks::
271 * backup-specs example:: An Example Text of @file{Backup-specs}
272
273 Choosing Files and Names for @command{tar}
274
275 * file:: Choosing the Archive's Name
276 * Selecting Archive Members::
277 * files:: Reading Names from a File
278 * exclude:: Excluding Some Files
279 * wildcards:: Wildcards Patterns and Matching
280 * quoting styles:: Ways of Quoting Special Characters in Names
281 * transform:: Modifying File and Member Names
282 * after:: Operating Only on New Files
283 * recurse:: Descending into Directories
284 * one:: Crossing File System Boundaries
285
286 Reading Names from a File
287
288 * nul::
289
290 Excluding Some Files
291
292 * problems with exclude::
293
294 Wildcards Patterns and Matching
295
296 * controlling pattern-matching::
297
298 Crossing File System Boundaries
299
300 * directory:: Changing Directory
301 * absolute:: Absolute File Names
302
303 Date input formats
304
305 * General date syntax:: Common rules.
306 * Calendar date items:: 19 Dec 1994.
307 * Time of day items:: 9:20pm.
308 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
309 * Day of week items:: Monday and others.
310 * Relative items in date strings:: next tuesday, 2 years ago.
311 * Pure numbers in date strings:: 19931219, 1440.
312 * Seconds since the Epoch:: @@1078100502.
313 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
314 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
315
316 Controlling the Archive Format
317
318 * Portability:: Making @command{tar} Archives More Portable
319 * Compression:: Using Less Space through Compression
320 * Attributes:: Handling File Attributes
321 * cpio:: Comparison of @command{tar} and @command{cpio}
322
323 Making @command{tar} Archives More Portable
324
325 * Portable Names:: Portable Names
326 * dereference:: Symbolic Links
327 * old:: Old V7 Archives
328 * ustar:: Ustar Archives
329 * gnu:: GNU and old GNU format archives.
330 * posix:: @acronym{POSIX} archives
331 * Checksumming:: Checksumming Problems
332 * Large or Negative Values:: Large files, negative time stamps, etc.
333 * Other Tars:: How to Extract GNU-Specific Data Using
334 Other @command{tar} Implementations
335
336 @GNUTAR{} and @acronym{POSIX} @command{tar}
337
338 * PAX keywords:: Controlling Extended Header Keywords.
339
340 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
341
342 * Split Recovery:: Members Split Between Volumes
343 * Sparse Recovery:: Sparse Members
344
345 Using Less Space through Compression
346
347 * gzip:: Creating and Reading Compressed Archives
348 * sparse:: Archiving Sparse Files
349
350 Tapes and Other Archive Media
351
352 * Device:: Device selection and switching
353 * Remote Tape Server::
354 * Common Problems and Solutions::
355 * Blocking:: Blocking
356 * Many:: Many archives on one tape
357 * Using Multiple Tapes:: Using Multiple Tapes
358 * label:: Including a Label in the Archive
359 * verify::
360 * Write Protection::
361
362 Blocking
363
364 * Format Variations:: Format Variations
365 * Blocking Factor:: The Blocking Factor of an Archive
366
367 Many Archives on One Tape
368
369 * Tape Positioning:: Tape Positions and Tape Marks
370 * mt:: The @command{mt} Utility
371
372 Using Multiple Tapes
373
374 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
375 * Tape Files:: Tape Files
376 * Tarcat:: Concatenate Volumes into a Single Archive
377
378
379 Tar Internals
380
381 * Standard:: Basic Tar Format
382 * Extensions:: @acronym{GNU} Extensions to the Archive Format
383 * Sparse Formats:: Storing Sparse Files
384 * Snapshot Files::
385 * Dumpdir::
386
387 Storing Sparse Files
388
389 * Old GNU Format::
390 * PAX 0:: PAX Format, Versions 0.0 and 0.1
391 * PAX 1:: PAX Format, Version 1.0
392
393 Genfile
394
395 * Generate Mode:: File Generation Mode.
396 * Status Mode:: File Status Mode.
397 * Exec Mode:: Synchronous Execution mode.
398
399 Copying This Manual
400
401 * GNU Free Documentation License:: License for copying this manual
402
403 @end detailmenu
404 @end menu
405
406 @node Introduction
407 @chapter Introduction
408
409 @GNUTAR{} creates
410 and manipulates @dfn{archives} which are actually collections of
411 many other files; the program provides users with an organized and
412 systematic method for controlling a large amount of data.
413 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
414 archives need not (and these days, typically do not) reside on tapes.
415
416 @menu
417 * Book Contents:: What this Book Contains
418 * Definitions:: Some Definitions
419 * What tar Does:: What @command{tar} Does
420 * Naming tar Archives:: How @command{tar} Archives are Named
421 * Authors:: @GNUTAR{} Authors
422 * Reports:: Reporting bugs or suggestions
423 @end menu
424
425 @node Book Contents
426 @section What this Book Contains
427
428 The first part of this chapter introduces you to various terms that will
429 recur throughout the book. It also tells you who has worked on @GNUTAR{}
430 and its documentation, and where you should send bug reports
431 or comments.
432
433 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
434 gentle introduction for people who are new to using @command{tar}. It is
435 meant to be self contained, not requiring any reading from subsequent
436 chapters to make sense. It moves from topic to topic in a logical,
437 progressive order, building on information already explained.
438
439 Although the tutorial is paced and structured to allow beginners to
440 learn how to use @command{tar}, it is not intended solely for beginners.
441 The tutorial explains how to use the three most frequently used
442 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
443 two frequently used options (@samp{file} and @samp{verbose}). The other
444 chapters do not refer to the tutorial frequently; however, if a section
445 discusses something which is a complex variant of a basic concept, there
446 may be a cross reference to that basic concept. (The entire book,
447 including the tutorial, assumes that the reader understands some basic
448 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
449
450 The third chapter presents the remaining five operations, and
451 information about using @command{tar} options and option syntax.
452
453 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
454 than the reality. should think about whether this makes sense to say
455 here, or not.} The other chapters are meant to be used as a
456 reference. Each chapter presents everything that needs to be said
457 about a specific topic.
458
459 One of the chapters (@pxref{Date input formats}) exists in its
460 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
461 In addition, one section of this manual (@pxref{Standard}) contains a
462 big quote which is taken directly from @command{tar} sources.
463
464 In general, we give both long and short (abbreviated) option names
465 at least once in each section where the relevant option is covered, so
466 that novice readers will become familiar with both styles. (A few
467 options have no short versions, and the relevant sections will
468 indicate this.)
469
470 @node Definitions
471 @section Some Definitions
472
473 @cindex archive
474 @cindex tar archive
475 The @command{tar} program is used to create and manipulate @command{tar}
476 archives. An @dfn{archive} is a single file which contains the contents
477 of many files, while still identifying the names of the files, their
478 owner(s), and so forth. (In addition, archives record access
479 permissions, user and group, size in bytes, and data modification time.
480 Some archives also record the file names in each archived directory, as
481 well as other file and directory information.) You can use @command{tar}
482 to @dfn{create} a new archive in a specified directory.
483
484 @cindex member
485 @cindex archive member
486 @cindex file name
487 @cindex member name
488 The files inside an archive are called @dfn{members}. Within this
489 manual, we use the term @dfn{file} to refer only to files accessible in
490 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
491 @dfn{member} to refer only to the members of an archive. Similarly, a
492 @dfn{file name} is the name of a file, as it resides in the file system,
493 and a @dfn{member name} is the name of an archive member within the
494 archive.
495
496 @cindex extraction
497 @cindex unpacking
498 The term @dfn{extraction} refers to the process of copying an archive
499 member (or multiple members) into a file in the file system. Extracting
500 all the members of an archive is often called @dfn{extracting the
501 archive}. The term @dfn{unpack} can also be used to refer to the
502 extraction of many or all the members of an archive. Extracting an
503 archive does not destroy the archive's structure, just as creating an
504 archive does not destroy the copies of the files that exist outside of
505 the archive. You may also @dfn{list} the members in a given archive
506 (this is often thought of as ``printing'' them to the standard output,
507 or the command line), or @dfn{append} members to a pre-existing archive.
508 All of these operations can be performed using @command{tar}.
509
510 @node What tar Does
511 @section What @command{tar} Does
512
513 @cindex tar
514 The @command{tar} program provides the ability to create @command{tar}
515 archives, as well as various other kinds of manipulation. For example,
516 you can use @command{tar} on previously created archives to extract files,
517 to store additional files, or to update or list files which were already
518 stored.
519
520 Initially, @command{tar} archives were used to store files conveniently on
521 magnetic tape. The name @command{tar} comes from this use; it stands for
522 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
523 direct its output to available devices, files, or other programs (using
524 pipes). @command{tar} may even access remote devices or files (as archives).
525
526 You can use @command{tar} archives in many ways. We want to stress a few
527 of them: storage, backup, and transportation.
528
529 @FIXME{the following table entries need a bit of work..}
530 @table @asis
531 @item Storage
532 Often, @command{tar} archives are used to store related files for
533 convenient file transfer over a network. For example, the
534 @acronym{GNU} Project distributes its software bundled into
535 @command{tar} archives, so that all the files relating to a particular
536 program (or set of related programs) can be transferred as a single
537 unit.
538
539 A magnetic tape can store several files in sequence. However, the tape
540 has no names for these files; it only knows their relative position on
541 the tape. One way to store several files on one tape and retain their
542 names is by creating a @command{tar} archive. Even when the basic transfer
543 mechanism can keep track of names, as FTP can, the nuisance of handling
544 multiple files, directories, and multiple links makes @command{tar}
545 archives useful.
546
547 Archive files are also used for long-term storage. You can think of
548 this as transportation from the present into the future. (It is a
549 science-fiction idiom that you can move through time as well as in
550 space; the idea here is that @command{tar} can be used to move archives in
551 all dimensions, even time!)
552
553 @item Backup
554 Because the archive created by @command{tar} is capable of preserving
555 file information and directory structure, @command{tar} is commonly
556 used for performing full and incremental backups of disks. A backup
557 puts a collection of files (possibly pertaining to many users and
558 projects) together on a disk or a tape. This guards against
559 accidental destruction of the information in those files.
560 @GNUTAR{} has special features that allow it to be
561 used to make incremental and full dumps of all the files in a
562 file system.
563
564 @item Transportation
565 You can create an archive on one system, transfer it to another system,
566 and extract the contents there. This allows you to transport a group of
567 files from one system to another.
568 @end table
569
570 @node Naming tar Archives
571 @section How @command{tar} Archives are Named
572
573 Conventionally, @command{tar} archives are given names ending with
574 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
575 but this manual follows that convention in order to accustom readers to
576 it and to make examples more clear.
577
578 @cindex tar file
579 @cindex entry
580 @cindex tar entry
581 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
582 archive members as ``files'' or ``entries''. For people familiar with
583 the operation of @command{tar}, this causes no difficulty. However, in
584 this manual, we consistently refer to ``archives'' and ``archive
585 members'' to make learning to use @command{tar} easier for novice users.
586
587 @node Authors
588 @section @GNUTAR{} Authors
589
590 @GNUTAR{} was originally written by John Gilmore,
591 and modified by many people. The @acronym{GNU} enhancements were
592 written by Jay Fenlason, then Joy Kendall, and the whole package has
593 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
594 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
595 numerous and kind users.
596
597 We wish to stress that @command{tar} is a collective work, and owes much to
598 all those people who reported problems, offered solutions and other
599 insights, or shared their thoughts and suggestions. An impressive, yet
600 partial list of those contributors can be found in the @file{THANKS}
601 file from the @GNUTAR{} distribution.
602
603 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
604 sure i want to spell out the history in this detail, at least not for
605 the printed book. i'm just not sure it needs to be said this way.
606 i'll think about it.}
607
608 @FIXME{History is more important, and surely more interesting, than
609 actual names. Quoting names without history would be meaningless. FP}
610
611 Jay Fenlason put together a draft of a @GNUTAR{}
612 manual, borrowing notes from the original man page from John Gilmore.
613 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
614 Gorin worked on a tutorial and manual for @GNUTAR{}.
615 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
616 taking information from all these sources and merging them. Melissa
617 Weisshaus finally edited and redesigned the book to create version
618 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
619 by the current maintainer, Sergey Poznyakoff.
620
621 For version 1.12, Daniel Hagerty contributed a great deal of technical
622 consulting. In particular, he is the primary author of @ref{Backups}.
623
624 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
625 (see @url{http://savannah.gnu.org/projects/tar}), and
626 active development and maintenance work has started
627 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
628 Poznyakoff and Jeff Bailey.
629
630 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
631
632 @node Reports
633 @section Reporting bugs or suggestions
634
635 @cindex bug reports
636 @cindex reporting bugs
637 If you find problems or have suggestions about this program or manual,
638 please report them to @file{bug-tar@@gnu.org}.
639
640 When reporting a bug, please be sure to include as much detail as
641 possible, in order to reproduce it. @FIXME{Be more specific, I'd
642 like to make this node as detailed as 'Bug reporting' node in Emacs
643 manual}.
644
645 @node Tutorial
646 @chapter Tutorial Introduction to @command{tar}
647
648 This chapter guides you through some basic examples of three @command{tar}
649 operations: @option{--create}, @option{--list}, and @option{--extract}. If
650 you already know how to use some other version of @command{tar}, then you
651 may not need to read this chapter. This chapter omits most complicated
652 details about how @command{tar} works.
653
654 @menu
655 * assumptions::
656 * stylistic conventions::
657 * basic tar options:: Basic @command{tar} Operations and Options
658 * frequent operations::
659 * Two Frequent Options::
660 * create:: How to Create Archives
661 * list:: How to List Archives
662 * extract:: How to Extract Members from an Archive
663 * going further::
664 @end menu
665
666 @node assumptions
667 @section Assumptions this Tutorial Makes
668
669 This chapter is paced to allow beginners to learn about @command{tar}
670 slowly. At the same time, we will try to cover all the basic aspects of
671 these three operations. In order to accomplish both of these tasks, we
672 have made certain assumptions about your knowledge before reading this
673 manual, and the hardware you will be using:
674
675 @itemize @bullet
676 @item
677 Before you start to work through this tutorial, you should understand
678 what the terms ``archive'' and ``archive member'' mean
679 (@pxref{Definitions}). In addition, you should understand something
680 about how Unix-type operating systems work, and you should know how to
681 use some basic utilities. For example, you should know how to create,
682 list, copy, rename, edit, and delete files and directories; how to
683 change between directories; and how to figure out where you are in the
684 file system. You should have some basic understanding of directory
685 structure and how files are named according to which directory they are
686 in. You should understand concepts such as standard output and standard
687 input, what various definitions of the term ``argument'' mean, and the
688 differences between relative and absolute path names. @FIXME{and what
689 else?}
690
691 @item
692 This manual assumes that you are working from your own home directory
693 (unless we state otherwise). In this tutorial, you will create a
694 directory to practice @command{tar} commands in. When we show path names,
695 we will assume that those paths are relative to your home directory.
696 For example, my home directory path is @file{/home/fsf/melissa}. All of
697 my examples are in a subdirectory of the directory named by that path
698 name; the subdirectory is called @file{practice}.
699
700 @item
701 In general, we show examples of archives which exist on (or can be
702 written to, or worked with from) a directory on a hard disk. In most
703 cases, you could write those archives to, or work with them on any other
704 device, such as a tape drive. However, some of the later examples in
705 the tutorial and next chapter will not work on tape drives.
706 Additionally, working with tapes is much more complicated than working
707 with hard disks. For these reasons, the tutorial does not cover working
708 with tape drives. @xref{Media}, for complete information on using
709 @command{tar} archives with tape drives.
710
711 @FIXME{this is a cop out. need to add some simple tape drive info.}
712 @end itemize
713
714 @node stylistic conventions
715 @section Stylistic Conventions
716
717 In the examples, @samp{$} represents a typical shell prompt. It
718 precedes lines you should type; to make this more clear, those lines are
719 shown in @kbd{this font}, as opposed to lines which represent the
720 computer's response; those lines are shown in @code{this font}, or
721 sometimes @samp{like this}.
722
723 @c When we have lines which are too long to be
724 @c displayed in any other way, we will show them like this:
725
726 @node basic tar options
727 @section Basic @command{tar} Operations and Options
728
729 @command{tar} can take a wide variety of arguments which specify and define
730 the actions it will have on the particular set of files or the archive.
731 The main types of arguments to @command{tar} fall into one of two classes:
732 operations, and options.
733
734 Some arguments fall into a class called @dfn{operations}; exactly one of
735 these is both allowed and required for any instance of using @command{tar};
736 you may @emph{not} specify more than one. People sometimes speak of
737 @dfn{operating modes}. You are in a particular operating mode when you
738 have specified the operation which specifies it; there are eight
739 operations in total, and thus there are eight operating modes.
740
741 The other arguments fall into the class known as @dfn{options}. You are
742 not required to specify any options, and you are allowed to specify more
743 than one at a time (depending on the way you are using @command{tar} at
744 that time). Some options are used so frequently, and are so useful for
745 helping you type commands more carefully that they are effectively
746 ``required''. We will discuss them in this chapter.
747
748 You can write most of the @command{tar} operations and options in any
749 of three forms: long (mnemonic) form, short form, and old style. Some
750 of the operations and options have no short or ``old'' forms; however,
751 the operations and options which we will cover in this tutorial have
752 corresponding abbreviations. @FIXME{make sure this is still the case,
753 at the end}We will indicate those abbreviations appropriately to get
754 you used to seeing them. (Note that the ``old style'' option forms
755 exist in @GNUTAR{} for compatibility with Unix
756 @command{tar}. In this book we present a full discussion of this way
757 of writing options and operations (@pxref{Old Options}), and we discuss
758 the other two styles of writing options (@xref{Long Options}, and
759 @pxref{Short Options}).
760
761 In the examples and in the text of this tutorial, we usually use the
762 long forms of operations and options; but the ``short'' forms produce
763 the same result and can make typing long @command{tar} commands easier.
764 For example, instead of typing
765
766 @smallexample
767 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
768 @end smallexample
769
770 @noindent
771 you can type
772 @smallexample
773 @kbd{tar -c -v -f afiles.tar apple angst aspic}
774 @end smallexample
775
776 @noindent
777 or even
778 @smallexample
779 @kbd{tar -cvf afiles.tar apple angst aspic}
780 @end smallexample
781
782 @noindent
783 For more information on option syntax, see @ref{Advanced tar}. In
784 discussions in the text, when we name an option by its long form, we
785 also give the corresponding short option in parentheses.
786
787 The term, ``option'', can be confusing at times, since ``operations''
788 are often lumped in with the actual, @emph{optional} ``options'' in certain
789 general class statements. For example, we just talked about ``short and
790 long forms of options and operations''. However, experienced @command{tar}
791 users often refer to these by shorthand terms such as, ``short and long
792 options''. This term assumes that the ``operations'' are included, also.
793 Context will help you determine which definition of ``options'' to use.
794
795 Similarly, the term ``command'' can be confusing, as it is often used in
796 two different ways. People sometimes refer to @command{tar} ``commands''.
797 A @command{tar} @dfn{command} is the entire command line of user input
798 which tells @command{tar} what to do --- including the operation, options,
799 and any arguments (file names, pipes, other commands, etc). However,
800 you will also sometimes hear the term ``the @command{tar} command''. When
801 the word ``command'' is used specifically like this, a person is usually
802 referring to the @command{tar} @emph{operation}, not the whole line.
803 Again, use context to figure out which of the meanings the speaker
804 intends.
805
806 @node frequent operations
807 @section The Three Most Frequently Used Operations
808
809 Here are the three most frequently used operations (both short and long
810 forms), as well as a brief description of their meanings. The rest of
811 this chapter will cover how to use these operations in detail. We will
812 present the rest of the operations in the next chapter.
813
814 @table @option
815 @item --create
816 @itemx -c
817 Create a new @command{tar} archive.
818 @item --list
819 @itemx -t
820 List the contents of an archive.
821 @item --extract
822 @itemx -x
823 Extract one or more members from an archive.
824 @end table
825
826 @node Two Frequent Options
827 @section Two Frequently Used Options
828
829 To understand how to run @command{tar} in the three operating modes listed
830 previously, you also need to understand how to use two of the options to
831 @command{tar}: @option{--file} (which takes an archive file as an argument)
832 and @option{--verbose}. (You are usually not @emph{required} to specify
833 either of these options when you run @command{tar}, but they can be very
834 useful in making things more clear and helping you avoid errors.)
835
836 @menu
837 * file tutorial::
838 * verbose tutorial::
839 * help tutorial::
840 @end menu
841
842 @node file tutorial
843 @unnumberedsubsec The @option{--file} Option
844
845 @table @option
846 @xopindex{file, tutorial}
847 @item --file=@var{archive-name}
848 @itemx -f @var{archive-name}
849 Specify the name of an archive file.
850 @end table
851
852 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
853 use @command{tar}; this option determines the name of the archive file
854 that @command{tar} will work on.
855
856 @vrindex TAPE
857 If you don't specify this argument, then @command{tar} will examine
858 the environment variable @env{TAPE}. If it is set, its value will be
859 used as the archive name. Otherwise, @command{tar} will use the
860 default archive, determined at the compile time. Usually it is
861 standard output or some physical tape drive attached to your machine
862 (you can verify what the default is by running @kbd{tar
863 --show-defaults}, @pxref{defaults}). If there is no tape drive
864 attached, or the default is not meaningful, then @command{tar} will
865 print an error message. The error message might look roughly like one
866 of the following:
867
868 @smallexample
869 tar: can't open /dev/rmt8 : No such device or address
870 tar: can't open /dev/rsmt0 : I/O error
871 @end smallexample
872
873 @noindent
874 To avoid confusion, we recommend that you always specify an archive file
875 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
876 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
877 @ref{file}.
878
879 @node verbose tutorial
880 @unnumberedsubsec The @option{--verbose} Option
881
882 @table @option
883 @xopindex{verbose, introduced}
884 @item --verbose
885 @itemx -v
886 Show the files being worked on as @command{tar} is running.
887 @end table
888
889 @option{--verbose} (@option{-v}) shows details about the results of running
890 @command{tar}. This can be especially useful when the results might not be
891 obvious. For example, if you want to see the progress of @command{tar} as
892 it writes files into the archive, you can use the @option{--verbose}
893 option. In the beginning, you may find it useful to use
894 @option{--verbose} at all times; when you are more accustomed to
895 @command{tar}, you will likely want to use it at certain times but not at
896 others. We will use @option{--verbose} at times to help make something
897 clear, and we will give many examples both using and not using
898 @option{--verbose} to show the differences.
899
900 Each instance of @option{--verbose} on the command line increases the
901 verbosity level by one, so if you need more details on the output,
902 specify it twice.
903
904 When reading archives (@option{--list}, @option{--extract},
905 @option{--diff}), @command{tar} by default prints only the names of
906 the members being extracted. Using @option{--verbose} will show a full,
907 @command{ls} style member listing.
908
909 In contrast, when writing archives (@option{--create}, @option{--append},
910 @option{--update}), @command{tar} does not print file names by
911 default. So, a single @option{--verbose} option shows the file names
912 being added to the archive, while two @option{--verbose} options
913 enable the full listing.
914
915 For example, to create an archive in verbose mode:
916
917 @smallexample
918 $ @kbd{tar -cvf afiles.tar apple angst aspic}
919 apple
920 angst
921 aspic
922 @end smallexample
923
924 @noindent
925 Creating the same archive with the verbosity level 2 could give:
926
927 @smallexample
928 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
929 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
930 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
931 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
932 @end smallexample
933
934 @noindent
935 This works equally well using short or long forms of options. Using
936 long forms, you would simply write out the mnemonic form of the option
937 twice, like this:
938
939 @smallexample
940 $ @kbd{tar --create --verbose --verbose @dots{}}
941 @end smallexample
942
943 @noindent
944 Note that you must double the hyphens properly each time.
945
946 Later in the tutorial, we will give examples using @w{@option{--verbose
947 --verbose}}.
948
949 @anchor{verbose member listing}
950 The full output consists of six fields:
951
952 @itemize @bullet
953 @item File type and permissions in symbolic form.
954 These are displayed in the same format as the first column of
955 @command{ls -l} output (@pxref{What information is listed,
956 format=verbose, Verbose listing, fileutils, GNU file utilities}).
957
958 @item Owner name and group separated by a slash character.
959 If these data are not available (for example, when listing a @samp{v7} format
960 archive), numeric ID values are printed instead.
961
962 @item Size of the file, in bytes.
963
964 @item File modification date in ISO 8601 format.
965
966 @item File modification time.
967
968 @item File name.
969 If the name contains any special characters (white space, newlines,
970 etc.) these are displayed in an unambiguous form using so called
971 @dfn{quoting style}. For the detailed discussion of available styles
972 and on how to use them, see @ref{quoting styles}.
973
974 Depending on the file type, the name can be followed by some
975 additional information, described in the following table:
976
977 @table @samp
978 @item -> @var{link-name}
979 The file or archive member is a @dfn{symbolic link} and
980 @var{link-name} is the name of file it links to.
981
982 @item link to @var{link-name}
983 The file or archive member is a @dfn{hard link} and @var{link-name} is
984 the name of file it links to.
985
986 @item --Long Link--
987 The archive member is an old GNU format long link. You will normally
988 not encounter this.
989
990 @item --Long Name--
991 The archive member is an old GNU format long name. You will normally
992 not encounter this.
993
994 @item --Volume Header--
995 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
996
997 @item --Continued at byte @var{n}--
998 Encountered only at the beginning of a multy-volume archive
999 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1000 from the previous volume. The number @var{n} gives the offset where
1001 the original file was split.
1002
1003 @item --Mangled file names--
1004 This archive member contains @dfn{mangled file names} declarations,
1005 a special member type that was used by early versions of @GNUTAR{}.
1006 You probably will never encounter this, unless you are reading a very
1007 old archive.
1008
1009 @item unknown file type @var{c}
1010 An archive member of unknown type. @var{c} is the type character from
1011 the archive header. If you encounter such a message, it means that
1012 either your archive contains proprietary member types @GNUTAR{} is not
1013 able to handle, or the archive is corrupted.
1014 @end table
1015
1016 @end itemize
1017
1018 For example, here is an archive listing containing most of the special
1019 suffixes explained above:
1020
1021 @smallexample
1022 @group
1023 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1024 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1025 byte 32456--
1026 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1027 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1028 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1029 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1030 @end group
1031 @end smallexample
1032
1033 @smallexample
1034 @end smallexample
1035
1036 @node help tutorial
1037 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1038
1039 @table @option
1040 @opindex help
1041 @item --help
1042
1043 The @option{--help} option to @command{tar} prints out a very brief list of
1044 all operations and option available for the current version of
1045 @command{tar} available on your system.
1046 @end table
1047
1048 @node create
1049 @section How to Create Archives
1050 @UNREVISED
1051
1052 @cindex Creation of the archive
1053 @cindex Archive, creation of
1054 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1055 you use to create a @command{tar} archive. We will explain
1056 @option{--create} first because, in order to learn about the other
1057 operations, you will find it useful to have an archive available to
1058 practice on.
1059
1060 To make this easier, in this section you will first create a directory
1061 containing three files. Then, we will show you how to create an
1062 @emph{archive} (inside the new directory). Both the directory, and
1063 the archive are specifically for you to practice on. The rest of this
1064 chapter and the next chapter will show many examples using this
1065 directory and the files you will create: some of those files may be
1066 other directories and other archives.
1067
1068 The three files you will archive in this example are called
1069 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1070 @file{collection.tar}.
1071
1072 This section will proceed slowly, detailing how to use @option{--create}
1073 in @code{verbose} mode, and showing examples using both short and long
1074 forms. In the rest of the tutorial, and in the examples in the next
1075 chapter, we will proceed at a slightly quicker pace. This section
1076 moves more slowly to allow beginning users to understand how
1077 @command{tar} works.
1078
1079 @menu
1080 * prepare for examples::
1081 * Creating the archive::
1082 * create verbose::
1083 * short create::
1084 * create dir::
1085 @end menu
1086
1087 @node prepare for examples
1088 @subsection Preparing a Practice Directory for Examples
1089
1090 To follow along with this and future examples, create a new directory
1091 called @file{practice} containing files called @file{blues}, @file{folk}
1092 and @file{jazz}. The files can contain any information you like:
1093 ideally, they should contain information which relates to their names,
1094 and be of different lengths. Our examples assume that @file{practice}
1095 is a subdirectory of your home directory.
1096
1097 Now @command{cd} to the directory named @file{practice}; @file{practice}
1098 is now your @dfn{working directory}. (@emph{Please note}: Although
1099 the full path name of this directory is
1100 @file{/@var{homedir}/practice}, in our examples we will refer to
1101 this directory as @file{practice}; the @var{homedir} is presumed.
1102
1103 In general, you should check that the files to be archived exist where
1104 you think they do (in the working directory) by running @command{ls}.
1105 Because you just created the directory and the files and have changed to
1106 that directory, you probably don't need to do that this time.
1107
1108 It is very important to make sure there isn't already a file in the
1109 working directory with the archive name you intend to use (in this case,
1110 @samp{collection.tar}), or that you don't care about its contents.
1111 Whenever you use @samp{create}, @command{tar} will erase the current
1112 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1113 will not tell you if you are about to overwrite an archive unless you
1114 specify an option which does this (@pxref{backup}, for the
1115 information on how to do so). To add files to an existing archive,
1116 you need to use a different option, such as @option{--append} (@option{-r}); see
1117 @ref{append} for information on how to do this.
1118
1119 @node Creating the archive
1120 @subsection Creating the Archive
1121
1122 @xopindex{create, introduced}
1123 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1124 archive named @file{collection.tar}, use the following command:
1125
1126 @smallexample
1127 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1128 @end smallexample
1129
1130 The order of the arguments is not very important, @emph{when using long
1131 option forms}. You could also say:
1132
1133 @smallexample
1134 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1135 @end smallexample
1136
1137 @noindent
1138 However, you can see that this order is harder to understand; this is
1139 why we will list the arguments in the order that makes the commands
1140 easiest to understand (and we encourage you to do the same when you use
1141 @command{tar}, to avoid errors).
1142
1143 Note that the sequence
1144 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1145 If you substituted any other string of characters for
1146 @kbd{collection.tar}, then that string would become the name of the
1147 archive file you create.
1148
1149 The order of the options becomes more important when you begin to use
1150 short forms. With short forms, if you type commands in the wrong order
1151 (even if you type them correctly in all other ways), you may end up with
1152 results you don't expect. For this reason, it is a good idea to get
1153 into the habit of typing options in the order that makes inherent sense.
1154 @xref{short create}, for more information on this.
1155
1156 In this example, you type the command as shown above: @option{--create}
1157 is the operation which creates the new archive
1158 (@file{collection.tar}), and @option{--file} is the option which lets
1159 you give it the name you chose. The files, @file{blues}, @file{folk},
1160 and @file{jazz}, are now members of the archive, @file{collection.tar}
1161 (they are @dfn{file name arguments} to the @option{--create} operation.
1162 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1163 in the archive, they are called @emph{archive members}, not files.
1164 (@pxref{Definitions,members}).
1165
1166 When you create an archive, you @emph{must} specify which files you
1167 want placed in the archive. If you do not specify any archive
1168 members, @GNUTAR{} will complain.
1169
1170 If you now list the contents of the working directory (@command{ls}), you will
1171 find the archive file listed as well as the files you saw previously:
1172
1173 @smallexample
1174 blues folk jazz collection.tar
1175 @end smallexample
1176
1177 @noindent
1178 Creating the archive @samp{collection.tar} did not destroy the copies of
1179 the files in the directory.
1180
1181 Keep in mind that if you don't indicate an operation, @command{tar} will not
1182 run and will prompt you for one. If you don't name any files, @command{tar}
1183 will complain. You must have write access to the working directory,
1184 or else you will not be able to create an archive in that directory.
1185
1186 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1187 an existing archive; it will delete the archive and write a new one.
1188 Use @option{--append} (@option{-r}) instead. @xref{append}.
1189
1190 @node create verbose
1191 @subsection Running @option{--create} with @option{--verbose}
1192
1193 @xopindex{create, using with @option{--verbose}}
1194 @xopindex{verbose, using with @option{--create}}
1195 If you include the @option{--verbose} (@option{-v}) option on the command line,
1196 @command{tar} will list the files it is acting on as it is working. In
1197 verbose mode, the @code{create} example above would appear as:
1198
1199 @smallexample
1200 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1201 blues
1202 folk
1203 jazz
1204 @end smallexample
1205
1206 This example is just like the example we showed which did not use
1207 @option{--verbose}, except that @command{tar} generated the remaining lines
1208 @iftex
1209 (note the different font styles).
1210 @end iftex
1211 @ifinfo
1212 .
1213 @end ifinfo
1214
1215 In the rest of the examples in this chapter, we will frequently use
1216 @code{verbose} mode so we can show actions or @command{tar} responses that
1217 you would otherwise not see, and which are important for you to
1218 understand.
1219
1220 @node short create
1221 @subsection Short Forms with @samp{create}
1222
1223 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1224 basic uses of @command{tar}, and you will use it countless times.
1225 Eventually, you will probably want to use abbreviated (or ``short'')
1226 forms of options. A full discussion of the three different forms that
1227 options can take appears in @ref{Styles}; for now, here is what the
1228 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1229 using short option forms:
1230
1231 @smallexample
1232 $ @kbd{tar -cvf collection.tar blues folk jazz}
1233 blues
1234 folk
1235 jazz
1236 @end smallexample
1237
1238 @noindent
1239 As you can see, the system responds the same no matter whether you use
1240 long or short option forms.
1241
1242 @FIXME{i don't like how this is worded:} One difference between using
1243 short and long option forms is that, although the exact placement of
1244 arguments following options is no more specific when using short forms,
1245 it is easier to become confused and make a mistake when using short
1246 forms. For example, suppose you attempted the above example in the
1247 following way:
1248
1249 @smallexample
1250 $ @kbd{tar -cfv collection.tar blues folk jazz}
1251 @end smallexample
1252
1253 @noindent
1254 In this case, @command{tar} will make an archive file called @file{v},
1255 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1256 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1257 is thus taken to be the chosen archive file name. @command{tar} will try
1258 to add a file called @file{collection.tar} to the @file{v} archive file;
1259 if the file @file{collection.tar} did not already exist, @command{tar} will
1260 report an error indicating that this file does not exist. If the file
1261 @file{collection.tar} does already exist (e.g., from a previous command
1262 you may have run), then @command{tar} will add this file to the archive.
1263 Because the @option{-v} option did not get registered, @command{tar} will not
1264 run under @samp{verbose} mode, and will not report its progress.
1265
1266 The end result is that you may be quite confused about what happened,
1267 and possibly overwrite a file. To illustrate this further, we will show
1268 you how an example we showed previously would look using short forms.
1269
1270 This example,
1271
1272 @smallexample
1273 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1274 @end smallexample
1275
1276 @noindent
1277 is confusing as it is. When shown using short forms, however, it
1278 becomes much more so:
1279
1280 @smallexample
1281 $ @kbd{tar blues -c folk -f collection.tar jazz}
1282 @end smallexample
1283
1284 @noindent
1285 It would be very easy to put the wrong string of characters
1286 immediately following the @option{-f}, but doing that could sacrifice
1287 valuable data.
1288
1289 For this reason, we recommend that you pay very careful attention to
1290 the order of options and placement of file and archive names,
1291 especially when using short option forms. Not having the option name
1292 written out mnemonically can affect how well you remember which option
1293 does what, and therefore where different names have to be placed.
1294
1295 @node create dir
1296 @subsection Archiving Directories
1297
1298 @cindex Archiving Directories
1299 @cindex Directories, Archiving
1300 You can archive a directory by specifying its directory name as a
1301 file name argument to @command{tar}. The files in the directory will be
1302 archived relative to the working directory, and the directory will be
1303 re-created along with its contents when the archive is extracted.
1304
1305 To archive a directory, first move to its superior directory. If you
1306 have followed the previous instructions in this tutorial, you should
1307 type:
1308
1309 @smallexample
1310 $ @kbd{cd ..}
1311 $
1312 @end smallexample
1313
1314 @noindent
1315 This will put you into the directory which contains @file{practice},
1316 i.e., your home directory. Once in the superior directory, you can
1317 specify the subdirectory, @file{practice}, as a file name argument. To
1318 store @file{practice} in the new archive file @file{music.tar}, type:
1319
1320 @smallexample
1321 $ @kbd{tar --create --verbose --file=music.tar practice}
1322 @end smallexample
1323
1324 @noindent
1325 @command{tar} should output:
1326
1327 @smallexample
1328 practice/
1329 practice/blues
1330 practice/folk
1331 practice/jazz
1332 practice/collection.tar
1333 @end smallexample
1334
1335 Note that the archive thus created is not in the subdirectory
1336 @file{practice}, but rather in the current working directory---the
1337 directory from which @command{tar} was invoked. Before trying to archive a
1338 directory from its superior directory, you should make sure you have
1339 write access to the superior directory itself, not only the directory
1340 you are trying archive with @command{tar}. For example, you will probably
1341 not be able to store your home directory in an archive by invoking
1342 @command{tar} from the root directory; @xref{absolute}. (Note
1343 also that @file{collection.tar}, the original archive file, has itself
1344 been archived. @command{tar} will accept any file as a file to be
1345 archived, regardless of its content. When @file{music.tar} is
1346 extracted, the archive file @file{collection.tar} will be re-written
1347 into the file system).
1348
1349 If you give @command{tar} a command such as
1350
1351 @smallexample
1352 $ @kbd{tar --create --file=foo.tar .}
1353 @end smallexample
1354
1355 @noindent
1356 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1357 dumped}. This happens because @command{tar} creates the archive
1358 @file{foo.tar} in the current directory before putting any files into
1359 it. Then, when @command{tar} attempts to add all the files in the
1360 directory @file{.} to the archive, it notices that the file
1361 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1362 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1363 will continue in this case, and create the archive
1364 normally, except for the exclusion of that one file. (@emph{Please
1365 note:} Other implementations of @command{tar} may not be so clever;
1366 they will enter an infinite loop when this happens, so you should not
1367 depend on this behavior unless you are certain you are running
1368 @GNUTAR{}. In general, it is wise to always place the archive outside
1369 of the directory being dumped.
1370
1371 @node list
1372 @section How to List Archives
1373
1374 @opindex list
1375 Frequently, you will find yourself wanting to determine exactly what a
1376 particular archive contains. You can use the @option{--list}
1377 (@option{-t}) operation to get the member names as they currently
1378 appear in the archive, as well as various attributes of the files at
1379 the time they were archived. For example, you can examine the archive
1380 @file{collection.tar} that you created in the last section with the
1381 command,
1382
1383 @smallexample
1384 $ @kbd{tar --list --file=collection.tar}
1385 @end smallexample
1386
1387 @noindent
1388 The output of @command{tar} would then be:
1389
1390 @smallexample
1391 blues
1392 folk
1393 jazz
1394 @end smallexample
1395
1396 @noindent
1397 The archive @file{bfiles.tar} would list as follows:
1398
1399 @smallexample
1400 ./birds
1401 baboon
1402 ./box
1403 @end smallexample
1404
1405 @noindent
1406 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1407 @var{archive-name}}) option just as with @option{--create}
1408 (@option{-c}) to specify the name of the archive.
1409
1410 @xopindex{list, using with @option{--verbose}}
1411 @xopindex{verbose, using with @option{--list}}
1412 If you use the @option{--verbose} (@option{-v}) option with
1413 @option{--list}, then @command{tar} will print out a listing
1414 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1415 forth. This output is described in detail in @ref{verbose member listing}.
1416
1417 If you had used @option{--verbose} (@option{-v}) mode, the example
1418 above would look like:
1419
1420 @smallexample
1421 $ @kbd{tar --list --verbose --file=collection.tar folk}
1422 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1423 @end smallexample
1424
1425 @cindex listing member and file names
1426 @anchor{listing member and file names}
1427 It is important to notice that the output of @kbd{tar --list
1428 --verbose} does not necessarily match that produced by @kbd{tar
1429 --create --verbose} while creating the archive. It is because
1430 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1431 prefixes from file names before storing them in the archive
1432 (@xref{absolute}, for more information). In other
1433 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1434 an archive and @dfn{member names} when listing it. Consider this
1435 example:
1436
1437 @smallexample
1438 @group
1439 $ @kbd{tar cfv archive /etc/mail}
1440 tar: Removing leading `/' from member names
1441 /etc/mail/
1442 /etc/mail/sendmail.cf
1443 /etc/mail/aliases
1444 $ @kbd{tar tf archive}
1445 etc/mail/
1446 etc/mail/sendmail.cf
1447 etc/mail/aliases
1448 @end group
1449 @end smallexample
1450
1451 @opindex show-stored-names
1452 This default behavior can sometimes be inconvenient. You can force
1453 @GNUTAR{} show member names when creating archive by supplying
1454 @option{--show-stored-names} option.
1455
1456 @table @option
1457 @item --show-stored-names
1458 Print member (as opposed to @emph{file}) names when creating the archive.
1459 @end table
1460
1461 @cindex File name arguments, using @option{--list} with
1462 @xopindex{list, using with file name arguments}
1463 You can specify one or more individual member names as arguments when
1464 using @samp{list}. In this case, @command{tar} will only list the
1465 names of members you identify. For example, @w{@kbd{tar --list
1466 --file=afiles.tar apple}} would only print @file{apple}.
1467
1468 Because @command{tar} preserves paths, file names must be specified as
1469 they appear in the archive (i.e., relative to the directory from which
1470 the archive was created). Therefore, it is essential when specifying
1471 member names to @command{tar} that you give the exact member names.
1472 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1473 error message something like @samp{tar: birds: Not found in archive},
1474 because there is no member named @file{birds}, only one named
1475 @file{./birds}. While the names @file{birds} and @file{./birds} name
1476 the same file, @emph{member} names by default are compared verbatim.
1477
1478 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1479 with @file{baboon}, because this exact member name is in the archive file
1480 @file{bfiles.tar}. If you are not sure of the exact file name,
1481 use @dfn{globbing patterns}, for example:
1482
1483 @smallexample
1484 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1485 @end smallexample
1486
1487 @noindent
1488 will list all members whose name contains @samp{b}. @xref{wildcards},
1489 for a detailed discussion of globbing patterns and related
1490 @command{tar} command line options.
1491
1492 @menu
1493 * list dir::
1494 @end menu
1495
1496 @node list dir
1497 @unnumberedsubsec Listing the Contents of a Stored Directory
1498
1499 To get information about the contents of an archived directory,
1500 use the directory name as a file name argument in conjunction with
1501 @option{--list} (@option{-t}). To find out file attributes, include the
1502 @option{--verbose} (@option{-v}) option.
1503
1504 For example, to find out about files in the directory @file{practice}, in
1505 the archive file @file{music.tar}, type:
1506
1507 @smallexample
1508 $ @kbd{tar --list --verbose --file=music.tar practice}
1509 @end smallexample
1510
1511 @command{tar} responds:
1512
1513 @smallexample
1514 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1515 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1516 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1517 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1518 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1519 @end smallexample
1520
1521 When you use a directory name as a file name argument, @command{tar} acts on
1522 all the files (including sub-directories) in that directory.
1523
1524 @node extract
1525 @section How to Extract Members from an Archive
1526 @UNREVISED
1527 @cindex Extraction
1528 @cindex Retrieving files from an archive
1529 @cindex Resurrecting files from an archive
1530
1531 @opindex extract
1532 Creating an archive is only half the job---there is no point in storing
1533 files in an archive if you can't retrieve them. The act of retrieving
1534 members from an archive so they can be used and manipulated as
1535 unarchived files again is called @dfn{extraction}. To extract files
1536 from an archive, use the @option{--extract} (@option{--get} or
1537 @option{-x}) operation. As with @option{--create}, specify the name
1538 of the archive with @option{--file} (@option{-f}) option. Extracting
1539 an archive does not modify the archive in any way; you can extract it
1540 multiple times if you want or need to.
1541
1542 Using @option{--extract}, you can extract an entire archive, or specific
1543 files. The files can be directories containing other files, or not. As
1544 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1545 long form of the operation without affecting the performance.
1546
1547 @menu
1548 * extracting archives::
1549 * extracting files::
1550 * extract dir::
1551 * extracting untrusted archives::
1552 * failing commands::
1553 @end menu
1554
1555 @node extracting archives
1556 @subsection Extracting an Entire Archive
1557
1558 To extract an entire archive, specify the archive file name only, with
1559 no individual file names as arguments. For example,
1560
1561 @smallexample
1562 $ @kbd{tar -xvf collection.tar}
1563 @end smallexample
1564
1565 @noindent
1566 produces this:
1567
1568 @smallexample
1569 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1570 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1571 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1572 @end smallexample
1573
1574 @node extracting files
1575 @subsection Extracting Specific Files
1576
1577 To extract specific archive members, give their exact member names as
1578 arguments, as printed by @option{--list} (@option{-t}). If you had
1579 mistakenly deleted one of the files you had placed in the archive
1580 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1581 from the archive without changing the archive's structure. Its
1582 contents will be identical to the original file @file{blues} that you
1583 deleted.
1584
1585 First, make sure you are in the @file{practice} directory, and list the
1586 files in the directory. Now, delete the file, @samp{blues}, and list
1587 the files in the directory again.
1588
1589 You can now extract the member @file{blues} from the archive file
1590 @file{collection.tar} like this:
1591
1592 @smallexample
1593 $ @kbd{tar --extract --file=collection.tar blues}
1594 @end smallexample
1595
1596 @noindent
1597 If you list the files in the directory again, you will see that the file
1598 @file{blues} has been restored, with its original permissions, data
1599 modification times, and owner.@footnote{This is only accidentally
1600 true, but not in general. Whereas modification times are always
1601 restored, in most cases, one has to be root for restoring the owner,
1602 and use a special option for restoring permissions. Here, it just
1603 happens that the restoring user is also the owner of the archived
1604 members, and that the current @code{umask} is compatible with original
1605 permissions.} (These parameters will be identical to those which
1606 the file had when you originally placed it in the archive; any changes
1607 you may have made before deleting the file from the file system,
1608 however, will @emph{not} have been made to the archive member.) The
1609 archive file, @samp{collection.tar}, is the same as it was before you
1610 extracted @samp{blues}. You can confirm this by running @command{tar} with
1611 @option{--list} (@option{-t}).
1612
1613 Remember that as with other operations, specifying the exact member
1614 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1615 will fail, because there is no member named @file{birds}. To extract
1616 the member named @file{./birds}, you must specify @w{@kbd{tar
1617 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1618 exact member names, use @option{--list} (@option{-t}) option
1619 (@pxref{list}). You can also extract those members that match a
1620 specific @dfn{globbing pattern}. For example, to extract from
1621 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1622 directory prefix, you could type:
1623
1624 @smallexample
1625 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1626 @end smallexample
1627
1628 @noindent
1629 Here, @option{--wildcards} instructs @command{tar} to treat
1630 command line arguments as globbing patterns and @option{--no-anchored}
1631 informs it that the patterns apply to member names after any @samp{/}
1632 delimiter. The use of globbing patterns is discussed in detail in
1633 @xref{wildcards}.
1634
1635 You can extract a file to standard output by combining the above options
1636 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1637 Output}).
1638
1639 If you give the @option{--verbose} option, then @option{--extract}
1640 will print the names of the archive members as it extracts them.
1641
1642 @node extract dir
1643 @subsection Extracting Files that are Directories
1644
1645 Extracting directories which are members of an archive is similar to
1646 extracting other files. The main difference to be aware of is that if
1647 the extracted directory has the same name as any directory already in
1648 the working directory, then files in the extracted directory will be
1649 placed into the directory of the same name. Likewise, if there are
1650 files in the pre-existing directory with the same names as the members
1651 which you extract, the files from the extracted archive will replace
1652 the files already in the working directory (and possible
1653 subdirectories). This will happen regardless of whether or not the
1654 files in the working directory were more recent than those extracted
1655 (there exist, however, special options that alter this behavior
1656 @pxref{Writing}).
1657
1658 However, if a file was stored with a directory name as part of its file
1659 name, and that directory does not exist under the working directory when
1660 the file is extracted, @command{tar} will create the directory.
1661
1662 We can demonstrate how to use @option{--extract} to extract a directory
1663 file with an example. Change to the @file{practice} directory if you
1664 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1665 go back to the parent directory and extract the archive
1666 @file{music.tar}. You may either extract the entire archive, or you may
1667 extract only the files you just deleted. To extract the entire archive,
1668 don't give any file names as arguments after the archive name
1669 @file{music.tar}. To extract only the files you deleted, use the
1670 following command:
1671
1672 @smallexample
1673 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1674 practice/folk
1675 practice/jazz
1676 @end smallexample
1677
1678 @noindent
1679 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1680 would have displayed more detail about the extracted files, as shown
1681 in the example below:
1682
1683 @smallexample
1684 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1685 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1686 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1687 @end smallexample
1688
1689 @noindent
1690 Because you created the directory with @file{practice} as part of the
1691 file names of each of the files by archiving the @file{practice}
1692 directory as @file{practice}, you must give @file{practice} as part
1693 of the file names when you extract those files from the archive.
1694
1695 @node extracting untrusted archives
1696 @subsection Extracting Archives from Untrusted Sources
1697
1698 Extracting files from archives can overwrite files that already exist.
1699 If you receive an archive from an untrusted source, you should make a
1700 new directory and extract into that directory, so that you don't have
1701 to worry about the extraction overwriting one of your existing files.
1702 For example, if @file{untrusted.tar} came from somewhere else on the
1703 Internet, and you don't necessarily trust its contents, you can
1704 extract it as follows:
1705
1706 @smallexample
1707 $ @kbd{mkdir newdir}
1708 $ @kbd{cd newdir}
1709 $ @kbd{tar -xvf ../untrusted.tar}
1710 @end smallexample
1711
1712 It is also a good practice to examine contents of the archive
1713 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1714 with @option{--verbose} (@option{-v}).
1715
1716 @node failing commands
1717 @subsection Commands That Will Fail
1718
1719 Here are some sample commands you might try which will not work, and why
1720 they won't work.
1721
1722 If you try to use this command,
1723
1724 @smallexample
1725 $ @kbd{tar -xvf music.tar folk jazz}
1726 @end smallexample
1727
1728 @noindent
1729 you will get the following response:
1730
1731 @smallexample
1732 tar: folk: Not found in archive
1733 tar: jazz: Not found in archive
1734 $
1735 @end smallexample
1736
1737 @noindent
1738 This is because these files were not originally @emph{in} the parent
1739 directory @file{..}, where the archive is located; they were in the
1740 @file{practice} directory, and their file names reflect this:
1741
1742 @smallexample
1743 $ @kbd{tar -tvf music.tar}
1744 practice/folk
1745 practice/jazz
1746 practice/rock
1747 @end smallexample
1748
1749 @FIXME{make sure the above works when going through the examples in
1750 order...}
1751
1752 @noindent
1753 Likewise, if you try to use this command,
1754
1755 @smallexample
1756 $ @kbd{tar -tvf music.tar folk jazz}
1757 @end smallexample
1758
1759 @noindent
1760 you would get a similar response. Members with those names are not in the
1761 archive. You must use the correct member names, or wildcards, in order
1762 to extract the files from the archive.
1763
1764 If you have forgotten the correct names of the files in the archive,
1765 use @w{@kbd{tar --list --verbose}} to list them correctly.
1766
1767 @FIXME{more examples, here? hag thinks it's a good idea.}
1768
1769 @node going further
1770 @section Going Further Ahead in this Manual
1771
1772 @FIXME{need to write up a node here about the things that are going to
1773 be in the rest of the manual.}
1774
1775 @node tar invocation
1776 @chapter Invoking @GNUTAR{}
1777 @UNREVISED
1778
1779 This chapter is about how one invokes the @GNUTAR{}
1780 command, from the command synopsis (@pxref{Synopsis}). There are
1781 numerous options, and many styles for writing them. One mandatory
1782 option specifies the operation @command{tar} should perform
1783 (@pxref{Operation Summary}), other options are meant to detail how
1784 this operation should be performed (@pxref{Option Summary}).
1785 Non-option arguments are not always interpreted the same way,
1786 depending on what the operation is.
1787
1788 You will find in this chapter everything about option styles and rules for
1789 writing them (@pxref{Styles}). On the other hand, operations and options
1790 are fully described elsewhere, in other chapters. Here, you will find
1791 only synthetic descriptions for operations and options, together with
1792 pointers to other parts of the @command{tar} manual.
1793
1794 Some options are so special they are fully described right in this
1795 chapter. They have the effect of inhibiting the normal operation of
1796 @command{tar} or else, they globally alter the amount of feedback the user
1797 receives about what is going on. These are the @option{--help} and
1798 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1799 and @option{--interactive} options (@pxref{interactive}).
1800
1801 @menu
1802 * Synopsis::
1803 * using tar options::
1804 * Styles::
1805 * All Options::
1806 * help::
1807 * defaults::
1808 * verbose::
1809 * interactive::
1810 @end menu
1811
1812 @node Synopsis
1813 @section General Synopsis of @command{tar}
1814
1815 The @GNUTAR{} program is invoked as either one of:
1816
1817 @smallexample
1818 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1819 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1820 @end smallexample
1821
1822 The second form is for when old options are being used.
1823
1824 You can use @command{tar} to store files in an archive, to extract them from
1825 an archive, and to do other types of archive manipulation. The primary
1826 argument to @command{tar}, which is called the @dfn{operation}, specifies
1827 which action to take. The other arguments to @command{tar} are either
1828 @dfn{options}, which change the way @command{tar} performs an operation,
1829 or file names or archive members, which specify the files or members
1830 @command{tar} is to act on.
1831
1832 You can actually type in arguments in any order, even if in this manual
1833 the options always precede the other arguments, to make examples easier
1834 to understand. Further, the option stating the main operation mode
1835 (the @command{tar} main command) is usually given first.
1836
1837 Each @var{name} in the synopsis above is interpreted as an archive member
1838 name when the main command is one of @option{--compare}
1839 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1840 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1841 @option{--update} (@option{-u}). When naming archive members, you
1842 must give the exact name of the member in the archive, as it is
1843 printed by @option{--list}. For @option{--append} (@option{-r}) and
1844 @option{--create} (@option{-c}), these @var{name} arguments specify
1845 the names of either files or directory hierarchies to place in the archive.
1846 These files or hierarchies should already exist in the file system,
1847 prior to the execution of the @command{tar} command.
1848
1849 @command{tar} interprets relative file names as being relative to the
1850 working directory. @command{tar} will make all file names relative
1851 (by removing leading slashes when archiving or restoring files),
1852 unless you specify otherwise (using the @option{--absolute-names}
1853 option). @xref{absolute}, for more information about
1854 @option{--absolute-names}.
1855
1856 If you give the name of a directory as either a file name or a member
1857 name, then @command{tar} acts recursively on all the files and directories
1858 beneath that directory. For example, the name @file{/} identifies all
1859 the files in the file system to @command{tar}.
1860
1861 The distinction between file names and archive member names is especially
1862 important when shell globbing is used, and sometimes a source of confusion
1863 for newcomers. @xref{wildcards}, for more information about globbing.
1864 The problem is that shells may only glob using existing files in the
1865 file system. Only @command{tar} itself may glob on archive members, so when
1866 needed, you must ensure that wildcard characters reach @command{tar} without
1867 being interpreted by the shell first. Using a backslash before @samp{*}
1868 or @samp{?}, or putting the whole argument between quotes, is usually
1869 sufficient for this.
1870
1871 Even if @var{name}s are often specified on the command line, they
1872 can also be read from a text file in the file system, using the
1873 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1874
1875 If you don't use any file name arguments, @option{--append} (@option{-r}),
1876 @option{--delete} and @option{--concatenate} (@option{--catenate},
1877 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1878 will usually yield a diagnostic and inhibit @command{tar} execution.
1879 The other operations of @command{tar} (@option{--list},
1880 @option{--extract}, @option{--compare}, and @option{--update})
1881 will act on the entire contents of the archive.
1882
1883 @cindex exit status
1884 @cindex return status
1885 Besides successful exits, @GNUTAR{} may fail for
1886 many reasons. Some reasons correspond to bad usage, that is, when the
1887 @command{tar} command is improperly written. Errors may be
1888 encountered later, while encountering an error processing the archive
1889 or the files. Some errors are recoverable, in which case the failure
1890 is delayed until @command{tar} has completed all its work. Some
1891 errors are such that it would not meaningful, or at least risky, to
1892 continue processing: @command{tar} then aborts processing immediately.
1893 All abnormal exits, whether immediate or delayed, should always be
1894 clearly diagnosed on @code{stderr}, after a line stating the nature of
1895 the error.
1896
1897 @GNUTAR{} returns only a few exit statuses. I'm really
1898 aiming simplicity in that area, for now. If you are not using the
1899 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1900 that everything went well, besides maybe innocuous warnings. Nonzero
1901 means that something went wrong. Right now, as of today, ``nonzero''
1902 is almost always 2, except for remote operations, where it may be
1903 128.
1904
1905 @node using tar options
1906 @section Using @command{tar} Options
1907
1908 @GNUTAR{} has a total of eight operating modes which
1909 allow you to perform a variety of tasks. You are required to choose
1910 one operating mode each time you employ the @command{tar} program by
1911 specifying one, and only one operation as an argument to the
1912 @command{tar} command (two lists of four operations each may be found
1913 at @ref{frequent operations} and @ref{Operations}). Depending on
1914 circumstances, you may also wish to customize how the chosen operating
1915 mode behaves. For example, you may wish to change the way the output
1916 looks, or the format of the files that you wish to archive may require
1917 you to do something special in order to make the archive look right.
1918
1919 You can customize and control @command{tar}'s performance by running
1920 @command{tar} with one or more options (such as @option{--verbose}
1921 (@option{-v}), which we used in the tutorial). As we said in the
1922 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1923 their name suggests) optional. Depending on the operating mode, you
1924 may specify one or more options. Different options will have different
1925 effects, but in general they all change details of the operation, such
1926 as archive format, archive name, or level of user interaction. Some
1927 options make sense with all operating modes, while others are
1928 meaningful only with particular modes. You will likely use some
1929 options frequently, while you will only use others infrequently, or
1930 not at all. (A full list of options is available in @pxref{All Options}.)
1931
1932 @vrindex TAR_OPTIONS, environment variable
1933 @anchor{TAR_OPTIONS}
1934 The @env{TAR_OPTIONS} environment variable specifies default options to
1935 be placed in front of any explicit options. For example, if
1936 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1937 if the two options @option{-v} and @option{--unlink-first} had been
1938 specified before any explicit options. Option specifications are
1939 separated by whitespace. A backslash escapes the next character, so it
1940 can be used to specify an option containing whitespace or a backslash.
1941
1942 Note that @command{tar} options are case sensitive. For example, the
1943 options @option{-T} and @option{-t} are different; the first requires an
1944 argument for stating the name of a file providing a list of @var{name}s,
1945 while the second does not require an argument and is another way to
1946 write @option{--list} (@option{-t}).
1947
1948 In addition to the eight operations, there are many options to
1949 @command{tar}, and three different styles for writing both: long (mnemonic)
1950 form, short form, and old style. These styles are discussed below.
1951 Both the options and the operations can be written in any of these three
1952 styles.
1953
1954 @FIXME{menu at end of this node. need to think of an actual outline
1955 for this chapter; probably do that after stuff from chapter 4 is
1956 incorporated.}
1957
1958 @node Styles
1959 @section The Three Option Styles
1960
1961 There are three styles for writing operations and options to the command
1962 line invoking @command{tar}. The different styles were developed at
1963 different times during the history of @command{tar}. These styles will be
1964 presented below, from the most recent to the oldest.
1965
1966 Some options must take an argument. (For example, @option{--file}
1967 (@option{-f})) takes the name of an archive file as an argument. If
1968 you do not supply an archive file name, @command{tar} will use a
1969 default, but this can be confusing; thus, we recommend that you always
1970 supply a specific archive file name.) Where you @emph{place} the
1971 arguments generally depends on which style of options you choose. We
1972 will detail specific information relevant to each option style in the
1973 sections on the different option styles, below. The differences are
1974 subtle, yet can often be very important; incorrect option placement
1975 can cause you to overwrite a number of important files. We urge you
1976 to note these differences, and only use the option style(s) which
1977 makes the most sense to you until you feel comfortable with the others.
1978
1979 Some options @emph{may} take an argument. Such options may have at
1980 most long and short forms, they do not have old style equivalent. The
1981 rules for specifying an argument for such options are stricter than
1982 those for specifying mandatory arguments. Please, pay special
1983 attention to them.
1984
1985 @menu
1986 * Long Options:: Long Option Style
1987 * Short Options:: Short Option Style
1988 * Old Options:: Old Option Style
1989 * Mixing:: Mixing Option Styles
1990 @end menu
1991
1992 @node Long Options
1993 @subsection Long Option Style
1994
1995 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
1996 dashes in a row, e.g., @option{--list}. The long names are more clear than
1997 their corresponding short or old names. It sometimes happens that a
1998 single long option has many different different names which are
1999 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2000 long option names can be given unique abbreviations. For example,
2001 @option{--cre} can be used in place of @option{--create} because there is no
2002 other long option which begins with @samp{cre}. (One way to find
2003 this out is by trying it and seeing what happens; if a particular
2004 abbreviation could represent more than one option, @command{tar} will tell
2005 you that that abbreviation is ambiguous and you'll know that that
2006 abbreviation won't work. You may also choose to run @samp{tar --help}
2007 to see a list of options. Be aware that if you run @command{tar} with a
2008 unique abbreviation for the long name of an option you didn't want to
2009 use, you are stuck; @command{tar} will perform the command as ordered.)
2010
2011 Long options are meant to be obvious and easy to remember, and their
2012 meanings are generally easier to discern than those of their
2013 corresponding short options (see below). For example:
2014
2015 @smallexample
2016 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2017 @end smallexample
2018
2019 @noindent
2020 gives a fairly good set of hints about what the command does, even
2021 for those not fully acquainted with @command{tar}.
2022
2023 Long options which require arguments take those arguments
2024 immediately following the option name. There are two ways of
2025 specifying a mandatory argument. It can be separated from the
2026 option name either by an equal sign, or by any amount of
2027 white space characters. For example, the @option{--file} option (which
2028 tells the name of the @command{tar} archive) is given a file such as
2029 @file{archive.tar} as argument by using any of the following notations:
2030 @option{--file=archive.tar} or @option{--file archive.tar}.
2031
2032 In contrast, optional arguments must always be introduced using
2033 an equal sign. For example, the @option{--backup} option takes
2034 an optional argument specifying backup type. It must be used
2035 as @option{--backup=@var{backup-type}}.
2036
2037 @node Short Options
2038 @subsection Short Option Style
2039
2040 Most options also have a @dfn{short option} name. Short options start with
2041 a single dash, and are followed by a single character, e.g., @option{-t}
2042 (which is equivalent to @option{--list}). The forms are absolutely
2043 identical in function; they are interchangeable.
2044
2045 The short option names are faster to type than long option names.
2046
2047 Short options which require arguments take their arguments immediately
2048 following the option, usually separated by white space. It is also
2049 possible to stick the argument right after the short option name, using
2050 no intervening space. For example, you might write @w{@option{-f
2051 archive.tar}} or @option{-farchive.tar} instead of using
2052 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2053 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2054 specific archive, here named @file{archive.tar}.
2055
2056 Short options which take optional arguments take their arguments
2057 immediately following the option letter, @emph{without any intervening
2058 white space characters}.
2059
2060 Short options' letters may be clumped together, but you are not
2061 required to do this (as compared to old options; see below). When
2062 short options are clumped as a set, use one (single) dash for them
2063 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2064 such a set is allowed to have an argument@footnote{Clustering many
2065 options, the last of which has an argument, is a rather opaque way to
2066 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2067 even be made helpful enough for considering such usages as invalid.}.
2068
2069 When the options are separated, the argument for each option which requires
2070 an argument directly follows that option, as is usual for Unix programs.
2071 For example:
2072
2073 @smallexample
2074 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2075 @end smallexample
2076
2077 If you reorder short options' locations, be sure to move any arguments
2078 that belong to them. If you do not move the arguments properly, you may
2079 end up overwriting files.
2080
2081 @node Old Options
2082 @subsection Old Option Style
2083 @UNREVISED
2084
2085 Like short options, @dfn{old options} are single letters. However, old options
2086 must be written together as a single clumped set, without spaces separating
2087 them or dashes preceding them@footnote{Beware that if you precede options
2088 with a dash, you are announcing the short option style instead of the
2089 old option style; short options are decoded differently.}. This set
2090 of letters must be the first to appear on the command line, after the
2091 @command{tar} program name and some white space; old options cannot appear
2092 anywhere else. The letter of an old option is exactly the same letter as
2093 the corresponding short option. For example, the old option @samp{t} is
2094 the same as the short option @option{-t}, and consequently, the same as the
2095 long option @option{--list}. So for example, the command @w{@samp{tar
2096 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2097
2098 When options that need arguments are given together with the command,
2099 all the associated arguments follow, in the same order as the options.
2100 Thus, the example given previously could also be written in the old
2101 style as follows:
2102
2103 @smallexample
2104 $ @kbd{tar cvbf 20 /dev/rmt0}
2105 @end smallexample
2106
2107 @noindent
2108 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2109 the argument of @option{-f}.
2110
2111 On the other hand, this old style syntax makes it difficult to match
2112 option letters with their corresponding arguments, and is often
2113 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2114 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2115 argument for @option{-f}, and @option{-v} does not have a corresponding
2116 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2117 /dev/rmt0}} is clearer, putting all arguments next to the option they
2118 pertain to.
2119
2120 If you want to reorder the letters in the old option argument, be
2121 sure to reorder any corresponding argument appropriately.
2122
2123 This old way of writing @command{tar} options can surprise even experienced
2124 users. For example, the two commands:
2125
2126 @smallexample
2127 @kbd{tar cfz archive.tar.gz file}
2128 @kbd{tar -cfz archive.tar.gz file}
2129 @end smallexample
2130
2131 @noindent
2132 are quite different. The first example uses @file{archive.tar.gz} as
2133 the value for option @samp{f} and recognizes the option @samp{z}. The
2134 second example, however, uses @file{z} as the value for option
2135 @samp{f} --- probably not what was intended.
2136
2137 Old options are kept for compatibility with old versions of @command{tar}.
2138
2139 This second example could be corrected in many ways, among which the
2140 following are equivalent:
2141
2142 @smallexample
2143 @kbd{tar -czf archive.tar.gz file}
2144 @kbd{tar -cf archive.tar.gz -z file}
2145 @kbd{tar cf archive.tar.gz -z file}
2146 @end smallexample
2147
2148 @cindex option syntax, traditional
2149 As far as we know, all @command{tar} programs, @acronym{GNU} and
2150 non-@acronym{GNU}, support old options. @GNUTAR{}
2151 supports them not only for historical reasons, but also because many
2152 people are used to them. For compatibility with Unix @command{tar},
2153 the first argument is always treated as containing command and option
2154 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2155 equivalent to @w{@samp{tar -c}:} both of them specify the
2156 @option{--create} (@option{-c}) command to create an archive.
2157
2158 @node Mixing
2159 @subsection Mixing Option Styles
2160
2161 All three styles may be intermixed in a single @command{tar} command,
2162 so long as the rules for each style are fully
2163 respected@footnote{Before @GNUTAR{} version 1.11.6,
2164 a bug prevented intermixing old style options with long options in
2165 some cases.}. Old style options and either of the modern styles of
2166 options may be mixed within a single @command{tar} command. However,
2167 old style options must be introduced as the first arguments only,
2168 following the rule for old options (old options must appear directly
2169 after the @command{tar} command and some white space). Modern options
2170 may be given only after all arguments to the old options have been
2171 collected. If this rule is not respected, a modern option might be
2172 falsely interpreted as the value of the argument to one of the old
2173 style options.
2174
2175 For example, all the following commands are wholly equivalent, and
2176 illustrate the many combinations and orderings of option styles.
2177
2178 @smallexample
2179 @kbd{tar --create --file=archive.tar}
2180 @kbd{tar --create -f archive.tar}
2181 @kbd{tar --create -farchive.tar}
2182 @kbd{tar --file=archive.tar --create}
2183 @kbd{tar --file=archive.tar -c}
2184 @kbd{tar -c --file=archive.tar}
2185 @kbd{tar -c -f archive.tar}
2186 @kbd{tar -c -farchive.tar}
2187 @kbd{tar -cf archive.tar}
2188 @kbd{tar -cfarchive.tar}
2189 @kbd{tar -f archive.tar --create}
2190 @kbd{tar -f archive.tar -c}
2191 @kbd{tar -farchive.tar --create}
2192 @kbd{tar -farchive.tar -c}
2193 @kbd{tar c --file=archive.tar}
2194 @kbd{tar c -f archive.tar}
2195 @kbd{tar c -farchive.tar}
2196 @kbd{tar cf archive.tar}
2197 @kbd{tar f archive.tar --create}
2198 @kbd{tar f archive.tar -c}
2199 @kbd{tar fc archive.tar}
2200 @end smallexample
2201
2202 On the other hand, the following commands are @emph{not} equivalent to
2203 the previous set:
2204
2205 @smallexample
2206 @kbd{tar -f -c archive.tar}
2207 @kbd{tar -fc archive.tar}
2208 @kbd{tar -fcarchive.tar}
2209 @kbd{tar -farchive.tarc}
2210 @kbd{tar cfarchive.tar}
2211 @end smallexample
2212
2213 @noindent
2214 These last examples mean something completely different from what the
2215 user intended (judging based on the example in the previous set which
2216 uses long options, whose intent is therefore very clear). The first
2217 four specify that the @command{tar} archive would be a file named
2218 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2219 respectively. The first two examples also specify a single non-option,
2220 @var{name} argument having the value @samp{archive.tar}. The last
2221 example contains only old style option letters (repeating option
2222 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2223 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2224 the first sentence of this paragraph..}
2225
2226 @node All Options
2227 @section All @command{tar} Options
2228
2229 The coming manual sections contain an alphabetical listing of all
2230 @command{tar} operations and options, with brief descriptions and cross
2231 references to more in-depth explanations in the body of the manual.
2232 They also contain an alphabetically arranged table of the short option
2233 forms with their corresponding long option. You can use this table as
2234 a reference for deciphering @command{tar} commands in scripts.
2235
2236 @menu
2237 * Operation Summary::
2238 * Option Summary::
2239 * Short Option Summary::
2240 @end menu
2241
2242 @node Operation Summary
2243 @subsection Operations
2244
2245 @table @option
2246
2247 @opsummary{append}
2248 @item --append
2249 @itemx -r
2250
2251 Appends files to the end of the archive. @xref{append}.
2252
2253 @opsummary{catenate}
2254 @item --catenate
2255 @itemx -A
2256
2257 Same as @option{--concatenate}. @xref{concatenate}.
2258
2259 @opsummary{compare}
2260 @item --compare
2261 @itemx -d
2262
2263 Compares archive members with their counterparts in the file
2264 system, and reports differences in file size, mode, owner,
2265 modification date and contents. @xref{compare}.
2266
2267 @opsummary{concatenate}
2268 @item --concatenate
2269 @itemx -A
2270
2271 Appends other @command{tar} archives to the end of the archive.
2272 @xref{concatenate}.
2273
2274 @opsummary{create}
2275 @item --create
2276 @itemx -c
2277
2278 Creates a new @command{tar} archive. @xref{create}.
2279
2280 @opsummary{delete}
2281 @item --delete
2282
2283 Deletes members from the archive. Don't try this on a archive on a
2284 tape! @xref{delete}.
2285
2286 @opsummary{diff}
2287 @item --diff
2288 @itemx -d
2289
2290 Same @option{--compare}. @xref{compare}.
2291
2292 @opsummary{extract}
2293 @item --extract
2294 @itemx -x
2295
2296 Extracts members from the archive into the file system. @xref{extract}.
2297
2298 @opsummary{get}
2299 @item --get
2300 @itemx -x
2301
2302 Same as @option{--extract}. @xref{extract}.
2303
2304 @opsummary{list}
2305 @item --list
2306 @itemx -t
2307
2308 Lists the members in an archive. @xref{list}.
2309
2310 @opsummary{update}
2311 @item --update
2312 @itemx -u
2313
2314 Adds files to the end of the archive, but only if they are newer than
2315 their counterparts already in the archive, or if they do not already
2316 exist in the archive. @xref{update}.
2317
2318 @end table
2319
2320 @node Option Summary
2321 @subsection @command{tar} Options
2322
2323 @table @option
2324
2325 @opsummary{absolute-names}
2326 @item --absolute-names
2327 @itemx -P
2328
2329 Normally when creating an archive, @command{tar} strips an initial
2330 @samp{/} from member names. This option disables that behavior.
2331 @xref{absolute}.
2332
2333 @opsummary{after-date}
2334 @item --after-date
2335
2336 (See @option{--newer}, @pxref{after})
2337
2338 @opsummary{anchored}
2339 @item --anchored
2340 A pattern must match an initial subsequence of the name's components.
2341 @xref{controlling pattern-matching}.
2342
2343 @opsummary{atime-preserve}
2344 @item --atime-preserve
2345 @itemx --atime-preserve=replace
2346 @itemx --atime-preserve=system
2347
2348 Attempt to preserve the access time of files when reading them. This
2349 option currently is effective only on files that you own, unless you
2350 have superuser privileges.
2351
2352 @option{--atime-preserve=replace} remembers the access time of a file
2353 before reading it, and then restores the access time afterwards. This
2354 may cause problems if other programs are reading the file at the same
2355 time, as the times of their accesses will be lost. On most platforms
2356 restoring the access time also requires @command{tar} to restore the
2357 data modification time too, so this option may also cause problems if
2358 other programs are writing the file at the same time. (Tar attempts
2359 to detect this situation, but cannot do so reliably due to race
2360 conditions.) Worse, on most platforms restoring the access time also
2361 updates the status change time, which means that this option is
2362 incompatible with incremental backups.
2363
2364 @option{--atime-preserve=system} avoids changing time stamps on files,
2365 without interfering with time stamp updates
2366 caused by other programs, so it works better with incremental backups.
2367 However, it requires a special @code{O_NOATIME} option from the
2368 underlying operating and file system implementation, and it also requires
2369 that searching directories does not update their access times. As of
2370 this writing (November 2005) this works only with Linux, and only with
2371 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2372 way to know whether this feature actually works. Sometimes
2373 @command{tar} knows that it does not work, and if you use
2374 @option{--atime-preserve=system} then @command{tar} complains and
2375 exits right away. But other times @command{tar} might think that the
2376 option works when it actually does not.
2377
2378 Currently @option{--atime-preserve} with no operand defaults to
2379 @option{--atime-preserve=replace}, but this may change in the future
2380 as support for @option{--atime-preserve=system} improves.
2381
2382 If your operating system does not support
2383 @option{--atime-preserve=@-system}, you might be able to preserve access
2384 times reliably by by using the @command{mount} command. For example,
2385 you can mount the file system read-only, or access the file system via
2386 a read-only loopback mount, or use the @samp{noatime} mount option
2387 available on some systems. However, mounting typically requires
2388 superuser privileges and can be a pain to manage.
2389
2390 @opsummary{backup}
2391 @item --backup=@var{backup-type}
2392
2393 Rather than deleting files from the file system, @command{tar} will
2394 back them up using simple or numbered backups, depending upon
2395 @var{backup-type}. @xref{backup}.
2396
2397 @opsummary{block-number}
2398 @item --block-number
2399 @itemx -R
2400
2401 With this option present, @command{tar} prints error messages for read errors
2402 with the block number in the archive file. @xref{block-number}.
2403
2404 @opsummary{blocking-factor}
2405 @item --blocking-factor=@var{blocking}
2406 @itemx -b @var{blocking}
2407
2408 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2409 record. @xref{Blocking Factor}.
2410
2411 @opsummary{bzip2}
2412 @item --bzip2
2413 @itemx -j
2414
2415 This option tells @command{tar} to read or write archives through
2416 @code{bzip2}. @xref{gzip}.
2417
2418 @opsummary{checkpoint}
2419 @item --checkpoint[=@var{number}]
2420
2421 This option directs @command{tar} to print periodic checkpoint
2422 messages as it reads through the archive. It is intended for when you
2423 want a visual indication that @command{tar} is still running, but
2424 don't want to see @option{--verbose} output. For a detailed
2425 description, see @ref{Progress information}.
2426
2427 @opsummary{check-links}
2428 @item --check-links
2429 @itemx -l
2430 If this option was given, @command{tar} will check the number of links
2431 dumped for each processed file. If this number does not match the
2432 total number of hard links for the file, a warning message will be
2433 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2434 synonym for @option{--one-file-system}. The current semantics, which
2435 complies to UNIX98, was introduced with version
2436 1.15.91. @xref{Changes}, for more information.}.
2437
2438 @opsummary{compress}
2439 @opsummary{uncompress}
2440 @item --compress
2441 @itemx --uncompress
2442 @itemx -Z
2443
2444 @command{tar} will use the @command{compress} program when reading or
2445 writing the archive. This allows you to directly act on archives
2446 while saving space. @xref{gzip}.
2447
2448 @opsummary{confirmation}
2449 @item --confirmation
2450
2451 (See @option{--interactive}.) @xref{interactive}.
2452
2453 @opsummary{delay-directory-restore}
2454 @item --delay-directory-restore
2455
2456 Delay setting modification times and permissions of extracted
2457 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2458
2459 @opsummary{dereference}
2460 @item --dereference
2461 @itemx -h
2462
2463 When creating a @command{tar} archive, @command{tar} will archive the
2464 file that a symbolic link points to, rather than archiving the
2465 symlink. @xref{dereference}.
2466
2467 @opsummary{directory}
2468 @item --directory=@var{dir}
2469 @itemx -C @var{dir}
2470
2471 When this option is specified, @command{tar} will change its current directory
2472 to @var{dir} before performing any operations. When this option is used
2473 during archive creation, it is order sensitive. @xref{directory}.
2474
2475 @opsummary{exclude}
2476 @item --exclude=@var{pattern}
2477
2478 When performing operations, @command{tar} will skip files that match
2479 @var{pattern}. @xref{exclude}.
2480
2481 @opsummary{exclude-from}
2482 @item --exclude-from=@var{file}
2483 @itemx -X @var{file}
2484
2485 Similar to @option{--exclude}, except @command{tar} will use the list of
2486 patterns in the file @var{file}. @xref{exclude}.
2487
2488 @opsummary{exclude-caches}
2489 @item --exclude-caches
2490
2491 Automatically excludes all directories
2492 containing a cache directory tag. @xref{exclude}.
2493
2494 @opsummary{file}
2495 @item --file=@var{archive}
2496 @itemx -f @var{archive}
2497
2498 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2499 performs operations on, rather than @command{tar}'s compilation dependent
2500 default. @xref{file tutorial}.
2501
2502 @opsummary{files-from}
2503 @item --files-from=@var{file}
2504 @itemx -T @var{file}
2505
2506 @command{tar} will use the contents of @var{file} as a list of archive members
2507 or files to operate on, in addition to those specified on the
2508 command-line. @xref{files}.
2509
2510 @opsummary{force-local}
2511 @item --force-local
2512
2513 Forces @command{tar} to interpret the filename given to @option{--file}
2514 as a local file, even if it looks like a remote tape drive name.
2515 @xref{local and remote archives}.
2516
2517 @opsummary{format}
2518 @item --format=@var{format}
2519 @itemx -H @var{format}
2520
2521 Selects output archive format. @var{Format} may be one of the
2522 following:
2523
2524 @table @samp
2525 @item v7
2526 Creates an archive that is compatible with Unix V7 @command{tar}.
2527
2528 @item oldgnu
2529 Creates an archive that is compatible with GNU @command{tar} version
2530 1.12 or earlier.
2531
2532 @item gnu
2533 Creates archive in GNU tar 1.13 format. Basically it is the same as
2534 @samp{oldgnu} with the only difference in the way it handles long
2535 numeric fields.
2536
2537 @item ustar
2538 Creates a @acronym{POSIX.1-1988} compatible archive.
2539
2540 @item posix
2541 Creates a @acronym{POSIX.1-2001 archive}.
2542
2543 @end table
2544
2545 @xref{Formats}, for a detailed discussion of these formats.
2546
2547 @opsummary{group}
2548 @item --group=@var{group}
2549
2550 Files added to the @command{tar} archive will have a group id of @var{group},
2551 rather than the group from the source file. @var{group} is first decoded
2552 as a group symbolic name, but if this interpretation fails, it has to be
2553 a decimal numeric group ID. @xref{override}.
2554
2555 Also see the comments for the @option{--owner=@var{user}} option.
2556
2557 @opsummary{gzip}
2558 @opsummary{gunzip}
2559 @opsummary{ungzip}
2560 @item --gzip
2561 @itemx --gunzip
2562 @itemx --ungzip
2563 @itemx -z
2564
2565 This option tells @command{tar} to read or write archives through
2566 @command{gzip}, allowing @command{tar} to directly operate on several
2567 kinds of compressed archives transparently. @xref{gzip}.
2568
2569 @opsummary{help}
2570 @item --help
2571 @itemx -?
2572
2573 @command{tar} will print out a short message summarizing the operations and
2574 options to @command{tar} and exit. @xref{help}.
2575
2576 @opsummary{ignore-case}
2577 @item --ignore-case
2578 Ignore case when matching member or file names with
2579 patterns. @xref{controlling pattern-matching}.
2580
2581 @opsummary{ignore-command-error}
2582 @item --ignore-command-error
2583 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2584
2585 @opsummary{ignore-failed-read}
2586 @item --ignore-failed-read
2587
2588 Do not exit unsuccessfully merely because an unreadable file was encountered.
2589 @xref{Reading}.
2590
2591 @opsummary{ignore-zeros}
2592 @item --ignore-zeros
2593 @itemx -i
2594
2595 With this option, @command{tar} will ignore zeroed blocks in the
2596 archive, which normally signals EOF. @xref{Reading}.
2597
2598 @opsummary{incremental}
2599 @item --incremental
2600 @itemx -G
2601
2602 Used to inform @command{tar} that it is working with an old
2603 @acronym{GNU}-format incremental backup archive. It is intended
2604 primarily for backwards compatibility only. @xref{Incremental Dumps},
2605 for a detailed discussion of incremental archives.
2606
2607 @opsummary{index-file}
2608 @item --index-file=@var{file}
2609
2610 Send verbose output to @var{file} instead of to standard output.
2611
2612 @opsummary{info-script}
2613 @opsummary{new-volume-script}
2614 @item --info-script=@var{script-file}
2615 @itemx --new-volume-script=@var{script-file}
2616 @itemx -F @var{script-file}
2617
2618 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2619 at the end of each tape. If @var{script-file} exits with nonzero status,
2620 @command{tar} fails immediately. @xref{info-script}, for a detailed
2621 discussion of @var{script-file}.
2622
2623 @opsummary{interactive}
2624 @item --interactive
2625 @itemx --confirmation
2626 @itemx -w
2627
2628 Specifies that @command{tar} should ask the user for confirmation before
2629 performing potentially destructive options, such as overwriting files.
2630 @xref{interactive}.
2631
2632 @opsummary{keep-newer-files}
2633 @item --keep-newer-files
2634
2635 Do not replace existing files that are newer than their archive copies
2636 when extracting files from an archive.
2637
2638 @opsummary{keep-old-files}
2639 @item --keep-old-files
2640 @itemx -k
2641
2642 Do not overwrite existing files when extracting files from an archive.
2643 @xref{Keep Old Files}.
2644
2645 @opsummary{label}
2646 @item --label=@var{name}
2647 @itemx -V @var{name}
2648
2649 When creating an archive, instructs @command{tar} to write @var{name}
2650 as a name record in the archive. When extracting or listing archives,
2651 @command{tar} will only operate on archives that have a label matching
2652 the pattern specified in @var{name}. @xref{Tape Files}.
2653
2654 @opsummary{listed-incremental}
2655 @item --listed-incremental=@var{snapshot-file}
2656 @itemx -g @var{snapshot-file}
2657
2658 During a @option{--create} operation, specifies that the archive that
2659 @command{tar} creates is a new @acronym{GNU}-format incremental
2660 backup, using @var{snapshot-file} to determine which files to backup.
2661 With other operations, informs @command{tar} that the archive is in
2662 incremental format. @xref{Incremental Dumps}.
2663
2664 @opsummary{mode}
2665 @item --mode=@var{permissions}
2666
2667 When adding files to an archive, @command{tar} will use
2668 @var{permissions} for the archive members, rather than the permissions
2669 from the files. @var{permissions} can be specified either as an octal
2670 number or as symbolic permissions, like with
2671 @command{chmod}. @xref{override}.
2672
2673 @opsummary{mtime}
2674 @item --mtime=@var{date}
2675
2676 When adding files to an archive, @command{tar} will use @var{date} as
2677 the modification time of members when creating archives, instead of
2678 their actual modification times. The value of @var{date} can be
2679 either a textual date representation (@pxref{Date input formats}) or a
2680 name of the existing file, starting with @samp{/} or @samp{.}. In the
2681 latter case, the modification time of that file is used. @xref{override}.
2682
2683 @opsummary{multi-volume}
2684 @item --multi-volume
2685 @itemx -M
2686
2687 Informs @command{tar} that it should create or otherwise operate on a
2688 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2689
2690 @opsummary{new-volume-script}
2691 @item --new-volume-script
2692
2693 (see --info-script)
2694
2695 @opsummary{seek}
2696 @item --seek
2697 @itemx -n
2698
2699 Assume that the archive media supports seeks to arbitrary
2700 locations. Usually @command{tar} determines automatically whether
2701 the archive can be seeked or not. This option is intended for use
2702 in cases when such recognition fails.
2703
2704 @opsummary{newer}
2705 @item --newer=@var{date}
2706 @itemx --after-date=@var{date}
2707 @itemx -N
2708
2709 When creating an archive, @command{tar} will only add files that have changed
2710 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2711 is taken to be the name of a file whose data modification time specifies
2712 the date. @xref{after}.
2713
2714 @opsummary{newer-mtime}
2715 @item --newer-mtime=@var{date}
2716
2717 Like @option{--newer}, but add only files whose
2718 contents have changed (as opposed to just @option{--newer}, which will
2719 also back up files for which any status information has
2720 changed). @xref{after}.
2721
2722 @opsummary{no-anchored}
2723 @item --no-anchored
2724 An exclude pattern can match any subsequence of the name's components.
2725 @xref{controlling pattern-matching}.
2726
2727 @opsummary{no-delay-directory-restore}
2728 @item --no-delay-directory-restore
2729
2730 Setting modification times and permissions of extracted
2731 directories when all files from this directory has been
2732 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2733
2734 @opsummary{no-ignore-case}
2735 @item --no-ignore-case
2736 Use case-sensitive matching.
2737 @xref{controlling pattern-matching}.
2738
2739 @opsummary{no-ignore-command-error}
2740 @item --no-ignore-command-error
2741 Print warnings about subprocesses terminated with a non-zero exit
2742 code. @xref{Writing to an External Program}.
2743
2744 @opsummary{no-overwrite-dir}
2745 @item --no-overwrite-dir
2746
2747 Preserve metadata of existing directories when extracting files
2748 from an archive. @xref{Overwrite Old Files}.
2749
2750 @opsummary{no-quote-chars}
2751 @item --no-quote-chars=@var{string}
2752 Remove characters listed in @var{string} from the list of quoted
2753 characters set by the previous @option{--quote-chars} option
2754 (@pxref{quoting styles}).
2755
2756 @opsummary{no-recursion}
2757 @item --no-recursion
2758
2759 With this option, @command{tar} will not recurse into directories.
2760 @xref{recurse}.
2761
2762 @opsummary{no-same-owner}
2763 @item --no-same-owner
2764 @itemx -o
2765
2766 When extracting an archive, do not attempt to preserve the owner
2767 specified in the @command{tar} archive. This the default behavior
2768 for ordinary users.
2769
2770 @opsummary{no-same-permissions}
2771 @item --no-same-permissions
2772
2773 When extracting an archive, subtract the user's umask from files from
2774 the permissions specified in the archive. This is the default behavior
2775 for ordinary users.
2776
2777 @opsummary{no-unquote}
2778 @item --no-unquote
2779 Treat all input file or member names literally, do not interpret
2780 escape sequences. @xref{input name quoting}.
2781
2782 @opsummary{no-wildcards}
2783 @item --no-wildcards
2784 Do not use wildcards.
2785 @xref{controlling pattern-matching}.
2786
2787 @opsummary{no-wildcards-match-slash}
2788 @item --no-wildcards-match-slash
2789 Wildcards do not match @samp{/}.
2790 @xref{controlling pattern-matching}.
2791
2792 @opsummary{null}
2793 @item --null
2794
2795 When @command{tar} is using the @option{--files-from} option, this option
2796 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2797 @command{tar} can correctly work with file names that contain newlines.
2798 @xref{nul}.
2799
2800 @opsummary{numeric-owner}
2801 @item --numeric-owner
2802
2803 This option will notify @command{tar} that it should use numeric user
2804 and group IDs when creating a @command{tar} file, rather than names.
2805 @xref{Attributes}.
2806
2807 @item -o
2808 The function of this option depends on the action @command{tar} is
2809 performing. When extracting files, @option{-o} is a synonym for
2810 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2811 restoring ownership of files being extracted.
2812
2813 When creating an archive, it is a synonym for
2814 @option{--old-archive}. This behavior is for compatibility
2815 with previous versions of @GNUTAR{}, and will be
2816 removed in the future releases.
2817
2818 @xref{Changes}, for more information.
2819
2820 @opsummary{occurrence}
2821 @item --occurrence[=@var{number}]
2822
2823 This option can be used in conjunction with one of the subcommands
2824 @option{--delete}, @option{--diff}, @option{--extract} or
2825 @option{--list} when a list of files is given either on the command
2826 line or via @option{-T} option.
2827
2828 This option instructs @command{tar} to process only the @var{number}th
2829 occurrence of each named file. @var{Number} defaults to 1, so
2830
2831 @smallexample
2832 tar -x -f archive.tar --occurrence filename
2833 @end smallexample
2834
2835 @noindent
2836 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2837 and will terminate without scanning to the end of the archive.
2838
2839 @opsummary{old-archive}
2840 @item --old-archive
2841 Synonym for @option{--format=v7}.
2842
2843 @opsummary{one-file-system}
2844 @item --one-file-system
2845 Used when creating an archive. Prevents @command{tar} from recursing into
2846 directories that are on different file systems from the current
2847 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2848 synonym for @option{--one-file-system}. This has changed in version
2849 1.15.91. @xref{Changes}, for more information.}.
2850
2851 @opsummary{overwrite}
2852 @item --overwrite
2853
2854 Overwrite existing files and directory metadata when extracting files
2855 from an archive. @xref{Overwrite Old Files}.
2856
2857 @opsummary{overwrite-dir}
2858 @item --overwrite-dir
2859
2860 Overwrite the metadata of existing directories when extracting files
2861 from an archive. @xref{Overwrite Old Files}.
2862
2863 @opsummary{owner}
2864 @item --owner=@var{user}
2865
2866 Specifies that @command{tar} should use @var{user} as the owner of members
2867 when creating archives, instead of the user associated with the source
2868 file. @var{user} is first decoded as a user symbolic name, but if
2869 this interpretation fails, it has to be a decimal numeric user ID.
2870 @xref{override}.
2871
2872 This option does not affect extraction from archives.
2873
2874 @opsummary{transform}
2875 @item --transform=@var{sed-expr}
2876
2877 Transform file or member names using @command{sed} replacement expression
2878 @var{sed-expr}. For example,
2879
2880 @smallexample
2881 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2882 @end smallexample
2883
2884 @noindent
2885 will add to @file{archive} files from the current working directory,
2886 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2887 discussion, @xref{transform}.
2888
2889 To see transformed member names in verbose listings, use
2890 @option{--show-transformed-names} option
2891 (@pxref{show-transformed-names}).
2892
2893 @opsummary{quote-chars}
2894 @item --quote-chars=@var{string}
2895 Always quote characters from @var{string}, even if the selected
2896 quoting style would not quote them (@pxref{quoting styles}).
2897
2898 @opsummary{quoting-style}
2899 @item --quoting-style=@var{style}
2900 Set quoting style to use when printing member and file names
2901 (@pxref{quoting styles}). Valid @var{style} values are:
2902 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2903 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2904 style is @code{escape}, unless overridden while configuring the
2905 package.
2906
2907 @opsummary{pax-option}
2908 @item --pax-option=@var{keyword-list}
2909 This option is meaningful only with @acronym{POSIX.1-2001} archives
2910 (@pxref{posix}). It modifies the way @command{tar} handles the
2911 extended header keywords. @var{Keyword-list} is a comma-separated
2912 list of keyword options. @xref{PAX keywords}, for a detailed
2913 discussion.
2914
2915 @opsummary{portability}
2916 @item --portability
2917 @itemx --old-archive
2918 Synonym for @option{--format=v7}.
2919
2920 @opsummary{posix}
2921 @item --posix
2922 Same as @option{--format=posix}.
2923
2924 @opsummary{preserve}
2925 @item --preserve
2926
2927 Synonymous with specifying both @option{--preserve-permissions} and
2928 @option{--same-order}. @xref{Setting Access Permissions}.
2929
2930 @opsummary{preserve-order}
2931 @item --preserve-order
2932
2933 (See @option{--same-order}; @pxref{Reading}.)
2934
2935 @opsummary{preserve-permissions}
2936 @opsummary{same-permissions}
2937 @item --preserve-permissions
2938 @itemx --same-permissions
2939 @itemx -p
2940
2941 When @command{tar} is extracting an archive, it normally subtracts the
2942 users' umask from the permissions specified in the archive and uses
2943 that number as the permissions to create the destination file.
2944 Specifying this option instructs @command{tar} that it should use the
2945 permissions directly from the archive. @xref{Setting Access Permissions}.
2946
2947 @opsummary{read-full-records}
2948 @item --read-full-records
2949 @itemx -B
2950
2951 Specifies that @command{tar} should reblock its input, for reading
2952 from pipes on systems with buggy implementations. @xref{Reading}.
2953
2954 @opsummary{record-size}
2955 @item --record-size=@var{size}
2956
2957 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2958 archive. @xref{Blocking Factor}.
2959
2960 @opsummary{recursion}
2961 @item --recursion
2962
2963 With this option, @command{tar} recurses into directories.
2964 @xref{recurse}.
2965
2966 @opsummary{recursive-unlink}
2967 @item --recursive-unlink
2968
2969 Remove existing
2970 directory hierarchies before extracting directories of the same name
2971 from the archive. @xref{Recursive Unlink}.
2972
2973 @opsummary{remove-files}
2974 @item --remove-files
2975
2976 Directs @command{tar} to remove the source file from the file system after
2977 appending it to an archive. @xref{remove files}.
2978
2979 @opsummary{restrict}
2980 @item --restrict
2981
2982 Disable use of some potentially harmful @command{tar} options.
2983 Currently this option disables shell invocaton from multi-volume menu
2984 (@pxref{Using Multiple Tapes}).
2985
2986 @opsummary{rmt-command}
2987 @item --rmt-command=@var{cmd}
2988
2989 Notifies @command{tar} that it should use @var{cmd} instead of
2990 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2991
2992 @opsummary{rsh-command}
2993 @item --rsh-command=@var{cmd}
2994
2995 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2996 devices. @xref{Device}.
2997
2998 @opsummary{same-order}
2999 @item --same-order
3000 @itemx --preserve-order
3001 @itemx -s
3002
3003 This option is an optimization for @command{tar} when running on machines with
3004 small amounts of memory. It informs @command{tar} that the list of file
3005 arguments has already been sorted to match the order of files in the
3006 archive. @xref{Reading}.
3007
3008 @opsummary{same-owner}
3009 @item --same-owner
3010
3011 When extracting an archive, @command{tar} will attempt to preserve the owner
3012 specified in the @command{tar} archive with this option present.
3013 This is the default behavior for the superuser; this option has an
3014 effect only for ordinary users. @xref{Attributes}.
3015
3016 @opsummary{same-permissions}
3017 @item --same-permissions
3018
3019 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3020
3021 @opsummary{show-defaults}
3022 @item --show-defaults
3023
3024 Displays the default options used by @command{tar} and exits
3025 successfully. This option is intended for use in shell scripts.
3026 Here is an example of what you can see using this option:
3027
3028 @smallexample
3029 $ tar --show-defaults
3030 --format=gnu -f- -b20 --quoting-style=escape \
3031 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3032 @end smallexample
3033
3034 @opsummary{show-omitted-dirs}
3035 @item --show-omitted-dirs
3036
3037 Instructs @command{tar} to mention directories its skipping over when
3038 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3039
3040 @opsummary{show-transformed-names}
3041 @opsummary{show-stored-names}
3042 @item --show-transformed-names
3043 @itemx --show-stored-names
3044
3045 Display file or member names after applying any transformations
3046 (@pxref{transform}). In particular, when used in conjunction with one of
3047 archive creation operations it instructs tar to list the member names
3048 stored in the archive, as opposed to the actual file
3049 names. @xref{listing member and file names}.
3050
3051 @opsummary{sparse}
3052 @item --sparse
3053 @itemx -S
3054
3055 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3056 sparse files efficiently. @xref{sparse}.
3057
3058 @opsummary{starting-file}
3059 @item --starting-file=@var{name}
3060 @itemx -K @var{name}
3061
3062 This option affects extraction only; @command{tar} will skip extracting
3063 files in the archive until it finds one that matches @var{name}.
3064 @xref{Scarce}.
3065
3066 @opsummary{strip-components}
3067 @item --strip-components=@var{number}
3068 Strip given @var{number} of leading components from file names before
3069 extraction.@footnote{This option was called @option{--strip-path} in
3070 version 1.14.} For example, if archive @file{archive.tar} contained
3071 @file{/some/file/name}, then running
3072
3073 @smallexample
3074 tar --extract --file archive.tar --strip-components=2
3075 @end smallexample
3076
3077 @noindent
3078 would extract this file to file @file{name}.
3079
3080 @opsummary{suffix}, summary
3081 @item --suffix=@var{suffix}
3082
3083 Alters the suffix @command{tar} uses when backing up files from the default
3084 @samp{~}. @xref{backup}.
3085
3086 @opsummary{tape-length}
3087 @item --tape-length=@var{num}
3088 @itemx -L @var{num}
3089
3090 Specifies the length of tapes that @command{tar} is writing as being
3091 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3092
3093 @opsummary{test-label}
3094 @item --test-label
3095
3096 Reads the volume label. If an argument is specified, test whether it
3097 matches the volume label. @xref{--test-label option}.
3098
3099 @opsummary{to-command}
3100 @item --to-command=@var{command}
3101
3102 During extraction @command{tar} will pipe extracted files to the
3103 standard input of @var{command}. @xref{Writing to an External Program}.
3104
3105 @opsummary{to-stdout}
3106 @item --to-stdout
3107 @itemx -O
3108
3109 During extraction, @command{tar} will extract files to stdout rather
3110 than to the file system. @xref{Writing to Standard Output}.
3111
3112 @opsummary{totals}
3113 @item --totals[=@var{signo}]
3114
3115 Displays the total number of bytes transferred when processing an
3116 archive. If an argument is given, these data are displayed on
3117 request, when signal @var{signo} is delivered to @command{tar}.
3118 @xref{totals}.
3119
3120 @opsummary{touch}
3121 @item --touch
3122 @itemx -m
3123
3124 Sets the data modification time of extracted files to the extraction time,
3125 rather than the data modification time stored in the archive.
3126 @xref{Data Modification Times}.
3127
3128 @opsummary{uncompress}
3129 @item --uncompress
3130
3131 (See @option{--compress}. @pxref{gzip})
3132
3133 @opsummary{ungzip}
3134 @item --ungzip
3135
3136 (See @option{--gzip}. @pxref{gzip})
3137
3138 @opsummary{unlink-first}
3139 @item --unlink-first
3140 @itemx -U
3141
3142 Directs @command{tar} to remove the corresponding file from the file
3143 system before extracting it from the archive. @xref{Unlink First}.
3144
3145 @opsummary{unquote}
3146 @item --unquote
3147 Enable unquoting input file or member names (default). @xref{input
3148 name quoting}.
3149
3150 @opsummary{use-compress-program}
3151 @item --use-compress-program=@var{prog}
3152
3153 Instructs @command{tar} to access the archive through @var{prog}, which is
3154 presumed to be a compression program of some sort. @xref{gzip}.
3155
3156 @opsummary{utc}
3157 @item --utc
3158
3159 Display file modification dates in @acronym{UTC}. This option implies
3160 @option{--verbose}.
3161
3162 @opsummary{verbose}
3163 @item --verbose
3164 @itemx -v
3165
3166 Specifies that @command{tar} should be more verbose about the operations its
3167 performing. This option can be specified multiple times for some
3168 operations to increase the amount of information displayed.
3169 @xref{verbose}.
3170
3171 @opsummary{verify}
3172 @item --verify
3173 @itemx -W
3174
3175 Verifies that the archive was correctly written when creating an
3176 archive. @xref{verify}.
3177
3178 @opsummary{version}
3179 @item --version
3180
3181 Print information about the program's name, version, origin and legal
3182 status, all on standard output, and then exit successfully.
3183 @xref{help}.
3184
3185 @opsummary{volno-file}
3186 @item --volno-file=@var{file}
3187
3188 Used in conjunction with @option{--multi-volume}. @command{tar} will
3189 keep track of which volume of a multi-volume archive its working in
3190 @var{file}. @xref{volno-file}.
3191
3192 @opsummary{wildcards}
3193 @item --wildcards
3194 Use wildcards when matching member names with patterns.
3195 @xref{controlling pattern-matching}.
3196
3197 @opsummary{wildcards-match-slash}
3198 @item --wildcards-match-slash
3199 Wildcards match @samp{/}.
3200 @xref{controlling pattern-matching}.
3201 @end table
3202
3203 @node Short Option Summary
3204 @subsection Short Options Cross Reference
3205
3206 Here is an alphabetized list of all of the short option forms, matching
3207 them with the equivalent long option.
3208
3209 @multitable @columnfractions 0.20 0.80
3210 @headitem Short Option @tab Reference
3211
3212 @item -A @tab @ref{--concatenate}.
3213
3214 @item -B @tab @ref{--read-full-records}.
3215
3216 @item -C @tab @ref{--directory}.
3217
3218 @item -F @tab @ref{--info-script}.
3219
3220 @item -G @tab @ref{--incremental}.
3221
3222 @item -K @tab @ref{--starting-file}.
3223
3224 @item -L @tab @ref{--tape-length}.
3225
3226 @item -M @tab @ref{--multi-volume}.
3227
3228 @item -N @tab @ref{--newer}.
3229
3230 @item -O @tab @ref{--to-stdout}.
3231
3232 @item -P @tab @ref{--absolute-names}.
3233
3234 @item -R @tab @ref{--block-number}.
3235
3236 @item -S @tab @ref{--sparse}.
3237
3238 @item -T @tab @ref{--files-from}.
3239
3240 @item -U @tab @ref{--unlink-first}.
3241
3242 @item -V @tab @ref{--label}.
3243
3244 @item -W @tab @ref{--verify}.
3245
3246 @item -X @tab @ref{--exclude-from}.
3247
3248 @item -Z @tab @ref{--compress}.
3249
3250 @item -b @tab @ref{--blocking-factor}.
3251
3252 @item -c @tab @ref{--create}.
3253
3254 @item -d @tab @ref{--compare}.
3255
3256 @item -f @tab @ref{--file}.
3257
3258 @item -g @tab @ref{--listed-incremental}.
3259
3260 @item -h @tab @ref{--dereference}.
3261
3262 @item -i @tab @ref{--ignore-zeros}.
3263
3264 @item -j @tab @ref{--bzip2}.
3265
3266 @item -k @tab @ref{--keep-old-files}.
3267
3268 @item -l @tab @ref{--check-links}.
3269
3270 @item -m @tab @ref{--touch}.
3271
3272 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3273 @ref{--portability}.
3274
3275 The later usage is deprecated. It is retained for compatibility with
3276 the earlier versions of @GNUTAR{}. In the future releases
3277 @option{-o} will be equivalent to @option{--no-same-owner} only.
3278
3279 @item -p @tab @ref{--preserve-permissions}.
3280
3281 @item -r @tab @ref{--append}.
3282
3283 @item -s @tab @ref{--same-order}.
3284
3285 @item -t @tab @ref{--list}.
3286
3287 @item -u @tab @ref{--update}.
3288
3289 @item -v @tab @ref{--verbose}.
3290
3291 @item -w @tab @ref{--interactive}.
3292
3293 @item -x @tab @ref{--extract}.
3294
3295 @item -z @tab @ref{--gzip}.
3296
3297 @end multitable
3298
3299 @node help
3300 @section @GNUTAR{} documentation
3301
3302 @cindex Getting program version number
3303 @opindex version
3304 @cindex Version of the @command{tar} program
3305 Being careful, the first thing is really checking that you are using
3306 @GNUTAR{}, indeed. The @option{--version} option
3307 causes @command{tar} to print information about its name, version,
3308 origin and legal status, all on standard output, and then exit
3309 successfully. For example, @w{@samp{tar --version}} might print:
3310
3311 @smallexample
3312 tar (GNU tar) @value{VERSION}
3313 Copyright (C) 2006 Free Software Foundation, Inc.
3314 This is free software. You may redistribute copies of it under the terms
3315 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3316 There is NO WARRANTY, to the extent permitted by law.
3317
3318 Written by John Gilmore and Jay Fenlason.
3319 @end smallexample
3320
3321 @noindent
3322 The first occurrence of @samp{tar} in the result above is the program
3323 name in the package (for example, @command{rmt} is another program),
3324 while the second occurrence of @samp{tar} is the name of the package
3325 itself, containing possibly many programs. The package is currently
3326 named @samp{tar}, after the name of the main program it
3327 contains@footnote{There are plans to merge the @command{cpio} and
3328 @command{tar} packages into a single one which would be called
3329 @code{paxutils}. So, who knows if, one of this days, the
3330 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3331 paxutils) 3.2}}}.
3332
3333 @cindex Obtaining help
3334 @cindex Listing all @command{tar} options
3335 @xopindex{help, introduction}
3336 Another thing you might want to do is checking the spelling or meaning
3337 of some particular @command{tar} option, without resorting to this
3338 manual, for once you have carefully read it. @GNUTAR{}
3339 has a short help feature, triggerable through the
3340 @option{--help} option. By using this option, @command{tar} will
3341 print a usage message listing all available options on standard
3342 output, then exit successfully, without doing anything else and
3343 ignoring all other options. Even if this is only a brief summary, it
3344 may be several screens long. So, if you are not using some kind of
3345 scrollable window, you might prefer to use something like:
3346
3347 @smallexample
3348 $ @kbd{tar --help | less}
3349 @end smallexample
3350
3351 @noindent
3352 presuming, here, that you like using @command{less} for a pager. Other
3353 popular pagers are @command{more} and @command{pg}. If you know about some
3354 @var{keyword} which interests you and do not want to read all the
3355 @option{--help} output, another common idiom is doing:
3356
3357 @smallexample
3358 tar --help | grep @var{keyword}
3359 @end smallexample
3360
3361 @noindent
3362 for getting only the pertinent lines. Notice, however, that some
3363 @command{tar} options have long description lines and the above
3364 command will list only the first of them.
3365
3366 The exact look of the option summary displayed by @kbd{tar --help} is
3367 configurable. @xref{Configuring Help Summary}, for a detailed description.
3368
3369 @opindex usage
3370 If you only wish to check the spelling of an option, running @kbd{tar
3371 --usage} may be a better choice. This will display a terse list of
3372 @command{tar} option without accompanying explanations.
3373
3374 The short help output is quite succinct, and you might have to get
3375 back to the full documentation for precise points. If you are reading
3376 this paragraph, you already have the @command{tar} manual in some
3377 form. This manual is available in a variety of forms from
3378 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3379 distribution, provided you have @TeX{} already installed somewhere,
3380 and a laser printer around. Just configure the distribution, execute
3381 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3382 usual way (contact your local guru to know how). If @GNUTAR{}
3383 has been conveniently installed at your place, this
3384 manual is also available in interactive, hypertextual form as an Info
3385 file. Just call @w{@samp{info tar}} or, if you do not have the
3386 @command{info} program handy, use the Info reader provided within
3387 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3388
3389 There is currently no @code{man} page for @GNUTAR{}.
3390 If you observe such a @code{man} page on the system you are running,
3391 either it does not belong to @GNUTAR{}, or it has not
3392 been produced by @acronym{GNU}. Some package maintainers convert
3393 @kbd{tar --help} output to a man page, using @command{help2man}. In
3394 any case, please bear in mind that the authoritative source of
3395 information about @GNUTAR{} is this Texinfo documentation.
3396
3397 @node defaults
3398 @section Obtaining @GNUTAR{} default values
3399
3400 @opindex show-defaults
3401 @GNUTAR{} has some predefined defaults that are used when you do not
3402 explicitely specify another values. To obtain a list of such
3403 defaults, use @option{--show-defaults} option. This will output the
3404 values in the form of @command{tar} command line options:
3405
3406 @smallexample
3407 @group
3408 @kbd{tar --show-defaults}
3409 --format=gnu -f- -b20 --quoting-style=escape
3410 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3411 @end group
3412 @end smallexample
3413
3414 @noindent
3415 Notice, that this option outputs only one line. The example output above
3416 has been split to fit page boundaries.
3417
3418 @noindent
3419 The above output shows that this version of @GNUTAR{} defaults to
3420 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3421 output as the archive, if no @option{--file} option has been given
3422 (@pxref{file tutorial}), the default blocking factor is 20
3423 (@pxref{Blocking Factor}). It also shows the default locations where
3424 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3425
3426 @node verbose
3427 @section Checking @command{tar} progress
3428
3429 Typically, @command{tar} performs most operations without reporting any
3430 information to the user except error messages. When using @command{tar}
3431 with many options, particularly ones with complicated or
3432 difficult-to-predict behavior, it is possible to make serious mistakes.
3433 @command{tar} provides several options that make observing @command{tar}
3434 easier. These options cause @command{tar} to print information as it
3435 progresses in its job, and you might want to use them just for being
3436 more careful about what is going on, or merely for entertaining
3437 yourself. If you have encountered a problem when operating on an
3438 archive, however, you may need more information than just an error
3439 message in order to solve the problem. The following options can be
3440 helpful diagnostic tools.
3441
3442 @cindex Verbose operation
3443 @opindex verbose
3444 Normally, the @option{--list} (@option{-t}) command to list an archive
3445 prints just the file names (one per line) and the other commands are
3446 silent. When used with most operations, the @option{--verbose}
3447 (@option{-v}) option causes @command{tar} to print the name of each
3448 file or archive member as it is processed. This and the other options
3449 which make @command{tar} print status information can be useful in
3450 monitoring @command{tar}.
3451
3452 With @option{--create} or @option{--extract}, @option{--verbose} used
3453 once just prints the names of the files or members as they are processed.
3454 Using it twice causes @command{tar} to print a longer listing
3455 (@xref{verbose member listing}, for the description) for each member.
3456 Since @option{--list} already prints the names of the members,
3457 @option{--verbose} used once with @option{--list} causes @command{tar}
3458 to print an @samp{ls -l} type listing of the files in the archive.
3459 The following examples both extract members with long list output:
3460
3461 @smallexample
3462 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3463 $ @kbd{tar xvvf archive.tar}
3464 @end smallexample
3465
3466 Verbose output appears on the standard output except when an archive is
3467 being written to the standard output, as with @samp{tar --create
3468 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3469 installer let standard output be the default archive). In that case
3470 @command{tar} writes verbose output to the standard error stream.
3471
3472 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3473 verbose output to @var{file} rather than to standard output or standard
3474 error.
3475
3476 @anchor{totals}
3477 @cindex Obtaining total status information
3478 @opindex totals
3479 The @option{--totals} option causes @command{tar} to print on the
3480 standard error the total amount of bytes transferred when processing
3481 an archive. When creating or appending to an archive, this option
3482 prints the number of bytes written to the archive and the average
3483 speed at which they have been written, e.g.:
3484
3485 @smallexample
3486 @group
3487 $ @kbd{tar -c -f archive.tar --totals /home}
3488 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3489 @end group
3490 @end smallexample
3491
3492 When reading an archive, this option displays the number of bytes
3493 read:
3494
3495 @smallexample
3496 @group
3497 $ @kbd{tar -x -f archive.tar --totals}
3498 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3499 @end group
3500 @end smallexample
3501
3502 Finally, when deleting from an archive, the @option{--totals} option
3503 displays both numbers plus number of bytes removed from the archive:
3504
3505 @smallexample
3506 @group
3507 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3508 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3509 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3510 Total bytes deleted: 1474048
3511 @end group
3512 @end smallexample
3513
3514 You can also obtain this information on request. When
3515 @option{--totals} is used with an argument, this argument is
3516 interpreted as a symbolic name of a signal, upon delivery of which the
3517 statistics is to be printed:
3518
3519 @table @option
3520 @item --totals=@var{signo}
3521 Print statistics upon delivery of signal @var{signo}. Valid arguments
3522 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3523 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3524 accepted.
3525 @end table
3526
3527 Both forms of @option{--totals} option can be used simultaneously.
3528 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3529 extract all members from its default archive and print statistics
3530 after finishing the extraction, as well as when receiving signal
3531 @code{SIGUSR1}.
3532
3533 @anchor{Progress information}
3534 @cindex Progress information
3535 @opindex checkpoint
3536 The @option{--checkpoint} option prints an occasional message
3537 as @command{tar} reads or writes the archive. It is designed for
3538 those who don't need the more detailed (and voluminous) output of
3539 @option{--block-number} (@option{-R}), but do want visual confirmation
3540 that @command{tar} is actually making forward progress. By default it
3541 prints a message each 10 records read or written. This can be changed
3542 by giving it a numeric argument after an equal sign:
3543
3544 @smallexample
3545 $ @kbd{tar -c --checkpoint=1000} /var
3546 tar: Write checkpoint 1000
3547 tar: Write checkpoint 2000
3548 tar: Write checkpoint 3000
3549 @end smallexample
3550
3551 This example shows the default checkpoint message used by
3552 @command{tar}. If you place a dot immediately after the equal
3553 sign, it will print a @samp{.} at each checkpoint. For example:
3554
3555 @smallexample
3556 $ @kbd{tar -c --checkpoint=.1000} /var
3557 ...
3558 @end smallexample
3559
3560 @opindex show-omitted-dirs
3561 @anchor{show-omitted-dirs}
3562 The @option{--show-omitted-dirs} option, when reading an archive---with
3563 @option{--list} or @option{--extract}, for example---causes a message
3564 to be printed for each directory in the archive which is skipped.
3565 This happens regardless of the reason for skipping: the directory might
3566 not have been named on the command line (implicitly or explicitly),
3567 it might be excluded by the use of the
3568 @option{--exclude=@var{pattern}} option, or some other reason.
3569
3570 @opindex block-number
3571 @cindex Block number where error occurred
3572 @anchor{block-number}
3573 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3574 every message it would normally produce, the block number within the
3575 archive where the message was triggered. Also, supplementary messages
3576 are triggered when reading blocks full of NULs, or when hitting end of
3577 file on the archive. As of now, if the archive if properly terminated
3578 with a NUL block, the reading of the file may stop before end of file
3579 is met, so the position of end of file will not usually show when
3580 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3581 drains the archive before exiting when reading the
3582 archive from a pipe.
3583
3584 @cindex Error message, block number of
3585 This option is especially useful when reading damaged archives, since
3586 it helps pinpoint the damaged sections. It can also be used with
3587 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3588 choose among several backup tapes when retrieving a file later, in
3589 favor of the tape where the file appears earliest (closest to the
3590 front of the tape). @xref{backup}.
3591
3592 @node interactive
3593 @section Asking for Confirmation During Operations
3594 @cindex Interactive operation
3595
3596 Typically, @command{tar} carries out a command without stopping for
3597 further instructions. In some situations however, you may want to
3598 exclude some files and archive members from the operation (for instance
3599 if disk or storage space is tight). You can do this by excluding
3600 certain files automatically (@pxref{Choosing}), or by performing
3601 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3602 @command{tar} also accepts @option{--confirmation} for this option.
3603
3604 @opindex interactive
3605 When the @option{--interactive} (@option{-w}) option is specified, before
3606 reading, writing, or deleting files, @command{tar} first prints a message
3607 for each such file, telling what operation it intends to take, then asks
3608 for confirmation on the terminal. The actions which require
3609 confirmation include adding a file to the archive, extracting a file
3610 from the archive, deleting a file from the archive, and deleting a file
3611 from disk. To confirm the action, you must type a line of input
3612 beginning with @samp{y}. If your input line begins with anything other
3613 than @samp{y}, @command{tar} skips that file.
3614
3615 If @command{tar} is reading the archive from the standard input,
3616 @command{tar} opens the file @file{/dev/tty} to support the interactive
3617 communications.
3618
3619 Verbose output is normally sent to standard output, separate from
3620 other error messages. However, if the archive is produced directly
3621 on standard output, then verbose output is mixed with errors on
3622 @code{stderr}. Producing the archive on standard output may be used
3623 as a way to avoid using disk space, when the archive is soon to be
3624 consumed by another process reading it, say. Some people felt the need
3625 of producing an archive on stdout, still willing to segregate between
3626 verbose output and error output. A possible approach would be using a
3627 named pipe to receive the archive, and having the consumer process to
3628 read from that named pipe. This has the advantage of letting standard
3629 output free to receive verbose output, all separate from errors.
3630
3631 @node operations
3632 @chapter @GNUTAR{} Operations
3633
3634 @menu
3635 * Basic tar::
3636 * Advanced tar::
3637 * create options::
3638 * extract options::
3639 * backup::
3640 * Applications::
3641 * looking ahead::
3642 @end menu
3643
3644 @node Basic tar
3645 @section Basic @GNUTAR{} Operations
3646
3647 The basic @command{tar} operations, @option{--create} (@option{-c}),
3648 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3649 @option{-x}), are currently presented and described in the tutorial
3650 chapter of this manual. This section provides some complementary notes
3651 for these operations.
3652
3653 @table @option
3654 @xopindex{create, complementary notes}
3655 @item --create
3656 @itemx -c
3657
3658 Creating an empty archive would have some kind of elegance. One can
3659 initialize an empty archive and later use @option{--append}
3660 (@option{-r}) for adding all members. Some applications would not
3661 welcome making an exception in the way of adding the first archive
3662 member. On the other hand, many people reported that it is
3663 dangerously too easy for @command{tar} to destroy a magnetic tape with
3664 an empty archive@footnote{This is well described in @cite{Unix-haters
3665 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3666 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3667
3668 @enumerate
3669 @item
3670 Mistakingly using @code{create} instead of @code{extract}, when the
3671 intent was to extract the full contents of an archive. This error
3672 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3673 the QWERTY keyboard. Instead of being unpacked, the archive then
3674 gets wholly destroyed. When users speak about @dfn{exploding} an
3675 archive, they usually mean something else :-).
3676
3677 @item
3678 Forgetting the argument to @code{file}, when the intent was to create
3679 an archive with a single file in it. This error is likely because a
3680 tired user can easily add the @kbd{f} key to the cluster of option
3681 letters, by the mere force of habit, without realizing the full
3682 consequence of doing so. The usual consequence is that the single
3683 file, which was meant to be saved, is rather destroyed.
3684 @end enumerate
3685
3686 So, recognizing the likelihood and the catastrophical nature of these
3687 errors, @GNUTAR{} now takes some distance from elegance, and
3688 cowardly refuses to create an archive when @option{--create} option is
3689 given, there are no arguments besides options, and
3690 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3691 around the cautiousness of @GNUTAR{} and nevertheless create an
3692 archive with nothing in it, one may still use, as the value for the
3693 @option{--files-from} option, a file with no names in it, as shown in
3694 the following commands:
3695
3696 @smallexample
3697 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3698 @kbd{tar cfT empty-archive.tar /dev/null}
3699 @end smallexample
3700
3701 @xopindex{extract, complementary notes}
3702 @item --extract
3703 @itemx --get
3704 @itemx -x
3705
3706 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3707
3708 @item @option{--list} (@option{-t})
3709
3710 @GNUTAR{} now shows dates as @samp{1996-08-30},
3711 while it used to show them as @samp{Aug 30 1996}. Preferably,
3712 people should get used to ISO 8601 dates. Local American dates should
3713 be made available again with full date localization support, once
3714 ready. In the meantime, programs not being localizable for dates
3715 should prefer international dates, that's really the way to go.
3716
3717 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
3718 are curious, it contains a detailed explanation of the ISO 8601 standard.
3719
3720 @end table
3721
3722 @node Advanced tar
3723 @section Advanced @GNUTAR{} Operations
3724
3725 Now that you have learned the basics of using @GNUTAR{}, you may want
3726 to learn about further ways in which @command{tar} can help you.
3727
3728 This chapter presents five, more advanced operations which you probably
3729 won't use on a daily basis, but which serve more specialized functions.
3730 We also explain the different styles of options and why you might want
3731 to use one or another, or a combination of them in your @command{tar}
3732 commands. Additionally, this chapter includes options which allow you to
3733 define the output from @command{tar} more carefully, and provide help and
3734 error correction in special circumstances.
3735
3736 @FIXME{check this after the chapter is actually revised to make sure
3737 it still introduces the info in the chapter correctly : ).}
3738
3739 @menu
3740 * Operations::
3741 * append::
3742 * update::
3743 * concatenate::
3744 * delete::
3745 * compare::
3746 @end menu
3747
3748 @node Operations
3749 @subsection The Five Advanced @command{tar} Operations
3750 @UNREVISED
3751
3752 In the last chapter, you learned about the first three operations to
3753 @command{tar}. This chapter presents the remaining five operations to
3754 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3755 @option{--delete}, and @option{--compare}.
3756
3757 You are not likely to use these operations as frequently as those
3758 covered in the last chapter; however, since they perform specialized
3759 functions, they are quite useful when you do need to use them. We
3760 will give examples using the same directory and files that you created
3761 in the last chapter. As you may recall, the directory is called
3762 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3763 @samp{rock}, and the two archive files you created are
3764 @samp{collection.tar} and @samp{music.tar}.
3765
3766 We will also use the archive files @samp{afiles.tar} and
3767 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
3768 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
3769 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3770
3771 Unless we state otherwise, all practicing you do and examples you follow
3772 in this chapter will take place in the @file{practice} directory that
3773 you created in the previous chapter; see @ref{prepare for examples}.
3774 (Below in this section, we will remind you of the state of the examples
3775 where the last chapter left them.)
3776
3777 The five operations that we will cover in this chapter are:
3778
3779 @table @option
3780 @item --append
3781 @itemx -r
3782 Add new entries to an archive that already exists.
3783 @item --update
3784 @itemx -r
3785 Add more recent copies of archive members to the end of an archive, if
3786 they exist.
3787 @item --concatenate
3788 @itemx --catenate
3789 @itemx -A
3790 Add one or more pre-existing archives to the end of another archive.
3791 @item --delete
3792 Delete items from an archive (does not work on tapes).
3793 @item --compare
3794 @itemx --diff
3795 @itemx -d
3796 Compare archive members to their counterparts in the file system.
3797 @end table
3798
3799 @node append
3800 @subsection How to Add Files to Existing Archives: @option{--append}
3801 @UNREVISED
3802
3803 @opindex append
3804 If you want to add files to an existing archive, you don't need to
3805 create a new archive; you can use @option{--append} (@option{-r}).
3806 The archive must already exist in order to use @option{--append}. (A
3807 related operation is the @option{--update} operation; you can use this
3808 to add newer versions of archive members to an existing archive. To learn how to
3809 do this with @option{--update}, @pxref{update}.)
3810
3811 If you use @option{--append} to add a file that has the same name as an
3812 archive member to an archive containing that archive member, then the
3813 old member is not deleted. What does happen, however, is somewhat
3814 complex. @command{tar} @emph{allows} you to have infinite number of files
3815 with the same name. Some operations treat these same-named members no
3816 differently than any other set of archive members: for example, if you
3817 view an archive with @option{--list} (@option{-t}), you will see all
3818 of those members listed, with their data modification times, owners, etc.
3819
3820 Other operations don't deal with these members as perfectly as you might
3821 prefer; if you were to use @option{--extract} to extract the archive,
3822 only the most recently added copy of a member with the same name as four
3823 other members would end up in the working directory. This is because
3824 @option{--extract} extracts an archive in the order the members appeared
3825 in the archive; the most recently archived members will be extracted
3826 last. Additionally, an extracted member will @emph{replace} a file of
3827 the same name which existed in the directory already, and @command{tar}
3828 will not prompt you about this@footnote{Unless you give it
3829 @option{--keep-old-files} option, or the disk copy is newer than the
3830 the one in the archive and you invoke @command{tar} with
3831 @option{--keep-newer-files} option}. Thus, only the most recently archived
3832 member will end up being extracted, as it will replace the one
3833 extracted before it, and so on.
3834
3835 There exists a special option that allows you to get around this
3836 behavior and extract (or list) only a particular copy of the file.
3837 This is @option{--occurrence} option. If you run @command{tar} with
3838 this option, it will extract only the first copy of the file. You
3839 may also give this option an argument specifying the number of
3840 copy to be extracted. Thus, for example if the archive
3841 @file{archive.tar} contained three copies of file @file{myfile}, then
3842 the command
3843
3844 @smallexample
3845 tar --extract --file archive.tar --occurrence=2 myfile
3846 @end smallexample
3847
3848 @noindent
3849 would extract only the second copy. @xref{Option
3850 Summary,---occurrence}, for the description of @option{--occurrence}
3851 option.
3852
3853 @FIXME{ hag -- you might want to incorporate some of the above into the
3854 MMwtSN node; not sure. i didn't know how to make it simpler...
3855
3856 There are a few ways to get around this. (maybe xref Multiple Members
3857 with the Same Name.}
3858
3859 @cindex Members, replacing with other members
3860 @cindex Replacing members with other members
3861 If you want to replace an archive member, use @option{--delete} to
3862 delete the member you want to remove from the archive, , and then use
3863 @option{--append} to add the member you want to be in the archive. Note
3864 that you can not change the order of the archive; the most recently
3865 added member will still appear last. In this sense, you cannot truly
3866 ``replace'' one member with another. (Replacing one member with another
3867 will not work on certain types of media, such as tapes; see @ref{delete}
3868 and @ref{Media}, for more information.)
3869
3870 @menu
3871 * appending files:: Appending Files to an Archive
3872 * multiple::
3873 @end menu
3874
3875 @node appending files
3876 @subsubsection Appending Files to an Archive
3877 @UNREVISED
3878 @cindex Adding files to an Archive
3879 @cindex Appending files to an Archive
3880 @cindex Archives, Appending files to
3881
3882 The simplest way to add a file to an already existing archive is the
3883 @option{--append} (@option{-r}) operation, which writes specified
3884 files into the archive whether or not they are already among the
3885 archived files.
3886
3887 When you use @option{--append}, you @emph{must} specify file name
3888 arguments, as there is no default. If you specify a file that already
3889 exists in the archive, another copy of the file will be added to the
3890 end of the archive. As with other operations, the member names of the
3891 newly added files will be exactly the same as their names given on the
3892 command line. The @option{--verbose} (@option{-v}) option will print
3893 out the names of the files as they are written into the archive.
3894
3895 @option{--append} cannot be performed on some tape drives, unfortunately,
3896 due to deficiencies in the formats those tape drives use. The archive
3897 must be a valid @command{tar} archive, or else the results of using this
3898 operation will be unpredictable. @xref{Media}.
3899
3900 To demonstrate using @option{--append} to add a file to an archive,
3901 create a file called @file{rock} in the @file{practice} directory.
3902 Make sure you are in the @file{practice} directory. Then, run the
3903 following @command{tar} command to add @file{rock} to
3904 @file{collection.tar}:
3905
3906 @smallexample
3907 $ @kbd{tar --append --file=collection.tar rock}
3908 @end smallexample
3909
3910 @noindent
3911 If you now use the @option{--list} (@option{-t}) operation, you will see that
3912 @file{rock} has been added to the archive:
3913
3914 @smallexample
3915 $ @kbd{tar --list --file=collection.tar}
3916 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3917 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3918 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3919 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3920 @end smallexample
3921
3922 @node multiple
3923 @subsubsection Multiple Members with the Same Name
3924
3925 You can use @option{--append} (@option{-r}) to add copies of files
3926 which have been updated since the archive was created. (However, we
3927 do not recommend doing this since there is another @command{tar}
3928 option called @option{--update}; @xref{update}, for more information.
3929 We describe this use of @option{--append} here for the sake of
3930 completeness.) When you extract the archive, the older version will
3931 be effectively lost. This works because files are extracted from an
3932 archive in the order in which they were archived. Thus, when the
3933 archive is extracted, a file archived later in time will replace a
3934 file of the same name which was archived earlier, even though the
3935 older version of the file will remain in the archive unless you delete
3936 all versions of the file.
3937
3938 Supposing you change the file @file{blues} and then append the changed
3939 version to @file{collection.tar}. As you saw above, the original
3940 @file{blues} is in the archive @file{collection.tar}. If you change the
3941 file and append the new version of the file to the archive, there will
3942 be two copies in the archive. When you extract the archive, the older
3943 version of the file will be extracted first, and then replaced by the
3944 newer version when it is extracted.
3945
3946 You can append the new, changed copy of the file @file{blues} to the
3947 archive in this way:
3948
3949 @smallexample
3950 $ @kbd{tar --append --verbose --file=collection.tar blues}
3951 blues
3952 @end smallexample
3953
3954 @noindent
3955 Because you specified the @option{--verbose} option, @command{tar} has
3956 printed the name of the file being appended as it was acted on. Now
3957 list the contents of the archive:
3958
3959 @smallexample
3960 $ @kbd{tar --list --verbose --file=collection.tar}
3961 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3962 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3963 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3964 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3965 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3966 @end smallexample
3967
3968 @noindent
3969 The newest version of @file{blues} is now at the end of the archive
3970 (note the different creation dates and file sizes). If you extract
3971 the archive, the older version of the file @file{blues} will be
3972 replaced by the newer version. You can confirm this by extracting
3973 the archive and running @samp{ls} on the directory.
3974
3975 If you wish to extract the first occurrence of the file @file{blues}
3976 from the archive, use @option{--occurrence} option, as shown in
3977 the following example:
3978
3979 @smallexample
3980 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
3981 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3982 @end smallexample
3983
3984 @xref{Writing}, for more information on @option{--extract} and
3985 @xref{Option Summary, --occurrence}, for the description of
3986 @option{--occurrence} option.
3987
3988 @node update
3989 @subsection Updating an Archive
3990 @UNREVISED
3991 @cindex Updating an archive
3992
3993 @opindex update
3994 In the previous section, you learned how to use @option{--append} to
3995 add a file to an existing archive. A related operation is
3996 @option{--update} (@option{-u}). The @option{--update} operation
3997 updates a @command{tar} archive by comparing the date of the specified
3998 archive members against the date of the file with the same name. If
3999 the file has been modified more recently than the archive member, then
4000 the newer version of the file is added to the archive (as with
4001 @option{--append}).
4002
4003 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4004 The operation will fail.
4005
4006 @FIXME{other examples of media on which --update will fail? need to ask
4007 charles and/or mib/thomas/dave shevett..}
4008
4009 Both @option{--update} and @option{--append} work by adding to the end
4010 of the archive. When you extract a file from the archive, only the
4011 version stored last will wind up in the file system, unless you use
4012 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4013
4014 @menu
4015 * how to update::
4016 @end menu
4017
4018 @node how to update
4019 @subsubsection How to Update an Archive Using @option{--update}
4020
4021 You must use file name arguments with the @option{--update}
4022 (@option{-u}) operation. If you don't specify any files,
4023 @command{tar} won't act on any files and won't tell you that it didn't
4024 do anything (which may end up confusing you).
4025
4026 @c note: the above parenthetical added because in fact, this
4027 @c behavior just confused the author. :-)
4028
4029 To see the @option{--update} option at work, create a new file,
4030 @file{classical}, in your practice directory, and some extra text to the
4031 file @file{blues}, using any text editor. Then invoke @command{tar} with
4032 the @samp{update} operation and the @option{--verbose} (@option{-v})
4033 option specified, using the names of all the files in the practice
4034 directory as file name arguments:
4035
4036 @smallexample
4037 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4038 blues
4039 classical
4040 $
4041 @end smallexample
4042
4043 @noindent
4044 Because we have specified verbose mode, @command{tar} prints out the names
4045 of the files it is working on, which in this case are the names of the
4046 files that needed to be updated. If you run @samp{tar --list} and look
4047 at the archive, you will see @file{blues} and @file{classical} at its
4048 end. There will be a total of two versions of the member @samp{blues};
4049 the one at the end will be newer and larger, since you added text before
4050 updating it.
4051
4052 (The reason @command{tar} does not overwrite the older file when updating
4053 it is because writing to the middle of a section of tape is a difficult
4054 process. Tapes are not designed to go backward. @xref{Media}, for more
4055 information about tapes.
4056
4057 @option{--update} (@option{-u}) is not suitable for performing backups for two
4058 reasons: it does not change directory content entries, and it
4059 lengthens the archive every time it is used. The @GNUTAR{}
4060 options intended specifically for backups are more
4061 efficient. If you need to run backups, please consult @ref{Backups}.
4062
4063 @node concatenate
4064 @subsection Combining Archives with @option{--concatenate}
4065
4066 @cindex Adding archives to an archive
4067 @cindex Concatenating Archives
4068 @opindex concatenate
4069 @opindex catenate
4070 @c @cindex @option{-A} described
4071 Sometimes it may be convenient to add a second archive onto the end of
4072 an archive rather than adding individual files to the archive. To add
4073 one or more archives to the end of another archive, you should use the
4074 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4075
4076 To use @option{--concatenate}, give the first archive with
4077 @option{--file} option and name the rest of archives to be
4078 concatenated on the command line. The members, and their member
4079 names, will be copied verbatim from those archives to the first one.
4080 @footnote{This can cause multiple members to have the same name, for
4081 information on how this affects reading the archive, @ref{multiple}.}
4082 The new, concatenated archive will be called by the same name as the
4083 one given with the @option{--file} option. As usual, if you omit
4084 @option{--file}, @command{tar} will use the value of the environment
4085 variable @env{TAPE}, or, if this has not been set, the default archive name.
4086
4087 @FIXME{There is no way to specify a new name...}
4088
4089 To demonstrate how @option{--concatenate} works, create two small archives
4090 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4091 files from @file{practice}:
4092
4093 @smallexample
4094 $ @kbd{tar -cvf bluesrock.tar blues rock}
4095 blues
4096 rock
4097 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4098 folk
4099 jazz
4100 @end smallexample
4101
4102 @noindent
4103 If you like, You can run @samp{tar --list} to make sure the archives
4104 contain what they are supposed to:
4105
4106 @smallexample
4107 $ @kbd{tar -tvf bluesrock.tar}
4108 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4109 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4110 $ @kbd{tar -tvf jazzfolk.tar}
4111 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4112 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4113 @end smallexample
4114
4115 We can concatenate these two archives with @command{tar}:
4116
4117 @smallexample
4118 $ @kbd{cd ..}
4119 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4120 @end smallexample
4121
4122 If you now list the contents of the @file{bluesrock.tar}, you will see
4123 that now it also contains the archive members of @file{jazzfolk.tar}:
4124
4125 @smallexample
4126 $ @kbd{tar --list --file=bluesrock.tar}
4127 blues
4128 rock
4129 folk
4130 jazz
4131 @end smallexample
4132
4133 When you use @option{--concatenate}, the source and target archives must
4134 already exist and must have been created using compatible format
4135 parameters. Notice, that @command{tar} does not check whether the
4136 archives it concatenates have compatible formats, it does not
4137 even check if the files are really tar archives.
4138
4139 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4140 tape drives, due to deficiencies in the formats those tape drives use.
4141
4142 @cindex @code{concatenate} vs @command{cat}
4143 @cindex @command{cat} vs @code{concatenate}
4144 It may seem more intuitive to you to want or try to use @command{cat} to
4145 concatenate two archives instead of using the @option{--concatenate}
4146 operation; after all, @command{cat} is the utility for combining files.
4147
4148 However, @command{tar} archives incorporate an end-of-file marker which
4149 must be removed if the concatenated archives are to be read properly as
4150 one archive. @option{--concatenate} removes the end-of-archive marker
4151 from the target archive before each new archive is appended. If you use
4152 @command{cat} to combine the archives, the result will not be a valid
4153 @command{tar} format archive. If you need to retrieve files from an
4154 archive that was added to using the @command{cat} utility, use the
4155 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4156 information on dealing with archives improperly combined using the
4157 @command{cat} shell utility.
4158
4159 @node delete
4160 @subsection Removing Archive Members Using @option{--delete}
4161 @UNREVISED
4162 @cindex Deleting files from an archive
4163 @cindex Removing files from an archive
4164
4165 @opindex delete
4166 You can remove members from an archive by using the @option{--delete}
4167 option. Specify the name of the archive with @option{--file}
4168 (@option{-f}) and then specify the names of the members to be deleted;
4169 if you list no member names, nothing will be deleted. The
4170 @option{--verbose} option will cause @command{tar} to print the names
4171 of the members as they are deleted. As with @option{--extract}, you
4172 must give the exact member names when using @samp{tar --delete}.
4173 @option{--delete} will remove all versions of the named file from the
4174 archive. The @option{--delete} operation can run very slowly.
4175
4176 Unlike other operations, @option{--delete} has no short form.
4177
4178 @cindex Tapes, using @option{--delete} and
4179 @cindex Deleting from tape archives
4180 This operation will rewrite the archive. You can only use
4181 @option{--delete} on an archive if the archive device allows you to
4182 write to any point on the media, such as a disk; because of this, it
4183 does not work on magnetic tapes. Do not try to delete an archive member
4184 from a magnetic tape; the action will not succeed, and you will be
4185 likely to scramble the archive and damage your tape. There is no safe
4186 way (except by completely re-writing the archive) to delete files from
4187 most kinds of magnetic tape. @xref{Media}.
4188
4189 To delete all versions of the file @file{blues} from the archive
4190 @file{collection.tar} in the @file{practice} directory, make sure you
4191 are in that directory, and then,
4192
4193 @smallexample
4194 $ @kbd{tar --list --file=collection.tar}
4195 blues
4196 folk
4197 jazz
4198 rock
4199 $ @kbd{tar --delete --file=collection.tar blues}
4200 $ @kbd{tar --list --file=collection.tar}
4201 folk
4202 jazz
4203 rock
4204 $
4205 @end smallexample
4206
4207 @FIXME{Check if the above listing is actually produced after running
4208 all the examples on collection.tar.}
4209
4210 The @option{--delete} option has been reported to work properly when
4211 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4212
4213 @node compare
4214 @subsection Comparing Archive Members with the File System
4215 @cindex Verifying the currency of an archive
4216 @UNREVISED
4217
4218 @opindex compare
4219 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4220 specified archive members against files with the same names, and then
4221 reports differences in file size, mode, owner, modification date and
4222 contents. You should @emph{only} specify archive member names, not file
4223 names. If you do not name any members, then @command{tar} will compare the
4224 entire archive. If a file is represented in the archive but does not
4225 exist in the file system, @command{tar} reports a difference.
4226
4227 You have to specify the record size of the archive when modifying an
4228 archive with a non-default record size.
4229
4230 @command{tar} ignores files in the file system that do not have
4231 corresponding members in the archive.
4232
4233 The following example compares the archive members @file{rock},
4234 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4235 files of the same name in the file system. (Note that there is no file,
4236 @file{funk}; @command{tar} will report an error message.)
4237
4238 @smallexample
4239 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4240 rock
4241 blues
4242 tar: funk not found in archive
4243 @end smallexample
4244
4245 The spirit behind the @option{--compare} (@option{--diff},
4246 @option{-d}) option is to check whether the archive represents the
4247 current state of files on disk, more than validating the integrity of
4248 the archive media. For this later goal, @xref{verify}.
4249
4250 @node create options
4251 @section Options Used by @option{--create}
4252
4253 @xopindex{create, additional options}
4254 The previous chapter described the basics of how to use
4255 @option{--create} (@option{-c}) to create an archive from a set of files.
4256 @xref{create}. This section described advanced options to be used with
4257 @option{--create}.
4258
4259 @menu
4260 * override:: Overriding File Metadata.
4261 * Ignore Failed Read::
4262 @end menu
4263
4264 @node override
4265 @subsection Overriding File Metadata
4266
4267 As described above, a @command{tar} archive keeps, for each member it contains,
4268 its @dfn{metadata}, such as modification time, mode and ownership of
4269 the file. @GNUTAR{} allows to replace these data with other values
4270 when adding files to the archive. The options described in this
4271 section affect creation of archives of any type. For POSIX archives,
4272 see also @ref{PAX keywords}, for additional ways of controlling
4273 metadata, stored in the archive.
4274
4275 @table @option
4276 @opindex mode
4277 @item --mode=@var{permissions}
4278
4279 When adding files to an archive, @command{tar} will use
4280 @var{permissions} for the archive members, rather than the permissions
4281 from the files. @var{permissions} can be specified either as an octal
4282 number or as symbolic permissions, like with
4283 @command{chmod} (@xref{File permissions, Permissions, File
4284 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4285 also has useful information for those not being overly familiar with
4286 the UNIX permission system). Using latter syntax allows for
4287 more flexibility. For example, the value @samp{a+rw} adds read and write
4288 permissions for everybody, while retaining executable bits on directories
4289 or on any other file already marked as executable:
4290
4291 @smallexample
4292 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4293 @end smallexample
4294
4295 @item --mtime=@var{date}
4296 @opindex mtime
4297
4298 When adding files to an archive, @command{tar} will use @var{date} as
4299 the modification time of members when creating archives, instead of
4300 their actual modification times. The argument @var{date} can be
4301 either a textual date representation in almost arbitrary format
4302 (@pxref{Date input formats}) or a name of the existing file, starting
4303 with @samp{/} or @samp{.}. In the latter case, the modification time
4304 of that file will be used.
4305
4306 The following example will set the modification date to 00:00:00 UTC,
4307 January 1, 1970:
4308
4309 @smallexample
4310 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4311 @end smallexample
4312
4313 @noindent
4314 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4315 will try to convert the specified date back to its textual
4316 representation and compare it with the one given with
4317 @option{--mtime} options. If the two dates differ, @command{tar} will
4318 print a warning saying what date it will use. This is to help user
4319 ensure he is using the right date.
4320
4321 For example:
4322
4323 @smallexample
4324 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4325 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4326 13:06:29.152478
4327 @dots{}
4328 @end smallexample
4329
4330 @item --owner=@var{user}
4331 @opindex owner
4332
4333 Specifies that @command{tar} should use @var{user} as the owner of members
4334 when creating archives, instead of the user associated with the source
4335 file. The argument @var{user} can be either an existing user symbolic
4336 name, or a decimal numeric user ID.
4337
4338 There is no value indicating a missing number, and @samp{0} usually means
4339 @code{root}. Some people like to force @samp{0} as the value to offer in
4340 their distributions for the owner of files, because the @code{root} user is
4341 anonymous anyway, so that might as well be the owner of anonymous
4342 archives. For example:
4343
4344 @smallexample
4345 @group
4346 $ @kbd{tar -c -f archive.tar --owner=0 .}
4347 # @r{Or:}
4348 $ @kbd{tar -c -f archive.tar --owner=root .}
4349 @end group
4350 @end smallexample
4351
4352 @item --group=@var{group}
4353 @opindex group
4354
4355 Files added to the @command{tar} archive will have a group id of @var{group},
4356 rather than the group from the source file. The argument @var{group}
4357 can be either an existing group symbolic name, or a decimal numeric group ID.
4358 @end table
4359
4360 @node Ignore Failed Read
4361 @subsection Ignore Fail Read
4362
4363 @table @option
4364 @item --ignore-failed-read
4365 @opindex ignore-failed-read
4366 Do not exit with nonzero on unreadable files or directories.
4367 @end table
4368
4369 @node extract options
4370 @section Options Used by @option{--extract}
4371 @UNREVISED
4372
4373 @xopindex{extract, additional options}
4374 The previous chapter showed how to use @option{--extract} to extract
4375 an archive into the file system. Various options cause @command{tar} to
4376 extract more information than just file contents, such as the owner,
4377 the permissions, the modification date, and so forth. This section
4378 presents options to be used with @option{--extract} when certain special
4379 considerations arise. You may review the information presented in
4380 @ref{extract} for more basic information about the
4381 @option{--extract} operation.
4382
4383 @menu
4384 * Reading:: Options to Help Read Archives
4385 * Writing:: Changing How @command{tar} Writes Files
4386 * Scarce:: Coping with Scarce Resources
4387 @end menu
4388
4389 @node Reading
4390 @subsection Options to Help Read Archives
4391 @cindex Options when reading archives
4392 @UNREVISED
4393
4394 @cindex Reading incomplete records
4395 @cindex Records, incomplete
4396 @opindex read-full-records
4397 Normally, @command{tar} will request data in full record increments from
4398 an archive storage device. If the device cannot return a full record,
4399 @command{tar} will report an error. However, some devices do not always
4400 return full records, or do not require the last record of an archive to
4401 be padded out to the next record boundary. To keep reading until you
4402 obtain a full record, or to accept an incomplete record if it contains
4403 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4404 in conjunction with the @option{--extract} or @option{--list} operations.
4405 @xref{Blocking}.
4406
4407 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4408 @command{tar} reads an archive from standard input, or from a remote
4409 machine. This is because on BSD Unix systems, attempting to read a
4410 pipe returns however much happens to be in the pipe, even if it is
4411 less than was requested. If this option were not enabled, @command{tar}
4412 would fail as soon as it read an incomplete record from the pipe.
4413
4414 If you're not sure of the blocking factor of an archive, you can
4415 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4416 @option{--blocking-factor=@var{512-size}} (@option{-b
4417 @var{512-size}}), using a blocking factor larger than what the archive
4418 uses. This lets you avoid having to determine the blocking factor
4419 of an archive. @xref{Blocking Factor}.
4420
4421 @menu
4422 * read full records::
4423 * Ignore Zeros::
4424 @end menu
4425
4426 @node read full records
4427 @unnumberedsubsubsec Reading Full Records
4428
4429 @FIXME{need sentence or so of intro here}
4430
4431 @table @option
4432 @opindex read-full-records
4433 @item --read-full-records
4434 @item -B
4435 Use in conjunction with @option{--extract} (@option{--get},
4436 @option{-x}) to read an archive which contains incomplete records, or
4437 one which has a blocking factor less than the one specified.
4438 @end table
4439
4440 @node Ignore Zeros
4441 @unnumberedsubsubsec Ignoring Blocks of Zeros
4442
4443 @cindex End-of-archive blocks, ignoring
4444 @cindex Ignoring end-of-archive blocks
4445 @opindex ignore-zeros
4446 Normally, @command{tar} stops reading when it encounters a block of zeros
4447 between file entries (which usually indicates the end of the archive).
4448 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4449 completely read an archive which contains a block of zeros before the
4450 end (i.e., a damaged archive, or one that was created by concatenating
4451 several archives together).
4452
4453 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4454 versions of @command{tar} write garbage after the end-of-archive entry,
4455 since that part of the media is never supposed to be read. @GNUTAR{}
4456 does not write after the end of an archive, but seeks to
4457 maintain compatiblity among archiving utilities.
4458
4459 @table @option
4460 @item --ignore-zeros
4461 @itemx -i
4462 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4463 encountered while reading an archive. Use in conjunction with
4464 @option{--extract} or @option{--list}.
4465 @end table
4466
4467 @node Writing
4468 @subsection Changing How @command{tar} Writes Files
4469 @UNREVISED
4470
4471 @FIXME{Introductory paragraph}
4472
4473 @menu
4474 * Dealing with Old Files::
4475 * Overwrite Old Files::
4476 * Keep Old Files::
4477 * Keep Newer Files::
4478 * Unlink First::
4479 * Recursive Unlink::
4480 * Data Modification Times::
4481 * Setting Access Permissions::
4482 * Directory Modification Times and Permissions::
4483 * Writing to Standard Output::
4484 * Writing to an External Program::
4485 * remove files::
4486 @end menu
4487
4488 @node Dealing with Old Files
4489 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4490
4491 @xopindex{overwrite-dir, introduced}
4492 When extracting files, if @command{tar} discovers that the extracted
4493 file already exists, it normally replaces the file by removing it before
4494 extracting it, to prevent confusion in the presence of hard or symbolic
4495 links. (If the existing file is a symbolic link, it is removed, not
4496 followed.) However, if a directory cannot be removed because it is
4497 nonempty, @command{tar} normally overwrites its metadata (ownership,
4498 permission, etc.). The @option{--overwrite-dir} option enables this
4499 default behavior. To be more cautious and preserve the metadata of
4500 such a directory, use the @option{--no-overwrite-dir} option.
4501
4502 @cindex Overwriting old files, prevention
4503 @xopindex{keep-old-files, introduced}
4504 To be even more cautious and prevent existing files from being replaced, use
4505 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4506 to replace or update a file that already exists, i.e., a file with the
4507 same name as an archive member prevents extraction of that archive
4508 member. Instead, it reports an error.
4509
4510 @xopindex{overwrite, introduced}
4511 To be more aggressive about altering existing files, use the
4512 @option{--overwrite} option. It causes @command{tar} to overwrite
4513 existing files and to follow existing symbolic links when extracting.
4514
4515 @cindex Protecting old files
4516 Some people argue that @GNUTAR{} should not hesitate
4517 to overwrite files with other files when extracting. When extracting
4518 a @command{tar} archive, they expect to see a faithful copy of the
4519 state of the file system when the archive was created. It is debatable
4520 that this would always be a proper behavior. For example, suppose one
4521 has an archive in which @file{usr/local} is a link to
4522 @file{usr/local2}. Since then, maybe the site removed the link and
4523 renamed the whole hierarchy from @file{/usr/local2} to
4524 @file{/usr/local}. Such things happen all the time. I guess it would
4525 not be welcome at all that @GNUTAR{} removes the
4526 whole hierarchy just to make room for the link to be reinstated
4527 (unless it @emph{also} simultaneously restores the full
4528 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4529 able to remove a whole hierarchy to reestablish a symbolic link, for
4530 example, but @emph{only if} @option{--recursive-unlink} is specified
4531 to allow this behavior. In any case, single files are silently
4532 removed.
4533
4534 @xopindex{unlink-first, introduced}
4535 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4536 some cases by causing @command{tar} to remove files unconditionally
4537 before extracting them.
4538
4539 @node Overwrite Old Files
4540 @unnumberedsubsubsec Overwrite Old Files
4541
4542 @table @option
4543 @opindex overwrite
4544 @item --overwrite
4545 Overwrite existing files and directory metadata when extracting files
4546 from an archive.
4547
4548 This causes @command{tar} to write extracted files into the file system without
4549 regard to the files already on the system; i.e., files with the same
4550 names as archive members are overwritten when the archive is extracted.
4551 It also causes @command{tar} to extract the ownership, permissions,
4552 and time stamps onto any preexisting files or directories.
4553 If the name of a corresponding file name is a symbolic link, the file
4554 pointed to by the symbolic link will be overwritten instead of the
4555 symbolic link itself (if this is possible). Moreover, special devices,
4556 empty directories and even symbolic links are automatically removed if
4557 they are in the way of extraction.
4558
4559 Be careful when using the @option{--overwrite} option, particularly when
4560 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4561 can change the contents, ownership or permissions of any file on your
4562 system. Also, many systems do not take kindly to overwriting files that
4563 are currently being executed.
4564
4565 @opindex overwrite-dir
4566 @item --overwrite-dir
4567 Overwrite the metadata of directories when extracting files from an
4568 archive, but remove other files before extracting.
4569 @end table
4570
4571 @node Keep Old Files
4572 @unnumberedsubsubsec Keep Old Files
4573
4574 @table @option
4575 @opindex keep-old-files
4576 @item --keep-old-files
4577 @itemx -k
4578 Do not replace existing files from archive. The
4579 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4580 from replacing existing files with files with the same name from the
4581 archive. The @option{--keep-old-files} option is meaningless with
4582 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4583 files in the file system during extraction.
4584 @end table
4585
4586 @node Keep Newer Files
4587 @unnumberedsubsubsec Keep Newer Files
4588
4589 @table @option
4590 @opindex keep-newer-files
4591 @item --keep-newer-files
4592 Do not replace existing files that are newer than their archive
4593 copies. This option is meaningless with @option{--list} (@option{-t}).
4594 @end table
4595
4596 @node Unlink First
4597 @unnumberedsubsubsec Unlink First
4598
4599 @table @option
4600 @opindex unlink-first
4601 @item --unlink-first
4602 @itemx -U
4603 Remove files before extracting over them.
4604 This can make @command{tar} run a bit faster if you know in advance
4605 that the extracted files all need to be removed. Normally this option
4606 slows @command{tar} down slightly, so it is disabled by default.
4607 @end table
4608
4609 @node Recursive Unlink
4610 @unnumberedsubsubsec Recursive Unlink
4611
4612 @table @option
4613 @opindex recursive-unlink
4614 @item --recursive-unlink
4615 When this option is specified, try removing files and directory hierarchies
4616 before extracting over them. @emph{This is a dangerous option!}
4617 @end table
4618
4619 If you specify the @option{--recursive-unlink} option,
4620 @command{tar} removes @emph{anything} that keeps you from extracting a file
4621 as far as current permissions will allow it. This could include removal
4622 of the contents of a full directory hierarchy.
4623
4624 @node Data Modification Times
4625 @unnumberedsubsubsec Setting Data Modification Times
4626
4627 @cindex Data modification times of extracted files
4628 @cindex Modification times of extracted files
4629 Normally, @command{tar} sets the data modification times of extracted
4630 files to the corresponding times recorded for the files in the archive, but
4631 limits the permissions of extracted files by the current @code{umask}
4632 setting.
4633
4634 To set the data modification times of extracted files to the time when
4635 the files were extracted, use the @option{--touch} (@option{-m}) option in
4636 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4637
4638 @table @option
4639 @opindex touch
4640 @item --touch
4641 @itemx -m
4642 Sets the data modification time of extracted archive members to the time
4643 they were extracted, not the time recorded for them in the archive.
4644 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4645 @end table
4646
4647 @node Setting Access Permissions
4648 @unnumberedsubsubsec Setting Access Permissions
4649
4650 @cindex Permissions of extracted files
4651 @cindex Modes of extracted files
4652 To set the modes (access permissions) of extracted files to those
4653 recorded for those files in the archive, use @option{--same-permissions}
4654 in conjunction with the @option{--extract} (@option{--get},
4655 @option{-x}) operation.
4656
4657 @table @option
4658 @opindex preserve-permissions
4659 @opindex same-permissions
4660 @item --preserve-permissions
4661 @itemx --same-permissions
4662 @c @itemx --ignore-umask
4663 @itemx -p
4664 Set modes of extracted archive members to those recorded in the
4665 archive, instead of current umask settings. Use in conjunction with
4666 @option{--extract} (@option{--get}, @option{-x}).
4667 @end table
4668
4669 @node Directory Modification Times and Permissions
4670 @unnumberedsubsubsec Directory Modification Times and Permissions
4671
4672 After sucessfully extracting a file member, @GNUTAR{} normally
4673 restores its permissions and modification times, as described in the
4674 previous sections. This cannot be done for directories, because
4675 after extracting a directory @command{tar} will almost certainly
4676 extract files into that directory and this will cause the directory
4677 modification time to be updated. Moreover, restoring that directory
4678 permissions may not permit file creation within it. Thus, restoring
4679 directory permissions and modification times must be delayed at least
4680 until all files have been extracted into that directory. @GNUTAR{}
4681 restores directories using the following approach.
4682
4683 The extracted directories are created with the mode specified in the
4684 archive, as modified by the umask of the user, which gives sufficient
4685 permissions to allow file creation. The meta-information about the
4686 directory is recorded in the temporary list of directories. When
4687 preparing to extract next archive member, @GNUTAR{} checks if the
4688 directory prefix of this file contains the remembered directory. If
4689 it does not, the program assumes that all files have been extracted
4690 into that directory, restores its modification time and permissions
4691 and removes its entry from the internal list. This approach allows
4692 to correctly restore directory meta-information in the majority of
4693 cases, while keeping memory requirements sufficiently small. It is
4694 based on the fact, that most @command{tar} archives use the predefined
4695 order of members: first the directory, then all the files and
4696 subdirectories in that directory.
4697
4698 However, this is not always true. The most important exception are
4699 incremental archives (@pxref{Incremental Dumps}). The member order in
4700 an incremental archive is reversed: first all directory members are
4701 stored, followed by other (non-directory) members. So, when extracting
4702 from incremental archives, @GNUTAR{} alters the above procedure. It
4703 remebers all restored directories, and restores their meta-data
4704 only after the entire archive has been processed. Notice, that you do
4705 not need to specity any special options for that, as @GNUTAR{}
4706 automatically detects archives in incremental format.
4707
4708 There may be cases, when such processing is required for normal archives
4709 too. Consider the following example:
4710
4711 @smallexample
4712 @group
4713 $ @kbd{tar --no-recursion -cvf archive \
4714 foo foo/file1 bar bar/file foo/file2}
4715 foo/
4716 foo/file1
4717 bar/
4718 bar/file
4719 foo/file2
4720 @end group
4721 @end smallexample
4722
4723 During the normal operation, after encountering @file{bar}
4724 @GNUTAR{} will assume that all files from the directory @file{foo}
4725 were already extracted and will therefore restore its timestamp and
4726 permission bits. However, after extracting @file{foo/file2} the
4727 directory timestamp will be offset again.
4728
4729 To correctly restore directory meta-information in such cases, use
4730 @option{delay-directory-restore} command line option:
4731
4732 @table @option
4733 @opindex delay-directory-restore
4734 @item --delay-directory-restore
4735 Delays restoring of the modification times and permissions of extracted
4736 directories until the end of extraction. This way, correct
4737 meta-information is restored even if the archive has unusual member
4738 ordering.
4739
4740 @opindex no-delay-directory-restore
4741 @item --no-delay-directory-restore
4742 Cancel the effect of the previous @option{--delay-directory-restore}.
4743 Use this option if you have used @option{--delay-directory-restore} in
4744 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4745 temporarily disable it.
4746 @end table
4747
4748 @node Writing to Standard Output
4749 @unnumberedsubsubsec Writing to Standard Output
4750
4751 @cindex Writing extracted files to standard output
4752 @cindex Standard output, writing extracted files to
4753 To write the extracted files to the standard output, instead of
4754 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4755 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4756 extracting files to send them through a pipe, and do not need to
4757 preserve them in the file system. If you extract multiple members,
4758 they appear on standard output concatenated, in the order they are
4759 found in the archive.
4760
4761 @table @option
4762 @opindex to-stdout
4763 @item --to-stdout
4764 @itemx -O
4765 Writes files to the standard output. Use only in conjunction with
4766 @option{--extract} (@option{--get}, @option{-x}). When this option is
4767 used, instead of creating the files specified, @command{tar} writes
4768 the contents of the files extracted to its standard output. This may
4769 be useful if you are only extracting the files in order to send them
4770 through a pipe. This option is meaningless with @option{--list}
4771 (@option{-t}).
4772 @end table
4773
4774 This can be useful, for example, if you have a tar archive containing
4775 a big file and don't want to store the file on disk before processing
4776 it. You can use a command like this:
4777
4778 @smallexample
4779 tar -xOzf foo.tgz bigfile | process
4780 @end smallexample
4781
4782 or even like this if you want to process the concatenation of the files:
4783
4784 @smallexample
4785 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4786 @end smallexample
4787
4788 Hovewer, @option{--to-command} may be more convenient for use with
4789 multiple files. See the next section.
4790
4791 @node Writing to an External Program
4792 @unnumberedsubsubsec Writing to an External Program
4793
4794 You can instruct @command{tar} to send the contents of each extracted
4795 file to the standard input of an external program:
4796
4797 @table @option
4798 @opindex to-command
4799 @item --to-command=@var{command}
4800 Extract files and pipe their contents to the standard input of
4801 @var{command}. When this option is used, instead of creating the
4802 files specified, @command{tar} invokes @var{command} and pipes the
4803 contents of the files to its standard output. @var{Command} may
4804 contain command line arguments. The program is executed via
4805 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4806 extracted. Non-regular files (directories, etc.) are ignored when this
4807 option is used.
4808 @end table
4809
4810 The command can obtain the information about the file it processes
4811 from the following environment variables:
4812
4813 @table @var
4814 @vrindex TAR_FILETYPE, to-command environment
4815 @item TAR_FILETYPE
4816 Type of the file. It is a single letter with the following meaning:
4817
4818 @multitable @columnfractions 0.10 0.90
4819 @item f @tab Regular file
4820 @item d @tab Directory
4821 @item l @tab Symbolic link
4822 @item h @tab Hard link
4823 @item b @tab Block device
4824 @item c @tab Character device
4825 @end multitable
4826
4827 Currently only regular files are supported.
4828
4829 @vrindex TAR_MODE, to-command environment
4830 @item TAR_MODE
4831 File mode, an octal number.
4832
4833 @vrindex TAR_FILENAME, to-command environment
4834 @item TAR_FILENAME
4835 The name of the file.
4836
4837 @vrindex TAR_REALNAME, to-command environment
4838 @item TAR_REALNAME
4839 Name of the file as stored in the archive.
4840
4841 @vrindex TAR_UNAME, to-command environment
4842 @item TAR_UNAME
4843 Name of the file owner.
4844
4845 @vrindex TAR_GNAME, to-command environment
4846 @item TAR_GNAME
4847 Name of the file owner group.
4848
4849 @vrindex TAR_ATIME, to-command environment
4850 @item TAR_ATIME
4851 Time of last access. It is a decimal number, representing seconds
4852 since the epoch. If the archive provides times with nanosecond
4853 precision, the nanoseconds are appended to the timestamp after a
4854 decimal point.
4855
4856 @vrindex TAR_MTIME, to-command environment
4857 @item TAR_MTIME
4858 Time of last modification.
4859
4860 @vrindex TAR_CTIME, to-command environment
4861 @item TAR_CTIME
4862 Time of last status change.
4863
4864 @vrindex TAR_SIZE, to-command environment
4865 @item TAR_SIZE
4866 Size of the file.
4867
4868 @vrindex TAR_UID, to-command environment
4869 @item TAR_UID
4870 UID of the file owner.
4871
4872 @vrindex TAR_GID, to-command environment
4873 @item TAR_GID
4874 GID of the file owner.
4875 @end table
4876
4877 In addition to these variables, @env{TAR_VERSION} contains the
4878 @GNUTAR{} version number.
4879
4880 If @var{command} exits with a non-0 status, @command{tar} will print
4881 an error message similar to the following:
4882
4883 @smallexample
4884 tar: 2345: Child returned status 1
4885 @end smallexample
4886
4887 Here, @samp{2345} is the PID of the finished process.
4888
4889 If this behavior is not wanted, use @option{--ignore-command-error}:
4890
4891 @table @option
4892 @opindex ignore-command-error
4893 @item --ignore-command-error
4894 Ignore exit codes of subprocesses. Notice that if the program
4895 exits on signal or otherwise terminates abnormally, the error message
4896 will be printed even if this option is used.
4897
4898 @opindex no-ignore-command-error
4899 @item --no-ignore-command-error
4900 Cancel the effect of any previous @option{--ignore-command-error}
4901 option. This option is useful if you have set
4902 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4903 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4904 @end table
4905
4906 @node remove files
4907 @unnumberedsubsubsec Removing Files
4908
4909 @FIXME{The section is too terse. Something more to add? An example,
4910 maybe?}
4911
4912 @table @option
4913 @opindex remove-files
4914 @item --remove-files
4915 Remove files after adding them to the archive.
4916 @end table
4917
4918 @node Scarce
4919 @subsection Coping with Scarce Resources
4920 @UNREVISED
4921
4922 @cindex Small memory
4923 @cindex Running out of space
4924
4925 @menu
4926 * Starting File::
4927 * Same Order::
4928 @end menu
4929
4930 @node Starting File
4931 @unnumberedsubsubsec Starting File
4932
4933 @table @option
4934 @opindex starting-file
4935 @item --starting-file=@var{name}
4936 @itemx -K @var{name}
4937 Starts an operation in the middle of an archive. Use in conjunction
4938 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4939 @end table
4940
4941 @cindex Middle of the archive, starting in the
4942 If a previous attempt to extract files failed due to lack of disk
4943 space, you can use @option{--starting-file=@var{name}} (@option{-K
4944 @var{name}}) to start extracting only after member @var{name} of the
4945 archive. This assumes, of course, that there is now free space, or
4946 that you are now extracting into a different file system. (You could
4947 also choose to suspend @command{tar}, remove unnecessary files from
4948 the file system, and then restart the same @command{tar} operation.
4949 In this case, @option{--starting-file} is not necessary.
4950 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4951
4952 @node Same Order
4953 @unnumberedsubsubsec Same Order
4954
4955 @table @option
4956 @cindex Large lists of file names on small machines
4957 @opindex same-order
4958 @opindex preserve-order
4959 @item --same-order
4960 @itemx --preserve-order
4961 @itemx -s
4962 To process large lists of file names on machines with small amounts of
4963 memory. Use in conjunction with @option{--compare} (@option{--diff},
4964 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4965 (@option{--get}, @option{-x}).
4966 @end table
4967
4968 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4969 names to be listed or extracted is sorted in the same order as the
4970 files in the archive. This allows a large list of names to be used,
4971 even on a small machine that would not otherwise be able to hold all
4972 the names in memory at the same time. Such a sorted list can easily be
4973 created by running @samp{tar -t} on the archive and editing its output.
4974
4975 This option is probably never needed on modern computer systems.
4976
4977 @node backup
4978 @section Backup options
4979
4980 @cindex backup options
4981
4982 @GNUTAR{} offers options for making backups of files
4983 before writing new versions. These options control the details of
4984 these backups. They may apply to the archive itself before it is
4985 created or rewritten, as well as individual extracted members. Other
4986 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4987 and @command{mv}, for example) offer similar options.
4988
4989 Backup options may prove unexpectedly useful when extracting archives
4990 containing many members having identical name, or when extracting archives
4991 on systems having file name limitations, making different members appear
4992 has having similar names through the side-effect of name truncation.
4993 (This is true only if we have a good scheme for truncated backup names,
4994 which I'm not sure at all: I suspect work is needed in this area.)
4995 When any existing file is backed up before being overwritten by extraction,
4996 then clashing files are automatically be renamed to be unique, and the
4997 true name is kept for only the last file of a series of clashing files.
4998 By using verbose mode, users may track exactly what happens.
4999
5000 At the detail level, some decisions are still experimental, and may
5001 change in the future, we are waiting comments from our users. So, please
5002 do not learn to depend blindly on the details of the backup features.
5003 For example, currently, directories themselves are never renamed through
5004 using these options, so, extracting a file over a directory still has
5005 good chances to fail. Also, backup options apply to created archives,
5006 not only to extracted members. For created archives, backups will not
5007 be attempted when the archive is a block or character device, or when it
5008 refers to a remote file.
5009
5010 For the sake of simplicity and efficiency, backups are made by renaming old
5011 files prior to creation or extraction, and not by copying. The original
5012 name is restored if the file creation fails. If a failure occurs after a
5013 partial extraction of a file, both the backup and the partially extracted
5014 file are kept.
5015
5016 @table @samp
5017 @item --backup[=@var{method}]
5018 @opindex backup
5019 @vindex VERSION_CONTROL
5020 @cindex backups
5021 Back up files that are about to be overwritten or removed.
5022 Without this option, the original versions are destroyed.
5023
5024 Use @var{method} to determine the type of backups made.
5025 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5026 environment variable. And if @env{VERSION_CONTROL} is not set,
5027 use the @samp{existing} method.
5028
5029 @vindex version-control @r{Emacs variable}
5030 This option corresponds to the Emacs variable @samp{version-control};
5031 the same values for @var{method} are accepted as in Emacs. This option
5032 also allows more descriptive names. The valid @var{method}s are:
5033
5034 @table @samp
5035 @item t
5036 @itemx numbered
5037 @cindex numbered @r{backup method}
5038 Always make numbered backups.
5039
5040 @item nil
5041 @itemx existing
5042 @cindex existing @r{backup method}
5043 Make numbered backups of files that already have them, simple backups
5044 of the others.
5045
5046 @item never
5047 @itemx simple
5048 @cindex simple @r{backup method}
5049 Always make simple backups.
5050
5051 @end table
5052
5053 @item --suffix=@var{suffix}
5054 @opindex suffix
5055 @cindex backup suffix
5056 @vindex SIMPLE_BACKUP_SUFFIX
5057 Append @var{suffix} to each backup file made with @option{--backup}. If this
5058 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5059 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5060 set, the default is @samp{~}, just as in Emacs.
5061
5062 @end table
5063
5064 @node Applications
5065 @section Notable @command{tar} Usages
5066 @UNREVISED
5067
5068 @FIXME{Using Unix file linking capability to recreate directory
5069 structures---linking files into one subdirectory and then
5070 @command{tar}ring that directory.}
5071
5072 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5073
5074 @findex uuencode
5075 You can easily use archive files to transport a group of files from
5076 one system to another: put all relevant files into an archive on one
5077 computer system, transfer the archive to another system, and extract
5078 the contents there. The basic transfer medium might be magnetic tape,
5079 Internet FTP, or even electronic mail (though you must encode the
5080 archive with @command{uuencode} in order to transport it properly by
5081 mail). Both machines do not have to use the same operating system, as
5082 long as they both support the @command{tar} program.
5083
5084 For example, here is how you might copy a directory's contents from
5085 one disk to another, while preserving the dates, modes, owners and
5086 link-structure of all the files therein. In this case, the transfer
5087 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5088
5089 @smallexample
5090 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5091 @end smallexample
5092
5093 @noindent
5094 You can avoid subshells by using @option{-C} option:
5095
5096 @smallexample
5097 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5098 @end smallexample
5099
5100 @noindent
5101 The command also works using short option forms:
5102
5103 @smallexample
5104 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5105 | (cd targetdir; tar --extract --file=-)}
5106 # Or:
5107 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5108 | tar --directory targetdir --extract --file=-}
5109 @end smallexample
5110
5111 @noindent
5112 This is one of the easiest methods to transfer a @command{tar} archive.
5113
5114 @node looking ahead
5115 @section Looking Ahead: The Rest of this Manual
5116
5117 You have now seen how to use all eight of the operations available to
5118 @command{tar}, and a number of the possible options. The next chapter
5119 explains how to choose and change file and archive names, how to use
5120 files to store names of other files which you can then call as
5121 arguments to @command{tar} (this can help you save time if you expect to
5122 archive the same list of files a number of times), and so forth.
5123 @FIXME{in case it's not obvious, i'm making this up in some sense
5124 based on my limited memory of what the next chapter *really* does. i
5125 just wanted to flesh out this final section a little bit so i'd
5126 remember to stick it in here. :-)}
5127
5128 If there are too many files to conveniently list on the command line,
5129 you can list the names in a file, and @command{tar} will read that file.
5130 @xref{files}.
5131
5132 There are various ways of causing @command{tar} to skip over some files,
5133 and not archive them. @xref{Choosing}.
5134
5135 @node Backups
5136 @chapter Performing Backups and Restoring Files
5137 @UNREVISED
5138
5139 @GNUTAR{} is distributed along with the scripts
5140 which the Free Software Foundation uses for performing backups. There
5141 is no corresponding scripts available yet for doing restoration of
5142 files. Even if there is a good chance those scripts may be satisfying
5143 to you, they are not the only scripts or methods available for doing
5144 backups and restore. You may well create your own, or use more
5145 sophisticated packages dedicated to that purpose.
5146
5147 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5148 Automatic Network Disk Archiver), a backup system developed by James
5149 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5150 This is free software, and it is available at these places:
5151
5152 @smallexample
5153 http://www.cs.umd.edu/projects/amanda/amanda.html
5154 ftp://ftp.cs.umd.edu/pub/amanda
5155 @end smallexample
5156
5157 @FIXME{
5158
5159 Here is a possible plan for a future documentation about the backuping
5160 scripts which are provided within the @GNUTAR{}
5161 distribution.
5162
5163 @itemize @bullet
5164 @item dumps
5165 @itemize @minus
5166 @item what are dumps
5167 @item different levels of dumps
5168 @itemize +
5169 @item full dump = dump everything
5170 @item level 1, level 2 dumps etc
5171 A level @var{n} dump dumps everything changed since the last level
5172 @var{n}-1 dump (?)
5173 @end itemize
5174 @item how to use scripts for dumps (ie, the concept)
5175 @itemize +
5176 @item scripts to run after editing backup specs (details)
5177 @end itemize
5178 @item Backup Specs, what is it.
5179 @itemize +
5180 @item how to customize
5181 @item actual text of script [/sp/dump/backup-specs]
5182 @end itemize
5183 @item Problems
5184 @itemize +
5185 @item rsh doesn't work
5186 @item rtape isn't installed
5187 @item (others?)
5188 @end itemize
5189 @item the @option{--incremental} option of tar
5190 @item tapes
5191 @itemize +
5192 @item write protection
5193 @item types of media, different sizes and types, useful for different things
5194 @item files and tape marks
5195 one tape mark between files, two at end.
5196 @item positioning the tape
5197 MT writes two at end of write,
5198 backspaces over one when writing again.
5199 @end itemize
5200 @end itemize
5201 @end itemize
5202 }
5203
5204 This chapter documents both the provided shell scripts and @command{tar}
5205 options which are more specific to usage as a backup tool.
5206
5207 To @dfn{back up} a file system means to create archives that contain
5208 all the files in that file system. Those archives can then be used to
5209 restore any or all of those files (for instance if a disk crashes or a
5210 file is accidentally deleted). File system @dfn{backups} are also
5211 called @dfn{dumps}.
5212
5213 @menu
5214 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5215 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5216 * Backup Levels:: Levels of Backups
5217 * Backup Parameters:: Setting Parameters for Backups and Restoration
5218 * Scripted Backups:: Using the Backup Scripts
5219 * Scripted Restoration:: Using the Restore Script
5220 @end menu
5221
5222 @node Full Dumps
5223 @section Using @command{tar} to Perform Full Dumps
5224 @UNREVISED
5225
5226 @cindex full dumps
5227 @cindex dumps, full
5228
5229 @cindex corrupted archives
5230 Full dumps should only be made when no other people or programs
5231 are modifying files in the file system. If files are modified while
5232 @command{tar} is making the backup, they may not be stored properly in
5233 the archive, in which case you won't be able to restore them if you
5234 have to. (Files not being modified are written with no trouble, and do
5235 not corrupt the entire archive.)
5236
5237 You will want to use the @option{--label=@var{archive-label}}
5238 (@option{-V @var{archive-label}}) option to give the archive a
5239 volume label, so you can tell what this archive is even if the label
5240 falls off the tape, or anything like that.
5241
5242 Unless the file system you are dumping is guaranteed to fit on
5243 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5244 Make sure you have enough tapes on hand to complete the backup.
5245
5246 If you want to dump each file system separately you will need to use
5247 the @option{--one-file-system} option to prevent
5248 @command{tar} from crossing file system boundaries when storing
5249 (sub)directories.
5250
5251 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5252 option is not needed, since this is a complete copy of everything in
5253 the file system, and a full restore from this backup would only be
5254 done onto a completely
5255 empty disk.
5256
5257 Unless you are in a hurry, and trust the @command{tar} program (and your
5258 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5259 option, to make sure your files really made it onto the dump properly.
5260 This will also detect cases where the file was modified while (or just
5261 after) it was being archived. Not all media (notably cartridge tapes)
5262 are capable of being verified, unfortunately.
5263
5264 @node Incremental Dumps
5265 @section Using @command{tar} to Perform Incremental Dumps
5266
5267 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5268 stores additional metadata so that exact state of the file system
5269 can be restored when extracting the archive.
5270
5271 @GNUTAR{} currently offers two options for handling incremental
5272 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5273 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5274
5275 @opindex listed-incremental
5276 The option @option{--listed-incremental} instructs tar to operate on
5277 an incremental archive with additional metadata stored in a standalone
5278 file, called a @dfn{snapshot file}. The purpose of this file is to help
5279 determine which files have been changed, added or deleted since the
5280 last backup, so that the next incremental backup will contain only
5281 modified files. The name of the snapshot file is given as an argument
5282 to the option:
5283
5284 @table @option
5285 @item --listed-incremental=@var{file}
5286 @itemx -g @var{file}
5287 Handle incremental backups with snapshot data in @var{file}.
5288 @end table
5289
5290 To create an incremental backup, you would use
5291 @option{--listed-incremental} together with @option{--create}
5292 (@pxref{create}). For example:
5293
5294 @smallexample
5295 $ @kbd{tar --create \
5296 --file=archive.1.tar \
5297 --listed-incremental=/var/log/usr.snar \
5298 /usr}
5299 @end smallexample
5300
5301 This will create in @file{archive.1.tar} an incremental backup of
5302 the @file{/usr} file system, storing additional metadata in the file
5303 @file{/var/log/usr.snar}. If this file does not exist, it will be
5304 created. The created archive will then be a @dfn{level 0 backup};
5305 please see the next section for more on backup levels.
5306
5307 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5308 determines which files are modified. In this case only these files will be
5309 stored in the archive. Suppose, for example, that after running the
5310 above command, you delete file @file{/usr/doc/old} and create
5311 directory @file{/usr/local/db} with the following contents:
5312
5313 @smallexample
5314 $ @kbd{ls /usr/local/db}
5315 /usr/local/db/data
5316 /usr/local/db/index
5317 @end smallexample
5318
5319 Some time later you create another incremental backup. You will
5320 then see:
5321
5322 @smallexample
5323 $ @kbd{tar --create \
5324 --file=archive.2.tar \
5325 --listed-incremental=/var/log/usr.snar \
5326 /usr}
5327 tar: usr/local/db: Directory is new
5328 usr/local/db/
5329 usr/local/db/data
5330 usr/local/db/index
5331 @end smallexample
5332
5333 @noindent
5334 The created archive @file{archive.2.tar} will contain only these
5335 three members. This archive is called a @dfn{level 1 backup}. Notice
5336 that @file{/var/log/usr.snar} will be updated with the new data, so if
5337 you plan to create more @samp{level 1} backups, it is necessary to
5338 create a working copy of the snapshot file before running
5339 @command{tar}. The above example will then be modified as follows:
5340
5341 @smallexample
5342 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5343 $ @kbd{tar --create \
5344 --file=archive.2.tar \
5345 --listed-incremental=/var/log/usr.snar-1 \
5346 /usr}
5347 @end smallexample
5348
5349 Incremental dumps depend crucially on time stamps, so the results are
5350 unreliable if you modify a file's time stamps during dumping (e.g.,
5351 with the @option{--atime-preserve=replace} option), or if you set the clock
5352 backwards.
5353
5354 Metadata stored in snapshot files include device numbers, which,
5355 obviously is supposed to be a non-volatile value. However, it turns
5356 out that NFS devices have undependable values when an automounter
5357 gets in the picture. This can lead to a great deal of spurious
5358 redumping in incremental dumps, so it is somewhat useless to compare
5359 two NFS devices numbers over time. The solution implemented currently
5360 is to considers all NFS devices as being equal when it comes to
5361 comparing directories; this is fairly gross, but there does not seem
5362 to be a better way to go.
5363
5364 Note that incremental archives use @command{tar} extensions and may
5365 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5366
5367 @xopindex{listed-incremental, using with @option{--extract}}
5368 @xopindex{extract, using with @option{--listed-incremental}}
5369 To extract from the incremental dumps, use
5370 @option{--listed-incremental} together with @option{--extract}
5371 option (@pxref{extracting files}). In this case, @command{tar} does
5372 not need to access snapshot file, since all the data necessary for
5373 extraction are stored in the archive itself. So, when extracting, you
5374 can give whatever argument to @option{--listed-incremental}, the usual
5375 practice is to use @option{--listed-incremental=/dev/null}.
5376 Alternatively, you can use @option{--incremental}, which needs no
5377 arguments. In general, @option{--incremental} (@option{-G}) can be
5378 used as a shortcut for @option{--listed-incremental} when listing or
5379 extracting incremental backups (for more information, regarding this
5380 option, @pxref{incremental-op}).
5381
5382 When extracting from the incremental backup @GNUTAR{} attempts to
5383 restore the exact state the file system had when the archive was
5384 created. In particular, it will @emph{delete} those files in the file
5385 system that did not exist in their directories when the archive was
5386 created. If you have created several levels of incremental files,
5387 then in order to restore the exact contents the file system had when
5388 the last level was created, you will need to restore from all backups
5389 in turn. Continuing our example, to restore the state of @file{/usr}
5390 file system, one would do@footnote{Notice, that since both archives
5391 were created withouth @option{-P} option (@pxref{absolute}), these
5392 commands should be run from the root file system.}:
5393
5394 @smallexample
5395 $ @kbd{tar --extract \
5396 --listed-incremental=/dev/null \
5397 --file archive.1.tar}
5398 $ @kbd{tar --extract \
5399 --listed-incremental=/dev/null \
5400 --file archive.2.tar}
5401 @end smallexample
5402
5403 To list the contents of an incremental archive, use @option{--list}
5404 (@pxref{list}), as usual. To obtain more information about the
5405 archive, use @option{--listed-incremental} or @option{--incremental}
5406 combined with two @option{--verbose} options@footnote{Two
5407 @option{--verbose} options were selected to avoid breaking usual
5408 verbose listing output (@option{--list --verbose}) when using in
5409 scripts.
5410
5411 @xopindex{incremental, using with @option{--list}}
5412 @xopindex{listed-incremental, using with @option{--list}}
5413 @xopindex{list, using with @option{--incremental}}
5414 @xopindex{list, using with @option{--listed-incremental}}
5415 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5416 contents of the DUMPDIR header (with terminating nulls) when
5417 @option{--incremental} or @option{--listed-incremental} option was
5418 given, no matter what the verbosity level. This behavior, and,
5419 especially, the binary output it produced were considered incovenient
5420 and were changed in version 1.16}:
5421
5422 @smallexample
5423 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5424 @end smallexample
5425
5426 This command will print, for each directory in the archive, the list
5427 of files in that directory at the time the archive was created. This
5428 information is put out in a format which is both human-readable and
5429 unambiguous for a program: each file name is printed as
5430
5431 @smallexample
5432 @var{x} @var{file}
5433 @end smallexample
5434
5435 @noindent
5436 where @var{x} is a letter describing the status of the file: @samp{Y}
5437 if the file is present in the archive, @samp{N} if the file is not
5438 included in the archive, or a @samp{D} if the file is a directory (and
5439 is included in the archive). @xref{Dumpdir}, for the detailed
5440 description of dumpdirs and status codes. Each such
5441 line is terminated by a newline character. The last line is followed
5442 by an additional newline to indicate the end of the data.
5443
5444 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5445 gives the same behavior as @option{--listed-incremental} when used
5446 with @option{--list} and @option{--extract} options. When used with
5447 @option{--create} option, it creates an incremental archive without
5448 creating snapshot file. Thus, it is impossible to create several
5449 levels of incremental backups with @option{--incremental} option.
5450
5451 @node Backup Levels
5452 @section Levels of Backups
5453
5454 An archive containing all the files in the file system is called a
5455 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5456 creating a full dump every day. This strategy, however, would waste a
5457 substantial amount of archive media and user time, as unchanged files
5458 are daily re-archived.
5459
5460 It is more efficient to do a full dump only occasionally. To back up
5461 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5462 one} dump archives all the files that have changed since the last full
5463 dump.
5464
5465 A typical dump strategy would be to perform a full dump once a week,
5466 and a level one dump once a day. This means some versions of files
5467 will in fact be archived more than once, but this dump strategy makes
5468 it possible to restore a file system to within one day of accuracy by
5469 only extracting two archives---the last weekly (full) dump and the
5470 last daily (level one) dump. The only information lost would be in
5471 files changed or created since the last daily backup. (Doing dumps
5472 more than once a day is usually not worth the trouble).
5473
5474 @GNUTAR{} comes with scripts you can use to do full
5475 and level-one (actually, even level-two and so on) dumps. Using
5476 scripts (shell programs) to perform backups and restoration is a
5477 convenient and reliable alternative to typing out file name lists
5478 and @command{tar} commands by hand.
5479
5480 Before you use these scripts, you need to edit the file
5481 @file{backup-specs}, which specifies parameters used by the backup
5482 scripts and by the restore script. This file is usually located
5483 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5484 detailed description. Once the backup parameters are set, you can
5485 perform backups or restoration by running the appropriate script.
5486
5487 The name of the backup script is @code{backup}. The name of the
5488 restore script is @code{restore}. The following sections describe
5489 their use in detail.
5490
5491 @emph{Please Note:} The backup and restoration scripts are
5492 designed to be used together. While it is possible to restore files by
5493 hand from an archive which was created using a backup script, and to create
5494 an archive by hand which could then be extracted using the restore script,
5495 it is easier to use the scripts. @xref{Incremental Dumps}, before
5496 making such an attempt.
5497
5498 @node Backup Parameters
5499 @section Setting Parameters for Backups and Restoration
5500
5501 The file @file{backup-specs} specifies backup parameters for the
5502 backup and restoration scripts provided with @command{tar}. You must
5503 edit @file{backup-specs} to fit your system configuration and schedule
5504 before using these scripts.
5505
5506 Syntactically, @file{backup-specs} is a shell script, containing
5507 mainly variable assignments. However, any valid shell construct
5508 is allowed in this file. Particularly, you may wish to define
5509 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5510 For more information about shell script syntax, please refer to
5511 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5512 g_02, the definition of the Shell Command Language}. See also
5513 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5514
5515 The shell variables controlling behavior of @code{backup} and
5516 @code{restore} are described in the following subsections.
5517
5518 @menu
5519 * General-Purpose Variables::
5520 * Magnetic Tape Control::
5521 * User Hooks::
5522 * backup-specs example:: An Example Text of @file{Backup-specs}
5523 @end menu
5524
5525 @node General-Purpose Variables
5526 @subsection General-Purpose Variables
5527
5528 @defvr {Backup variable} ADMINISTRATOR
5529 The user name of the backup administrator. @code{Backup} scripts
5530 sends a backup report to this address.
5531 @end defvr
5532
5533 @defvr {Backup variable} BACKUP_HOUR
5534 The hour at which the backups are done. This can be a number from 0
5535 to 23, or the time specification in form @var{hours}:@var{minutes},
5536 or the string @samp{now}.
5537
5538 This variable is used by @code{backup}. Its value may be overridden
5539 using @option{--time} option (@pxref{Scripted Backups}).
5540 @end defvr
5541
5542 @defvr {Backup variable} TAPE_FILE
5543
5544 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5545 is a remote archive (@pxref{remote-dev}), backup script will suppose
5546 that your @command{mt} is able to access remote devices. If @var{RSH}
5547 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5548 invocations of @command{mt}.
5549 @end defvr
5550
5551 @defvr {Backup variable} BLOCKING
5552
5553 The blocking factor @command{tar} will use when writing the dump archive.
5554 @xref{Blocking Factor}.
5555 @end defvr
5556
5557 @defvr {Backup variable} BACKUP_DIRS
5558
5559 A list of file systems to be dumped (for @code{backup}), or restored
5560 (for @code{restore}). You can include any directory
5561 name in the list --- subdirectories on that file system will be
5562 included, regardless of how they may look to other networked machines.
5563 Subdirectories on other file systems will be ignored.
5564
5565 The host name specifies which host to run @command{tar} on, and should
5566 normally be the host that actually contains the file system. However,
5567 the host machine must have @GNUTAR{} installed, and
5568 must be able to access the directory containing the backup scripts and
5569 their support files using the same file name that is used on the
5570 machine where the scripts are run (i.e. what @command{pwd} will print
5571 when in that directory on that machine). If the host that contains
5572 the file system does not have this capability, you can specify another
5573 host as long as it can access the file system through NFS.
5574
5575 If the list of file systems is very long you may wish to put it
5576 in a separate file. This file is usually named
5577 @file{/etc/backup/dirs}, but this name may be overridden in
5578 @file{backup-specs} using @code{DIRLIST} variable.
5579 @end defvr
5580
5581 @defvr {Backup variable} DIRLIST
5582
5583 A path to the file containing the list of the file systems to backup
5584 or restore. By default it is @file{/etc/backup/dirs}.
5585 @end defvr
5586
5587 @defvr {Backup variable} BACKUP_FILES
5588
5589 A list of individual files to be dumped (for @code{backup}), or restored
5590 (for @code{restore}). These should be accessible from the machine on
5591 which the backup script is run.
5592
5593 If the list of file systems is very long you may wish to store it
5594 in a separate file. This file is usually named
5595 @file{/etc/backup/files}, but this name may be overridden in
5596 @file{backup-specs} using @code{FILELIST} variable.
5597 @end defvr
5598
5599 @defvr {Backup variable} FILELIST
5600
5601 A path to the file containing the list of the individual files to backup
5602 or restore. By default it is @file{/etc/backup/files}.
5603 @end defvr
5604
5605 @defvr {Backup variable} MT
5606
5607 Full file name of @command{mt} binary.
5608 @end defvr
5609
5610 @defvr {Backup variable} RSH
5611 @anchor{RSH}
5612 Full file name of @command{rsh} binary or its equivalent. You may wish to
5613 set it to @code{ssh}, to improve security. In this case you will have
5614 to use public key authentication.
5615 @end defvr
5616
5617 @defvr {Backup variable} RSH_COMMAND
5618
5619 Full file name of @command{rsh} binary on remote mashines. This will
5620 be passed via @option{--rsh-command} option to the remote invocation
5621 of @GNUTAR{}.
5622 @end defvr
5623
5624 @defvr {Backup variable} VOLNO_FILE
5625
5626 Name of temporary file to hold volume numbers. This needs to be accessible
5627 by all the machines which have file systems to be dumped.
5628 @end defvr
5629
5630 @defvr {Backup variable} XLIST
5631
5632 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5633 located on the remote machine and containing the list of files to
5634 be excluded from the backup. Exclude file lists are searched in
5635 /etc/tar-backup directory. A common use for exclude file lists
5636 is to exclude files containing security-sensitive information
5637 (e.g., @file{/etc/shadow} from backups).
5638
5639 This variable affects only @code{backup}.
5640 @end defvr
5641
5642 @defvr {Backup variable} SLEEP_TIME
5643
5644 Time to sleep between dumps of any two successive file systems
5645
5646 This variable affects only @code{backup}.
5647 @end defvr
5648
5649 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5650
5651 Script to be run when it's time to insert a new tape in for the next
5652 volume. Administrators may want to tailor this script for their site.
5653 If this variable isn't set, @GNUTAR{} will display its built-in
5654 prompt, and will expect confirmation from the console. For the
5655 description of the default prompt, see @ref{change volume prompt}.
5656
5657 @end defvr
5658
5659 @defvr {Backup variable} SLEEP_MESSAGE
5660
5661 Message to display on the terminal while waiting for dump time. Usually
5662 this will just be some literal text.
5663 @end defvr
5664
5665 @defvr {Backup variable} TAR
5666
5667 Full file name of the @GNUTAR{} executable. If this is not set, backup
5668 scripts will search @command{tar} in the current shell path.
5669 @end defvr
5670
5671 @node Magnetic Tape Control
5672 @subsection Magnetic Tape Control
5673
5674 Backup scripts access tape device using special @dfn{hook functions}.
5675 These functions take a single argument -- the name of the tape
5676 device. Their names are kept in the following variables:
5677
5678 @defvr {Backup variable} MT_BEGIN
5679 The name of @dfn{begin} function. This function is called before
5680 accessing the drive. By default it retensions the tape:
5681
5682 @smallexample
5683 MT_BEGIN=mt_begin
5684
5685 mt_begin() @{
5686 mt -f "$1" retension
5687 @}
5688 @end smallexample
5689 @end defvr
5690
5691 @defvr {Backup variable} MT_REWIND
5692 The name of @dfn{rewind} function. The default definition is as
5693 follows:
5694
5695 @smallexample
5696 MT_REWIND=mt_rewind
5697
5698 mt_rewind() @{
5699 mt -f "$1" rewind
5700 @}
5701 @end smallexample
5702
5703 @end defvr
5704
5705 @defvr {Backup variable} MT_OFFLINE
5706 The name of the function switching the tape off line. By default
5707 it is defined as follows:
5708
5709 @smallexample
5710 MT_OFFLINE=mt_offline
5711
5712 mt_offline() @{
5713 mt -f "$1" offl
5714 @}
5715 @end smallexample
5716 @end defvr
5717
5718 @defvr {Backup variable} MT_STATUS
5719 The name of the function used to obtain the status of the archive device,
5720 including error count. Default definition:
5721
5722 @smallexample
5723 MT_STATUS=mt_status
5724
5725 mt_status() @{
5726 mt -f "$1" status
5727 @}
5728 @end smallexample
5729 @end defvr
5730
5731 @node User Hooks
5732 @subsection User Hooks
5733
5734 @dfn{User hooks} are shell functions executed before and after
5735 each @command{tar} invocation. Thus, there are @dfn{backup
5736 hooks}, which are executed before and after dumping each file
5737 system, and @dfn{restore hooks}, executed before and
5738 after restoring a file system. Each user hook is a shell function
5739 taking four arguments:
5740
5741 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5742 Its arguments are:
5743
5744 @table @var
5745 @item level
5746 Current backup or restore level.
5747
5748 @item host
5749 Name or IP address of the host machine being dumped or restored.
5750
5751 @item fs
5752 Full path name to the file system being dumped or restored.
5753
5754 @item fsname
5755 File system name with directory separators replaced with colons. This
5756 is useful, e.g., for creating unique files.
5757 @end table
5758 @end deffn
5759
5760 Following variables keep the names of user hook functions
5761
5762 @defvr {Backup variable} DUMP_BEGIN
5763 Dump begin function. It is executed before dumping the file system.
5764 @end defvr
5765
5766 @defvr {Backup variable} DUMP_END
5767 Executed after dumping the file system.
5768 @end defvr
5769
5770 @defvr {Backup variable} RESTORE_BEGIN
5771 Executed before restoring the file system.
5772 @end defvr
5773
5774 @defvr {Backup variable} RESTORE_END
5775 Executed after restoring the file system.
5776 @end defvr
5777
5778 @node backup-specs example
5779 @subsection An Example Text of @file{Backup-specs}
5780
5781 The following is an example of @file{backup-specs}:
5782
5783 @smallexample
5784 # site-specific parameters for file system backup.
5785
5786 ADMINISTRATOR=friedman
5787 BACKUP_HOUR=1
5788 TAPE_FILE=/dev/nrsmt0
5789
5790 # Use @code{ssh} instead of the less secure @code{rsh}
5791 RSH=/usr/bin/ssh
5792 RSH_COMMAND=/usr/bin/ssh
5793
5794 # Override MT_STATUS function:
5795 my_status() @{
5796 mts -t $TAPE_FILE
5797 @}
5798 MT_STATUS=my_status
5799
5800 # Disable MT_OFFLINE function
5801 MT_OFFLINE=:
5802
5803 BLOCKING=124
5804 BACKUP_DIRS="
5805 albert:/fs/fsf
5806 apple-gunkies:/gd
5807 albert:/fs/gd2
5808 albert:/fs/gp
5809 geech:/usr/jla
5810 churchy:/usr/roland
5811 albert:/
5812 albert:/usr
5813 apple-gunkies:/
5814 apple-gunkies:/usr
5815 gnu:/hack
5816 gnu:/u
5817 apple-gunkies:/com/mailer/gnu
5818 apple-gunkies:/com/archive/gnu"
5819
5820 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5821
5822 @end smallexample
5823
5824 @node Scripted Backups
5825 @section Using the Backup Scripts
5826
5827 The syntax for running a backup script is:
5828
5829 @smallexample
5830 backup --level=@var{level} --time=@var{time}
5831 @end smallexample
5832
5833 The @option{level} option requests the dump level. Thus, to produce
5834 a full dump, specify @code{--level=0} (this is the default, so
5835 @option{--level} may be omitted if its value is @code{0}).
5836 @footnote{For backward compatibility, the @code{backup} will also
5837 try to deduce the requested dump level from the name of the
5838 script itself. If the name consists of a string @samp{level-}
5839 followed by a single decimal digit, that digit is taken as
5840 the dump level number. Thus, you may create a link from @code{backup}
5841 to @code{level-1} and then run @code{level-1} whenever you need to
5842 create a level one dump.}
5843
5844 The @option{--time} option determines when should the backup be
5845 run. @var{Time} may take three forms:
5846
5847 @table @asis
5848 @item @var{hh}:@var{mm}
5849
5850 The dump must be run at @var{hh} hours @var{mm} minutes.
5851
5852 @item @var{hh}
5853
5854 The dump must be run at @var{hh} hours
5855
5856 @item now
5857
5858 The dump must be run immediately.
5859 @end table
5860
5861 You should start a script with a tape or disk mounted. Once you
5862 start a script, it prompts you for new tapes or disks as it
5863 needs them. Media volumes don't have to correspond to archive
5864 files --- a multi-volume archive can be started in the middle of a
5865 tape that already contains the end of another multi-volume archive.
5866 The @code{restore} script prompts for media by its archive volume,
5867 so to avoid an error message you should keep track of which tape
5868 (or disk) contains which volume of the archive (@pxref{Scripted
5869 Restoration}).
5870
5871 The backup scripts write two files on the file system. The first is a
5872 record file in @file{/etc/tar-backup/}, which is used by the scripts
5873 to store and retrieve information about which files were dumped. This
5874 file is not meant to be read by humans, and should not be deleted by
5875 them. @xref{Snapshot Files}, for a more detailed explanation of this
5876 file.
5877
5878 The second file is a log file containing the names of the file systems
5879 and files dumped, what time the backup was made, and any error
5880 messages that were generated, as well as how much space was left in
5881 the media volume after the last volume of the archive was written.
5882 You should check this log file after every backup. The file name is
5883 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5884 represents current date, and @var{n} represents current dump level number.
5885
5886 The script also prints the name of each system being dumped to the
5887 standard output.
5888
5889 Following is the full list of options accepted by @code{backup}
5890 script:
5891
5892 @table @option
5893 @item -l @var{level}
5894 @itemx --level=@var{level}
5895 Do backup level @var{level} (default 0).
5896
5897 @item -f
5898 @itemx --force
5899 Force backup even if today's log file already exists.
5900
5901 @item -v[@var{level}]
5902 @itemx --verbose[=@var{level}]
5903 Set verbosity level. The higher the level is, the more debugging
5904 information will be output during execution. Devault @var{level}
5905 is 100, which means the highest debugging level.
5906
5907 @item -t @var{start-time}
5908 @itemx --time=@var{start-time}
5909 Wait till @var{time}, then do backup.
5910
5911 @item -h
5912 @itemx --help
5913 Display short help message and exit.
5914
5915 @item -V
5916 @itemx --version
5917 Display information about the program's name, version, origin and legal
5918 status, all on standard output, and then exit successfully.
5919 @end table
5920
5921
5922 @node Scripted Restoration
5923 @section Using the Restore Script
5924
5925 To restore files that were archived using a scripted backup, use the
5926 @code{restore} script. Its usage is quite straightforward. In the
5927 simplest form, invoke @code{restore --all}, it will
5928 then restore all the file systems and files specified in
5929 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5930
5931 You may select the file systems (and/or files) to restore by
5932 giving @code{restore} list of @dfn{patterns} in its command
5933 line. For example, running
5934
5935 @smallexample
5936 restore 'albert:*'
5937 @end smallexample
5938
5939 @noindent
5940 will restore all file systems on the machine @samp{albert}. A more
5941 complicated example:
5942
5943 @smallexample
5944 restore 'albert:*' '*:/var'
5945 @end smallexample
5946
5947 @noindent
5948 This command will restore all file systems on the machine @samp{albert}
5949 as well as @file{/var} file system on all machines.
5950
5951 By default @code{restore} will start restoring files from the lowest
5952 available dump level (usually zero) and will continue through
5953 all available dump levels. There may be situations where such a
5954 thorough restore is not necessary. For example, you may wish to
5955 restore only files from the recent level one backup. To do so,
5956 use @option{--level} option, as shown in the example below:
5957
5958 @smallexample
5959 restore --level=1
5960 @end smallexample
5961
5962 The full list of options accepted by @code{restore} follows:
5963
5964 @table @option
5965 @item -a
5966 @itemx --all
5967 Restore all file systems and files specified in @file{backup-specs}
5968
5969 @item -l @var{level}
5970 @itemx --level=@var{level}
5971 Start restoring from the given backup level, instead of the default 0.
5972
5973 @item -v[@var{level}]
5974 @itemx --verbose[=@var{level}]
5975 Set verbosity level. The higher the level is, the more debugging
5976 information will be output during execution. Devault @var{level}
5977 is 100, which means the highest debugging level.
5978
5979 @item -h
5980 @itemx --help
5981 Display short help message and exit.
5982
5983 @item -V
5984 @itemx --version
5985 Display information about the program's name, version, origin and legal
5986 status, all on standard output, and then exit successfully.
5987 @end table
5988
5989 You should start the restore script with the media containing the
5990 first volume of the archive mounted. The script will prompt for other
5991 volumes as they are needed. If the archive is on tape, you don't need
5992 to rewind the tape to to its beginning---if the tape head is
5993 positioned past the beginning of the archive, the script will rewind
5994 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
5995 positioning.
5996
5997 @quotation
5998 @strong{Warning:} The script will delete files from the active file
5999 system if they were not in the file system when the archive was made.
6000 @end quotation
6001
6002 @xref{Incremental Dumps}, for an explanation of how the script makes
6003 that determination.
6004
6005 @node Choosing
6006 @chapter Choosing Files and Names for @command{tar}
6007 @UNREVISED
6008
6009 Certain options to @command{tar} enable you to specify a name for your
6010 archive. Other options let you decide which files to include or exclude
6011 from the archive, based on when or whether files were modified, whether
6012 the file names do or don't match specified patterns, or whether files
6013 are in specified directories.
6014
6015 This chapter discusses these options in detail.
6016
6017 @menu
6018 * file:: Choosing the Archive's Name
6019 * Selecting Archive Members::
6020 * files:: Reading Names from a File
6021 * exclude:: Excluding Some Files
6022 * wildcards:: Wildcards Patterns and Matching
6023 * quoting styles:: Ways of Quoting Special Characters in Names
6024 * transform:: Modifying File and Member Names
6025 * after:: Operating Only on New Files
6026 * recurse:: Descending into Directories
6027 * one:: Crossing File System Boundaries
6028 @end menu
6029
6030 @node file
6031 @section Choosing and Naming Archive Files
6032 @UNREVISED
6033
6034 @cindex Naming an archive
6035 @cindex Archive Name
6036 @cindex Choosing an archive file
6037 @cindex Where is the archive?
6038 By default, @command{tar} uses an archive file name that was compiled when
6039 it was built on the system; usually this name refers to some physical
6040 tape drive on the machine. However, the person who installed @command{tar}
6041 on the system may not have set the default to a meaningful value as far as
6042 most users are concerned. As a result, you will usually want to tell
6043 @command{tar} where to find (or create) the archive. The
6044 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6045 option allows you to either specify or name a file to use as the archive
6046 instead of the default archive file location.
6047
6048 @table @option
6049 @xopindex{file, short description}
6050 @item --file=@var{archive-name}
6051 @itemx -f @var{archive-name}
6052 Name the archive to create or operate on. Use in conjunction with
6053 any operation.
6054 @end table
6055
6056 For example, in this @command{tar} command,
6057
6058 @smallexample
6059 $ @kbd{tar -cvf collection.tar blues folk jazz}
6060 @end smallexample
6061
6062 @noindent
6063 @file{collection.tar} is the name of the archive. It must directly
6064 follow the @option{-f} option, since whatever directly follows @option{-f}
6065 @emph{will} end up naming the archive. If you neglect to specify an
6066 archive name, you may end up overwriting a file in the working directory
6067 with the archive you create since @command{tar} will use this file's name
6068 for the archive name.
6069
6070 An archive can be saved as a file in the file system, sent through a
6071 pipe or over a network, or written to an I/O device such as a tape,
6072 floppy disk, or CD write drive.
6073
6074 @cindex Writing new archives
6075 @cindex Archive creation
6076 If you do not name the archive, @command{tar} uses the value of the
6077 environment variable @env{TAPE} as the file name for the archive. If
6078 that is not available, @command{tar} uses a default, compiled-in archive
6079 name, usually that for tape unit zero (i.e. @file{/dev/tu00}).
6080
6081 @cindex Standard input and output
6082 @cindex tar to standard input and output
6083 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6084 archive from standard input (when listing or extracting files), or
6085 writes it to standard output (when creating an archive). If you use
6086 @file{-} as an @var{archive-name} when modifying an archive,
6087 @command{tar} reads the original archive from its standard input and
6088 writes the entire new archive to its standard output.
6089
6090 The following example is a convenient way of copying directory
6091 hierarchy from @file{sourcedir} to @file{targetdir}.
6092
6093 @smallexample
6094 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6095 @end smallexample
6096
6097 The @option{-C} option allows to avoid using subshells:
6098
6099 @smallexample
6100 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6101 @end smallexample
6102
6103 In both examples above, the leftmost @command{tar} invocation archives
6104 the contents of @file{sourcedir} to the standard output, while the
6105 rightmost one reads this archive from its standard input and
6106 extracts it. The @option{-p} option tells it to restore permissions
6107 of the extracted files.
6108
6109 @cindex Remote devices
6110 @cindex tar to a remote device
6111 @anchor{remote-dev}
6112 To specify an archive file on a device attached to a remote machine,
6113 use the following:
6114
6115 @smallexample
6116 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6117 @end smallexample
6118
6119 @noindent
6120 @command{tar} will complete the remote connection, if possible, and
6121 prompt you for a username and password. If you use
6122 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6123 will complete the remote connection, if possible, using your username
6124 as the username on the remote machine.
6125
6126 @cindex Local and remote archives
6127 @anchor{local and remote archives}
6128 If the archive file name includes a colon (@samp{:}), then it is assumed
6129 to be a file on another machine. If the archive file is
6130 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6131 host @var{host}. The remote host is accessed using the @command{rsh}
6132 program, with a username of @var{user}. If the username is omitted
6133 (along with the @samp{@@} sign), then your user name will be used.
6134 (This is the normal @command{rsh} behavior.) It is necessary for the
6135 remote machine, in addition to permitting your @command{rsh} access, to
6136 have the @file{rmt} program installed (This command is included in
6137 the @GNUTAR{} distribution and by default is installed under
6138 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6139 installation prefix). If you need to use a file whose name includes a
6140 colon, then the remote tape drive behavior
6141 can be inhibited by using the @option{--force-local} option.
6142
6143 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6144 tries to minimize input and output operations. The Amanda backup
6145 system, when used with @GNUTAR{}, has an initial sizing pass which
6146 uses this feature.
6147
6148 @node Selecting Archive Members
6149 @section Selecting Archive Members
6150 @cindex Specifying files to act on
6151 @cindex Specifying archive members
6152
6153 @dfn{File Name arguments} specify which files in the file system
6154 @command{tar} operates on, when creating or adding to an archive, or which
6155 archive members @command{tar} operates on, when reading or deleting from
6156 an archive. @xref{Operations}.
6157
6158 To specify file names, you can include them as the last arguments on
6159 the command line, as follows:
6160 @smallexample
6161 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6162 @end smallexample
6163
6164 If a file name begins with dash (@samp{-}), precede it with
6165 @option{--add-file} option to prevent it from being treated as an
6166 option.
6167
6168 @anchor{input name quoting}
6169 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6170 name, replacing @dfn{escape sequences} according to the following
6171 table:
6172
6173 @multitable @columnfractions 0.20 0.60
6174 @headitem Escape @tab Replaced with
6175 @item \a @tab Audible bell (ASCII 7)
6176 @item \b @tab Backspace (ASCII 8)
6177 @item \f @tab Form feed (ASCII 12)
6178 @item \n @tab New line (ASCII 10)
6179 @item \r @tab Carriage return (ASCII 13)
6180 @item \t @tab Horizontal tabulation (ASCII 9)
6181 @item \v @tab Vertical tabulation (ASCII 11)
6182 @item \? @tab ASCII 127
6183 @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
6184 of up to 3 digits)
6185 @end multitable
6186
6187 A backslash followed by any other symbol is retained.
6188
6189 This default behavior is controlled by the following command line
6190 option:
6191
6192 @table @option
6193 @opindex unquote
6194 @item --unquote
6195 Enable unquoting input file or member names (default).
6196
6197 @opindex no-unquote
6198 @item --no-unquote
6199 Disable unquoting input file or member names.
6200 @end table
6201
6202 If you specify a directory name as a file name argument, all the files
6203 in that directory are operated on by @command{tar}.
6204
6205 If you do not specify files, @command{tar} behavior differs depending
6206 on the operation mode as described below:
6207
6208 When @command{tar} is invoked with @option{--create} (@option{-c}),
6209 @command{tar} will stop immediately, reporting the following:
6210
6211 @smallexample
6212 @group
6213 $ @kbd{tar cf a.tar}
6214 tar: Cowardly refusing to create an empty archive
6215 Try `tar --help' or `tar --usage' for more information.
6216 @end group
6217 @end smallexample
6218
6219 If you specify either @option{--list} (@option{-t}) or
6220 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6221 operates on all the archive members in the archive.
6222
6223 If run with @option{--diff} option, tar will compare the archive with
6224 the contents of the current working directory.
6225
6226 If you specify any other operation, @command{tar} does nothing.
6227
6228 By default, @command{tar} takes file names from the command line. However,
6229 there are other ways to specify file or member names, or to modify the
6230 manner in which @command{tar} selects the files or members upon which to
6231 operate. In general, these methods work both for specifying the names
6232 of files and archive members.
6233
6234 @node files
6235 @section Reading Names from a File
6236
6237 @cindex Reading file names from a file
6238 @cindex Lists of file names
6239 @cindex File Name arguments, alternatives
6240 Instead of giving the names of files or archive members on the command
6241 line, you can put the names into a file, and then use the
6242 @option{--files-from=@var{file-of-names}} (@option{-T
6243 @var{file-of-names}}) option to @command{tar}. Give the name of the
6244 file which contains the list of files to include as the argument to
6245 @option{--files-from}. In the list, the file names should be separated by
6246 newlines. You will frequently use this option when you have generated
6247 the list of files to archive with the @command{find} utility.
6248
6249 @table @option
6250 @opindex files-from
6251 @item --files-from=@var{file-name}
6252 @itemx -T @var{file-name}
6253 Get names to extract or create from file @var{file-name}.
6254 @end table
6255
6256 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6257 you specify either @code{--files-from=-} or @code{-T -}), then the file
6258 names are read from standard input.
6259
6260 Unless you are running @command{tar} with @option{--create}, you can not use
6261 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6262 command.
6263
6264 Any number of @option{-T} options can be given in the command line.
6265
6266 The following example shows how to use @command{find} to generate a list of
6267 files smaller than 400K in length and put that list into a file
6268 called @file{small-files}. You can then use the @option{-T} option to
6269 @command{tar} to specify the files from that file, @file{small-files}, to
6270 create the archive @file{little.tgz}. (The @option{-z} option to
6271 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6272 more information.)
6273
6274 @smallexample
6275 $ @kbd{find . -size -400 -print > small-files}
6276 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6277 @end smallexample
6278
6279 @noindent
6280 In the file list given by @option{-T} option, any file name beginning
6281 with @samp{-} character is considered a @command{tar} option and is
6282 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6283 recognized only @option{-C} option in file lists, and only if the
6284 option and its argument occupied two consecutive lines.} For example,
6285 the common use of this feature is to change to another directory by
6286 specifying @option{-C} option:
6287
6288 @smallexample
6289 @group
6290 $ @kbd{cat list}
6291 -C/etc
6292 passwd
6293 hosts
6294 -C/lib
6295 libc.a
6296 $ @kbd{tar -c -f foo.tar --files-from list}
6297 @end group
6298 @end smallexample
6299
6300 @noindent
6301 In this example, @command{tar} will first switch to @file{/etc}
6302 directory and add files @file{passwd} and @file{hosts} to the
6303 archive. Then it will change to @file{/lib} directory and will archive
6304 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6305 contain:
6306
6307 @smallexample
6308 @group
6309 $ @kbd{tar tf foo.tar}
6310 passwd
6311 hosts
6312 libc.a
6313 @end group
6314 @end smallexample
6315
6316 @noindent
6317 @xopindex{directory, using in @option{--files-from} argument}
6318 Notice that the option parsing algorithm used with @option{-T} is
6319 stricter than the one used by shell. Namely, when specifying option
6320 arguments, you should observe the following rules:
6321
6322 @itemize @bullet
6323 @item
6324 When using short (single-letter) option form, its argument must
6325 immediately follow the option letter, without any intervening
6326 whitespace. For example: @code{-Cdir}.
6327
6328 @item
6329 When using long option form, the option argument must be separated
6330 from the option by a single equal sign. No whitespace is allowed on
6331 any side of the equal sign. For example: @code{--directory=dir}.
6332
6333 @item
6334 For both short and long option forms, the option argument can be given
6335 on the next line after the option name, e.g.:
6336
6337 @smallexample
6338 @group
6339 --directory
6340 dir
6341 @end group
6342 @end smallexample
6343
6344 @noindent
6345 and
6346
6347 @smallexample
6348 @group
6349 -C
6350 dir
6351 @end group
6352 @end smallexample
6353 @end itemize
6354
6355 @opindex add-file
6356 If you happen to have a file whose name starts with @samp{-},
6357 precede it with @option{--add-file} option to prevent it from
6358 being recognized as an option. For example: @code{--add-file=--my-file}.
6359
6360 @menu
6361 * nul::
6362 @end menu
6363
6364 @node nul
6365 @subsection @code{NUL} Terminated File Names
6366
6367 @cindex File names, terminated by @code{NUL}
6368 @cindex @code{NUL} terminated file names
6369 The @option{--null} option causes
6370 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6371 to read file names terminated by a @code{NUL} instead of a newline, so
6372 files whose names contain newlines can be archived using
6373 @option{--files-from}.
6374
6375 @table @option
6376 @opindex null
6377 @item --null
6378 Only consider @code{NUL} terminated file names, instead of files that
6379 terminate in a newline.
6380 @end table
6381
6382 The @option{--null} option is just like the one in @acronym{GNU}
6383 @command{xargs} and @command{cpio}, and is useful with the
6384 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6385 @command{tar}, @option{--null} also disables special handling for
6386 file names that begin with dash.
6387
6388 This example shows how to use @command{find} to generate a list of files
6389 larger than 800K in length and put that list into a file called
6390 @file{long-files}. The @option{-print0} option to @command{find} is just
6391 like @option{-print}, except that it separates files with a @code{NUL}
6392 rather than with a newline. You can then run @command{tar} with both the
6393 @option{--null} and @option{-T} options to specify that @command{tar} get the
6394 files from that file, @file{long-files}, to create the archive
6395 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6396 @command{tar} to recognize the @code{NUL} separator between files.
6397
6398 @smallexample
6399 $ @kbd{find . -size +800 -print0 > long-files}
6400 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6401 @end smallexample
6402
6403 @FIXME{say anything else here to conclude the section?}
6404
6405 @node exclude
6406 @section Excluding Some Files
6407 @UNREVISED
6408
6409 @cindex File names, excluding files by
6410 @cindex Excluding files by name and pattern
6411 @cindex Excluding files by file system
6412 To avoid operating on files whose names match a particular pattern,
6413 use the @option{--exclude} or @option{--exclude-from} options.
6414
6415 @table @option
6416 @opindex exclude
6417 @item --exclude=@var{pattern}
6418 Causes @command{tar} to ignore files that match the @var{pattern}.
6419 @end table
6420
6421 @findex exclude
6422 The @option{--exclude=@var{pattern}} option prevents any file or
6423 member whose name matches the shell wildcard (@var{pattern}) from
6424 being operated on.
6425 For example, to create an archive with all the contents of the directory
6426 @file{src} except for files whose names end in @file{.o}, use the
6427 command @samp{tar -cf src.tar --exclude='*.o' src}.
6428
6429 You may give multiple @option{--exclude} options.
6430
6431 @table @option
6432 @opindex exclude-from
6433 @item --exclude-from=@var{file}
6434 @itemx -X @var{file}
6435 Causes @command{tar} to ignore files that match the patterns listed in
6436 @var{file}.
6437 @end table
6438
6439 @findex exclude-from
6440 Use the @option{--exclude-from} option to read a
6441 list of patterns, one per line, from @var{file}; @command{tar} will
6442 ignore files matching those patterns. Thus if @command{tar} is
6443 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6444 single line @file{*.o}, no files whose names end in @file{.o} will be
6445 added to the archive.
6446
6447 @table @option
6448 @opindex exclude-caches
6449 @item --exclude-caches
6450 Causes @command{tar} to ignore directories containing a cache directory tag.
6451 @end table
6452
6453 @findex exclude-caches
6454 When creating an archive, the @option{--exclude-caches} option causes
6455 @command{tar} to exclude all directories that contain a @dfn{cache
6456 directory tag}. A cache directory tag is a short file with the
6457 well-known name @file{CACHEDIR.TAG} and having a standard header
6458 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6459 Various applications write cache directory tags into directories they
6460 use to hold regenerable, non-precious data, so that such data can be
6461 more easily excluded from backups.
6462
6463 @menu
6464 * problems with exclude::
6465 @end menu
6466
6467 @node problems with exclude
6468 @unnumberedsubsec Problems with Using the @code{exclude} Options
6469
6470 @xopindex{exclude, potential problems with}
6471 Some users find @samp{exclude} options confusing. Here are some common
6472 pitfalls:
6473
6474 @itemize @bullet
6475 @item
6476 The main operating mode of @command{tar} does not act on a path name
6477 explicitly listed on the command line if one of its file name
6478 components is excluded. In the example above, if
6479 you create an archive and exclude files that end with @samp{*.o}, but
6480 explicitly name the file @samp{dir.o/foo} after all the options have been
6481 listed, @samp{dir.o/foo} will be excluded from the archive.
6482
6483 @item
6484 You can sometimes confuse the meanings of @option{--exclude} and
6485 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6486 to be excluded are given as a pattern on the command line. Use
6487 @option{--exclude-from} to introduce the name of a file which contains
6488 a list of patterns, one per line; each of these patterns can exclude
6489 zero, one, or many files.
6490
6491 @item
6492 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6493 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6494 like @samp{*}. If you do not do this, the shell might expand the
6495 @samp{*} itself using files at hand, so @command{tar} might receive a
6496 list of files instead of one pattern, or none at all, making the
6497 command somewhat illegal. This might not correspond to what you want.
6498
6499 For example, write:
6500
6501 @smallexample
6502 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6503 @end smallexample
6504
6505 @noindent
6506 rather than:
6507
6508 @smallexample
6509 # @emph{Wrong!}
6510 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6511 @end smallexample
6512
6513 @item
6514 You must use use shell syntax, or globbing, rather than @code{regexp}
6515 syntax, when using exclude options in @command{tar}. If you try to use
6516 @code{regexp} syntax to describe files to be excluded, your command
6517 might fail.
6518
6519 @item
6520 @FIXME{The change in semantics must have occurred before 1.11,
6521 so I doubt if it is worth mentioning at all. Anyway, should at
6522 least specify in which version the semantics changed.}
6523 In earlier versions of @command{tar}, what is now the
6524 @option{--exclude-from} option was called @option{--exclude} instead.
6525 Now, @option{--exclude} applies to patterns listed on the command
6526 line and @option{--exclude-from} applies to patterns listed in a
6527 file.
6528
6529 @end itemize
6530
6531 @node wildcards
6532 @section Wildcards Patterns and Matching
6533
6534 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6535 @samp{*} or @samp{?} for example, are replaced and expanded into all
6536 existing files matching the given pattern. @GNUTAR{} can use wildcard
6537 patterns for matching (or globbing) archive members when extracting
6538 from or listing an archive. Wildcard patterns are also used for
6539 verifying volume labels of @command{tar} archives. This section has the
6540 purpose of explaining wildcard syntax for @command{tar}.
6541
6542 @FIXME{the next few paragraphs need work.}
6543
6544 A @var{pattern} should be written according to shell syntax, using wildcard
6545 characters to effect globbing. Most characters in the pattern stand
6546 for themselves in the matched string, and case is significant: @samp{a}
6547 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6548 pattern matches any single character in the matched string. The character
6549 @samp{*} in the pattern matches zero, one, or more single characters in
6550 the matched string. The character @samp{\} says to take the following
6551 character of the pattern @emph{literally}; it is useful when one needs to
6552 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6553
6554 The character @samp{[}, up to the matching @samp{]}, introduces a character
6555 class. A @dfn{character class} is a list of acceptable characters
6556 for the next single character of the matched string. For example,
6557 @samp{[abcde]} would match any of the first five letters of the alphabet.
6558 Note that within a character class, all of the ``special characters''
6559 listed above other than @samp{\} lose their special meaning; for example,
6560 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6561 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6562 the characters @samp{-} and @samp{]} must either come @emph{first} or
6563 @emph{last} in a character class.)
6564
6565 @cindex Excluding characters from a character class
6566 @cindex Character class, excluding characters from
6567 If the first character of the class after the opening @samp{[}
6568 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6569 Rather than listing character to match, it lists those characters which
6570 are @emph{forbidden} as the next single character of the matched string.
6571
6572 Other characters of the class stand for themselves. The special
6573 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6574 letters, is meant to represent all characters between @var{a} and
6575 @var{e}, inclusive.
6576
6577 @FIXME{need to add a sentence or so here to make this clear for those
6578 who don't have dan around.}
6579
6580 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6581 special for wildcard matches. However, if a pattern completely matches
6582 a directory prefix of a matched string, then it matches the full matched
6583 string: thus, excluding a directory also excludes all the files beneath it.
6584
6585 @menu
6586 * controlling pattern-matching::
6587 @end menu
6588
6589 @node controlling pattern-matching
6590 @unnumberedsubsec Controlling Pattern-Matching
6591
6592 For the purposes of this section, we call @dfn{exclusion members} all
6593 member names obtained while processing @option{--exclude} and
6594 @option{--exclude-from} options, and @dfn{inclusion members} those
6595 member names that were given in the command line or read from the file
6596 specified with @option{--files-from} option.
6597
6598 These two pairs of member lists are used in the following operations:
6599 @option{--diff}, @option{--extract}, @option{--list},
6600 @option{--update}.
6601
6602 There are no inclusion members in create mode (@option{--create} and
6603 @option{--append}), since in this mode the names obtained from the
6604 command line refer to @emph{files}, not archive members.
6605
6606 By default, inclusion members are compared with archive members
6607 literally @footnote{Notice that earlier @GNUTAR{} versions used
6608 globbing for inclusion members, which contradicted to UNIX98
6609 specification and was not documented. @xref{Changes}, for more
6610 information on this and other changes.} and exclusion members are
6611 treated as globbing patterns. For example:
6612
6613 @smallexample
6614 @group
6615 $ @kbd{tar tf foo.tar}
6616 a.c
6617 b.c
6618 a.txt
6619 [remarks]
6620 # @i{Member names are used verbatim:}
6621 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6622 [remarks]
6623 # @i{Exclude member names are globbed:}
6624 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6625 a.txt
6626 [remarks]
6627 @end group
6628 @end smallexample
6629
6630 This behavior can be altered by using the following options:
6631
6632 @table @option
6633 @opindex wildcards
6634 @item --wildcards
6635 Treat all member names as wildcards.
6636
6637 @opindex no-wildcards
6638 @item --no-wildcards
6639 Treat all member names as literal strings.
6640 @end table
6641
6642 Thus, to extract files whose names end in @samp{.c}, you can use:
6643
6644 @smallexample
6645 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6646 a.c
6647 b.c
6648 @end smallexample
6649
6650 @noindent
6651 Notice quoting of the pattern to prevent the shell from interpreting
6652 it.
6653
6654 The effect of @option{--wildcards} option is cancelled by
6655 @option{--no-wildcards}. This can be used to pass part of
6656 the command line arguments verbatim and other part as globbing
6657 patterns. For example, the following invocation:
6658
6659 @smallexample
6660 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6661 @end smallexample
6662
6663 @noindent
6664 instructs @command{tar} to extract from @file{foo.tar} all files whose
6665 names end in @samp{.txt} and the file named @file{[remarks]}.
6666
6667 Normally, a pattern matches a name if an initial subsequence of the
6668 name's components matches the pattern, where @samp{*}, @samp{?}, and
6669 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6670 and wildcards can match @samp{/}.
6671
6672 Other than optionally stripping leading @samp{/} from names
6673 (@pxref{absolute}), patterns and names are used as-is. For
6674 example, trailing @samp{/} is not trimmed from a user-specified name
6675 before deciding whether to exclude it.
6676
6677 However, this matching procedure can be altered by the options listed
6678 below. These options accumulate. For example:
6679
6680 @smallexample
6681 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6682 @end smallexample
6683
6684 @noindent
6685 ignores case when excluding @samp{makefile}, but not when excluding
6686 @samp{readme}.
6687
6688 @table @option
6689 @opindex anchored
6690 @opindex no-anchored
6691 @item --anchored
6692 @itemx --no-anchored
6693 If anchored, a pattern must match an initial subsequence
6694 of the name's components. Otherwise, the pattern can match any
6695 subsequence. Default is @option{--no-anchored} for exclusion members
6696 and @option{--anchored} inclusion members.
6697
6698 @opindex ignore-case
6699 @opindex no-ignore-case
6700 @item --ignore-case
6701 @itemx --no-ignore-case
6702 When ignoring case, upper-case patterns match lower-case names and vice versa.
6703 When not ignoring case (the default), matching is case-sensitive.
6704
6705 @opindex wildcards-match-slash
6706 @opindex no-wildcards-match-slash
6707 @item --wildcards-match-slash
6708 @itemx --no-wildcards-match-slash
6709 When wildcards match slash (the default for exclusion members), a
6710 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6711 name. Otherwise, @samp{/} is matched only by @samp{/}.
6712
6713 @end table
6714
6715 The @option{--recursion} and @option{--no-recursion} options
6716 (@pxref{recurse}) also affect how member patterns are interpreted. If
6717 recursion is in effect, a pattern matches a name if it matches any of
6718 the name's parent directories.
6719
6720 The following table summarizes pattern-matching default values:
6721
6722 @multitable @columnfractions .3 .7
6723 @headitem Members @tab Default settings
6724 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6725 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6726 @end multitable
6727
6728 @node quoting styles
6729 @section Quoting Member Names
6730
6731 When displaying member names, @command{tar} takes care to avoid
6732 ambiguities caused by certain characters. This is called @dfn{name
6733 quoting}. The characters in question are:
6734
6735 @itemize @bullet
6736 @item Non-printable control characters:
6737
6738 @multitable @columnfractions 0.20 0.10 0.60
6739 @headitem Character @tab ASCII @tab Character name
6740 @item \a @tab 7 @tab Audible bell
6741 @item \b @tab 8 @tab Backspace
6742 @item \f @tab 12 @tab Form feed
6743 @item \n @tab 10 @tab New line
6744 @item \r @tab 13 @tab Carriage return
6745 @item \t @tab 9 @tab Horizontal tabulation
6746 @item \v @tab 11 @tab Vertical tabulation
6747 @end multitable
6748
6749 @item Space (ASCII 32)
6750
6751 @item Single and double quotes (@samp{'} and @samp{"})
6752
6753 @item Backslash (@samp{\})
6754 @end itemize
6755
6756 The exact way @command{tar} uses to quote these characters depends on
6757 the @dfn{quoting style}. The default quoting style, called
6758 @dfn{escape} (see below), uses backslash notation to represent control
6759 characters, space and backslash. Using this quoting style, control
6760 characters are represented as listed in column @samp{Character} in the
6761 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6762
6763 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6764 using @option{--quoting-style} option:
6765
6766 @table @option
6767 @item --quoting-style=@var{style}
6768 @opindex quoting-style
6769
6770 Sets quoting style. Valid values for @var{style} argument are:
6771 literal, shell, shell-always, c, escape, locale, clocale.
6772 @end table
6773
6774 These styles are described in detail below. To illustrate their
6775 effect, we will use an imaginary tar archive @file{arch.tar}
6776 containing the following members:
6777
6778 @smallexample
6779 @group
6780 # 1. Contains horizontal tabulation character.
6781 a tab
6782 # 2. Contains newline character
6783 a
6784 newline
6785 # 3. Contains a space
6786 a space
6787 # 4. Contains double quotes
6788 a"double"quote
6789 # 5. Contains single quotes
6790 a'single'quote
6791 # 6. Contains a backslash character:
6792 a\backslash
6793 @end group
6794 @end smallexample
6795
6796 Here is how usual @command{ls} command would have listed them, if they
6797 had existed in the current working directory:
6798
6799 @smallexample
6800 @group
6801 $ @kbd{ls}
6802 a\ttab
6803 a\nnewline
6804 a\ space
6805 a"double"quote
6806 a'single'quote
6807 a\\backslash
6808 @end group
6809 @end smallexample
6810
6811 Quoting styles:
6812
6813 @table @samp
6814 @item literal
6815 No quoting, display each character as is:
6816
6817 @smallexample
6818 @group
6819 $ @kbd{tar tf arch.tar --quoting-style=literal}
6820 ./
6821 ./a space
6822 ./a'single'quote
6823 ./a"double"quote
6824 ./a\backslash
6825 ./a tab
6826 ./a
6827 newline
6828 @end group
6829 @end smallexample
6830
6831 @item shell
6832 Display characters the same way Bourne shell does:
6833 control characters, except @samp{\t} and @samp{\n}, are printed using
6834 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6835 single quote is printed as @samp{\'}. If a name contains any quoted
6836 characters, it is enclosed in single quotes. In particular, if a name
6837 contains single quotes, it is printed as several single-quoted strings:
6838
6839 @smallexample
6840 @group
6841 $ @kbd{tar tf arch.tar --quoting-style=shell}
6842 ./
6843 './a space'
6844 './a'\''single'\''quote'
6845 './a"double"quote'
6846 './a\backslash'
6847 './a tab'
6848 './a
6849 newline'
6850 @end group
6851 @end smallexample
6852
6853 @item shell-always
6854 Same as @samp{shell}, but the names are always enclosed in single
6855 quotes:
6856
6857 @smallexample
6858 @group
6859 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6860 './'
6861 './a space'
6862 './a'\''single'\''quote'
6863 './a"double"quote'
6864 './a\backslash'
6865 './a tab'
6866 './a
6867 newline'
6868 @end group
6869 @end smallexample
6870
6871 @item c
6872 Use the notation of the C programming language. All names are
6873 enclosed in double quotes. Control characters are quoted using
6874 backslash notations, double quotes are represented as @samp{\"},
6875 backslash characters are represented as @samp{\\}. Single quotes and
6876 spaces are not quoted:
6877
6878 @smallexample
6879 @group
6880 $ @kbd{tar tf arch.tar --quoting-style=c}
6881 "./"
6882 "./a space"
6883 "./a'single'quote"
6884 "./a\"double\"quote"
6885 "./a\\backslash"
6886 "./a\ttab"
6887 "./a\nnewline"
6888 @end group
6889 @end smallexample
6890
6891 @item escape
6892 Control characters are printed using backslash notation, a space is
6893 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6894 default quoting style, unless it was changed when configured the
6895 package.
6896
6897 @smallexample
6898 @group
6899 $ @kbd{tar tf arch.tar --quoting-style=escape}
6900 ./
6901 ./a space
6902 ./a'single'quote
6903 ./a"double"quote
6904 ./a\\backslash
6905 ./a\ttab
6906 ./a\nnewline
6907 @end group
6908 @end smallexample
6909
6910 @item locale
6911 Control characters, single quote and backslash are printed using
6912 backslash notation. All names are quoted using left and right
6913 quotation marks, appropriate to the current locale. If it does not
6914 define quotation marks, use @samp{`} as left and @samp{'} as right
6915 quotation marks. Any occurrences of the right quotation mark in a
6916 name are escaped with @samp{\}, for example:
6917
6918 For example:
6919
6920 @smallexample
6921 @group
6922 $ @kbd{tar tf arch.tar --quoting-style=locale}
6923 `./'
6924 `./a space'
6925 `./a\'single\'quote'
6926 `./a"double"quote'
6927 `./a\\backslash'
6928 `./a\ttab'
6929 `./a\nnewline'
6930 @end group
6931 @end smallexample
6932
6933 @item clocale
6934 Same as @samp{locale}, but @samp{"} is used for both left and right
6935 quotation marks, if not provided by the currently selected locale:
6936
6937 @smallexample
6938 @group
6939 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6940 "./"
6941 "./a space"
6942 "./a'single'quote"
6943 "./a\"double\"quote"
6944 "./a\\backslash"
6945 "./a\ttab"
6946 "./a\nnewline"
6947 @end group
6948 @end smallexample
6949 @end table
6950
6951 You can specify which characters should be quoted in addition to those
6952 implied by the current quoting style:
6953
6954 @table @option
6955 @item --quote-chars=@var{string}
6956 Always quote characters from @var{string}, even if the selected
6957 quoting style would not quote them.
6958 @end table
6959
6960 For example, using @samp{escape} quoting (compare with the usual
6961 escape listing above):
6962
6963 @smallexample
6964 @group
6965 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6966 ./
6967 ./a\ space
6968 ./a'single'quote
6969 ./a\"double\"quote
6970 ./a\\backslash
6971 ./a\ttab
6972 ./a\nnewline
6973 @end group
6974 @end smallexample
6975
6976 To disable quoting of such additional characters, use the following
6977 option:
6978
6979 @table @option
6980 @item --no-quote-chars=@var{string}
6981 Remove characters listed in @var{string} from the list of quoted
6982 characters set by the previous @option{--quote-chars} option.
6983 @end table
6984
6985 This option is particularly useful if you have added
6986 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
6987 and wish to disable it for the current invocation.
6988
6989 Note, that @option{--no-quote-chars} does @emph{not} disable those
6990 characters that are quoted by default in the selected quoting style.
6991
6992 @node transform
6993 @section Modifying File and Member Names
6994
6995 @command{Tar} archives contain detailed information about files stored
6996 in them and full file names are part of that information. When
6997 storing file to an archive, its file name is recorded in the archive
6998 along with the actual file contents. When restoring from an archive,
6999 a file is created on disk with exactly the same name as that stored
7000 in the archive. In the majority of cases this is the desired behavior
7001 of a file archiver. However, there are some cases when it is not.
7002
7003 First of all, it is often unsafe to extract archive members with
7004 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7005 takes special precautions when extracting such names and provides a
7006 special option for handling them, which is described in
7007 @ref{absolute}.
7008
7009 Secondly, you may wish to extract file names without some leading
7010 directory components, or with otherwise modified names. In other
7011 cases it is desirable to store files under differing names in the
7012 archive.
7013
7014 @GNUTAR{} provides two options for these needs.
7015
7016 @table @option
7017 @opindex strip-components
7018 @item --strip-components=@var{number}
7019 Strip given @var{number} of leading components from file names before
7020 extraction.
7021 @end table
7022
7023 For example, suppose you have archived whole @file{/usr} hierarchy to
7024 a tar archive named @file{usr.tar}. Among other files, this archive
7025 contains @file{usr/include/stdlib.h}, which you wish to extract to
7026 the current working directory. To do so, you type:
7027
7028 @smallexample
7029 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7030 @end smallexample
7031
7032 The option @option{--strip=2} instructs @command{tar} to strip the
7033 two leading components (@file{usr/} and @file{include/}) off the file
7034 name.
7035
7036 If you add to the above invocation @option{--verbose} (@option{-v})
7037 option, you will note that the verbose listing still contains the
7038 full file name, with the two removed components still in place. This
7039 can be inconvenient, so @command{tar} provides a special option for
7040 altering this behavior:
7041
7042 @anchor{show-transformed-names}
7043 @table @option
7044 @opindex show-transformed-names
7045 @item --show-transformed-names
7046 Display file or member names with all requested transformations
7047 applied.
7048 @end table
7049
7050 @noindent
7051 For example:
7052
7053 @smallexample
7054 @group
7055 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7056 usr/include/stdlib.h
7057 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7058 stdlib.h
7059 @end group
7060 @end smallexample
7061
7062 Notice that in both cases the file is @file{stdlib.h} extracted to the
7063 current working directory, @option{--show-transformed-names} affects
7064 only the way its name is displayed.
7065
7066 This option is especially useful for verifying whether the invocation
7067 will have the desired effect. Thus, before running
7068
7069 @smallexample
7070 $ @kbd{tar -x --strip=@var{n}}
7071 @end smallexample
7072
7073 @noindent
7074 it is often advisable to run
7075
7076 @smallexample
7077 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7078 @end smallexample
7079
7080 @noindent
7081 to make sure the command will produce the intended results.
7082
7083 In case you need to apply more complex modifications to the file name,
7084 @GNUTAR{} provides a general-purpose transformation option:
7085
7086 @table @option
7087 @opindex transform
7088 @item --transform=@var{expression}
7089 Modify file names using supplied @var{expression}.
7090 @end table
7091
7092 @noindent
7093 The @var{expression} is a @command{sed}-like replace expression of the
7094 form:
7095
7096 @smallexample
7097 s/@var{regexp}/@var{replace}/[@var{flags}]
7098 @end smallexample
7099
7100 @noindent
7101 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7102 replacement for each file name part that matches @var{regexp}. Both
7103 @var{regexp} and @var{replace} are described in detail in
7104 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7105
7106 Supported @var{flags} are:
7107
7108 @table @samp
7109 @item g
7110 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7111 just the first.
7112
7113 @item i
7114 Use case-insensitive matching
7115
7116 @item x
7117 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7118 regexps, Extended regular expressions, Extended regular expressions,
7119 sed, GNU sed}).
7120
7121 @item @var{number}
7122 Only replace the @var{number}th match of the @var{regexp}.
7123
7124 Note: the @var{posix} standard does not specify what should happen
7125 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7126 follows the GNU @command{sed} implementation in this regard, so
7127 the the interaction is defined to be: ignore matches before the
7128 @var{number}th, and then match and replace all matches from the
7129 @var{number}th on.
7130
7131 @end table
7132
7133 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7134 that it be used consistently throughout the expression. For example,
7135 the following two expressions are equivalent:
7136
7137 @smallexample
7138 @group
7139 s/one/two/
7140 s,one,two,
7141 @end group
7142 @end smallexample
7143
7144 Changing delimiters is often useful when the @var{regex} contains
7145 slashes. For example, it is more convenient to write @code{s,/,-,} than
7146 @code{s/\//-/}.
7147
7148 Here are several examples of @option{--transform} usage:
7149
7150 @enumerate
7151 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7152
7153 @smallexample
7154 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7155 @end smallexample
7156
7157 @item Strip two leading directory components (equivalent to
7158 @option{--strip-components=2}):
7159
7160 @smallexample
7161 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7162 @end smallexample
7163
7164 @item Prepend @file{/prefix/} to each file name:
7165
7166 @smallexample
7167 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7168 @end smallexample
7169
7170 @item Convert each file name to lower case:
7171
7172 @smallexample
7173 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7174 @end smallexample
7175
7176 @end enumerate
7177
7178 Unlike @option{--strip-components}, @option{--transform} can be used
7179 in any @GNUTAR{} operation mode. For example, the following command
7180 adds files to the archive while replacing the leading @file{usr/}
7181 component with @file{var/}:
7182
7183 @smallexample
7184 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7185 @end smallexample
7186
7187 To test @option{--transform} effect we suggest using
7188 @option{--show-transformed-names} option:
7189
7190 @smallexample
7191 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7192 --verbose --show-transformed-names /}
7193 @end smallexample
7194
7195 If both @option{--strip-components} and @option{--transform} are used
7196 together, then @option{--transform} is applied first, and the required
7197 number of components is then stripped from its result.
7198
7199 @node after
7200 @section Operating Only on New Files
7201 @UNREVISED
7202
7203 @cindex Excluding file by age
7204 @cindex Data Modification time, excluding files by
7205 @cindex Modification time, excluding files by
7206 @cindex Age, excluding files by
7207 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7208 @option{-N @var{date}}) option causes @command{tar} to only work on
7209 files whose data modification or status change times are newer than
7210 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7211 it is taken to be a file name; the data modification time of that file
7212 is used as the date. If you use this option when creating or appending
7213 to an archive, the archive will only include new files. If you use
7214 @option{--after-date} when extracting an archive, @command{tar} will
7215 only extract files newer than the @var{date} you specify.
7216
7217 If you only want @command{tar} to make the date comparison based on
7218 modification of the file's data (rather than status
7219 changes), then use the @option{--newer-mtime=@var{date}} option.
7220
7221 You may use these options with any operation. Note that these options
7222 differ from the @option{--update} (@option{-u}) operation in that they
7223 allow you to specify a particular date against which @command{tar} can
7224 compare when deciding whether or not to archive the files.
7225
7226 @table @option
7227 @opindex after-date
7228 @opindex newer
7229 @item --after-date=@var{date}
7230 @itemx --newer=@var{date}
7231 @itemx -N @var{date}
7232 Only store files newer than @var{date}.
7233
7234 Acts on files only if their data modification or status change times are
7235 later than @var{date}. Use in conjunction with any operation.
7236
7237 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7238 name; the data modification time of that file is used as the date.
7239
7240 @opindex newer-mtime
7241 @item --newer-mtime=@var{date}
7242 Acts like @option{--after-date}, but only looks at data modification times.
7243 @end table
7244
7245 These options limit @command{tar} to operate only on files which have
7246 been modified after the date specified. A file's status is considered to have
7247 changed if its contents have been modified, or if its owner,
7248 permissions, and so forth, have been changed. (For more information on
7249 how to specify a date, see @ref{Date input formats}; remember that the
7250 entire date argument must be quoted if it contains any spaces.)
7251
7252 Gurus would say that @option{--after-date} tests both the data
7253 modification time (@code{mtime}, the time the contents of the file
7254 were last modified) and the status change time (@code{ctime}, the time
7255 the file's status was last changed: owner, permissions, etc.@:)
7256 fields, while @option{--newer-mtime} tests only the @code{mtime}
7257 field.
7258
7259 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7260 @code{ctime} and processes the file if either one is more recent than
7261 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7262 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7263 contents of the file were looked at).
7264
7265 Date specifiers can have embedded spaces. Because of this, you may need
7266 to quote date arguments to keep the shell from parsing them as separate
7267 arguments. For example, the following command will add to the archive
7268 all the files modified less than two days ago:
7269
7270 @smallexample
7271 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7272 @end smallexample
7273
7274 When any of these options is used with the option @option{--verbose}
7275 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7276 date back to its textual representation and compare that with the
7277 one given with the option. If the two dates differ, @command{tar} will
7278 print a warning saying what date it will use. This is to help user
7279 ensure he is using the right date. For example:
7280
7281 @smallexample
7282 @group
7283 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7284 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7285 13:19:37.232434
7286 @end group
7287 @end smallexample
7288
7289 @quotation
7290 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7291 should not be used for incremental backups. @xref{Incremental Dumps},
7292 for proper way of creating incremental backups.
7293 @end quotation
7294
7295 @node recurse
7296 @section Descending into Directories
7297 @UNREVISED
7298 @cindex Avoiding recursion in directories
7299 @cindex Descending directories, avoiding
7300 @cindex Directories, avoiding recursion
7301 @cindex Recursion in directories, avoiding
7302
7303 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7304
7305 Usually, @command{tar} will recursively explore all directories (either
7306 those given on the command line or through the @option{--files-from}
7307 option) for the various files they contain. However, you may not always
7308 want @command{tar} to act this way.
7309
7310 @opindex no-recursion
7311 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7312 into specified directories. If you specify @option{--no-recursion}, you can
7313 use the @command{find} utility for hunting through levels of directories to
7314 construct a list of file names which you could then pass to @command{tar}.
7315 @command{find} allows you to be more selective when choosing which files to
7316 archive; see @ref{files}, for more information on using @command{find} with
7317 @command{tar}, or look.
7318
7319 @table @option
7320 @item --no-recursion
7321 Prevents @command{tar} from recursively descending directories.
7322
7323 @opindex recursion
7324 @item --recursion
7325 Requires @command{tar} to recursively descend directories.
7326 This is the default.
7327 @end table
7328
7329 When you use @option{--no-recursion}, @GNUTAR{} grabs
7330 directory entries themselves, but does not descend on them
7331 recursively. Many people use @command{find} for locating files they
7332 want to back up, and since @command{tar} @emph{usually} recursively
7333 descends on directories, they have to use the @samp{@w{-not -type d}}
7334 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7335 find, Finding Files}), as they usually do not want all the files in a
7336 directory. They then use the @option{--files-from} option to archive
7337 the files located via @command{find}.
7338
7339 The problem when restoring files archived in this manner is that the
7340 directories themselves are not in the archive; so the
7341 @option{--same-permissions} (@option{--preserve-permissions},
7342 @option{-p}) option does not affect them---while users might really
7343 like it to. Specifying @option{--no-recursion} is a way to tell
7344 @command{tar} to grab only the directory entries given to it, adding
7345 no new files on its own. To summarize, if you use @command{find} to
7346 create a list of files to be stored in an archive, use it as follows:
7347
7348 @smallexample
7349 @group
7350 $ @kbd{find @var{dir} @var{tests} | \
7351 tar -cf @var{archive} -T - --no-recursion}
7352 @end group
7353 @end smallexample
7354
7355 The @option{--no-recursion} option also applies when extracting: it
7356 causes @command{tar} to extract only the matched directory entries, not
7357 the files under those directories.
7358
7359 The @option{--no-recursion} option also affects how globbing patterns
7360 are interpreted (@pxref{controlling pattern-matching}).
7361
7362 The @option{--no-recursion} and @option{--recursion} options apply to
7363 later options and operands, and can be overridden by later occurrences
7364 of @option{--no-recursion} and @option{--recursion}. For example:
7365
7366 @smallexample
7367 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7368 @end smallexample
7369
7370 @noindent
7371 creates an archive with one entry for @file{grape}, and the recursive
7372 contents of @file{grape/concord}, but no entries under @file{grape}
7373 other than @file{grape/concord}.
7374
7375 @node one
7376 @section Crossing File System Boundaries
7377 @cindex File system boundaries, not crossing
7378 @UNREVISED
7379
7380 @command{tar} will normally automatically cross file system boundaries in
7381 order to archive files which are part of a directory tree. You can
7382 change this behavior by running @command{tar} and specifying
7383 @option{--one-file-system}. This option only affects files that are
7384 archived because they are in a directory that is being archived;
7385 @command{tar} will still archive files explicitly named on the command line
7386 or through @option{--files-from}, regardless of where they reside.
7387
7388 @table @option
7389 @opindex one-file-system
7390 @item --one-file-system
7391 Prevents @command{tar} from crossing file system boundaries when
7392 archiving. Use in conjunction with any write operation.
7393 @end table
7394
7395 The @option{--one-file-system} option causes @command{tar} to modify its
7396 normal behavior in archiving the contents of directories. If a file in
7397 a directory is not on the same file system as the directory itself, then
7398 @command{tar} will not archive that file. If the file is a directory
7399 itself, @command{tar} will not archive anything beneath it; in other words,
7400 @command{tar} will not cross mount points.
7401
7402 This option is useful for making full or incremental archival backups of
7403 a file system. If this option is used in conjunction with
7404 @option{--verbose} (@option{-v}), files that are excluded are
7405 mentioned by name on the standard error.
7406
7407 @menu
7408 * directory:: Changing Directory
7409 * absolute:: Absolute File Names
7410 @end menu
7411
7412 @node directory
7413 @subsection Changing the Working Directory
7414 @UNREVISED
7415
7416 @FIXME{need to read over this node now for continuity; i've switched
7417 things around some.}
7418
7419 @cindex Changing directory mid-stream
7420 @cindex Directory, changing mid-stream
7421 @cindex Working directory, specifying
7422 To change the working directory in the middle of a list of file names,
7423 either on the command line or in a file specified using
7424 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7425 This will change the working directory to the specified directory
7426 after that point in the list.
7427
7428 @table @option
7429 @opindex directory
7430 @item --directory=@var{directory}
7431 @itemx -C @var{directory}
7432 Changes the working directory in the middle of a command line.
7433 @end table
7434
7435 For example,
7436
7437 @smallexample
7438 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7439 @end smallexample
7440
7441 @noindent
7442 will place the files @file{grape} and @file{prune} from the current
7443 directory into the archive @file{jams.tar}, followed by the file
7444 @file{cherry} from the directory @file{food}. This option is especially
7445 useful when you have several widely separated files that you want to
7446 store in the same archive.
7447
7448 Note that the file @file{cherry} is recorded in the archive under the
7449 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7450 archive will contain three files that all appear to have come from the
7451 same directory; if the archive is extracted with plain @samp{tar
7452 --extract}, all three files will be written in the current directory.
7453
7454 Contrast this with the command,
7455
7456 @smallexample
7457 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7458 @end smallexample
7459
7460 @noindent
7461 which records the third file in the archive under the name
7462 @file{red/cherry} so that, if the archive is extracted using
7463 @samp{tar --extract}, the third file will be written in a subdirectory
7464 named @file{orange-colored}.
7465
7466 You can use the @option{--directory} option to make the archive
7467 independent of the original name of the directory holding the files.
7468 The following command places the files @file{/etc/passwd},
7469 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7470 @file{foo.tar}:
7471
7472 @smallexample
7473 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7474 @end smallexample
7475
7476 @noindent
7477 However, the names of the archive members will be exactly what they were
7478 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7479 They will not appear to be related by file name to the original
7480 directories where those files were located.
7481
7482 Note that @option{--directory} options are interpreted consecutively. If
7483 @option{--directory} specifies a relative file name, it is interpreted
7484 relative to the then current directory, which might not be the same as
7485 the original current working directory of @command{tar}, due to a previous
7486 @option{--directory} option.
7487
7488 When using @option{--files-from} (@pxref{files}), you can put various
7489 @command{tar} options (including @option{-C}) in the file list. Notice,
7490 however, that in this case the option and its argument may not be
7491 separated by whitespace. If you use short option, its argument must
7492 either follow the option letter immediately, without any intervening
7493 whitespace, or occupy the next line. Otherwise, if you use long
7494 option, separate its argument by an equal sign.
7495
7496 For instance, the file list for the above example will be:
7497
7498 @smallexample
7499 @group
7500 -C
7501 /etc
7502 passwd
7503 hosts
7504 -C
7505 /lib
7506 libc.a
7507 @end group
7508 @end smallexample
7509
7510 @noindent
7511 To use it, you would invoke @command{tar} as follows:
7512
7513 @smallexample
7514 $ @kbd{tar -c -f foo.tar --files-from list}
7515 @end smallexample
7516
7517 Notice also that you can only use the short option variant in the file
7518 list, i.e., always use @option{-C}, not @option{--directory}.
7519
7520 The interpretation of @option{--directory} is disabled by
7521 @option{--null} option.
7522
7523 @node absolute
7524 @subsection Absolute File Names
7525 @UNREVISED
7526
7527 @table @option
7528 @opindex absolute-names
7529 @item --absolute-names
7530 @itemx -P
7531 Do not strip leading slashes from file names, and permit file names
7532 containing a @file{..} file name component.
7533 @end table
7534
7535 By default, @GNUTAR{} drops a leading @samp{/} on
7536 input or output, and complains about file names containing a @file{..}
7537 component. This option turns off this behavior.
7538
7539 When @command{tar} extracts archive members from an archive, it strips any
7540 leading slashes (@samp{/}) from the member name. This causes absolute
7541 member names in the archive to be treated as relative file names. This
7542 allows you to have such members extracted wherever you want, instead of
7543 being restricted to extracting the member in the exact directory named
7544 in the archive. For example, if the archive member has the name
7545 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7546 really @file{etc/passwd}.
7547
7548 File names containing @file{..} can cause problems when extracting, so
7549 @command{tar} normally warns you about such files when creating an
7550 archive, and rejects attempts to extracts such files.
7551
7552 Other @command{tar} programs do not do this. As a result, if you
7553 create an archive whose member names start with a slash, they will be
7554 difficult for other people with a non-@GNUTAR{}
7555 program to use. Therefore, @GNUTAR{} also strips
7556 leading slashes from member names when putting members into the
7557 archive. For example, if you ask @command{tar} to add the file
7558 @file{/bin/ls} to an archive, it will do so, but the member name will
7559 be @file{bin/ls}.@footnote{A side effect of this is that when
7560 @option{--create} is used with @option{--verbose} the resulting output
7561 is not, generally speaking, the same as the one you'd get running
7562 @kbd{tar --list} command. This may be important if you use some
7563 scripts for comparing both outputs. @xref{listing member and file names},
7564 for the information on how to handle this case.}
7565
7566 If you use the @option{--absolute-names} (@option{-P}) option,
7567 @command{tar} will do none of these transformations.
7568
7569 To archive or extract files relative to the root directory, specify
7570 the @option{--absolute-names} (@option{-P}) option.
7571
7572 Normally, @command{tar} acts on files relative to the working
7573 directory---ignoring superior directory names when archiving, and
7574 ignoring leading slashes when extracting.
7575
7576 When you specify @option{--absolute-names} (@option{-P}),
7577 @command{tar} stores file names including all superior directory
7578 names, and preserves leading slashes. If you only invoked
7579 @command{tar} from the root directory you would never need the
7580 @option{--absolute-names} option, but using this option
7581 may be more convenient than switching to root.
7582
7583 @FIXME{Should be an example in the tutorial/wizardry section using this
7584 to transfer files between systems.}
7585
7586 @FIXME{Is write access an issue?}
7587
7588 @table @option
7589 @item --absolute-names
7590 Preserves full file names (including superior directory names) when
7591 archiving files. Preserves leading slash when extracting files.
7592
7593 @end table
7594
7595 @FIXME{this is still horrible; need to talk with dan on monday.}
7596
7597 @command{tar} prints out a message about removing the @samp{/} from
7598 file names. This message appears once per @GNUTAR{}
7599 invocation. It represents something which ought to be told; ignoring
7600 what it means can cause very serious surprises, later.
7601
7602 Some people, nevertheless, do not want to see this message. Wanting to
7603 play really dangerously, one may of course redirect @command{tar} standard
7604 error to the sink. For example, under @command{sh}:
7605
7606 @smallexample
7607 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7608 @end smallexample
7609
7610 @noindent
7611 Another solution, both nicer and simpler, would be to change to
7612 the @file{/} directory first, and then avoid absolute notation.
7613 For example:
7614
7615 @smallexample
7616 $ @kbd{(cd / && tar -c -f archive.tar home)}
7617 # @i{or}:
7618 $ @kbd{tar -c -f archive.tar -C / home}
7619 @end smallexample
7620
7621 @include getdate.texi
7622
7623 @node Formats
7624 @chapter Controlling the Archive Format
7625
7626 @cindex Tar archive formats
7627 Due to historical reasons, there are several formats of tar archives.
7628 All of them are based on the same principles, but have some subtle
7629 differences that often make them incompatible with each other.
7630
7631 GNU tar is able to create and handle archives in a variety of formats.
7632 The most frequently used formats are (in alphabetical order):
7633
7634 @table @asis
7635 @item gnu
7636 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7637 from an early @acronym{POSIX} standard, adding some improvements such as
7638 sparse file handling and incremental archives. Unfortunately these
7639 features were implemented in a way incompatible with other archive
7640 formats.
7641
7642 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7643 length.
7644
7645 @item oldgnu
7646 Format used by @GNUTAR{} of versions prior to 1.12.
7647
7648 @item v7
7649 Archive format, compatible with the V7 implementation of tar. This
7650 format imposes a number of limitations. The most important of them
7651 are:
7652
7653 @enumerate
7654 @item The maximum length of a file name is limited to 99 characters.
7655 @item The maximum length of a symbolic link is limited to 99 characters.
7656 @item It is impossible to store special files (block and character
7657 devices, fifos etc.)
7658 @item Maximum value of user or group ID is limited to 2097151 (7777777
7659 octal)
7660 @item V7 archives do not contain symbolic ownership information (user
7661 and group name of the file owner).
7662 @end enumerate
7663
7664 This format has traditionally been used by Automake when producing
7665 Makefiles. This practice will change in the future, in the meantime,
7666 however this means that projects containing filenames more than 99
7667 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7668 Automake prior to 1.9.
7669
7670 @item ustar
7671 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7672 symbolic ownership information. It is also able to store
7673 special files. However, it imposes several restrictions as well:
7674
7675 @enumerate
7676 @item The maximum length of a file name is limited to 256 characters,
7677 provided that the filename can be split at directory separator in
7678 two parts, first of them being at most 155 bytes long. So, in most
7679 cases the maximum file name length will be shorter than 256
7680 characters.
7681 @item The maximum length of a symbolic link name is limited to
7682 100 characters.
7683 @item Maximum size of a file the archive is able to accomodate
7684 is 8GB
7685 @item Maximum value of UID/GID is 2097151.
7686 @item Maximum number of bits in device major and minor numbers is 21.
7687 @end enumerate
7688
7689 @item star
7690 Format used by J@"org Schilling @command{star}
7691 implementation. @GNUTAR{} is able to read @samp{star} archives but
7692 currently does not produce them.
7693
7694 @item posix
7695 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7696 most flexible and feature-rich format. It does not impose any
7697 restrictions on file sizes or filename lengths. This format is quite
7698 recent, so not all tar implementations are able to handle it properly.
7699 However, this format is designed in such a way that any tar
7700 implementation able to read @samp{ustar} archives will be able to read
7701 most @samp{posix} archives as well, with the only exception that any
7702 additional information (such as long file names etc.) will in such
7703 case be extracted as plain text files along with the files it refers to.
7704
7705 This archive format will be the default format for future versions
7706 of @GNUTAR{}.
7707
7708 @end table
7709
7710 The following table summarizes the limitations of each of these
7711 formats:
7712
7713 @multitable @columnfractions .10 .20 .20 .20 .20
7714 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7715 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7716 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7717 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7718 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7719 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7720 @end multitable
7721
7722 The default format for @GNUTAR{} is defined at compilation
7723 time. You may check it by running @command{tar --help}, and examining
7724 the last lines of its output. Usually, @GNUTAR{} is configured
7725 to create archives in @samp{gnu} format, however, future version will
7726 switch to @samp{posix}.
7727
7728 @menu
7729 * Portability:: Making @command{tar} Archives More Portable
7730 * Compression:: Using Less Space through Compression
7731 * Attributes:: Handling File Attributes
7732 * cpio:: Comparison of @command{tar} and @command{cpio}
7733 @end menu
7734
7735 @node Portability
7736 @section Making @command{tar} Archives More Portable
7737
7738 Creating a @command{tar} archive on a particular system that is meant to be
7739 useful later on many other machines and with other versions of @command{tar}
7740 is more challenging than you might think. @command{tar} archive formats
7741 have been evolving since the first versions of Unix. Many such formats
7742 are around, and are not always compatible with each other. This section
7743 discusses a few problems, and gives some advice about making @command{tar}
7744 archives more portable.
7745
7746 One golden rule is simplicity. For example, limit your @command{tar}
7747 archives to contain only regular files and directories, avoiding
7748 other kind of special files. Do not attempt to save sparse files or
7749 contiguous files as such. Let's discuss a few more problems, in turn.
7750
7751 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7752 archives and archive labels) in GNU and PAX formats.}
7753
7754 @menu
7755 * Portable Names:: Portable Names
7756 * dereference:: Symbolic Links
7757 * old:: Old V7 Archives
7758 * ustar:: Ustar Archives
7759 * gnu:: GNU and old GNU format archives.
7760 * posix:: @acronym{POSIX} archives
7761 * Checksumming:: Checksumming Problems
7762 * Large or Negative Values:: Large files, negative time stamps, etc.
7763 * Other Tars:: How to Extract GNU-Specific Data Using
7764 Other @command{tar} Implementations
7765 @end menu
7766
7767 @node Portable Names
7768 @subsection Portable Names
7769
7770 Use portable file and member names. A name is portable if it contains
7771 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7772 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7773 contain @samp{/-}. Avoid deep directory nesting. For portability to
7774 old Unix hosts, limit your file name components to 14 characters or
7775 less.
7776
7777 If you intend to have your @command{tar} archives to be read under
7778 MSDOS, you should not rely on case distinction for file names, and you
7779 might use the @acronym{GNU} @command{doschk} program for helping you
7780 further diagnosing illegal MSDOS names, which are even more limited
7781 than System V's.
7782
7783 @node dereference
7784 @subsection Symbolic Links
7785 @cindex File names, using symbolic links
7786 @cindex Symbolic link as file name
7787
7788 @opindex dereference
7789 Normally, when @command{tar} archives a symbolic link, it writes a
7790 block to the archive naming the target of the link. In that way, the
7791 @command{tar} archive is a faithful record of the file system contents.
7792 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7793 @command{tar} to archive the files symbolic links point to, instead of
7794 the links themselves. When this option is used, when @command{tar}
7795 encounters a symbolic link, it will archive the linked-to file,
7796 instead of simply recording the presence of a symbolic link.
7797
7798 The name under which the file is stored in the file system is not
7799 recorded in the archive. To record both the symbolic link name and
7800 the file name in the system, archive the file under both names. If
7801 all links were recorded automatically by @command{tar}, an extracted file
7802 might be linked to a file name that no longer exists in the file
7803 system.
7804
7805 If a linked-to file is encountered again by @command{tar} while creating
7806 the same archive, an entire second copy of it will be stored. (This
7807 @emph{might} be considered a bug.)
7808
7809 So, for portable archives, do not archive symbolic links as such,
7810 and use @option{--dereference} (@option{-h}): many systems do not support
7811 symbolic links, and moreover, your distribution might be unusable if
7812 it contains unresolved symbolic links.
7813
7814 @node old
7815 @subsection Old V7 Archives
7816 @cindex Format, old style
7817 @cindex Old style format
7818 @cindex Old style archives
7819 @cindex v7 archive format
7820
7821 Certain old versions of @command{tar} cannot handle additional
7822 information recorded by newer @command{tar} programs. To create an
7823 archive in V7 format (not ANSI), which can be read by these old
7824 versions, specify the @option{--format=v7} option in
7825 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7826 accepts @option{--portability} or @samp{op-old-archive} for this
7827 option). When you specify it,
7828 @command{tar} leaves out information about directories, pipes, fifos,
7829 contiguous files, and device files, and specifies file ownership by
7830 group and user IDs instead of group and user names.
7831
7832 When updating an archive, do not use @option{--format=v7}
7833 unless the archive was created using this option.
7834
7835 In most cases, a @emph{new} format archive can be read by an @emph{old}
7836 @command{tar} program without serious trouble, so this option should
7837 seldom be needed. On the other hand, most modern @command{tar}s are
7838 able to read old format archives, so it might be safer for you to
7839 always use @option{--format=v7} for your distributions.
7840
7841 @node ustar
7842 @subsection Ustar Archive Format
7843
7844 @cindex ustar archive format
7845 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7846 @code{ustar}. Although it is more flexible than the V7 format, it
7847 still has many restrictions (@xref{Formats,ustar}, for the detailed
7848 description of @code{ustar} format). Along with V7 format,
7849 @code{ustar} format is a good choice for archives intended to be read
7850 with other implementations of @command{tar}.
7851
7852 To create archive in @code{ustar} format, use @option{--format=ustar}
7853 option in conjunction with the @option{--create} (@option{-c}).
7854
7855 @node gnu
7856 @subsection @acronym{GNU} and old @GNUTAR{} format
7857
7858 @cindex GNU archive format
7859 @cindex Old GNU archive format
7860 @GNUTAR{} was based on an early draft of the
7861 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7862 @command{tar}, such as the support for file names longer than 100
7863 characters, use portions of the @command{tar} header record which were
7864 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7865 @acronym{POSIX} have allocated the same parts of the header record for
7866 other purposes. As a result, @GNUTAR{} format is
7867 incompatible with the current @acronym{POSIX} specification, and with
7868 @command{tar} programs that follow it.
7869
7870 In the majority of cases, @command{tar} will be configured to create
7871 this format by default. This will change in the future releases, since
7872 we plan to make @samp{posix} format the default.
7873
7874 To force creation a @GNUTAR{} archive, use option
7875 @option{--format=gnu}.
7876
7877 @node posix
7878 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7879
7880 @cindex POSIX archive format
7881 @cindex PAX archive format
7882 Starting from version 1.14 @GNUTAR{} features full support for
7883 @acronym{POSIX.1-2001} archives.
7884
7885 A @acronym{POSIX} conformant archive will be created if @command{tar}
7886 was given @option{--format=posix} (@option{--format=pax}) option. No
7887 special option is required to read and extract from a @acronym{POSIX}
7888 archive.
7889
7890 @menu
7891 * PAX keywords:: Controlling Extended Header Keywords.
7892 @end menu
7893
7894 @node PAX keywords
7895 @subsubsection Controlling Extended Header Keywords
7896
7897 @table @option
7898 @opindex pax-option
7899 @item --pax-option=@var{keyword-list}
7900 Handle keywords in @acronym{PAX} extended headers. This option is
7901 equivalent to @option{-o} option of the @command{pax} utility.
7902 @end table
7903
7904 @var{Keyword-list} is a comma-separated
7905 list of keyword options, each keyword option taking one of
7906 the following forms:
7907
7908 @table @code
7909 @item delete=@var{pattern}
7910 When used with one of archive-creation commands,
7911 this option instructs @command{tar} to omit from extended header records
7912 that it produces any keywords matching the string @var{pattern}.
7913
7914 When used in extract or list mode, this option instructs tar
7915 to ignore any keywords matching the given @var{pattern} in the extended
7916 header records. In both cases, matching is performed using the pattern
7917 matching notation described in @acronym{POSIX 1003.2}, 3.13
7918 (@pxref{wildcards}). For example:
7919
7920 @smallexample
7921 --pax-option delete=security.*
7922 @end smallexample
7923
7924 would suppress security-related information.
7925
7926 @item exthdr.name=@var{string}
7927
7928 This keyword allows user control over the name that is written into the
7929 ustar header blocks for the extended headers. The name is obtained
7930 from @var{string} after making the following substitutions:
7931
7932 @multitable @columnfractions .25 .55
7933 @headitem Meta-character @tab Replaced By
7934 @item %d @tab The directory name of the file, equivalent to the
7935 result of the @command{dirname} utility on the translated pathname.
7936 @item %f @tab The filename of the file, equivalent to the result
7937 of the @command{basename} utility on the translated pathname.
7938 @item %p @tab The process ID of the @command{tar} process.
7939 @item %% @tab A @samp{%} character.
7940 @end multitable
7941
7942 Any other @samp{%} characters in @var{string} produce undefined
7943 results.
7944
7945 If no option @samp{exthdr.name=string} is specified, @command{tar}
7946 will use the following default value:
7947
7948 @smallexample
7949 %d/PaxHeaders.%p/%f
7950 @end smallexample
7951
7952 @item globexthdr.name=@var{string}
7953 This keyword allows user control over the name that is written into
7954 the ustar header blocks for global extended header records. The name
7955 is obtained from the contents of @var{string}, after making
7956 the following substitutions:
7957
7958 @multitable @columnfractions .25 .55
7959 @headitem Meta-character @tab Replaced By
7960 @item %n @tab An integer that represents the
7961 sequence number of the global extended header record in the archive,
7962 starting at 1.
7963 @item %p @tab The process ID of the @command{tar} process.
7964 @item %% @tab A @samp{%} character.
7965 @end multitable
7966
7967 Any other @samp{%} characters in @var{string} produce undefined results.
7968
7969 If no option @samp{globexthdr.name=string} is specified, @command{tar}
7970 will use the following default value:
7971
7972 @smallexample
7973 $TMPDIR/GlobalHead.%p.%n
7974 @end smallexample
7975
7976 @noindent
7977 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
7978 environment variable. If @var{TMPDIR} is not set, @command{tar}
7979 uses @samp{/tmp}.
7980
7981 @item @var{keyword}=@var{value}
7982 When used with one of archive-creation commands, these keyword/value pairs
7983 will be included at the beginning of the archive in a global extended
7984 header record. When used with one of archive-reading commands,
7985 @command{tar} will behave as if it has encountered these keyword/value
7986 pairs at the beginning of the archive in a global extended header
7987 record.
7988
7989 @item @var{keyword}:=@var{value}
7990 When used with one of archive-creation commands, these keyword/value pairs
7991 will be included as records at the beginning of an extended header for
7992 each file. This is effectively equivalent to @var{keyword}=@var{value}
7993 form except that it creates no global extended header records.
7994
7995 When used with one of archive-reading commands, @command{tar} will
7996 behave as if these keyword/value pairs were included as records at the
7997 end of each extended header; thus, they will override any global or
7998 file-specific extended header record keywords of the same names.
7999 For example, in the command:
8000
8001 @smallexample
8002 tar --format=posix --create \
8003 --file archive --pax-option gname:=user .
8004 @end smallexample
8005
8006 the group name will be forced to a new value for all files
8007 stored in the archive.
8008 @end table
8009
8010 @node Checksumming
8011 @subsection Checksumming Problems
8012
8013 SunOS and HP-UX @command{tar} fail to accept archives created using
8014 @GNUTAR{} and containing non-ASCII file names, that
8015 is, file names having characters with the eight bit set, because they
8016 use signed checksums, while @GNUTAR{} uses unsigned
8017 checksums while creating archives, as per @acronym{POSIX} standards. On
8018 reading, @GNUTAR{} computes both checksums and
8019 accept any. It is somewhat worrying that a lot of people may go
8020 around doing backup of their files using faulty (or at least
8021 non-standard) software, not learning about it until it's time to
8022 restore their missing files with an incompatible file extractor, or
8023 vice versa.
8024
8025 @GNUTAR{} compute checksums both ways, and accept
8026 any on read, so @acronym{GNU} tar can read Sun tapes even with their
8027 wrong checksums. @GNUTAR{} produces the standard
8028 checksum, however, raising incompatibilities with Sun. That is to
8029 say, @GNUTAR{} has not been modified to
8030 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
8031 I've been told that more recent Sun @command{tar} now read standard
8032 archives, so maybe Sun did a similar patch, after all?
8033
8034 The story seems to be that when Sun first imported @command{tar}
8035 sources on their system, they recompiled it without realizing that
8036 the checksums were computed differently, because of a change in
8037 the default signing of @code{char}'s in their compiler. So they
8038 started computing checksums wrongly. When they later realized their
8039 mistake, they merely decided to stay compatible with it, and with
8040 themselves afterwards. Presumably, but I do not really know, HP-UX
8041 has chosen that their @command{tar} archives to be compatible with Sun's.
8042 The current standards do not favor Sun @command{tar} format. In any
8043 case, it now falls on the shoulders of SunOS and HP-UX users to get
8044 a @command{tar} able to read the good archives they receive.
8045
8046 @node Large or Negative Values
8047 @subsection Large or Negative Values
8048 @cindex large values
8049 @cindex future time stamps
8050 @cindex negative time stamps
8051 @UNREVISED{}
8052
8053 The above sections suggest to use @samp{oldest possible} archive
8054 format if in doubt. However, sometimes it is not possible. If you
8055 attempt to archive a file whose metadata cannot be represented using
8056 required format, @GNUTAR{} will print error message and ignore such a
8057 file. You will than have to switch to a format that is able to
8058 handle such values. The format summary table (@pxref{Formats}) will
8059 help you to do so.
8060
8061 In particular, when trying to archive files larger than 8GB or with
8062 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
8063 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
8064 @acronym{POSIX} archive formats. When considering which format to
8065 choose, bear in mind that the @acronym{GNU} format uses
8066 two's-complement base-256 notation to store values that do not fit
8067 into standard @acronym{ustar} range. Such archives can generally be
8068 read only by a @GNUTAR{} implementation. Moreover, they sometimes
8069 cannot be correctly restored on another hosts even by @GNUTAR{}. For
8070 example, using two's complement representation for negative time
8071 stamps that assumes a signed 32-bit @code{time_t} generates archives
8072 that are not portable to hosts with differing @code{time_t}
8073 representations.
8074
8075 On the other hand, @acronym{POSIX} archives, generally speaking, can
8076 be extracted by any tar implementation that understands older
8077 @acronym{ustar} format. The only exception are files larger than 8GB.
8078
8079 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
8080 POSIX-aware tars.}
8081
8082 @node Other Tars
8083 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
8084
8085 In previous sections you became acquainted with various quircks
8086 necessary to make your archives portable. Sometimes you may need to
8087 extract archives containing GNU-specific members using some
8088 third-party @command{tar} implementation or an older version of
8089 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
8090 but if it is for some reason impossible, this section will explain
8091 how to cope without it.
8092
8093 When we speak about @dfn{GNU-specific} members we mean two classes of
8094 them: members split between the volumes of a multi-volume archive and
8095 sparse members. You will be able to always recover such members if
8096 the archive is in PAX format. In addition split members can be
8097 recovered from archives in old GNU format. The following subsections
8098 describe the required procedures in detail.
8099
8100 @menu
8101 * Split Recovery:: Members Split Between Volumes
8102 * Sparse Recovery:: Sparse Members
8103 @end menu
8104
8105 @node Split Recovery
8106 @subsubsection Extracting Members Split Between Volumes
8107
8108 If a member is split between several volumes of an old GNU format archive
8109 most third party @command{tar} implementation will fail to extract
8110 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
8111 This program is available from
8112 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat, @GNUTAR{}
8113 home page}. It concatenates several archive volumes into a single
8114 valid archive. For example, if you have three volumes named from
8115 @file{vol-1.tar} to @file{vol-2.tar}, you can do the following to
8116 extract them using a third-party @command{tar}:
8117
8118 @smallexample
8119 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
8120 @end smallexample
8121
8122 You could use this approach for many (although not all) PAX
8123 format archives as well. However, extracting split members from a PAX
8124 archive is a much easier task, because PAX volumes are constructed in
8125 such a way that each part of a split member is extracted as a
8126 different file by @command{tar} implementations that are not aware of
8127 GNU extensions. More specifically, the very first part retains its
8128 original name, and all subsequent parts are named using the pattern:
8129
8130 @smallexample
8131 %d/GNUFileParts.%p/%f.%n
8132 @end smallexample
8133
8134 @noindent
8135 where symbols preceeded by @samp{%} are @dfn{macro characters} that
8136 have the following meaning:
8137
8138 @multitable @columnfractions .25 .55
8139 @headitem Meta-character @tab Replaced By
8140 @item %d @tab The directory name of the file, equivalent to the
8141 result of the @command{dirname} utility on its full name.
8142 @item %f @tab The file name of the file, equivalent to the result
8143 of the @command{basename} utility on its full name.
8144 @item %p @tab The process ID of the @command{tar} process that
8145 created the archive.
8146 @item %n @tab Ordinal number of this particular part.
8147 @end multitable
8148
8149 For example, if, a file @file{var/longfile} was split during archive
8150 creation between three volumes, and the creator @command{tar} process
8151 had process ID @samp{27962}, then the member names will be:
8152
8153 @smallexample
8154 var/longfile
8155 var/GNUFileParts.27962/longfile.1
8156 var/GNUFileParts.27962/longfile.2
8157 @end smallexample
8158
8159 When you extract your archive using a third-party @command{tar}, these
8160 files will be created on your disk, and the only thing you will need
8161 to do to restore your file in its original form is concatenate them in
8162 the proper order, for example:
8163
8164 @smallexample
8165 @group
8166 $ @kbd{cd var}
8167 $ @kbd{cat GNUFileParts.27962/longfile.1 \
8168 GNUFileParts.27962/longfile.2 >> longfile}
8169 $ rm -f GNUFileParts.27962
8170 @end group
8171 @end smallexample
8172
8173 Notice, that if the @command{tar} implementation you use supports PAX
8174 format archives, it will probably emit warnings about unknown keywords
8175 during extraction. They will lool like this:
8176
8177 @smallexample
8178 @group
8179 Tar file too small
8180 Unknown extended header keyword 'GNU.volume.filename' ignored.
8181 Unknown extended header keyword 'GNU.volume.size' ignored.
8182 Unknown extended header keyword 'GNU.volume.offset' ignored.
8183 @end group
8184 @end smallexample
8185
8186 @noindent
8187 You can safely ignore these warnings.
8188
8189 If your @command{tar} implementation is not PAX-aware, you will get
8190 more warnigns and more files generated on your disk, e.g.:
8191
8192 @smallexample
8193 @group
8194 $ @kbd{tar xf vol-1.tar}
8195 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
8196 normal file
8197 Unexpected EOF in archive
8198 $ @kbd{tar xf vol-2.tar}
8199 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
8200 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
8201 'x', extracted as normal file
8202 @end group
8203 @end smallexample
8204
8205 Ignore these warnings. The @file{PaxHeaders.*} directories created
8206 will contain files with @dfn{extended header keywords} describing the
8207 extracted files. You can delete them, unless they describe sparse
8208 members. Read further to learn more about them.
8209
8210 @node Sparse Recovery
8211 @subsubsection Extracting Sparse Members
8212
8213 Any @command{tar} implementation will be able to extract sparse members from a
8214 PAX archive. However, the extracted files will be @dfn{condensed},
8215 i.e. any zero blocks will be removed from them. When we restore such
8216 a condensed file to its original form, by adding zero bloks (or
8217 @dfn{holes}) back to their original locations, we call this process
8218 @dfn{expanding} a compressed sparse file.
8219
8220 To expand a file, you will need a simple auxiliary program called
8221 @command{xsparse}. It is available in source form from
8222 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse, @GNUTAR{}
8223 home page}.
8224
8225 Let's begin with archive members in @dfn{sparse format
8226 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
8227 The condensed file will contain both file map and file data, so no
8228 additional data will be needed to restore it. If the original file
8229 name was @file{@var{dir}/@var{name}}, then the condensed file will be
8230 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
8231 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
8232 @dfn{process ID} of the @command{tar} process which created the
8233 archive (@pxref{PAX keywords}).}.
8234
8235 To expand a version 1.0 file, run @command{xsparse} as follows:
8236
8237 @smallexample
8238 $ @kbd{xsparse @file{cond-file}}
8239 @end smallexample
8240
8241 @noindent
8242 where @file{cond-file} is the name of the condensed file. The utility
8243 will deduce the name for the resulting expanded file using the
8244 following algorithm:
8245
8246 @enumerate 1
8247 @item If @file{cond-file} does not contain any directories,
8248 @file{../cond-file} will be used;
8249
8250 @item If @file{cond-file} has the form
8251 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
8252 are simple names, with no @samp{/} characters in them, the output file
8253 name will be @file{@var{dir}/@var{name}}.
8254
8255 @item Otherwise, if @file{cond-file} has the form
8256 @file{@var{dir}/@var{name}}, the output file name will be
8257 @file{@var{name}}.
8258 @end enumerate
8259
8260 In the unlikely case when this algorithm does not suite your needs,
8261 you can explicitely specify output file name as a second argument to
8262 the command:
8263
8264 @smallexample
8265 $ @kbd{xsparse @file{cond-file}}
8266 @end smallexample
8267
8268 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
8269 first. In this mode, the command does not actually expand the file,
8270 but verbosely lists all actions it would be taking to do so. The dry
8271 run mode is enabled by @option{-n} command line argument:
8272
8273 @smallexample
8274 @group
8275 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
8276 Reading v.1.0 sparse map
8277 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8278 `/home/gray/sparsefile'
8279 Finished dry run
8280 @end group
8281 @end smallexample
8282
8283 To actually expand the file, you would run:
8284
8285 @smallexample
8286 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
8287 @end smallexample
8288
8289 @noindent
8290 The program behaves the same way all UNIX utilities do: it will keep
8291 quiet unless it has simething important to tell you (e.g. an error
8292 condition or something). If you wish it to produce verbose output,
8293 similar to that from the dry run mode, give it @option{-v} option:
8294
8295 @smallexample
8296 @group
8297 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
8298 Reading v.1.0 sparse map
8299 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8300 `/home/gray/sparsefile'
8301 Done
8302 @end group
8303 @end smallexample
8304
8305 Additionally, if your @command{tar} implementation has extracted the
8306 @dfn{extended headers} for this file, you can instruct @command{xstar}
8307 to use them in order to verify the integrity of the expanded file.
8308 The option @option{-x} sets the name of the extended header file to
8309 use. Continuing our example:
8310
8311 @smallexample
8312 @group
8313 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
8314 /home/gray/GNUSparseFile.6058/sparsefile}
8315 Reading extended header file
8316 Found variable GNU.sparse.major = 1
8317 Found variable GNU.sparse.minor = 0
8318 Found variable GNU.sparse.name = sparsefile
8319 Found variable GNU.sparse.realsize = 217481216
8320 Reading v.1.0 sparse map
8321 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8322 `/home/gray/sparsefile'
8323 Done
8324 @end group
8325 @end smallexample
8326
8327 An @dfn{extended header} is a special @command{tar} archive header
8328 that precedes an archive member and contains a set of
8329 @dfn{variables}, describing the member properties that cannot be
8330 stored in the standard @code{ustar} header. While optional for
8331 expanding sparse version 1.0 members, use of extended headers is
8332 mandatory when expanding sparse members in older sparse formats: v.0.0
8333 and v.0.1 (The sparse formats are described in detail in @pxref{Sparse
8334 Formats}). So, for this format, the question is: how to obtain
8335 extended headers from the archive?
8336
8337 If you use a @command{tar} implementation that does not support PAX
8338 format, extended headers for each member will be extracted as a
8339 separate file. If we represent the member name as
8340 @file{@var{dir}/@var{name}}, then the extended header file will be
8341 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
8342 @var{n} is an integer number.
8343
8344 Things become more difficult if your @command{tar} implementation
8345 does support PAX headers, because in this case you will have to
8346 manually extract the headers. We recommend the following algorithm:
8347
8348 @enumerate 1
8349 @item
8350 Consult the documentation for your @command{tar} implementation for an
8351 option that will print @dfn{block numbers} along with the archive
8352 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
8353 @command{star} has @option{-block-number}.
8354
8355 @item
8356 Obtain the verbose listing using the @samp{block number} option, and
8357 find the position of the sparse member in question and the member
8358 immediately following it. For example, running @command{star} on our
8359 archive we obtain:
8360
8361 @smallexample
8362 @group
8363 $ @kbd{star -t -v -block-number -f arc.tar}
8364 @dots{}
8365 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
8366 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
8367 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
8368 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
8369 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
8370 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
8371 @dots{}
8372 @end group
8373 @end smallexample
8374
8375 @noindent
8376 (as usual, ignore the warnings about unknown keywords.)
8377
8378 @item
8379 Let the size of the sparse member be @var{size}, its block number be
8380 @var{Bs} and the block number of the next member be @var{Bn}.
8381 Compute:
8382
8383 @smallexample
8384 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
8385 @end smallexample
8386
8387 @noindent
8388 This number gives the size of the extended header part in tar @dfn{blocks}.
8389 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
8390 = 7}.
8391
8392 @item
8393 Use @command{dd} to extract the headers:
8394
8395 @smallexample
8396 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
8397 @end smallexample
8398
8399 @noindent
8400 where @var{archive} is the archive name, @var{hname} is a name of the
8401 file to store the extended header in, @var{Bs} and @var{N} are
8402 computed in previous steps.
8403
8404 In our example, this command will be
8405
8406 @smallexample
8407 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
8408 @end smallexample
8409 @end enumerate
8410
8411 Finally, you can expand the condensed file, using the obtained header:
8412
8413 @smallexample
8414 @group
8415 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
8416 Reading extended header file
8417 Found variable GNU.sparse.size = 217481216
8418 Found variable GNU.sparse.numblocks = 208
8419 Found variable GNU.sparse.name = sparsefile
8420 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
8421 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
8422 Done
8423 @end group
8424 @end smallexample
8425
8426 @node Compression
8427 @section Using Less Space through Compression
8428
8429 @menu
8430 * gzip:: Creating and Reading Compressed Archives
8431 * sparse:: Archiving Sparse Files
8432 @end menu
8433
8434 @node gzip
8435 @subsection Creating and Reading Compressed Archives
8436 @cindex Compressed archives
8437 @cindex Storing archives in compressed format
8438
8439 @GNUTAR{} is able to create and read compressed archives. It supports
8440 @command{gzip} and @command{bzip2} compression programs. For backward
8441 compatibilty, it also supports @command{compress} command, although
8442 we strongly recommend against using it, since there is a patent
8443 covering the algorithm it uses and you could be sued for patent
8444 infringement merely by running @command{compress}! Besides, it is less
8445 effective than @command{gzip} and @command{bzip2}.
8446
8447 Creating a compressed archive is simple: you just specify a
8448 @dfn{compression option} along with the usual archive creation
8449 commands. The compression option is @option{-z} (@option{--gzip}) to
8450 create a @command{gzip} compressed archive, @option{-j}
8451 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
8452 @option{-Z} (@option{--compress}) to use @command{compress} program.
8453 For example:
8454
8455 @smallexample
8456 $ @kbd{tar cfz archive.tar.gz .}
8457 @end smallexample
8458
8459 Reading compressed archive is even simpler: you don't need to specify
8460 any additional options as @GNUTAR{} recognizes its format
8461 automatically. Thus, the following commands will list and extract the
8462 archive created in previous example:
8463
8464 @smallexample
8465 # List the compressed archive
8466 $ @kbd{tar tf archive.tar.gz}
8467 # Extract the compressed archive
8468 $ @kbd{tar xf archive.tar.gz}
8469 @end smallexample
8470
8471 The only case when you have to specify a decompression option while
8472 reading the archive is when reading from a pipe or from a tape drive
8473 that does not support random access. However, in this case @GNUTAR{}
8474 will indicate which option you should use. For example:
8475
8476 @smallexample
8477 $ @kbd{cat archive.tar.gz | tar tf -}
8478 tar: Archive is compressed. Use -z option
8479 tar: Error is not recoverable: exiting now
8480 @end smallexample
8481
8482 If you see such diagnostics, just add the suggested option to the
8483 invocation of @GNUTAR{}:
8484
8485 @smallexample
8486 $ @kbd{cat archive.tar.gz | tar tfz -}
8487 @end smallexample
8488
8489 Notice also, that there are several restrictions on operations on
8490 compressed archives. First of all, compressed archives cannot be
8491 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8492 (@option{--delete}) members from them. Likewise, you cannot append
8493 another @command{tar} archive to a compressed archive using
8494 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8495 compressed.
8496
8497 The following table summarizes compression options used by @GNUTAR{}.
8498
8499 @table @option
8500 @opindex gzip
8501 @opindex ungzip
8502 @item -z
8503 @itemx --gzip
8504 @itemx --ungzip
8505 Filter the archive through @command{gzip}.
8506
8507 You can use @option{--gzip} and @option{--gunzip} on physical devices
8508 (tape drives, etc.) and remote files as well as on normal files; data
8509 to or from such devices or remote files is reblocked by another copy
8510 of the @command{tar} program to enforce the specified (or default) record
8511 size. The default compression parameters are used; if you need to
8512 override them, set @env{GZIP} environment variable, e.g.:
8513
8514 @smallexample
8515 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8516 @end smallexample
8517
8518 @noindent
8519 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8520 @command{gzip} explicitly:
8521
8522 @smallexample
8523 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8524 @end smallexample
8525
8526 @cindex corrupted archives
8527 About corrupted compressed archives: @command{gzip}'ed files have no
8528 redundancy, for maximum compression. The adaptive nature of the
8529 compression scheme means that the compression tables are implicitly
8530 spread all over the archive. If you lose a few blocks, the dynamic
8531 construction of the compression tables becomes unsynchronized, and there
8532 is little chance that you could recover later in the archive.
8533
8534 There are pending suggestions for having a per-volume or per-file
8535 compression in @GNUTAR{}. This would allow for viewing the
8536 contents without decompression, and for resynchronizing decompression at
8537 every volume or file, in case of corrupted archives. Doing so, we might
8538 lose some compressibility. But this would have make recovering easier.
8539 So, there are pros and cons. We'll see!
8540
8541 @opindex bzip2
8542 @item -j
8543 @itemx --bzip2
8544 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8545
8546 @opindex compress
8547 @opindex uncompress
8548 @item -Z
8549 @itemx --compress
8550 @itemx --uncompress
8551 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8552
8553 The @acronym{GNU} Project recommends you not use
8554 @command{compress}, because there is a patent covering the algorithm it
8555 uses. You could be sued for patent infringement merely by running
8556 @command{compress}.
8557
8558 @opindex use-compress-program
8559 @item --use-compress-program=@var{prog}
8560 Use external compression program @var{prog}. Use this option if you
8561 have a compression program that @GNUTAR{} does not support. There
8562 are two requirements to which @var{prog} should comply:
8563
8564 First, when called without options, it should read data from standard
8565 input, compress it and output it on standard output.
8566
8567 Secondly, if called with @option{-d} argument, it should do exactly
8568 the opposite, i.e., read the compressed data from the standard input
8569 and produce uncompressed data on the standard output.
8570 @end table
8571
8572 @cindex gpg, using with tar
8573 @cindex gnupg, using with tar
8574 @cindex Using encrypted archives
8575 The @option{--use-compress-program} option, in particular, lets you
8576 implement your own filters, not necessarily dealing with
8577 compression/decomression. For example, suppose you wish to implement
8578 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8579 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8580 Manual}). The following script does that:
8581
8582 @smallexample
8583 @group
8584 #! /bin/sh
8585 case $1 in
8586 -d) gpg --decrypt - | gzip -d -c;;
8587 '') gzip -c | gpg -s ;;
8588 *) echo "Unknown option $1">&2; exit 1;;
8589 esac
8590 @end group
8591 @end smallexample
8592
8593 Suppose you name it @file{gpgz} and save it somewhere in your
8594 @env{PATH}. Then the following command will create a commpressed
8595 archive signed with your private key:
8596
8597 @smallexample
8598 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8599 @end smallexample
8600
8601 @noindent
8602 Likewise, the following command will list its contents:
8603
8604 @smallexample
8605 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8606 @end smallexample
8607
8608 @ignore
8609 The above is based on the following discussion:
8610
8611 I have one question, or maybe it's a suggestion if there isn't a way
8612 to do it now. I would like to use @option{--gzip}, but I'd also like
8613 the output to be fed through a program like @acronym{GNU}
8614 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8615 to use :-)), basically adding ECC protection on top of compression.
8616 It seems as if this should be quite easy to do, but I can't work out
8617 exactly how to go about it. Of course, I can pipe the standard output
8618 of @command{tar} through @command{ecc}, but then I lose (though I
8619 haven't started using it yet, I confess) the ability to have
8620 @command{tar} use @command{rmt} for it's I/O (I think).
8621
8622 I think the most straightforward thing would be to let me specify a
8623 general set of filters outboard of compression (preferably ordered,
8624 so the order can be automatically reversed on input operations, and
8625 with the options they require specifiable), but beggars shouldn't be
8626 choosers and anything you decide on would be fine with me.
8627
8628 By the way, I like @command{ecc} but if (as the comments say) it can't
8629 deal with loss of block sync, I'm tempted to throw some time at adding
8630 that capability. Supposing I were to actually do such a thing and
8631 get it (apparently) working, do you accept contributed changes to
8632 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8633
8634 Isn't that exactly the role of the
8635 @option{--use-compress-prog=@var{program}} option?
8636 I never tried it myself, but I suspect you may want to write a
8637 @var{prog} script or program able to filter stdin to stdout to
8638 way you want. It should recognize the @option{-d} option, for when
8639 extraction is needed rather than creation.
8640
8641 It has been reported that if one writes compressed data (through the
8642 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8643 the DLT compression mode, the data will actually get bigger and one will
8644 end up with less space on the tape.
8645 @end ignore
8646
8647 @node sparse
8648 @subsection Archiving Sparse Files
8649 @cindex Sparse Files
8650 @UNREVISED
8651
8652 @table @option
8653 @opindex sparse
8654 @item -S
8655 @itemx --sparse
8656 Handle sparse files efficiently.
8657 @end table
8658
8659 This option causes all files to be put in the archive to be tested for
8660 sparseness, and handled specially if they are. The @option{--sparse}
8661 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
8662 backed up. Using this option dramatically decreases the amount of
8663 space needed to store such a file.
8664
8665 In later versions, this option may be removed, and the testing and
8666 treatment of sparse files may be done automatically with any special
8667 @acronym{GNU} options. For now, it is an option needing to be specified on
8668 the command line with the creation or updating of an archive.
8669
8670 Files in the file system occasionally have @dfn{holes}. A @dfn{hole} in a file
8671 is a section of the file's contents which was never written. The
8672 contents of a hole read as all zeros. On many operating systems,
8673 actual disk storage is not allocated for holes, but they are counted
8674 in the length of the file. If you archive such a file, @command{tar}
8675 could create an archive longer than the original. To have @command{tar}
8676 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
8677 you use this option, then, for any file using less disk space than
8678 would be expected from its length, @command{tar} searches the file for
8679 consecutive stretches of zeros. It then records in the archive for
8680 the file where the consecutive stretches of zeros are, and only
8681 archives the ``real contents'' of the file. On extraction (using
8682 @option{--sparse} is not needed on extraction) any such
8683 files have holes created wherever the continuous stretches of zeros
8684 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8685 won't take more space than the original.
8686
8687 A file is sparse if it contains blocks of zeros whose existence is
8688 recorded, but that have no space allocated on disk. When you specify
8689 the @option{--sparse} option in conjunction with the @option{--create}
8690 (@option{-c}) operation, @command{tar} tests all files for sparseness
8691 while archiving. If @command{tar} finds a file to be sparse, it uses a
8692 sparse representation of the file in the archive. @xref{create}, for
8693 more information about creating archives.
8694
8695 @option{--sparse} is useful when archiving files, such as dbm files,
8696 likely to contain many nulls. This option dramatically
8697 decreases the amount of space needed to store such an archive.
8698
8699 @quotation
8700 @strong{Please Note:} Always use @option{--sparse} when performing file
8701 system backups, to avoid archiving the expanded forms of files stored
8702 sparsely in the system.
8703
8704 Even if your system has no sparse files currently, some may be
8705 created in the future. If you use @option{--sparse} while making file
8706 system backups as a matter of course, you can be assured the archive
8707 will never take more space on the media than the files take on disk
8708 (otherwise, archiving a disk filled with sparse files might take
8709 hundreds of tapes). @xref{Incremental Dumps}.
8710 @end quotation
8711
8712 @command{tar} ignores the @option{--sparse} option when reading an archive.
8713
8714 @table @option
8715 @item --sparse
8716 @itemx -S
8717 Files stored sparsely in the file system are represented sparsely in
8718 the archive. Use in conjunction with write operations.
8719 @end table
8720
8721 However, users should be well aware that at archive creation time,
8722 @GNUTAR{} still has to read whole disk file to
8723 locate the @dfn{holes}, and so, even if sparse files use little space
8724 on disk and in the archive, they may sometimes require inordinate
8725 amount of time for reading and examining all-zero blocks of a file.
8726 Although it works, it's painfully slow for a large (sparse) file, even
8727 though the resulting tar archive may be small. (One user reports that
8728 dumping a @file{core} file of over 400 megabytes, but with only about
8729 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
8730 ELC, with full CPU utilization.)
8731
8732 This reading is required in all cases and is not related to the fact
8733 the @option{--sparse} option is used or not, so by merely @emph{not}
8734 using the option, you are not saving time@footnote{Well! We should say
8735 the whole truth, here. When @option{--sparse} is selected while creating
8736 an archive, the current @command{tar} algorithm requires sparse files to be
8737 read twice, not once. We hope to develop a new archive format for saving
8738 sparse files in which one pass will be sufficient.}.
8739
8740 Programs like @command{dump} do not have to read the entire file; by
8741 examining the file system directly, they can determine in advance
8742 exactly where the holes are and thus avoid reading through them. The
8743 only data it need read are the actual allocated data blocks.
8744 @GNUTAR{} uses a more portable and straightforward
8745 archiving approach, it would be fairly difficult that it does
8746 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8747 1990-12-10:
8748
8749 @quotation
8750 What I did say is that you cannot tell the difference between a hole and an
8751 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8752 best tells you how many holes there are; it doesn't tell you @emph{where}.
8753 Just as programs may, conceivably, care what @code{st_blocks} is (care
8754 to name one that does?), they may also care where the holes are (I have
8755 no examples of this one either, but it's equally imaginable).
8756
8757 I conclude from this that good archivers are not portable. One can
8758 arguably conclude that if you want a portable program, you can in good
8759 conscience restore files with as many holes as possible, since you can't
8760 get it right.
8761 @end quotation
8762
8763 @node Attributes
8764 @section Handling File Attributes
8765 @UNREVISED
8766
8767 When @command{tar} reads files, it updates their access times. To
8768 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8769 reset the access time retroactively or avoid changing it in the first
8770 place.
8771
8772 Handling of file attributes
8773
8774 @table @option
8775 @opindex atime-preserve
8776 @item --atime-preserve
8777 @itemx --atime-preserve=replace
8778 @itemx --atime-preserve=system
8779 Preserve the access times of files that are read. This works only for
8780 files that you own, unless you have superuser privileges.
8781
8782 @option{--atime-preserve=replace} works on most systems, but it also
8783 restores the data modification time and updates the status change
8784 time. Hence it doesn't interact with incremental dumps nicely
8785 (@pxref{Backups}), and it can set access or data modification times
8786 incorrectly if other programs access the file while @command{tar} is
8787 running.
8788
8789 @option{--atime-preserve=system} avoids changing the access time in
8790 the first place, if the operating system supports this.
8791 Unfortunately, this may or may not work on any given operating system
8792 or file system. If @command{tar} knows for sure it won't work, it
8793 complains right away.
8794
8795 Currently @option{--atime-preserve} with no operand defaults to
8796 @option{--atime-preserve=replace}, but this is intended to change to
8797 @option{--atime-preserve=system} when the latter is better-supported.
8798
8799 @opindex touch
8800 @item -m
8801 @itemx --touch
8802 Do not extract data modification time.
8803
8804 When this option is used, @command{tar} leaves the data modification times
8805 of the files it extracts as the times when the files were extracted,
8806 instead of setting it to the times recorded in the archive.
8807
8808 This option is meaningless with @option{--list} (@option{-t}).
8809
8810 @opindex same-owner
8811 @item --same-owner
8812 Create extracted files with the same ownership they have in the
8813 archive.
8814
8815 This is the default behavior for the superuser,
8816 so this option is meaningful only for non-root users, when @command{tar}
8817 is executed on those systems able to give files away. This is
8818 considered as a security flaw by many people, at least because it
8819 makes quite difficult to correctly account users for the disk space
8820 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8821 files are easily and silently lost when files are given away.
8822
8823 When writing an archive, @command{tar} writes the user id and user name
8824 separately. If it can't find a user name (because the user id is not
8825 in @file{/etc/passwd}), then it does not write one. When restoring,
8826 it tries to look the name (if one was written) up in
8827 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8828 the archive instead.
8829
8830 @opindex no-same-owner
8831 @item --no-same-owner
8832 @itemx -o
8833 Do not attempt to restore ownership when extracting. This is the
8834 default behavior for ordinary users, so this option has an effect
8835 only for the superuser.
8836
8837 @opindex numeric-owner
8838 @item --numeric-owner
8839 The @option{--numeric-owner} option allows (ANSI) archives to be written
8840 without user/group name information or such information to be ignored
8841 when extracting. It effectively disables the generation and/or use
8842 of user/group name information. This option forces extraction using
8843 the numeric ids from the archive, ignoring the names.
8844
8845 This is useful in certain circumstances, when restoring a backup from
8846 an emergency floppy with different passwd/group files for example.
8847 It is otherwise impossible to extract files with the right ownerships
8848 if the password file in use during the extraction does not match the
8849 one belonging to the file system(s) being extracted. This occurs,
8850 for example, if you are restoring your files after a major crash and
8851 had booted from an emergency floppy with no password file or put your
8852 disk into another machine to do the restore.
8853
8854 The numeric ids are @emph{always} saved into @command{tar} archives.
8855 The identifying names are added at create time when provided by the
8856 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8857 used when moving archives between a collection of machines using
8858 a centralized management for attribution of numeric ids to users
8859 and groups. This is often made through using the NIS capabilities.
8860
8861 When making a @command{tar} file for distribution to other sites, it
8862 is sometimes cleaner to use a single owner for all files in the
8863 distribution, and nicer to specify the write permission bits of the
8864 files as stored in the archive independently of their actual value on
8865 the file system. The way to prepare a clean distribution is usually
8866 to have some Makefile rule creating a directory, copying all needed
8867 files in that directory, then setting ownership and permissions as
8868 wanted (there are a lot of possible schemes), and only then making a
8869 @command{tar} archive out of this directory, before cleaning
8870 everything out. Of course, we could add a lot of options to
8871 @GNUTAR{} for fine tuning permissions and ownership.
8872 This is not the good way, I think. @GNUTAR{} is
8873 already crowded with options and moreover, the approach just explained
8874 gives you a great deal of control already.
8875
8876 @xopindex{same-permissions, short description}
8877 @xopindex{preserve-permissions, short description}
8878 @item -p
8879 @itemx --same-permissions
8880 @itemx --preserve-permissions
8881 Extract all protection information.
8882
8883 This option causes @command{tar} to set the modes (access permissions) of
8884 extracted files exactly as recorded in the archive. If this option
8885 is not used, the current @code{umask} setting limits the permissions
8886 on extracted files. This option is by default enabled when
8887 @command{tar} is executed by a superuser.
8888
8889
8890 This option is meaningless with @option{--list} (@option{-t}).
8891
8892 @opindex preserve
8893 @item --preserve
8894 Same as both @option{--same-permissions} and @option{--same-order}.
8895
8896 The @option{--preserve} option has no equivalent short option name.
8897 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8898
8899 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8900 Neither do I. --Sergey}
8901
8902 @end table
8903
8904 @node cpio
8905 @section Comparison of @command{tar} and @command{cpio}
8906 @UNREVISED
8907
8908 @FIXME{Reorganize the following material}
8909
8910 The @command{cpio} archive formats, like @command{tar}, do have maximum
8911 pathname lengths. The binary and old ASCII formats have a max path
8912 length of 256, and the new ASCII and CRC ASCII formats have a max
8913 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8914 with arbitrary pathname lengths, but other @command{cpio} implementations
8915 may crash unexplainedly trying to read them.
8916
8917 @command{tar} handles symbolic links in the form in which it comes in BSD;
8918 @command{cpio} doesn't handle symbolic links in the form in which it comes
8919 in System V prior to SVR4, and some vendors may have added symlinks
8920 to their system without enhancing @command{cpio} to know about them.
8921 Others may have enhanced it in a way other than the way I did it
8922 at Sun, and which was adopted by AT&T (and which is, I think, also
8923 present in the @command{cpio} that Berkeley picked up from AT&T and put
8924 into a later BSD release---I think I gave them my changes).
8925
8926 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8927 can handle @command{tar} format input, and write it on output, and it
8928 probably handles symbolic links. They may not have bothered doing
8929 anything to enhance @command{tar} as a result.)
8930
8931 @command{cpio} handles special files; traditional @command{tar} doesn't.
8932
8933 @command{tar} comes with V7, System III, System V, and BSD source;
8934 @command{cpio} comes only with System III, System V, and later BSD
8935 (4.3-tahoe and later).
8936
8937 @command{tar}'s way of handling multiple hard links to a file can handle
8938 file systems that support 32-bit inumbers (e.g., the BSD file system);
8939 @command{cpio}s way requires you to play some games (in its "binary"
8940 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8941 they're 18 bits---it would have to play games with the "file system ID"
8942 field of the header to make sure that the file system ID/i-number pairs
8943 of different files were always different), and I don't know which
8944 @command{cpio}s, if any, play those games. Those that don't might get
8945 confused and think two files are the same file when they're not, and
8946 make hard links between them.
8947
8948 @command{tar}s way of handling multiple hard links to a file places only
8949 one copy of the link on the tape, but the name attached to that copy
8950 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8951 way puts one copy for every link, but you can retrieve it using any
8952 of the names.
8953
8954 @quotation
8955 What type of check sum (if any) is used, and how is this calculated.
8956 @end quotation
8957
8958 See the attached manual pages for @command{tar} and @command{cpio} format.
8959 @command{tar} uses a checksum which is the sum of all the bytes in the
8960 @command{tar} header for a file; @command{cpio} uses no checksum.
8961
8962 @quotation
8963 If anyone knows why @command{cpio} was made when @command{tar} was present
8964 at the unix scene,
8965 @end quotation
8966
8967 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8968 generally-available version of UNIX had @command{tar} at the time. I don't
8969 know whether any version that was generally available @emph{within AT&T}
8970 had @command{tar}, or, if so, whether the people within AT&T who did
8971 @command{cpio} knew about it.
8972
8973 On restore, if there is a corruption on a tape @command{tar} will stop at
8974 that point, while @command{cpio} will skip over it and try to restore the
8975 rest of the files.
8976
8977 The main difference is just in the command syntax and header format.
8978
8979 @command{tar} is a little more tape-oriented in that everything is blocked
8980 to start on a record boundary.
8981
8982 @quotation
8983 Is there any differences between the ability to recover crashed
8984 archives between the two of them. (Is there any chance of recovering
8985 crashed archives at all.)
8986 @end quotation
8987
8988 Theoretically it should be easier under @command{tar} since the blocking
8989 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8990 However, modern @command{cpio}'s and variations have an option to just
8991 search for the next file header after an error with a reasonable chance
8992 of resyncing. However, lots of tape driver software won't allow you to
8993 continue past a media error which should be the only reason for getting
8994 out of sync unless a file changed sizes while you were writing the
8995 archive.
8996
8997 @quotation
8998 If anyone knows why @command{cpio} was made when @command{tar} was present
8999 at the unix scene, please tell me about this too.
9000 @end quotation
9001
9002 Probably because it is more media efficient (by not blocking everything
9003 and using only the space needed for the headers where @command{tar}
9004 always uses 512 bytes per file header) and it knows how to archive
9005 special files.
9006
9007 You might want to look at the freely available alternatives. The
9008 major ones are @command{afio}, @GNUTAR{}, and
9009 @command{pax}, each of which have their own extensions with some
9010 backwards compatibility.
9011
9012 Sparse files were @command{tar}red as sparse files (which you can
9013 easily test, because the resulting archive gets smaller, and
9014 @acronym{GNU} @command{cpio} can no longer read it).
9015
9016 @node Media
9017 @chapter Tapes and Other Archive Media
9018 @UNREVISED
9019
9020 A few special cases about tape handling warrant more detailed
9021 description. These special cases are discussed below.
9022
9023 Many complexities surround the use of @command{tar} on tape drives. Since
9024 the creation and manipulation of archives located on magnetic tape was
9025 the original purpose of @command{tar}, it contains many features making
9026 such manipulation easier.
9027
9028 Archives are usually written on dismountable media---tape cartridges,
9029 mag tapes, or floppy disks.
9030
9031 The amount of data a tape or disk holds depends not only on its size,
9032 but also on how it is formatted. A 2400 foot long reel of mag tape
9033 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9034 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9035
9036 Magnetic media are re-usable---once the archive on a tape is no longer
9037 needed, the archive can be erased and the tape or disk used over.
9038 Media quality does deteriorate with use, however. Most tapes or disks
9039 should be discarded when they begin to produce data errors. EXABYTE
9040 tape cartridges should be discarded when they generate an @dfn{error
9041 count} (number of non-usable bits) of more than 10k.
9042
9043 Magnetic media are written and erased using magnetic fields, and
9044 should be protected from such fields to avoid damage to stored data.
9045 Sticking a floppy disk to a filing cabinet using a magnet is probably
9046 not a good idea.
9047
9048 @menu
9049 * Device:: Device selection and switching
9050 * Remote Tape Server::
9051 * Common Problems and Solutions::
9052 * Blocking:: Blocking
9053 * Many:: Many archives on one tape
9054 * Using Multiple Tapes:: Using Multiple Tapes
9055 * label:: Including a Label in the Archive
9056 * verify::
9057 * Write Protection::
9058 @end menu
9059
9060 @node Device
9061 @section Device Selection and Switching
9062 @UNREVISED
9063
9064 @table @option
9065 @item -f [@var{hostname}:]@var{file}
9066 @itemx --file=[@var{hostname}:]@var{file}
9067 Use archive file or device @var{file} on @var{hostname}.
9068 @end table
9069
9070 This option is used to specify the file name of the archive @command{tar}
9071 works on.
9072
9073 If the file name is @samp{-}, @command{tar} reads the archive from standard
9074 input (when listing or extracting), or writes it to standard output
9075 (when creating). If the @samp{-} file name is given when updating an
9076 archive, @command{tar} will read the original archive from its standard
9077 input, and will write the entire new archive to its standard output.
9078
9079 If the file name contains a @samp{:}, it is interpreted as
9080 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9081 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9082 either case, @command{tar} will invoke the command @command{rsh} (or
9083 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9084 machine. If you give an alternate login name, it will be given to the
9085 @command{rsh}.
9086 Naturally, the remote machine must have an executable
9087 @command{/usr/libexec/rmt}. This program is free software from the
9088 University of California, and a copy of the source code can be found
9089 with the sources for @command{tar}; it's compiled and installed by default.
9090 The exact path to this utility is determined when configuring the package.
9091 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9092 your installation prefix. This location may also be overridden at
9093 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9094 ---rmt-command}, for detailed description of this option. @xref{Remote
9095 Tape Server}, for the description of @command{rmt} command).
9096
9097 If this option is not given, but the environment variable @env{TAPE}
9098 is set, its value is used; otherwise, old versions of @command{tar}
9099 used a default archive name (which was picked when @command{tar} was
9100 compiled). The default is normally set up to be the @dfn{first} tape
9101 drive or other transportable I/O medium on the system.
9102
9103 Starting with version 1.11.5, @GNUTAR{} uses
9104 standard input and standard output as the default device, and I will
9105 not try anymore supporting automatic device detection at installation
9106 time. This was failing really in too many cases, it was hopeless.
9107 This is now completely left to the installer to override standard
9108 input and standard output for default device, if this seems
9109 preferable. Further, I think @emph{most} actual usages of
9110 @command{tar} are done with pipes or disks, not really tapes,
9111 cartridges or diskettes.
9112
9113 Some users think that using standard input and output is running
9114 after trouble. This could lead to a nasty surprise on your screen if
9115 you forget to specify an output file name---especially if you are going
9116 through a network or terminal server capable of buffering large amounts
9117 of output. We had so many bug reports in that area of configuring
9118 default tapes automatically, and so many contradicting requests, that
9119 we finally consider the problem to be portably intractable. We could
9120 of course use something like @samp{/dev/tape} as a default, but this
9121 is @emph{also} running after various kind of trouble, going from hung
9122 processes to accidental destruction of real tapes. After having seen
9123 all this mess, using standard input and output as a default really
9124 sounds like the only clean choice left, and a very useful one too.
9125
9126 @GNUTAR{} reads and writes archive in records, I
9127 suspect this is the main reason why block devices are preferred over
9128 character devices. Most probably, block devices are more efficient
9129 too. The installer could also check for @samp{DEFTAPE} in
9130 @file{<sys/mtio.h>}.
9131
9132 @table @option
9133 @xopindex{force-local, short description}
9134 @item --force-local
9135 Archive file is local even if it contains a colon.
9136
9137 @opindex rsh-command
9138 @item --rsh-command=@var{command}
9139 Use remote @var{command} instead of @command{rsh}. This option exists
9140 so that people who use something other than the standard @command{rsh}
9141 (e.g., a Kerberized @command{rsh}) can access a remote device.
9142
9143 When this command is not used, the shell command found when
9144 the @command{tar} program was installed is used instead. This is
9145 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9146 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9147 The installer may have overridden this by defining the environment
9148 variable @env{RSH} @emph{at installation time}.
9149
9150 @item -[0-7][lmh]
9151 Specify drive and density.
9152
9153 @xopindex{multi-volume, short description}
9154 @item -M
9155 @itemx --multi-volume
9156 Create/list/extract multi-volume archive.
9157
9158 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9159 that may be larger than will fit on the medium used to hold it.
9160 @xref{Multi-Volume Archives}.
9161
9162 @xopindex{tape-length, short description}
9163 @item -L @var{num}
9164 @itemx --tape-length=@var{num}
9165 Change tape after writing @var{num} x 1024 bytes.
9166
9167 This option might be useful when your tape drivers do not properly
9168 detect end of physical tapes. By being slightly conservative on the
9169 maximum tape length, you might avoid the problem entirely.
9170
9171 @xopindex{info-script, short description}
9172 @xopindex{new-volume-script, short description}
9173 @item -F @var{file}
9174 @itemx --info-script=@var{file}
9175 @itemx --new-volume-script=@var{file}
9176 Execute @file{file} at end of each tape. This implies
9177 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9178 description of this option.
9179 @end table
9180
9181 @node Remote Tape Server
9182 @section The Remote Tape Server
9183
9184 @cindex remote tape drive
9185 @pindex rmt
9186 In order to access the tape drive on a remote machine, @command{tar}
9187 uses the remote tape server written at the University of California at
9188 Berkeley. The remote tape server must be installed as
9189 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9190 want to use. @command{tar} calls @command{rmt} by running an
9191 @command{rsh} or @command{remsh} to the remote machine, optionally
9192 using a different login name if one is supplied.
9193
9194 A copy of the source for the remote tape server is provided. It is
9195 Copyright @copyright{} 1983 by the Regents of the University of
9196 California, but can be freely distributed. It is compiled and
9197 installed by default.
9198
9199 @cindex absolute file names
9200 Unless you use the @option{--absolute-names} (@option{-P}) option,
9201 @GNUTAR{} will not allow you to create an archive that contains
9202 absolute file names (a file name beginning with @samp{/}.) If you try,
9203 @command{tar} will automatically remove the leading @samp{/} from the
9204 file names it stores in the archive. It will also type a warning
9205 message telling you what it is doing.
9206
9207 When reading an archive that was created with a different
9208 @command{tar} program, @GNUTAR{} automatically
9209 extracts entries in the archive which have absolute file names as if
9210 the file names were not absolute. This is an important feature. A
9211 visitor here once gave a @command{tar} tape to an operator to restore;
9212 the operator used Sun @command{tar} instead of @GNUTAR{},
9213 and the result was that it replaced large portions of
9214 our @file{/bin} and friends with versions from the tape; needless to
9215 say, we were unhappy about having to recover the file system from
9216 backup tapes.
9217
9218 For example, if the archive contained a file @file{/usr/bin/computoy},
9219 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9220 relative to the current directory. If you want to extract the files in
9221 an archive to the same absolute names that they had when the archive
9222 was created, you should do a @samp{cd /} before extracting the files
9223 from the archive, or you should either use the @option{--absolute-names}
9224 option, or use the command @samp{tar -C / @dots{}}.
9225
9226 @cindex Ultrix 3.1 and write failure
9227 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9228 can claim that a short write near the end of a tape succeeded,
9229 when it actually failed. This will result in the -M option not
9230 working correctly. The best workaround at the moment is to use a
9231 significantly larger blocking factor than the default 20.
9232
9233 In order to update an archive, @command{tar} must be able to backspace the
9234 archive in order to reread or rewrite a record that was just read (or
9235 written). This is currently possible only on two kinds of files: normal
9236 disk files (or any other file that can be backspaced with @samp{lseek}),
9237 and industry-standard 9-track magnetic tape (or any other kind of tape
9238 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9239
9240 This means that the @option{--append}, @option{--concatenate}, and
9241 @option{--delete} commands will not work on any other kind of file.
9242 Some media simply cannot be backspaced, which means these commands and
9243 options will never be able to work on them. These non-backspacing
9244 media include pipes and cartridge tape drives.
9245
9246 Some other media can be backspaced, and @command{tar} will work on them
9247 once @command{tar} is modified to do so.
9248
9249 Archives created with the @option{--multi-volume}, @option{--label}, and
9250 @option{--incremental} (@option{-G}) options may not be readable by other version
9251 of @command{tar}. In particular, restoring a file that was split over
9252 a volume boundary will require some careful work with @command{dd}, if
9253 it can be done at all. Other versions of @command{tar} may also create
9254 an empty file whose name is that of the volume header. Some versions
9255 of @command{tar} may create normal files instead of directories archived
9256 with the @option{--incremental} (@option{-G}) option.
9257
9258 @node Common Problems and Solutions
9259 @section Some Common Problems and their Solutions
9260
9261 @ifclear PUBLISH
9262
9263 @format
9264 errors from system:
9265 permission denied
9266 no such file or directory
9267 not owner
9268
9269 errors from @command{tar}:
9270 directory checksum error
9271 header format error
9272
9273 errors from media/system:
9274 i/o error
9275 device busy
9276 @end format
9277
9278 @end ifclear
9279
9280 @node Blocking
9281 @section Blocking
9282 @UNREVISED
9283
9284 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9285 is also confusing to the expert reader. On the other hand, readers
9286 who are new to the field have a fresh mind, and they may safely skip
9287 the next two paragraphs, as the remainder of this manual uses those
9288 two terms in a quite consistent way.
9289
9290 John Gilmore, the writer of the public domain @command{tar} from which
9291 @GNUTAR{} was originally derived, wrote (June 1995):
9292
9293 @quotation
9294 The nomenclature of tape drives comes from IBM, where I believe
9295 they were invented for the IBM 650 or so. On IBM mainframes, what
9296 is recorded on tape are tape blocks. The logical organization of
9297 data is into records. There are various ways of putting records into
9298 blocks, including @code{F} (fixed sized records), @code{V} (variable
9299 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9300 to a block), @code{VB} (variable size records, @var{n} to a block),
9301 @code{VSB} (variable spanned blocked: variable sized records that can
9302 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9303 parameter specified this to the operating system.
9304
9305 The Unix man page on @command{tar} was totally confused about this.
9306 When I wrote @code{PD TAR}, I used the historically correct terminology
9307 (@command{tar} writes data records, which are grouped into blocks).
9308 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9309 here), and now Fran@,{c}ois has migrated that terminology back
9310 into the source code too.
9311 @end quotation
9312
9313 The term @dfn{physical block} means the basic transfer chunk from or
9314 to a device, after which reading or writing may stop without anything
9315 being lost. In this manual, the term @dfn{block} usually refers to
9316 a disk physical block, @emph{assuming} that each disk block is 512
9317 bytes in length. It is true that some disk devices have different
9318 physical blocks, but @command{tar} ignore these differences in its own
9319 format, which is meant to be portable, so a @command{tar} block is always
9320 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9321 The term @dfn{logical block} often represents the basic chunk of
9322 allocation of many disk blocks as a single entity, which the operating
9323 system treats somewhat atomically; this concept is only barely used
9324 in @GNUTAR{}.
9325
9326 The term @dfn{physical record} is another way to speak of a physical
9327 block, those two terms are somewhat interchangeable. In this manual,
9328 the term @dfn{record} usually refers to a tape physical block,
9329 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9330 It is true that archives may be put on disk or used with pipes,
9331 but nevertheless, @command{tar} tries to read and write the archive one
9332 @dfn{record} at a time, whatever the medium in use. One record is made
9333 up of an integral number of blocks, and this operation of putting many
9334 disk blocks into a single tape block is called @dfn{reblocking}, or
9335 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9336 the logical organization of many characters into something meaningful
9337 to the application. The term @dfn{unit record} describes a small set
9338 of characters which are transmitted whole to or by the application,
9339 and often refers to a line of text. Those two last terms are unrelated
9340 to what we call a @dfn{record} in @GNUTAR{}.
9341
9342 When writing to tapes, @command{tar} writes the contents of the archive
9343 in chunks known as @dfn{records}. To change the default blocking
9344 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9345 @var{512-size}}) option. Each record will then be composed of
9346 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9347 @xref{Standard}.) Each file written to the archive uses at least one
9348 full record. As a result, using a larger record size can result in
9349 more wasted space for small files. On the other hand, a larger record
9350 size can often be read and written much more efficiently.
9351
9352 Further complicating the problem is that some tape drives ignore the
9353 blocking entirely. For these, a larger record size can still improve
9354 performance (because the software layers above the tape drive still
9355 honor the blocking), but not as dramatically as on tape drives that
9356 honor blocking.
9357
9358 When reading an archive, @command{tar} can usually figure out the
9359 record size on itself. When this is the case, and a non-standard
9360 record size was used when the archive was created, @command{tar} will
9361 print a message about a non-standard blocking factor, and then operate
9362 normally. On some tape devices, however, @command{tar} cannot figure
9363 out the record size itself. On most of those, you can specify a
9364 blocking factor (with @option{--blocking-factor}) larger than the
9365 actual blocking factor, and then use the @option{--read-full-records}
9366 (@option{-B}) option. (If you specify a blocking factor with
9367 @option{--blocking-factor} and don't use the
9368 @option{--read-full-records} option, then @command{tar} will not
9369 attempt to figure out the recording size itself.) On some devices,
9370 you must always specify the record size exactly with
9371 @option{--blocking-factor} when reading, because @command{tar} cannot
9372 figure it out. In any case, use @option{--list} (@option{-t}) before
9373 doing any extractions to see whether @command{tar} is reading the archive
9374 correctly.
9375
9376 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9377 putting them into records is to put a whole number of them (one or
9378 more) into each record. @command{tar} records are all the same size;
9379 at the end of the file there's a block containing all zeros, which
9380 is how you tell that the remainder of the last record(s) are garbage.
9381
9382 In a standard @command{tar} file (no options), the block size is 512
9383 and the record size is 10240, for a blocking factor of 20. What the
9384 @option{--blocking-factor} option does is sets the blocking factor,
9385 changing the record size while leaving the block size at 512 bytes.
9386 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9387 most tape drives these days prefer much bigger records in order to
9388 stream and not waste tape. When writing tapes for myself, some tend
9389 to use a factor of the order of 2048, say, giving a record size of
9390 around one megabyte.
9391
9392 If you use a blocking factor larger than 20, older @command{tar}
9393 programs might not be able to read the archive, so we recommend this
9394 as a limit to use in practice. @GNUTAR{}, however,
9395 will support arbitrarily large record sizes, limited only by the
9396 amount of virtual memory or the physical characteristics of the tape
9397 device.
9398
9399 @menu
9400 * Format Variations:: Format Variations
9401 * Blocking Factor:: The Blocking Factor of an Archive
9402 @end menu
9403
9404 @node Format Variations
9405 @subsection Format Variations
9406 @cindex Format Parameters
9407 @cindex Format Options
9408 @cindex Options, archive format specifying
9409 @cindex Options, format specifying
9410 @UNREVISED
9411
9412 Format parameters specify how an archive is written on the archive
9413 media. The best choice of format parameters will vary depending on
9414 the type and number of files being archived, and on the media used to
9415 store the archive.
9416
9417 To specify format parameters when accessing or creating an archive,
9418 you can use the options described in the following sections.
9419 If you do not specify any format parameters, @command{tar} uses
9420 default parameters. You cannot modify a compressed archive.
9421 If you create an archive with the @option{--blocking-factor} option
9422 specified (@pxref{Blocking Factor}), you must specify that
9423 blocking-factor when operating on the archive. @xref{Formats}, for other
9424 examples of format parameter considerations.
9425
9426 @node Blocking Factor
9427 @subsection The Blocking Factor of an Archive
9428 @cindex Blocking Factor
9429 @cindex Record Size
9430 @cindex Number of blocks per record
9431 @cindex Number of bytes per record
9432 @cindex Bytes per record
9433 @cindex Blocks per record
9434 @UNREVISED
9435
9436 @opindex blocking-factor
9437 The data in an archive is grouped into blocks, which are 512 bytes.
9438 Blocks are read and written in whole number multiples called
9439 @dfn{records}. The number of blocks in a record (i.e. the size of a
9440 record in units of 512 bytes) is called the @dfn{blocking factor}.
9441 The @option{--blocking-factor=@var{512-size}} (@option{-b
9442 @var{512-size}}) option specifies the blocking factor of an archive.
9443 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9444 can be specified at installation. To find out the blocking factor of
9445 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9446 This may not work on some devices.
9447
9448 Records are separated by gaps, which waste space on the archive media.
9449 If you are archiving on magnetic tape, using a larger blocking factor
9450 (and therefore larger records) provides faster throughput and allows you
9451 to fit more data on a tape (because there are fewer gaps). If you are
9452 archiving on cartridge, a very large blocking factor (say 126 or more)
9453 greatly increases performance. A smaller blocking factor, on the other
9454 hand, may be useful when archiving small files, to avoid archiving lots
9455 of nulls as @command{tar} fills out the archive to the end of the record.
9456 In general, the ideal record size depends on the size of the
9457 inter-record gaps on the tape you are using, and the average size of the
9458 files you are archiving. @xref{create}, for information on
9459 writing archives.
9460
9461 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9462
9463 Archives with blocking factors larger than 20 cannot be read
9464 by very old versions of @command{tar}, or by some newer versions
9465 of @command{tar} running on old machines with small address spaces.
9466 With @GNUTAR{}, the blocking factor of an archive is limited
9467 only by the maximum record size of the device containing the archive,
9468 or by the amount of available virtual memory.
9469
9470 Also, on some systems, not using adequate blocking factors, as sometimes
9471 imposed by the device drivers, may yield unexpected diagnostics. For
9472 example, this has been reported:
9473
9474 @smallexample
9475 Cannot write to /dev/dlt: Invalid argument
9476 @end smallexample
9477
9478 @noindent
9479 In such cases, it sometimes happen that the @command{tar} bundled by
9480 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9481 requires an explicit specification for the block size,
9482 which it cannot guess. This yields some people to consider
9483 @GNUTAR{} is misbehaving, because by comparison,
9484 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9485 for example, might resolve the problem.
9486
9487 If you use a non-default blocking factor when you create an archive, you
9488 must specify the same blocking factor when you modify that archive. Some
9489 archive devices will also require you to specify the blocking factor when
9490 reading that archive, however this is not typically the case. Usually, you
9491 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9492 reports a non-default record size and then lists the archive members as
9493 it would normally. To extract files from an archive with a non-standard
9494 blocking factor (particularly if you're not sure what the blocking factor
9495 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9496 specifying a blocking factor larger then the blocking factor of the archive
9497 (i.e. @samp{tar --extract --read-full-records --blocking-factor=300}.
9498 @xref{list}, for more information on the @option{--list} (@option{-t})
9499 operation. @xref{Reading}, for a more detailed explanation of that option.
9500
9501 @table @option
9502 @item --blocking-factor=@var{number}
9503 @itemx -b @var{number}
9504 Specifies the blocking factor of an archive. Can be used with any
9505 operation, but is usually not necessary with @option{--list} (@option{-t}).
9506 @end table
9507
9508 Device blocking
9509
9510 @table @option
9511 @item -b @var{blocks}
9512 @itemx --blocking-factor=@var{blocks}
9513 Set record size to @math{@var{blocks} * 512} bytes.
9514
9515 This option is used to specify a @dfn{blocking factor} for the archive.
9516 When reading or writing the archive, @command{tar}, will do reads and writes
9517 of the archive in records of @math{@var{block}*512} bytes. This is true
9518 even when the archive is compressed. Some devices requires that all
9519 write operations be a multiple of a certain size, and so, @command{tar}
9520 pads the archive out to the next record boundary.
9521
9522 The default blocking factor is set when @command{tar} is compiled, and is
9523 typically 20. Blocking factors larger than 20 cannot be read by very
9524 old versions of @command{tar}, or by some newer versions of @command{tar}
9525 running on old machines with small address spaces.
9526
9527 With a magnetic tape, larger records give faster throughput and fit
9528 more data on a tape (because there are fewer inter-record gaps).
9529 If the archive is in a disk file or a pipe, you may want to specify
9530 a smaller blocking factor, since a large one will result in a large
9531 number of null bytes at the end of the archive.
9532
9533 When writing cartridge or other streaming tapes, a much larger
9534 blocking factor (say 126 or more) will greatly increase performance.
9535 However, you must specify the same blocking factor when reading or
9536 updating the archive.
9537
9538 Apparently, Exabyte drives have a physical block size of 8K bytes.
9539 If we choose our blocksize as a multiple of 8k bytes, then the problem
9540 seems to disappear. Id est, we are using block size of 112 right
9541 now, and we haven't had the problem since we switched@dots{}
9542
9543 With @GNUTAR{} the blocking factor is limited only
9544 by the maximum record size of the device containing the archive, or by
9545 the amount of available virtual memory.
9546
9547 However, deblocking or reblocking is virtually avoided in a special
9548 case which often occurs in practice, but which requires all the
9549 following conditions to be simultaneously true:
9550 @itemize @bullet
9551 @item
9552 the archive is subject to a compression option,
9553 @item
9554 the archive is not handled through standard input or output, nor
9555 redirected nor piped,
9556 @item
9557 the archive is directly handled to a local disk, instead of any special
9558 device,
9559 @item
9560 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9561 invocation.
9562 @end itemize
9563
9564 If the output goes directly to a local disk, and not through
9565 stdout, then the last write is not extended to a full record size.
9566 Otherwise, reblocking occurs. Here are a few other remarks on this
9567 topic:
9568
9569 @itemize @bullet
9570
9571 @item
9572 @command{gzip} will complain about trailing garbage if asked to
9573 uncompress a compressed archive on tape, there is an option to turn
9574 the message off, but it breaks the regularity of simply having to use
9575 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9576 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9577 Gailly, by sending a copy of this message to him.
9578
9579 @item
9580 @command{compress} does not show this problem, but as Jean-loup pointed
9581 out to Michael, @samp{compress -d} silently adds garbage after
9582 the result of decompression, which tar ignores because it already
9583 recognized its end-of-file indicator. So this bug may be safely
9584 ignored.
9585
9586 @item
9587 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9588 but will still return an exit status of 2 which tar reports in turn.
9589 @command{tar} might ignore the exit status returned, but I hate doing
9590 that, as it weakens the protection @command{tar} offers users against
9591 other possible problems at decompression time. If @command{gzip} was
9592 silently skipping trailing zeros @emph{and} also avoiding setting the
9593 exit status in this innocuous case, that would solve this situation.
9594
9595 @item
9596 @command{tar} should become more solid at not stopping to read a pipe at
9597 the first null block encountered. This inelegantly breaks the pipe.
9598 @command{tar} should rather drain the pipe out before exiting itself.
9599 @end itemize
9600
9601 @xopindex{ignore-zeros, short description}
9602 @item -i
9603 @itemx --ignore-zeros
9604 Ignore blocks of zeros in archive (means EOF).
9605
9606 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9607 of zeros in the archive. Normally a block of zeros indicates the
9608 end of the archive, but when reading a damaged archive, or one which
9609 was created by concatenating several archives together, this option
9610 allows @command{tar} to read the entire archive. This option is not on
9611 by default because many versions of @command{tar} write garbage after
9612 the zeroed blocks.
9613
9614 Note that this option causes @command{tar} to read to the end of the
9615 archive file, which may sometimes avoid problems when multiple files
9616 are stored on a single physical tape.
9617
9618 @xopindex{read-full-records, short description}
9619 @item -B
9620 @itemx --read-full-records
9621 Reblock as we read (for reading 4.2BSD pipes).
9622
9623 If @option{--read-full-records} is used, @command{tar}
9624 will not panic if an attempt to read a record from the archive does
9625 not return a full record. Instead, @command{tar} will keep reading
9626 until it has obtained a full
9627 record.
9628
9629 This option is turned on by default when @command{tar} is reading
9630 an archive from standard input, or from a remote machine. This is
9631 because on BSD Unix systems, a read of a pipe will return however
9632 much happens to be in the pipe, even if it is less than @command{tar}
9633 requested. If this option was not used, @command{tar} would fail as
9634 soon as it read an incomplete record from the pipe.
9635
9636 This option is also useful with the commands for updating an archive.
9637
9638 @end table
9639
9640 Tape blocking
9641
9642 @FIXME{Appropriate options should be moved here from elsewhere.}
9643
9644 @cindex blocking factor
9645 @cindex tape blocking
9646
9647 When handling various tapes or cartridges, you have to take care of
9648 selecting a proper blocking, that is, the number of disk blocks you
9649 put together as a single tape block on the tape, without intervening
9650 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9651 with no information on it, used for decelerating the tape to a
9652 full stop, and for later regaining the reading or writing speed.
9653 When the tape driver starts reading a record, the record has to
9654 be read whole without stopping, as a tape gap is needed to stop the
9655 tape motion without loosing information.
9656
9657 @cindex Exabyte blocking
9658 @cindex DAT blocking
9659 Using higher blocking (putting more disk blocks per tape block) will use
9660 the tape more efficiently as there will be less tape gaps. But reading
9661 such tapes may be more difficult for the system, as more memory will be
9662 required to receive at once the whole record. Further, if there is a
9663 reading error on a huge record, this is less likely that the system will
9664 succeed in recovering the information. So, blocking should not be too
9665 low, nor it should be too high. @command{tar} uses by default a blocking of
9666 20 for historical reasons, and it does not really matter when reading or
9667 writing to disk. Current tape technology would easily accommodate higher
9668 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9669 We were told that for some DLT drives, the blocking should be a multiple
9670 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9671 Other manufacturers may use different recommendations for the same tapes.
9672 This might also depends of the buffering techniques used inside modern
9673 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9674 Others request blocking to be some exponent of two.
9675
9676 So, there is no fixed rule for blocking. But blocking at read time
9677 should ideally be the same as blocking used at write time. At one place
9678 I know, with a wide variety of equipment, they found it best to use a
9679 blocking of 32 to guarantee that their tapes are fully interchangeable.
9680
9681 I was also told that, for recycled tapes, prior erasure (by the same
9682 drive unit that will be used to create the archives) sometimes lowers
9683 the error rates observed at rewriting time.
9684
9685 I might also use @option{--number-blocks} instead of
9686 @option{--block-number}, so @option{--block} will then expand to
9687 @option{--blocking-factor} unambiguously.
9688
9689 @node Many
9690 @section Many Archives on One Tape
9691
9692 @FIXME{Appropriate options should be moved here from elsewhere.}
9693
9694 @findex ntape @r{device}
9695 Most tape devices have two entries in the @file{/dev} directory, or
9696 entries that come in pairs, which differ only in the minor number for
9697 this device. Let's take for example @file{/dev/tape}, which often
9698 points to the only or usual tape device of a given system. There might
9699 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9700 name is the @emph{rewinding} version of the device, while the name
9701 having @samp{nr} in it is the @emph{no rewinding} version of the same
9702 device.
9703
9704 A rewinding tape device will bring back the tape to its beginning point
9705 automatically when this device is opened or closed. Since @command{tar}
9706 opens the archive file before using it and closes it afterwards, this
9707 means that a simple:
9708
9709 @smallexample
9710 $ @kbd{tar cf /dev/tape @var{directory}}
9711 @end smallexample
9712
9713 @noindent
9714 will reposition the tape to its beginning both prior and after saving
9715 @var{directory} contents to it, thus erasing prior tape contents and
9716 making it so that any subsequent write operation will destroy what has
9717 just been saved.
9718
9719 @cindex tape positioning
9720 So, a rewinding device is normally meant to hold one and only one file.
9721 If you want to put more than one @command{tar} archive on a given tape, you
9722 will need to avoid using the rewinding version of the tape device. You
9723 will also have to pay special attention to tape positioning. Errors in
9724 positioning may overwrite the valuable data already on your tape. Many
9725 people, burnt by past experiences, will only use rewinding devices and
9726 limit themselves to one file per tape, precisely to avoid the risk of
9727 such errors. Be fully aware that writing at the wrong position on a
9728 tape loses all information past this point and most probably until the
9729 end of the tape, and this destroyed information @emph{cannot} be
9730 recovered.
9731
9732 To save @var{directory-1} as a first archive at the beginning of a
9733 tape, and leave that tape ready for a second archive, you should use:
9734
9735 @smallexample
9736 $ @kbd{mt -f /dev/nrtape rewind}
9737 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9738 @end smallexample
9739
9740 @cindex tape marks
9741 @dfn{Tape marks} are special magnetic patterns written on the tape
9742 media, which are later recognizable by the reading hardware. These
9743 marks are used after each file, when there are many on a single tape.
9744 An empty file (that is to say, two tape marks in a row) signal the
9745 logical end of the tape, after which no file exist. Usually,
9746 non-rewinding tape device drivers will react to the close request issued
9747 by @command{tar} by first writing two tape marks after your archive, and by
9748 backspacing over one of these. So, if you remove the tape at that time
9749 from the tape drive, it is properly terminated. But if you write
9750 another file at the current position, the second tape mark will be
9751 erased by the new information, leaving only one tape mark between files.
9752
9753 So, you may now save @var{directory-2} as a second archive after the
9754 first on the same tape by issuing the command:
9755
9756 @smallexample
9757 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9758 @end smallexample
9759
9760 @noindent
9761 and so on for all the archives you want to put on the same tape.
9762
9763 Another usual case is that you do not write all the archives the same
9764 day, and you need to remove and store the tape between two archive
9765 sessions. In general, you must remember how many files are already
9766 saved on your tape. Suppose your tape already has 16 files on it, and
9767 that you are ready to write the 17th. You have to take care of skipping
9768 the first 16 tape marks before saving @var{directory-17}, say, by using
9769 these commands:
9770
9771 @smallexample
9772 $ @kbd{mt -f /dev/nrtape rewind}
9773 $ @kbd{mt -f /dev/nrtape fsf 16}
9774 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9775 @end smallexample
9776
9777 In all the previous examples, we put aside blocking considerations, but
9778 you should do the proper things for that as well. @xref{Blocking}.
9779
9780 @menu
9781 * Tape Positioning:: Tape Positions and Tape Marks
9782 * mt:: The @command{mt} Utility
9783 @end menu
9784
9785 @node Tape Positioning
9786 @subsection Tape Positions and Tape Marks
9787 @UNREVISED
9788
9789 Just as archives can store more than one file from the file system,
9790 tapes can store more than one archive file. To keep track of where
9791 archive files (or any other type of file stored on tape) begin and
9792 end, tape archive devices write magnetic @dfn{tape marks} on the
9793 archive media. Tape drives write one tape mark between files,
9794 two at the end of all the file entries.
9795
9796 If you think of data as a series of records "rrrr"'s, and tape marks as
9797 "*"'s, a tape might look like the following:
9798
9799 @smallexample
9800 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9801 @end smallexample
9802
9803 Tape devices read and write tapes using a read/write @dfn{tape
9804 head}---a physical part of the device which can only access one
9805 point on the tape at a time. When you use @command{tar} to read or
9806 write archive data from a tape device, the device will begin reading
9807 or writing from wherever on the tape the tape head happens to be,
9808 regardless of which archive or what part of the archive the tape
9809 head is on. Before writing an archive, you should make sure that no
9810 data on the tape will be overwritten (unless it is no longer needed).
9811 Before reading an archive, you should make sure the tape head is at
9812 the beginning of the archive you want to read. You can do it manually
9813 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9814 that automatically (@pxref{Scripted Restoration}).
9815
9816 If you want to add new archive file entries to a tape, you should
9817 advance the tape to the end of the existing file entries, backspace
9818 over the last tape mark, and write the new archive file. If you were
9819 to add two archives to the example above, the tape might look like the
9820 following:
9821
9822 @smallexample
9823 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9824 @end smallexample
9825
9826 @node mt
9827 @subsection The @command{mt} Utility
9828 @UNREVISED
9829
9830 @FIXME{Is it true that this only works on non-block devices?
9831 should explain the difference, (fixed or variable).}
9832 @xref{Blocking Factor}.
9833
9834 You can use the @command{mt} utility to advance or rewind a tape past a
9835 specified number of archive files on the tape. This will allow you
9836 to move to the beginning of an archive before extracting or reading
9837 it, or to the end of all the archives before writing a new one.
9838 @FIXME{Why isn't there an "advance 'til you find two tape marks
9839 together"?}
9840
9841 The syntax of the @command{mt} command is:
9842
9843 @smallexample
9844 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9845 @end smallexample
9846
9847 where @var{tapename} is the name of the tape device, @var{number} is
9848 the number of times an operation is performed (with a default of one),
9849 and @var{operation} is one of the following:
9850
9851 @FIXME{is there any use for record operations?}
9852
9853 @table @option
9854 @item eof
9855 @itemx weof
9856 Writes @var{number} tape marks at the current position on the tape.
9857
9858 @item fsf
9859 Moves tape position forward @var{number} files.
9860
9861 @item bsf
9862 Moves tape position back @var{number} files.
9863
9864 @item rewind
9865 Rewinds the tape. (Ignores @var{number}).
9866
9867 @item offline
9868 @itemx rewoff1
9869 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9870
9871 @item status
9872 Prints status information about the tape unit.
9873
9874 @end table
9875
9876 @FIXME{Is there a better way to frob the spacing on the list?}
9877
9878 If you don't specify a @var{tapename}, @command{mt} uses the environment
9879 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9880 the default device specified in your @file{sys/mtio.h} file
9881 (@code{DEFTAPE} variable). If this is not defined, the program will
9882 display a descriptive error message and exit with code 1.
9883
9884 @command{mt} returns a 0 exit status when the operation(s) were
9885 successful, 1 if the command was unrecognized, and 2 if an operation
9886 failed.
9887
9888 @node Using Multiple Tapes
9889 @section Using Multiple Tapes
9890
9891 Often you might want to write a large archive, one larger than will fit
9892 on the actual tape you are using. In such a case, you can run multiple
9893 @command{tar} commands, but this can be inconvenient, particularly if you
9894 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9895 Therefore, @command{tar} provides a special mode for creating
9896 multi-volume archives.
9897
9898 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
9899 on several media volumes of fixed size. Although in this section we will
9900 often call @samp{volume} a @dfn{tape}, there is absolutely no
9901 requirement for multi-volume archives to be stored on tapes. Instead,
9902 they can use whatever media type the user finds convenient, they can
9903 even be located on files.
9904
9905 When creating a multi-volume arvhive, @GNUTAR{} continues to fill
9906 current volume until it runs out of space, then it switches to
9907 next volume (usually the operator is queried to replace the tape on
9908 this point), and continues working on the new volume. This operation
9909 continues untill all requested files are dumped. If @GNUTAR{} detects
9910 end of media while dumping a file, such a file is archived in split
9911 form. Some very big files can even be split across several volumes.
9912
9913 Each volume is itself a valid @GNUTAR{} archive, so it can be read
9914 without any special options. Consequently any file member residing
9915 entirely on one volume can be extracted or otherwise operated upon
9916 without needing the other volume. Sure enough, to extract a split
9917 member you would need all volumes its parts reside on.
9918
9919 Multi-volume archives suffer from several limitations. In particular,
9920 they cannot be compressed.
9921
9922 @GNUTAR{} is able to create multi-volume archives of two formats
9923 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
9924
9925 @menu
9926 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9927 * Tape Files:: Tape Files
9928 * Tarcat:: Concatenate Volumes into a Single Archive
9929
9930 @end menu
9931
9932 @node Multi-Volume Archives
9933 @subsection Archives Longer than One Tape or Disk
9934 @cindex Multi-volume archives
9935
9936 @opindex multi-volume
9937 To create an archive that is larger than will fit on a single unit of
9938 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9939 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9940 archive can be manipulated like any other archive (provided the
9941 @option{--multi-volume} option is specified), but is stored on more
9942 than one tape or disk.
9943
9944 When you specify @option{--multi-volume}, @command{tar} does not report an
9945 error when it comes to the end of an archive volume (when reading), or
9946 the end of the media (when writing). Instead, it prompts you to load
9947 a new storage volume. If the archive is on a magnetic tape, you
9948 should change tapes when you see the prompt; if the archive is on a
9949 floppy disk, you should change disks; etc.
9950
9951 @table @option
9952 @item --multi-volume
9953 @itemx -M
9954 Creates a multi-volume archive, when used in conjunction with
9955 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9956 archive, specify @option{--multi-volume} in conjunction with that
9957 operation.
9958 For example:
9959
9960 @smallexample
9961 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
9962 @end smallexample
9963 @end table
9964
9965 The method @command{tar} uses to detect end of tape is not perfect, and
9966 fails on some operating systems or on some devices. If @command{tar}
9967 cannot detect the end of the tape itself, you can use
9968 @option{--tape-length} option to inform it about the capacity of the
9969 tape:
9970
9971 @anchor{tape-length}
9972 @table @option
9973 @opindex tape-length
9974 @item --tape-length=@var{size}
9975 @itemx -L @var{size}
9976 Set maximum length of a volume. The @var{size} argument should then
9977 be the usable size of the tape in units of 1024 bytes. This option
9978 selects @option{--multi-volume} automatically. For example:
9979
9980 @smallexample
9981 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
9982 @end smallexample
9983 @end table
9984
9985 @anchor{change volume prompt}
9986 When @GNUTAR{} comes to the end of a storage media, it asks you to
9987 change the volume. The built-in prompt for POSIX locale
9988 is@footnote{If you run @GNUTAR{} under a different locale, the
9989 translation to the locale's language will be used.}:
9990
9991 @smallexample
9992 Prepare volume #@var{n} for `@var{archive}' and hit return:
9993 @end smallexample
9994
9995 @noindent
9996 where @var{n} is the ordinal number of the volume to be created and
9997 @var{archive} is archive file or device name.
9998
9999 When prompting for a new tape, @command{tar} accepts any of the following
10000 responses:
10001
10002 @table @kbd
10003 @item ?
10004 Request @command{tar} to explain possible responses
10005 @item q
10006 Request @command{tar} to exit immediately.
10007 @item n @var{file-name}
10008 Request @command{tar} to write the next volume on the file @var{file-name}.
10009 @item !
10010 Request @command{tar} to run a subshell. This option can be disabled
10011 by giving @option{--restrict} command line option to
10012 @command{tar}@footnote{@xref{--restrict}, for more information about
10013 this option}.
10014 @item y
10015 Request @command{tar} to begin writing the next volume.
10016 @end table
10017
10018 (You should only type @samp{y} after you have changed the tape;
10019 otherwise @command{tar} will write over the volume it just finished.)
10020
10021 @cindex Volume number file
10022 @cindex volno file
10023 @anchor{volno-file}
10024 @opindex volno-file
10025 The volume number used by @command{tar} in its tape-changing prompt
10026 can be changed; if you give the
10027 @option{--volno-file=@var{file-of-number}} option, then
10028 @var{file-of-number} should be an unexisting file to be created, or
10029 else, a file already containing a decimal number. That number will be
10030 used as the volume number of the first volume written. When
10031 @command{tar} is finished, it will rewrite the file with the
10032 now-current volume number. (This does not change the volume number
10033 written on a tape label, as per @ref{label}, it @emph{only} affects
10034 the number used in the prompt.)
10035
10036 @cindex End-of-archive info script
10037 @cindex Info script
10038 @anchor{info-script}
10039 @opindex info-script
10040 @opindex new-volume-script
10041 If you want more elaborate behavior than this, you can write a special
10042 @dfn{new volume script}, that will be responsible for changing the
10043 volume, and instruct @command{tar} to use it instead of its normal
10044 prompting procedure:
10045
10046 @table @option
10047 @item --info-script=@var{script-name}
10048 @itemx --new-volume-script=@var{script-name}
10049 @itemx -F @var{script-name}
10050 Specify the full name of the volume script to use. The script can be
10051 used to eject cassettes, or to broadcast messages such as
10052 @samp{Someone please come change my tape} when performing unattended
10053 backups.
10054 @end table
10055
10056 The @var{script-name} is executed without any command line
10057 arguments. It inherits @command{tar}'s shell environment.
10058 Additional data is passed to it via the following
10059 environment variables:
10060
10061 @table @env
10062 @vrindex TAR_VERSION, info script environment variable
10063 @item TAR_VERSION
10064 @GNUTAR{} version number.
10065
10066 @vrindex TAR_ARCHIVE, info script environment variable
10067 @item TAR_ARCHIVE
10068 The name of the archive @command{tar} is processing.
10069
10070 @vrindex TAR_VOLUME, info script environment variable
10071 @item TAR_VOLUME
10072 Ordinal number of the volume @command{tar} is about to start.
10073
10074 @vrindex TAR_SUBCOMMAND, info script environment variable
10075 @item TAR_SUBCOMMAND
10076 Short option describing the operation @command{tar} is executing
10077 @xref{Operations}, for a complete list of subcommand options.
10078
10079 @vrindex TAR_FORMAT, info script environment variable
10080 @item TAR_FORMAT
10081 Format of the archive being processed. @xref{Formats}, for a complete
10082 list of archive format names.
10083 @end table
10084
10085 The volume script can instruct @command{tar} to use new archive name,
10086 by writing in to file descriptor 3 (see below for an example).
10087
10088 If the info script fails, @command{tar} exits; otherwise, it begins
10089 writing the next volume.
10090
10091 If you want @command{tar} to cycle through a series of files or tape
10092 drives, there are three approaches to choose from. First of all, you
10093 can give @command{tar} multiple @option{--file} options. In this case
10094 the specified files will be used, in sequence, as the successive
10095 volumes of the archive. Only when the first one in the sequence needs
10096 to be used again will @command{tar} prompt for a tape change (or run
10097 the info script). For example, suppose someone has two tape drives on
10098 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10099 @GNUTAR{} to switch to the second drive when it needs to write the
10100 second tape, and then back to the first tape, etc., just do either of:
10101
10102 @smallexample
10103 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10104 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10105 @end smallexample
10106
10107 The second method is to use the @samp{n} response to the tape-change
10108 prompt.
10109
10110 Finally, the most flexible approach is to use a volume script, that
10111 writes new archive name to the file descriptor #3. For example, the
10112 following volume script will create a series of archive files, named
10113 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10114 archive being created (as given by @option{--file} option) and
10115 @var{vol} is the ordinal number of the archive being created:
10116
10117 @smallexample
10118 @group
10119 #! /bin/sh
10120 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10121
10122 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10123 case $TAR_SUBCOMMAND in
10124 -c) ;;
10125 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10126 ;;
10127 *) exit 1
10128 esac
10129
10130 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
10131 @end group
10132 @end smallexample
10133
10134 The same script cant be used while listing, comparing or extracting
10135 from the created archive. For example:
10136
10137 @smallexample
10138 @group
10139 # @r{Create a multi-volume archive:}
10140 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10141 # @r{Extract from the created archive:}
10142 $ @kbd{tar -x -f archive.tar -F new-volume .}
10143 @end group
10144 @end smallexample
10145
10146 @noindent
10147 Notice, that the first command had to use @option{-L} option, since
10148 otherwise @GNUTAR{} will end up writing everything to file
10149 @file{archive.tar}.
10150
10151 You can read each individual volume of a multi-volume archive as if it
10152 were an archive by itself. For example, to list the contents of one
10153 volume, use @option{--list}, without @option{--multi-volume} specified.
10154 To extract an archive member from one volume (assuming it is described
10155 that volume), use @option{--extract}, again without
10156 @option{--multi-volume}.
10157
10158 If an archive member is split across volumes (i.e. its entry begins on
10159 one volume of the media and ends on another), you need to specify
10160 @option{--multi-volume} to extract it successfully. In this case, you
10161 should load the volume where the archive member starts, and use
10162 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10163 volumes as it needs them. @xref{extracting archives}, for more
10164 information about extracting archives.
10165
10166 Multi-volume archives can be modified like any other archive. To add
10167 files to a multi-volume archive, you need to only mount the last
10168 volume of the archive media (and new volumes, if needed). For all
10169 other operations, you need to use the entire archive.
10170
10171 If a multi-volume archive was labeled using
10172 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10173 created, @command{tar} will not automatically label volumes which are
10174 added later. To label subsequent volumes, specify
10175 @option{--label=@var{archive-label}} again in conjunction with the
10176 @option{--append}, @option{--update} or @option{--concatenate} operation.
10177
10178 @FIXME{This is no longer true: Multivolume archives in @samp{POSIX}
10179 format can be extracted using any posix-compliant tar
10180 implementation. The split members can then be recreated from parts
10181 using a simple shell script. Provide more information about it:}
10182 Beware that there is @emph{no} real standard about the proper way, for
10183 a @command{tar} archive, to span volume boundaries. If you have a
10184 multi-volume created by some vendor's @command{tar}, there is almost
10185 no chance you could read all the volumes with @GNUTAR{}.
10186 The converse is also true: you may not expect
10187 multi-volume archives created by @GNUTAR{} to be
10188 fully recovered by vendor's @command{tar}. Since there is little
10189 chance that, in mixed system configurations, some vendor's
10190 @command{tar} will work on another vendor's machine, and there is a
10191 great chance that @GNUTAR{} will work on most of
10192 them, your best bet is to install @GNUTAR{} on all
10193 machines between which you know exchange of files is possible.
10194
10195 @node Tape Files
10196 @subsection Tape Files
10197 @UNREVISED
10198
10199 To give the archive a name which will be recorded in it, use the
10200 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10201 option. This will write a special block identifying
10202 @var{volume-label} as the name of the archive to the front of the
10203 archive which will be displayed when the archive is listed with
10204 @option{--list}. If you are creating a multi-volume archive with
10205 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10206 volume label will have @samp{Volume @var{nnn}} appended to the name
10207 you give, where @var{nnn} is the number of the volume of the archive.
10208 (If you use the @option{--label=@var{volume-label}}) option when
10209 reading an archive, it checks to make sure the label on the tape
10210 matches the one you give. @xref{label}.
10211
10212 When @command{tar} writes an archive to tape, it creates a single
10213 tape file. If multiple archives are written to the same tape, one
10214 after the other, they each get written as separate tape files. When
10215 extracting, it is necessary to position the tape at the right place
10216 before running @command{tar}. To do this, use the @command{mt} command.
10217 For more information on the @command{mt} command and on the organization
10218 of tapes into a sequence of tape files, see @ref{mt}.
10219
10220 People seem to often do:
10221
10222 @smallexample
10223 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10224 @end smallexample
10225
10226 or such, for pushing a common date in all volumes or an archive set.
10227
10228 @node Tarcat
10229 @subsection Concatenate Volumes into a Single Archive
10230
10231 @pindex tarcat
10232 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10233 archive to a single @command{tar} archive. Simply concatenating all
10234 volumes into one will not work, since each volume carries an additional
10235 information at the beginning. @GNUTAR{} is shipped with the shell
10236 script @command{tarcat} designed for this purpose.
10237
10238 The script takes a list of files comprising a multi-volume archive
10239 and creates the resulting archive at the standard output. For example:
10240
10241 @smallexample
10242 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10243 @end smallexample
10244
10245 The script implements a simple heuristics to determine the format of
10246 the first volume file and to decide how to process the rest of the
10247 files. However, it makes no attempt to verify whether the files are
10248 given in order or even if they are valid @command{tar} archives.
10249 It uses @command{dd} and does not filter its standard error, so you
10250 will usually see lots of spurious messages.
10251
10252 @FIXME{The script is not installed. Should we install it?}
10253
10254 @node label
10255 @section Including a Label in the Archive
10256 @cindex Labeling an archive
10257 @cindex Labels on the archive media
10258 @cindex Labeling multi-volume archives
10259 @UNREVISED
10260
10261 @opindex label
10262 To avoid problems caused by misplaced paper labels on the archive
10263 media, you can include a @dfn{label} entry---an archive member which
10264 contains the name of the archive---in the archive itself. Use the
10265 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10266 option in conjunction with the @option{--create} operation to include
10267 a label entry in the archive as it is being created.
10268
10269 @table @option
10270 @item --label=@var{archive-label}
10271 @itemx -V @var{archive-label}
10272 Includes an @dfn{archive-label} at the beginning of the archive when
10273 the archive is being created, when used in conjunction with the
10274 @option{--create} operation. Checks to make sure the archive label
10275 matches the one specified (when used in conjunction with any other
10276 operation.
10277 @end table
10278
10279 If you create an archive using both
10280 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10281 and @option{--multi-volume} (@option{-M}), each volume of the archive
10282 will have an archive label of the form @samp{@var{archive-label}
10283 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10284 next, and so on. @xref{Using Multiple Tapes}, for information on
10285 creating multiple volume archives.
10286
10287 @cindex Volume label, listing
10288 @cindex Listing volume label
10289 The volume label will be displayed by @option{--list} along with
10290 the file contents. If verbose display is requested, it will also be
10291 explicitely marked as in the example below:
10292
10293 @smallexample
10294 @group
10295 $ @kbd{tar --verbose --list --file=iamanarchive}
10296 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10297 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10298 @end group
10299 @end smallexample
10300
10301 @opindex test-label
10302 @anchor{--test-label option}
10303 However, @option{--list} option will cause listing entire
10304 contents of the archive, which may be undesirable (for example, if the
10305 archive is stored on a tape). You can request checking only the volume
10306 by specifying @option{--test-label} option. This option reads only the
10307 first block of an archive, so it can be used with slow storage
10308 devices. For example:
10309
10310 @smallexample
10311 @group
10312 $ @kbd{tar --test-label --file=iamanarchive}
10313 iamalabel
10314 @end group
10315 @end smallexample
10316
10317 If @option{--test-label} is used with a single command line
10318 argument, @command{tar} compares the volume label with the
10319 argument. It exits with code 0 if the two strings match, and with code
10320 2 otherwise. In this case no output is displayed. For example:
10321
10322 @smallexample
10323 @group
10324 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10325 @result{} 0
10326 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10327 @result{} 1
10328 @end group
10329 @end smallexample
10330
10331 If you request any operation, other than @option{--create}, along
10332 with using @option{--label} option, @command{tar} will first check if
10333 the archive label matches the one specified and will refuse to proceed
10334 if it does not. Use this as a safety precaution to avoid accidentally
10335 overwriting existing archives. For example, if you wish to add files
10336 to @file{archive}, presumably labelled with string @samp{My volume},
10337 you will get:
10338
10339 @smallexample
10340 @group
10341 $ @kbd{tar -rf archive --label 'My volume' .}
10342 tar: Archive not labeled to match `My volume'
10343 @end group
10344 @end smallexample
10345
10346 @noindent
10347 in case its label does not match. This will work even if
10348 @file{archive} is not labelled at all.
10349
10350 Similarly, @command{tar} will refuse to list or extract the
10351 archive if its label doesn't match the @var{archive-label}
10352 specified. In those cases, @var{archive-label} argument is interpreted
10353 as a globbing-style pattern which must match the actual magnetic
10354 volume label. @xref{exclude}, for a precise description of how match
10355 is attempted@footnote{Previous versions of @command{tar} used full
10356 regular expression matching, or before that, only exact string
10357 matching, instead of wildcard matchers. We decided for the sake of
10358 simplicity to use a uniform matching device through
10359 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10360 the volume label matcher will also suffix @var{archive-label} by
10361 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10362 up. Since the volume numbering is automatically added in labels at
10363 creation time, it sounded logical to equally help the user taking care
10364 of it when the archive is being read.
10365
10366 The @option{--label} was once called @option{--volume}, but is not
10367 available under that name anymore.
10368
10369 You can also use @option{--label} to get a common information on
10370 all tapes of a series. For having this information different in each
10371 series created through a single script used on a regular basis, just
10372 manage to get some date string as part of the label. For example:
10373
10374 @smallexample
10375 @group
10376 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10377 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10378 --volume="Daily backup for `date +%Y-%m-%d`"}
10379 @end group
10380 @end smallexample
10381
10382 Also note that each label has its own date and time, which corresponds
10383 to when @GNUTAR{} initially attempted to write it,
10384 often soon after the operator launches @command{tar} or types the
10385 carriage return telling that the next tape is ready. Comparing date
10386 labels does give an idea of tape throughput only if the delays for
10387 rewinding tapes and the operator switching them were negligible, which
10388 is usually not the case.
10389
10390 @node verify
10391 @section Verifying Data as It is Stored
10392 @cindex Verifying a write operation
10393 @cindex Double-checking a write operation
10394
10395 @table @option
10396 @item -W
10397 @itemx --verify
10398 @opindex verify, short description
10399 Attempt to verify the archive after writing.
10400 @end table
10401
10402 This option causes @command{tar} to verify the archive after writing it.
10403 Each volume is checked after it is written, and any discrepancies
10404 are recorded on the standard error output.
10405
10406 Verification requires that the archive be on a back-space-able medium.
10407 This means pipes, some cartridge tape drives, and some other devices
10408 cannot be verified.
10409
10410 You can insure the accuracy of an archive by comparing files in the
10411 system with archive members. @command{tar} can compare an archive to the
10412 file system as the archive is being written, to verify a write
10413 operation, or can compare a previously written archive, to insure that
10414 it is up to date.
10415
10416 @xopindex{verify, using with @option{--create}}
10417 @xopindex{create, using with @option{--verify}}
10418 To check for discrepancies in an archive immediately after it is
10419 written, use the @option{--verify} (@option{-W}) option in conjunction with
10420 the @option{--create} operation. When this option is
10421 specified, @command{tar} checks archive members against their counterparts
10422 in the file system, and reports discrepancies on the standard error.
10423
10424 To verify an archive, you must be able to read it from before the end
10425 of the last written entry. This option is useful for detecting data
10426 errors on some tapes. Archives written to pipes, some cartridge tape
10427 drives, and some other devices cannot be verified.
10428
10429 One can explicitly compare an already made archive with the file
10430 system by using the @option{--compare} (@option{--diff}, @option{-d})
10431 option, instead of using the more automatic @option{--verify} option.
10432 @xref{compare}.
10433
10434 Note that these two options have a slightly different intent. The
10435 @option{--compare} option checks how identical are the logical contents of some
10436 archive with what is on your disks, while the @option{--verify} option is
10437 really for checking if the physical contents agree and if the recording
10438 media itself is of dependable quality. So, for the @option{--verify}
10439 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10440 the archive, while it lets the speed optimization undisturbed for the
10441 @option{--compare} option. If you nevertheless use @option{--compare} for
10442 media verification, you may have to defeat the in-memory cache yourself,
10443 maybe by opening and reclosing the door latch of your recording unit,
10444 forcing some doubt in your operating system about the fact this is really
10445 the same volume as the one just written or read.
10446
10447 The @option{--verify} option would not be necessary if drivers were indeed
10448 able to detect dependably all write failures. This sometimes require many
10449 magnetic heads, some able to read after the writes occurred. One would
10450 not say that drivers unable to detect all cases are necessarily flawed,
10451 as long as programming is concerned.
10452
10453 The @option{--verify} (@option{-W}) option will not work in
10454 conjunction with the @option{--multi-volume} (@option{-M}) option or
10455 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
10456 and @option{--delete} operations. @xref{Operations}, for more
10457 information on these operations.
10458
10459 Also, since @command{tar} normally strips leading @samp{/} from file
10460 names (@pxref{absolute}), a command like @samp{tar --verify -cf
10461 /tmp/foo.tar /etc} will work as desired only if the working directory is
10462 @file{/}, as @command{tar} uses the archive's relative member names
10463 (e.g., @file{etc/motd}) when verifying the archive.
10464
10465 @node Write Protection
10466 @section Write Protection
10467
10468 Almost all tapes and diskettes, and in a few rare cases, even disks can
10469 be @dfn{write protected}, to protect data on them from being changed.
10470 Once an archive is written, you should write protect the media to prevent
10471 the archive from being accidentally overwritten or deleted. (This will
10472 protect the archive from being changed with a tape or floppy drive---it
10473 will not protect it from magnet fields or other physical hazards).
10474
10475 The write protection device itself is usually an integral part of the
10476 physical media, and can be a two position (write enabled/write
10477 disabled) switch, a notch which can be popped out or covered, a ring
10478 which can be removed from the center of a tape reel, or some other
10479 changeable feature.
10480
10481 @node Changes
10482 @appendix Changes
10483
10484 This appendix lists some important user-visible changes between
10485 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10486 version of this document is available at
10487 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10488 @GNUTAR{} documentation page}.
10489
10490 @table @asis
10491 @item Use of globbing patterns when listing and extracting.
10492
10493 Previous versions of GNU tar assumed shell-style globbing when
10494 extracting from or listing an archive. For example:
10495
10496 @smallexample
10497 $ @kbd{tar xf foo.tar '*.c'}
10498 @end smallexample
10499
10500 would extract all files whose names end in @samp{.c}. This behavior
10501 was not documented and was incompatible with traditional tar
10502 implementations. Therefore, starting from version 1.15.91, GNU tar
10503 no longer uses globbing by default. For example, the above invocation
10504 is now interpreted as a request to extract from the archive the file
10505 named @file{*.c}.
10506
10507 To facilitate transition to the new behavior for those users who got
10508 used to the previous incorrect one, @command{tar} will print a warning
10509 if it finds out that a requested member was not found in the archive
10510 and its name looks like a globbing pattern. For example:
10511
10512 @smallexample
10513 $ @kbd{tar xf foo.tar '*.c'}
10514 tar: Pattern matching characters used in file names. Please,
10515 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10516 tar: suppress this warning.
10517 tar: *.c: Not found in archive
10518 tar: Error exit delayed from previous errors
10519 @end smallexample
10520
10521 To treat member names as globbing patterns, use --wildcards option.
10522 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10523 add this option to your @env{TAR_OPTIONS} variable.
10524
10525 @xref{wildcards}, for the detailed discussion of the use of globbing
10526 patterns by @GNUTAR{}.
10527
10528 @item Use of short option @option{-o}.
10529
10530 Earlier versions of @GNUTAR{} understood @option{-o} command line
10531 option as a synonym for @option{--old-archive}.
10532
10533 @GNUTAR{} starting from version 1.13.90 understands this option as
10534 a synonym for @option{--no-same-owner}. This is compatible with
10535 UNIX98 @command{tar} implementations.
10536
10537 However, to facilitate transition, @option{-o} option retains its
10538 old semantics when it is used with one of archive-creation commands.
10539 Users are encouraged to use @option{--format=oldgnu} instead.
10540
10541 It is especially important, since versions of @acronym{GNU} Automake
10542 up to and including 1.8.4 invoke tar with this option to produce
10543 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10544 of this issue and its implications.
10545
10546 @FIXME{Change the first argument to tar-formats when the new Automake is
10547 out. The proposition to add @anchor{} to the appropriate place of its
10548 docs was accepted by Automake people --Sergey 2006-05-25}.
10549 @xref{Options, tar-v7, Changing Automake's Behavior,
10550 automake, GNU Automake}, for a description on how to use various
10551 archive formats with @command{automake}.
10552
10553 Future versions of @GNUTAR{} will understand @option{-o} only as a
10554 synonym for @option{--no-same-owner}.
10555
10556 @item Use of short option @option{-l}
10557
10558 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10559 synonym for @option{--one-file-system}. Since such usage contradicted
10560 to UNIX98 specification and harmed compatibility with other
10561 implementation, it was declared deprecated in version 1.14. However,
10562 to facilitate transition to its new semantics, it was supported by
10563 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10564 variant of @option{--check-links} was introduced in version 1.15.91.
10565
10566 @item Use of options @option{--portability} and @option{--old-archive}
10567
10568 These options are deprecated. Please use @option{--format=v7} instead.
10569
10570 @item Use of option @option{--posix}
10571
10572 This option is deprecated. Please use @option{--format=posix} instead.
10573 @end table
10574
10575 @node Configuring Help Summary
10576 @appendix Configuring Help Summary
10577
10578 Running @kbd{tar --help} displays the short @command{tar} option
10579 summary (@pxref{help}). This summary is organised by @dfn{groups} of
10580 semantically close options. The options within each group are printed
10581 in the following order: a short option, eventually followed by a list
10582 of corresponding long option names, followed by a short description of
10583 the option. For example, here is an excerpt from the actual @kbd{tar
10584 --help} output:
10585
10586 @verbatim
10587 Main operation mode:
10588
10589 -A, --catenate, --concatenate append tar files to an archive
10590 -c, --create create a new archive
10591 -d, --diff, --compare find differences between archive and
10592 file system
10593 --delete delete from the archive
10594 @end verbatim
10595
10596 @vrindex ARGP_HELP_FMT, environment variable
10597 The exact visual representation of the help output is configurable via
10598 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10599 is a comma-separated list of @dfn{format variable} assignments. There
10600 are two kinds of format variables. An @dfn{offset variable} keeps the
10601 offset of some part of help output text from the leftmost column on
10602 the screen. A @dfn{boolean} variable is a flag that toggles some
10603 output feature on or off. Depending on the type of the corresponding
10604 variable, there are two kinds of assignments:
10605
10606 @table @asis
10607 @item Offset assignment
10608
10609 The assignment to an offset variable has the following syntax:
10610
10611 @smallexample
10612 @var{variable}=@var{value}
10613 @end smallexample
10614
10615 @noindent
10616 where @var{variable} is the variable name, and @var{value} is a
10617 numeric value to be assigned to the variable.
10618
10619 @item Boolean assignment
10620
10621 To assign @code{true} value to a variable, simply put this variable name. To
10622 assign @code{false} value, prefix the variable name with @samp{no-}. For
10623 example:
10624
10625 @smallexample
10626 @group
10627 # Assign @code{true} value:
10628 dup-args
10629 # Assign @code{false} value:
10630 no-dup-args
10631 @end group
10632 @end smallexample
10633 @end table
10634
10635 Following variables are declared:
10636
10637 @deftypevr {Help Output} boolean dup-args
10638 If true, arguments for an option are shown with both short and long
10639 options, even when a given option has both forms, for example:
10640
10641 @smallexample
10642 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10643 @end smallexample
10644
10645 If false, then if an option has both short and long forms, the
10646 argument is only shown with the long one, for example:
10647
10648 @smallexample
10649 -f, --file=ARCHIVE use archive file or device ARCHIVE
10650 @end smallexample
10651
10652 @noindent
10653 and a message indicating that the argument is applicable to both
10654 forms is printed below the options. This message can be disabled
10655 using @code{dup-args-note} (see below).
10656
10657 The default is false.
10658 @end deftypevr
10659
10660 @deftypevr {Help Output} boolean dup-args-note
10661 If this variable is true, which is the default, the following notice
10662 is displayed at the end of the help output:
10663
10664 @quotation
10665 Mandatory or optional arguments to long options are also mandatory or
10666 optional for any corresponding short options.
10667 @end quotation
10668
10669 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10670 variables @code{dup-args} or @code{dup-args-note} should be set.
10671 @end deftypevr
10672
10673 @deftypevr {Help Output} offset short-opt-col
10674 Column in which short options start. Default is 2.
10675
10676 @smallexample
10677 @group
10678 $ @kbd{tar --help|grep ARCHIVE}
10679 -f, --file=ARCHIVE use archive file or device ARCHIVE
10680 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10681 -f, --file=ARCHIVE use archive file or device ARCHIVE
10682 @end group
10683 @end smallexample
10684 @end deftypevr
10685
10686 @deftypevr {Help Output} offset long-opt-col
10687 Column in which long options start. Default is 6. For example:
10688
10689 @smallexample
10690 @group
10691 $ @kbd{tar --help|grep ARCHIVE}
10692 -f, --file=ARCHIVE use archive file or device ARCHIVE
10693 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10694 -f, --file=ARCHIVE use archive file or device ARCHIVE
10695 @end group
10696 @end smallexample
10697 @end deftypevr
10698
10699 @deftypevr {Help Output} offset doc-opt-col
10700 Column in which @dfn{doc options} start. A doc option isn't actually
10701 an option, but rather an arbitrary piece of documentation that is
10702 displayed in much the same manner as the options. For example, in
10703 the description of @option{--format} option:
10704
10705 @smallexample
10706 @group
10707 -H, --format=FORMAT create archive of the given format.
10708
10709 FORMAT is one of the following:
10710
10711 gnu GNU tar 1.13.x format
10712 oldgnu GNU format as per tar <= 1.12
10713 pax POSIX 1003.1-2001 (pax) format
10714 posix same as pax
10715 ustar POSIX 1003.1-1988 (ustar) format
10716 v7 old V7 tar format
10717 @end group
10718 @end smallexample
10719
10720 @noindent
10721 the format names are doc options. Thus, if you set
10722 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10723 will look as follows:
10724
10725 @smallexample
10726 @group
10727 -H, --format=FORMAT create archive of the given format.
10728
10729 FORMAT is one of the following:
10730
10731 gnu GNU tar 1.13.x format
10732 oldgnu GNU format as per tar <= 1.12
10733 pax POSIX 1003.1-2001 (pax) format
10734 posix same as pax
10735 ustar POSIX 1003.1-1988 (ustar) format
10736 v7 old V7 tar format
10737 @end group
10738 @end smallexample
10739 @end deftypevr
10740
10741 @deftypevr {Help Output} offset opt-doc-col
10742 Column in which option description starts. Default is 29.
10743
10744 @smallexample
10745 @group
10746 $ @kbd{tar --help|grep ARCHIVE}
10747 -f, --file=ARCHIVE use archive file or device ARCHIVE
10748 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10749 -f, --file=ARCHIVE use archive file or device ARCHIVE
10750 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10751 -f, --file=ARCHIVE
10752 use archive file or device ARCHIVE
10753 @end group
10754 @end smallexample
10755
10756 @noindent
10757 Notice, that the description starts on a separate line if
10758 @code{opt-doc-col} value is too small.
10759 @end deftypevr
10760
10761 @deftypevr {Help Output} offset header-col
10762 Column in which @dfn{group headers} are printed. A group header is a
10763 descriptive text preceding an option group. For example, in the
10764 following text:
10765
10766 @verbatim
10767 Main operation mode:
10768
10769 -A, --catenate, --concatenate append tar files to
10770 an archive
10771 -c, --create create a new archive
10772 @end verbatim
10773 @noindent
10774 @samp{Main operation mode:} is the group header.
10775
10776 The default value is 1.
10777 @end deftypevr
10778
10779 @deftypevr {Help Output} offset usage-indent
10780 Indentation of wrapped usage lines. Affects @option{--usage}
10781 output. Default is 12.
10782 @end deftypevr
10783
10784 @deftypevr {Help Output} offset rmargin
10785 Right margin of the text output. Used for wrapping.
10786 @end deftypevr
10787
10788 @node Tar Internals
10789 @appendix Tar Internals
10790 @include intern.texi
10791
10792 @node Genfile
10793 @appendix Genfile
10794 @include genfile.texi
10795
10796 @node Free Software Needs Free Documentation
10797 @appendix Free Software Needs Free Documentation
10798 @include freemanuals.texi
10799
10800 @node Copying This Manual
10801 @appendix Copying This Manual
10802
10803 @menu
10804 * GNU Free Documentation License:: License for copying this manual
10805 @end menu
10806
10807 @include fdl.texi
10808
10809 @node Index of Command Line Options
10810 @appendix Index of Command Line Options
10811
10812 This appendix contains an index of all @GNUTAR{} long command line
10813 options. The options are listed without the preceeding double-dash.
10814 For a cross-reference of short command line options, @ref{Short Option Summary}.
10815
10816 @printindex op
10817
10818 @node Index
10819 @appendix Index
10820
10821 @printindex cp
10822
10823 @summarycontents
10824 @contents
10825 @bye
10826
10827 @c Local variables:
10828 @c texinfo-column-for-description: 32
10829 @c End:
This page took 0.527262 seconds and 5 git commands to generate.