]> Dogcows Code - chaz/tar/blob - doc/tar.texi
checkpoint handling
[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 2.1. Run `make check-options' to make sure all options are properly
17 @c documented;
18 @c 2.2. 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, 2007 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 * Fixing Snapshot Files::
113 * Tar Internals::
114 * Genfile::
115 * Free Software Needs Free Documentation::
116 * Copying This Manual::
117 * Index of Command Line Options::
118 * Index::
119
120 @detailmenu
121 --- The Detailed Node Listing ---
122
123 Introduction
124
125 * Book Contents:: What this Book Contains
126 * Definitions:: Some Definitions
127 * What tar Does:: What @command{tar} Does
128 * Naming tar Archives:: How @command{tar} Archives are Named
129 * Authors:: @GNUTAR{} Authors
130 * Reports:: Reporting bugs or suggestions
131
132 Tutorial Introduction to @command{tar}
133
134 * assumptions::
135 * stylistic conventions::
136 * basic tar options:: Basic @command{tar} Operations and Options
137 * frequent operations::
138 * Two Frequent Options::
139 * create:: How to Create Archives
140 * list:: How to List Archives
141 * extract:: How to Extract Members from an Archive
142 * going further::
143
144 Two Frequently Used Options
145
146 * file tutorial::
147 * verbose tutorial::
148 * help tutorial::
149
150 How to Create Archives
151
152 * prepare for examples::
153 * Creating the archive::
154 * create verbose::
155 * short create::
156 * create dir::
157
158 How to List Archives
159
160 * list dir::
161
162 How to Extract Members from an Archive
163
164 * extracting archives::
165 * extracting files::
166 * extract dir::
167 * extracting untrusted archives::
168 * failing commands::
169
170 Invoking @GNUTAR{}
171
172 * Synopsis::
173 * using tar options::
174 * Styles::
175 * All Options::
176 * help::
177 * defaults::
178 * verbose::
179 * interactive::
180
181 The Three Option Styles
182
183 * Long Options:: Long Option Style
184 * Short Options:: Short Option Style
185 * Old Options:: Old Option Style
186 * Mixing:: Mixing Option Styles
187
188 All @command{tar} Options
189
190 * Operation Summary::
191 * Option Summary::
192 * Short Option Summary::
193
194 @GNUTAR{} Operations
195
196 * Basic tar::
197 * Advanced tar::
198 * create options::
199 * extract options::
200 * backup::
201 * Applications::
202 * looking ahead::
203
204 Advanced @GNUTAR{} Operations
205
206 * Operations::
207 * append::
208 * update::
209 * concatenate::
210 * delete::
211 * compare::
212
213 How to Add Files to Existing Archives: @option{--append}
214
215 * appending files:: Appending Files to an Archive
216 * multiple::
217
218 Updating an Archive
219
220 * how to update::
221
222 Options Used by @option{--create}
223
224 * override:: Overriding File Metadata.
225 * Ignore Failed Read::
226
227 Options Used by @option{--extract}
228
229 * Reading:: Options to Help Read Archives
230 * Writing:: Changing How @command{tar} Writes Files
231 * Scarce:: Coping with Scarce Resources
232
233 Options to Help Read Archives
234
235 * read full records::
236 * Ignore Zeros::
237
238 Changing How @command{tar} Writes Files
239
240 * Dealing with Old Files::
241 * Overwrite Old Files::
242 * Keep Old Files::
243 * Keep Newer Files::
244 * Unlink First::
245 * Recursive Unlink::
246 * Data Modification Times::
247 * Setting Access Permissions::
248 * Directory Modification Times and Permissions::
249 * Writing to Standard Output::
250 * Writing to an External Program::
251 * remove files::
252
253 Coping with Scarce Resources
254
255 * Starting File::
256 * Same Order::
257
258 Performing Backups and Restoring Files
259
260 * Full Dumps:: Using @command{tar} to Perform Full Dumps
261 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
262 * Backup Levels:: Levels of Backups
263 * Backup Parameters:: Setting Parameters for Backups and Restoration
264 * Scripted Backups:: Using the Backup Scripts
265 * Scripted Restoration:: Using the Restore Script
266
267 Setting Parameters for Backups and Restoration
268
269 * General-Purpose Variables::
270 * Magnetic Tape Control::
271 * User Hooks::
272 * backup-specs example:: An Example Text of @file{Backup-specs}
273
274 Choosing Files and Names for @command{tar}
275
276 * file:: Choosing the Archive's Name
277 * Selecting Archive Members::
278 * files:: Reading Names from a File
279 * exclude:: Excluding Some Files
280 * wildcards:: Wildcards Patterns and Matching
281 * quoting styles:: Ways of Quoting Special Characters in Names
282 * transform:: Modifying File and Member Names
283 * after:: Operating Only on New Files
284 * recurse:: Descending into Directories
285 * one:: Crossing File System Boundaries
286
287 Reading Names from a File
288
289 * nul::
290
291 Excluding Some Files
292
293 * problems with exclude::
294
295 Wildcards Patterns and Matching
296
297 * controlling pattern-matching::
298
299 Crossing File System Boundaries
300
301 * directory:: Changing Directory
302 * absolute:: Absolute File Names
303
304 Date input formats
305
306 * General date syntax:: Common rules.
307 * Calendar date items:: 19 Dec 1994.
308 * Time of day items:: 9:20pm.
309 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
310 * Day of week items:: Monday and others.
311 * Relative items in date strings:: next tuesday, 2 years ago.
312 * Pure numbers in date strings:: 19931219, 1440.
313 * Seconds since the Epoch:: @@1078100502.
314 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
315 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
316
317 Controlling the Archive Format
318
319 * Compression:: Using Less Space through Compression
320 * Attributes:: Handling File Attributes
321 * Portability:: Making @command{tar} Archives More Portable
322 * cpio:: Comparison of @command{tar} and @command{cpio}
323
324 Using Less Space through Compression
325
326 * gzip:: Creating and Reading Compressed Archives
327 * sparse:: Archiving Sparse Files
328
329 Making @command{tar} Archives More Portable
330
331 * Portable Names:: Portable Names
332 * dereference:: Symbolic Links
333 * old:: Old V7 Archives
334 * ustar:: Ustar Archives
335 * gnu:: GNU and old GNU format archives.
336 * posix:: @acronym{POSIX} archives
337 * Checksumming:: Checksumming Problems
338 * Large or Negative Values:: Large files, negative time stamps, etc.
339 * Other Tars:: How to Extract GNU-Specific Data Using
340 Other @command{tar} Implementations
341
342 @GNUTAR{} and @acronym{POSIX} @command{tar}
343
344 * PAX keywords:: Controlling Extended Header Keywords.
345
346 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
347
348 * Split Recovery:: Members Split Between Volumes
349 * Sparse Recovery:: Sparse Members
350
351 Tapes and Other Archive Media
352
353 * Device:: Device selection and switching
354 * Remote Tape Server::
355 * Common Problems and Solutions::
356 * Blocking:: Blocking
357 * Many:: Many archives on one tape
358 * Using Multiple Tapes:: Using Multiple Tapes
359 * label:: Including a Label in the Archive
360 * verify::
361 * Write Protection::
362
363 Blocking
364
365 * Format Variations:: Format Variations
366 * Blocking Factor:: The Blocking Factor of an Archive
367
368 Many Archives on One Tape
369
370 * Tape Positioning:: Tape Positions and Tape Marks
371 * mt:: The @command{mt} Utility
372
373 Using Multiple Tapes
374
375 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
376 * Tape Files:: Tape Files
377 * Tarcat:: Concatenate Volumes into a Single Archive
378
379
380 Tar Internals
381
382 * Standard:: Basic Tar Format
383 * Extensions:: @acronym{GNU} Extensions to the Archive Format
384 * Sparse Formats:: Storing Sparse Files
385 * Snapshot Files::
386 * Dumpdir::
387
388 Storing Sparse Files
389
390 * Old GNU Format::
391 * PAX 0:: PAX Format, Versions 0.0 and 0.1
392 * PAX 1:: PAX Format, Version 1.0
393
394 Genfile
395
396 * Generate Mode:: File Generation Mode.
397 * Status Mode:: File Status Mode.
398 * Exec Mode:: Synchronous Execution mode.
399
400 Copying This Manual
401
402 * GNU Free Documentation License:: License for copying this manual
403
404 @end detailmenu
405 @end menu
406
407 @node Introduction
408 @chapter Introduction
409
410 @GNUTAR{} creates
411 and manipulates @dfn{archives} which are actually collections of
412 many other files; the program provides users with an organized and
413 systematic method for controlling a large amount of data.
414 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
415 archives need not (and these days, typically do not) reside on tapes.
416
417 @menu
418 * Book Contents:: What this Book Contains
419 * Definitions:: Some Definitions
420 * What tar Does:: What @command{tar} Does
421 * Naming tar Archives:: How @command{tar} Archives are Named
422 * Authors:: @GNUTAR{} Authors
423 * Reports:: Reporting bugs or suggestions
424 @end menu
425
426 @node Book Contents
427 @section What this Book Contains
428
429 The first part of this chapter introduces you to various terms that will
430 recur throughout the book. It also tells you who has worked on @GNUTAR{}
431 and its documentation, and where you should send bug reports
432 or comments.
433
434 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
435 gentle introduction for people who are new to using @command{tar}. It is
436 meant to be self contained, not requiring any reading from subsequent
437 chapters to make sense. It moves from topic to topic in a logical,
438 progressive order, building on information already explained.
439
440 Although the tutorial is paced and structured to allow beginners to
441 learn how to use @command{tar}, it is not intended solely for beginners.
442 The tutorial explains how to use the three most frequently used
443 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
444 two frequently used options (@samp{file} and @samp{verbose}). The other
445 chapters do not refer to the tutorial frequently; however, if a section
446 discusses something which is a complex variant of a basic concept, there
447 may be a cross reference to that basic concept. (The entire book,
448 including the tutorial, assumes that the reader understands some basic
449 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
450
451 The third chapter presents the remaining five operations, and
452 information about using @command{tar} options and option syntax.
453
454 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
455 than the reality. should think about whether this makes sense to say
456 here, or not.} The other chapters are meant to be used as a
457 reference. Each chapter presents everything that needs to be said
458 about a specific topic.
459
460 One of the chapters (@pxref{Date input formats}) exists in its
461 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
462 In addition, one section of this manual (@pxref{Standard}) contains a
463 big quote which is taken directly from @command{tar} sources.
464
465 In general, we give both long and short (abbreviated) option names
466 at least once in each section where the relevant option is covered, so
467 that novice readers will become familiar with both styles. (A few
468 options have no short versions, and the relevant sections will
469 indicate this.)
470
471 @node Definitions
472 @section Some Definitions
473
474 @cindex archive
475 @cindex tar archive
476 The @command{tar} program is used to create and manipulate @command{tar}
477 archives. An @dfn{archive} is a single file which contains the contents
478 of many files, while still identifying the names of the files, their
479 owner(s), and so forth. (In addition, archives record access
480 permissions, user and group, size in bytes, and data modification time.
481 Some archives also record the file names in each archived directory, as
482 well as other file and directory information.) You can use @command{tar}
483 to @dfn{create} a new archive in a specified directory.
484
485 @cindex member
486 @cindex archive member
487 @cindex file name
488 @cindex member name
489 The files inside an archive are called @dfn{members}. Within this
490 manual, we use the term @dfn{file} to refer only to files accessible in
491 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
492 @dfn{member} to refer only to the members of an archive. Similarly, a
493 @dfn{file name} is the name of a file, as it resides in the file system,
494 and a @dfn{member name} is the name of an archive member within the
495 archive.
496
497 @cindex extraction
498 @cindex unpacking
499 The term @dfn{extraction} refers to the process of copying an archive
500 member (or multiple members) into a file in the file system. Extracting
501 all the members of an archive is often called @dfn{extracting the
502 archive}. The term @dfn{unpack} can also be used to refer to the
503 extraction of many or all the members of an archive. Extracting an
504 archive does not destroy the archive's structure, just as creating an
505 archive does not destroy the copies of the files that exist outside of
506 the archive. You may also @dfn{list} the members in a given archive
507 (this is often thought of as ``printing'' them to the standard output,
508 or the command line), or @dfn{append} members to a pre-existing archive.
509 All of these operations can be performed using @command{tar}.
510
511 @node What tar Does
512 @section What @command{tar} Does
513
514 @cindex tar
515 The @command{tar} program provides the ability to create @command{tar}
516 archives, as well as various other kinds of manipulation. For example,
517 you can use @command{tar} on previously created archives to extract files,
518 to store additional files, or to update or list files which were already
519 stored.
520
521 Initially, @command{tar} archives were used to store files conveniently on
522 magnetic tape. The name @command{tar} comes from this use; it stands for
523 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
524 direct its output to available devices, files, or other programs (using
525 pipes). @command{tar} may even access remote devices or files (as archives).
526
527 You can use @command{tar} archives in many ways. We want to stress a few
528 of them: storage, backup, and transportation.
529
530 @FIXME{the following table entries need a bit of work.}
531 @table @asis
532 @item Storage
533 Often, @command{tar} archives are used to store related files for
534 convenient file transfer over a network. For example, the
535 @acronym{GNU} Project distributes its software bundled into
536 @command{tar} archives, so that all the files relating to a particular
537 program (or set of related programs) can be transferred as a single
538 unit.
539
540 A magnetic tape can store several files in sequence. However, the tape
541 has no names for these files; it only knows their relative position on
542 the tape. One way to store several files on one tape and retain their
543 names is by creating a @command{tar} archive. Even when the basic transfer
544 mechanism can keep track of names, as FTP can, the nuisance of handling
545 multiple files, directories, and multiple links makes @command{tar}
546 archives useful.
547
548 Archive files are also used for long-term storage. You can think of
549 this as transportation from the present into the future. (It is a
550 science-fiction idiom that you can move through time as well as in
551 space; the idea here is that @command{tar} can be used to move archives in
552 all dimensions, even time!)
553
554 @item Backup
555 Because the archive created by @command{tar} is capable of preserving
556 file information and directory structure, @command{tar} is commonly
557 used for performing full and incremental backups of disks. A backup
558 puts a collection of files (possibly pertaining to many users and
559 projects) together on a disk or a tape. This guards against
560 accidental destruction of the information in those files.
561 @GNUTAR{} has special features that allow it to be
562 used to make incremental and full dumps of all the files in a
563 file system.
564
565 @item Transportation
566 You can create an archive on one system, transfer it to another system,
567 and extract the contents there. This allows you to transport a group of
568 files from one system to another.
569 @end table
570
571 @node Naming tar Archives
572 @section How @command{tar} Archives are Named
573
574 Conventionally, @command{tar} archives are given names ending with
575 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
576 but this manual follows that convention in order to accustom readers to
577 it and to make examples more clear.
578
579 @cindex tar file
580 @cindex entry
581 @cindex tar entry
582 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
583 archive members as ``files'' or ``entries''. For people familiar with
584 the operation of @command{tar}, this causes no difficulty. However, in
585 this manual, we consistently refer to ``archives'' and ``archive
586 members'' to make learning to use @command{tar} easier for novice users.
587
588 @node Authors
589 @section @GNUTAR{} Authors
590
591 @GNUTAR{} was originally written by John Gilmore,
592 and modified by many people. The @acronym{GNU} enhancements were
593 written by Jay Fenlason, then Joy Kendall, and the whole package has
594 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
595 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
596 numerous and kind users.
597
598 We wish to stress that @command{tar} is a collective work, and owes much to
599 all those people who reported problems, offered solutions and other
600 insights, or shared their thoughts and suggestions. An impressive, yet
601 partial list of those contributors can be found in the @file{THANKS}
602 file from the @GNUTAR{} distribution.
603
604 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
605 sure i want to spell out the history in this detail, at least not for
606 the printed book. i'm just not sure it needs to be said this way.
607 i'll think about it.}
608
609 @FIXME{History is more important, and surely more interesting, than
610 actual names. Quoting names without history would be meaningless. FP}
611
612 Jay Fenlason put together a draft of a @GNUTAR{}
613 manual, borrowing notes from the original man page from John Gilmore.
614 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
615 Gorin worked on a tutorial and manual for @GNUTAR{}.
616 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
617 taking information from all these sources and merging them. Melissa
618 Weisshaus finally edited and redesigned the book to create version
619 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
620 by the current maintainer, Sergey Poznyakoff.
621
622 For version 1.12, Daniel Hagerty contributed a great deal of technical
623 consulting. In particular, he is the primary author of @ref{Backups}.
624
625 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
626 (see @url{http://savannah.gnu.org/projects/tar}), and
627 active development and maintenance work has started
628 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
629 Poznyakoff and Jeff Bailey.
630
631 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
632
633 @node Reports
634 @section Reporting bugs or suggestions
635
636 @cindex bug reports
637 @cindex reporting bugs
638 If you find problems or have suggestions about this program or manual,
639 please report them to @file{bug-tar@@gnu.org}.
640
641 When reporting a bug, please be sure to include as much detail as
642 possible, in order to reproduce it. @FIXME{Be more specific, I'd
643 like to make this node as detailed as 'Bug reporting' node in Emacs
644 manual}.
645
646 @node Tutorial
647 @chapter Tutorial Introduction to @command{tar}
648
649 This chapter guides you through some basic examples of three @command{tar}
650 operations: @option{--create}, @option{--list}, and @option{--extract}. If
651 you already know how to use some other version of @command{tar}, then you
652 may not need to read this chapter. This chapter omits most complicated
653 details about how @command{tar} works.
654
655 @menu
656 * assumptions::
657 * stylistic conventions::
658 * basic tar options:: Basic @command{tar} Operations and Options
659 * frequent operations::
660 * Two Frequent Options::
661 * create:: How to Create Archives
662 * list:: How to List Archives
663 * extract:: How to Extract Members from an Archive
664 * going further::
665 @end menu
666
667 @node assumptions
668 @section Assumptions this Tutorial Makes
669
670 This chapter is paced to allow beginners to learn about @command{tar}
671 slowly. At the same time, we will try to cover all the basic aspects of
672 these three operations. In order to accomplish both of these tasks, we
673 have made certain assumptions about your knowledge before reading this
674 manual, and the hardware you will be using:
675
676 @itemize @bullet
677 @item
678 Before you start to work through this tutorial, you should understand
679 what the terms ``archive'' and ``archive member'' mean
680 (@pxref{Definitions}). In addition, you should understand something
681 about how Unix-type operating systems work, and you should know how to
682 use some basic utilities. For example, you should know how to create,
683 list, copy, rename, edit, and delete files and directories; how to
684 change between directories; and how to figure out where you are in the
685 file system. You should have some basic understanding of directory
686 structure and how files are named according to which directory they are
687 in. You should understand concepts such as standard output and standard
688 input, what various definitions of the term ``argument'' mean, and the
689 differences between relative and absolute file names. @FIXME{and what
690 else?}
691
692 @item
693 This manual assumes that you are working from your own home directory
694 (unless we state otherwise). In this tutorial, you will create a
695 directory to practice @command{tar} commands in. When we show file names,
696 we will assume that those names are relative to your home directory.
697 For example, my home directory is @file{/home/fsf/melissa}. All of
698 my examples are in a subdirectory of the directory named by that file
699 name; the subdirectory is called @file{practice}.
700
701 @item
702 In general, we show examples of archives which exist on (or can be
703 written to, or worked with from) a directory on a hard disk. In most
704 cases, you could write those archives to, or work with them on any other
705 device, such as a tape drive. However, some of the later examples in
706 the tutorial and next chapter will not work on tape drives.
707 Additionally, working with tapes is much more complicated than working
708 with hard disks. For these reasons, the tutorial does not cover working
709 with tape drives. @xref{Media}, for complete information on using
710 @command{tar} archives with tape drives.
711
712 @FIXME{this is a cop out. need to add some simple tape drive info.}
713 @end itemize
714
715 @node stylistic conventions
716 @section Stylistic Conventions
717
718 In the examples, @samp{$} represents a typical shell prompt. It
719 precedes lines you should type; to make this more clear, those lines are
720 shown in @kbd{this font}, as opposed to lines which represent the
721 computer's response; those lines are shown in @code{this font}, or
722 sometimes @samp{like this}.
723
724 @c When we have lines which are too long to be
725 @c displayed in any other way, we will show them like this:
726
727 @node basic tar options
728 @section Basic @command{tar} Operations and Options
729
730 @command{tar} can take a wide variety of arguments which specify and define
731 the actions it will have on the particular set of files or the archive.
732 The main types of arguments to @command{tar} fall into one of two classes:
733 operations, and options.
734
735 Some arguments fall into a class called @dfn{operations}; exactly one of
736 these is both allowed and required for any instance of using @command{tar};
737 you may @emph{not} specify more than one. People sometimes speak of
738 @dfn{operating modes}. You are in a particular operating mode when you
739 have specified the operation which specifies it; there are eight
740 operations in total, and thus there are eight operating modes.
741
742 The other arguments fall into the class known as @dfn{options}. You are
743 not required to specify any options, and you are allowed to specify more
744 than one at a time (depending on the way you are using @command{tar} at
745 that time). Some options are used so frequently, and are so useful for
746 helping you type commands more carefully that they are effectively
747 ``required''. We will discuss them in this chapter.
748
749 You can write most of the @command{tar} operations and options in any
750 of three forms: long (mnemonic) form, short form, and old style. Some
751 of the operations and options have no short or ``old'' forms; however,
752 the operations and options which we will cover in this tutorial have
753 corresponding abbreviations. @FIXME{make sure this is still the case,
754 at the end}We will indicate those abbreviations appropriately to get
755 you used to seeing them. (Note that the ``old style'' option forms
756 exist in @GNUTAR{} for compatibility with Unix
757 @command{tar}. In this book we present a full discussion of this way
758 of writing options and operations (@pxref{Old Options}), and we discuss
759 the other two styles of writing options (@xref{Long Options}, and
760 @pxref{Short Options}).
761
762 In the examples and in the text of this tutorial, we usually use the
763 long forms of operations and options; but the ``short'' forms produce
764 the same result and can make typing long @command{tar} commands easier.
765 For example, instead of typing
766
767 @smallexample
768 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
769 @end smallexample
770
771 @noindent
772 you can type
773 @smallexample
774 @kbd{tar -c -v -f afiles.tar apple angst aspic}
775 @end smallexample
776
777 @noindent
778 or even
779 @smallexample
780 @kbd{tar -cvf afiles.tar apple angst aspic}
781 @end smallexample
782
783 @noindent
784 For more information on option syntax, see @ref{Advanced tar}. In
785 discussions in the text, when we name an option by its long form, we
786 also give the corresponding short option in parentheses.
787
788 The term, ``option'', can be confusing at times, since ``operations''
789 are often lumped in with the actual, @emph{optional} ``options'' in certain
790 general class statements. For example, we just talked about ``short and
791 long forms of options and operations''. However, experienced @command{tar}
792 users often refer to these by shorthand terms such as, ``short and long
793 options''. This term assumes that the ``operations'' are included, also.
794 Context will help you determine which definition of ``options'' to use.
795
796 Similarly, the term ``command'' can be confusing, as it is often used in
797 two different ways. People sometimes refer to @command{tar} ``commands''.
798 A @command{tar} @dfn{command} is the entire command line of user input
799 which tells @command{tar} what to do --- including the operation, options,
800 and any arguments (file names, pipes, other commands, etc.). However,
801 you will also sometimes hear the term ``the @command{tar} command''. When
802 the word ``command'' is used specifically like this, a person is usually
803 referring to the @command{tar} @emph{operation}, not the whole line.
804 Again, use context to figure out which of the meanings the speaker
805 intends.
806
807 @node frequent operations
808 @section The Three Most Frequently Used Operations
809
810 Here are the three most frequently used operations (both short and long
811 forms), as well as a brief description of their meanings. The rest of
812 this chapter will cover how to use these operations in detail. We will
813 present the rest of the operations in the next chapter.
814
815 @table @option
816 @item --create
817 @itemx -c
818 Create a new @command{tar} archive.
819 @item --list
820 @itemx -t
821 List the contents of an archive.
822 @item --extract
823 @itemx -x
824 Extract one or more members from an archive.
825 @end table
826
827 @node Two Frequent Options
828 @section Two Frequently Used Options
829
830 To understand how to run @command{tar} in the three operating modes listed
831 previously, you also need to understand how to use two of the options to
832 @command{tar}: @option{--file} (which takes an archive file as an argument)
833 and @option{--verbose}. (You are usually not @emph{required} to specify
834 either of these options when you run @command{tar}, but they can be very
835 useful in making things more clear and helping you avoid errors.)
836
837 @menu
838 * file tutorial::
839 * verbose tutorial::
840 * help tutorial::
841 @end menu
842
843 @node file tutorial
844 @unnumberedsubsec The @option{--file} Option
845
846 @table @option
847 @xopindex{file, tutorial}
848 @item --file=@var{archive-name}
849 @itemx -f @var{archive-name}
850 Specify the name of an archive file.
851 @end table
852
853 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
854 use @command{tar}; this option determines the name of the archive file
855 that @command{tar} will work on.
856
857 @vrindex TAPE
858 If you don't specify this argument, then @command{tar} will examine
859 the environment variable @env{TAPE}. If it is set, its value will be
860 used as the archive name. Otherwise, @command{tar} will use the
861 default archive, determined at the compile time. Usually it is
862 standard output or some physical tape drive attached to your machine
863 (you can verify what the default is by running @kbd{tar
864 --show-defaults}, @pxref{defaults}). If there is no tape drive
865 attached, or the default is not meaningful, then @command{tar} will
866 print an error message. The error message might look roughly like one
867 of the following:
868
869 @smallexample
870 tar: can't open /dev/rmt8 : No such device or address
871 tar: can't open /dev/rsmt0 : I/O error
872 @end smallexample
873
874 @noindent
875 To avoid confusion, we recommend that you always specify an archive file
876 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
877 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
878 @ref{file}.
879
880 @node verbose tutorial
881 @unnumberedsubsec The @option{--verbose} Option
882
883 @table @option
884 @xopindex{verbose, introduced}
885 @item --verbose
886 @itemx -v
887 Show the files being worked on as @command{tar} is running.
888 @end table
889
890 @option{--verbose} (@option{-v}) shows details about the results of running
891 @command{tar}. This can be especially useful when the results might not be
892 obvious. For example, if you want to see the progress of @command{tar} as
893 it writes files into the archive, you can use the @option{--verbose}
894 option. In the beginning, you may find it useful to use
895 @option{--verbose} at all times; when you are more accustomed to
896 @command{tar}, you will likely want to use it at certain times but not at
897 others. We will use @option{--verbose} at times to help make something
898 clear, and we will give many examples both using and not using
899 @option{--verbose} to show the differences.
900
901 Each instance of @option{--verbose} on the command line increases the
902 verbosity level by one, so if you need more details on the output,
903 specify it twice.
904
905 When reading archives (@option{--list}, @option{--extract},
906 @option{--diff}), @command{tar} by default prints only the names of
907 the members being extracted. Using @option{--verbose} will show a full,
908 @command{ls} style member listing.
909
910 In contrast, when writing archives (@option{--create}, @option{--append},
911 @option{--update}), @command{tar} does not print file names by
912 default. So, a single @option{--verbose} option shows the file names
913 being added to the archive, while two @option{--verbose} options
914 enable the full listing.
915
916 For example, to create an archive in verbose mode:
917
918 @smallexample
919 $ @kbd{tar -cvf afiles.tar apple angst aspic}
920 apple
921 angst
922 aspic
923 @end smallexample
924
925 @noindent
926 Creating the same archive with the verbosity level 2 could give:
927
928 @smallexample
929 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
930 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
931 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
932 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
933 @end smallexample
934
935 @noindent
936 This works equally well using short or long forms of options. Using
937 long forms, you would simply write out the mnemonic form of the option
938 twice, like this:
939
940 @smallexample
941 $ @kbd{tar --create --verbose --verbose @dots{}}
942 @end smallexample
943
944 @noindent
945 Note that you must double the hyphens properly each time.
946
947 Later in the tutorial, we will give examples using @w{@option{--verbose
948 --verbose}}.
949
950 @anchor{verbose member listing}
951 The full output consists of six fields:
952
953 @itemize @bullet
954 @item File type and permissions in symbolic form.
955 These are displayed in the same format as the first column of
956 @command{ls -l} output (@pxref{What information is listed,
957 format=verbose, Verbose listing, fileutils, GNU file utilities}).
958
959 @item Owner name and group separated by a slash character.
960 If these data are not available (for example, when listing a @samp{v7} format
961 archive), numeric @acronym{ID} values are printed instead.
962
963 @item Size of the file, in bytes.
964
965 @item File modification date in ISO 8601 format.
966
967 @item File modification time.
968
969 @item File name.
970 If the name contains any special characters (white space, newlines,
971 etc.) these are displayed in an unambiguous form using so called
972 @dfn{quoting style}. For the detailed discussion of available styles
973 and on how to use them, see @ref{quoting styles}.
974
975 Depending on the file type, the name can be followed by some
976 additional information, described in the following table:
977
978 @table @samp
979 @item -> @var{link-name}
980 The file or archive member is a @dfn{symbolic link} and
981 @var{link-name} is the name of file it links to.
982
983 @item link to @var{link-name}
984 The file or archive member is a @dfn{hard link} and @var{link-name} is
985 the name of file it links to.
986
987 @item --Long Link--
988 The archive member is an old GNU format long link. You will normally
989 not encounter this.
990
991 @item --Long Name--
992 The archive member is an old GNU format long name. You will normally
993 not encounter this.
994
995 @item --Volume Header--
996 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
997
998 @item --Continued at byte @var{n}--
999 Encountered only at the beginning of a multi-volume archive
1000 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1001 from the previous volume. The number @var{n} gives the offset where
1002 the original file was split.
1003
1004 @item unknown file type @var{c}
1005 An archive member of unknown type. @var{c} is the type character from
1006 the archive header. If you encounter such a message, it means that
1007 either your archive contains proprietary member types @GNUTAR{} is not
1008 able to handle, or the archive is corrupted.
1009 @end table
1010
1011 @end itemize
1012
1013 For example, here is an archive listing containing most of the special
1014 suffixes explained above:
1015
1016 @smallexample
1017 @group
1018 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1019 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1020 byte 32456--
1021 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1022 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1023 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1024 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1025 @end group
1026 @end smallexample
1027
1028 @smallexample
1029 @end smallexample
1030
1031 @node help tutorial
1032 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1033
1034 @table @option
1035 @opindex help
1036 @item --help
1037
1038 The @option{--help} option to @command{tar} prints out a very brief list of
1039 all operations and option available for the current version of
1040 @command{tar} available on your system.
1041 @end table
1042
1043 @node create
1044 @section How to Create Archives
1045 @UNREVISED
1046
1047 @cindex Creation of the archive
1048 @cindex Archive, creation of
1049 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1050 you use to create a @command{tar} archive. We will explain
1051 @option{--create} first because, in order to learn about the other
1052 operations, you will find it useful to have an archive available to
1053 practice on.
1054
1055 To make this easier, in this section you will first create a directory
1056 containing three files. Then, we will show you how to create an
1057 @emph{archive} (inside the new directory). Both the directory, and
1058 the archive are specifically for you to practice on. The rest of this
1059 chapter and the next chapter will show many examples using this
1060 directory and the files you will create: some of those files may be
1061 other directories and other archives.
1062
1063 The three files you will archive in this example are called
1064 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1065 @file{collection.tar}.
1066
1067 This section will proceed slowly, detailing how to use @option{--create}
1068 in @code{verbose} mode, and showing examples using both short and long
1069 forms. In the rest of the tutorial, and in the examples in the next
1070 chapter, we will proceed at a slightly quicker pace. This section
1071 moves more slowly to allow beginning users to understand how
1072 @command{tar} works.
1073
1074 @menu
1075 * prepare for examples::
1076 * Creating the archive::
1077 * create verbose::
1078 * short create::
1079 * create dir::
1080 @end menu
1081
1082 @node prepare for examples
1083 @subsection Preparing a Practice Directory for Examples
1084
1085 To follow along with this and future examples, create a new directory
1086 called @file{practice} containing files called @file{blues}, @file{folk}
1087 and @file{jazz}. The files can contain any information you like:
1088 ideally, they should contain information which relates to their names,
1089 and be of different lengths. Our examples assume that @file{practice}
1090 is a subdirectory of your home directory.
1091
1092 Now @command{cd} to the directory named @file{practice}; @file{practice}
1093 is now your @dfn{working directory}. (@emph{Please note}: Although
1094 the full file name of this directory is
1095 @file{/@var{homedir}/practice}, in our examples we will refer to
1096 this directory as @file{practice}; the @var{homedir} is presumed.
1097
1098 In general, you should check that the files to be archived exist where
1099 you think they do (in the working directory) by running @command{ls}.
1100 Because you just created the directory and the files and have changed to
1101 that directory, you probably don't need to do that this time.
1102
1103 It is very important to make sure there isn't already a file in the
1104 working directory with the archive name you intend to use (in this case,
1105 @samp{collection.tar}), or that you don't care about its contents.
1106 Whenever you use @samp{create}, @command{tar} will erase the current
1107 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1108 will not tell you if you are about to overwrite an archive unless you
1109 specify an option which does this (@pxref{backup}, for the
1110 information on how to do so). To add files to an existing archive,
1111 you need to use a different option, such as @option{--append} (@option{-r}); see
1112 @ref{append} for information on how to do this.
1113
1114 @node Creating the archive
1115 @subsection Creating the Archive
1116
1117 @xopindex{create, introduced}
1118 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1119 archive named @file{collection.tar}, use the following command:
1120
1121 @smallexample
1122 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1123 @end smallexample
1124
1125 The order of the arguments is not very important, @emph{when using long
1126 option forms}. You could also say:
1127
1128 @smallexample
1129 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1130 @end smallexample
1131
1132 @noindent
1133 However, you can see that this order is harder to understand; this is
1134 why we will list the arguments in the order that makes the commands
1135 easiest to understand (and we encourage you to do the same when you use
1136 @command{tar}, to avoid errors).
1137
1138 Note that the sequence
1139 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1140 If you substituted any other string of characters for
1141 @kbd{collection.tar}, then that string would become the name of the
1142 archive file you create.
1143
1144 The order of the options becomes more important when you begin to use
1145 short forms. With short forms, if you type commands in the wrong order
1146 (even if you type them correctly in all other ways), you may end up with
1147 results you don't expect. For this reason, it is a good idea to get
1148 into the habit of typing options in the order that makes inherent sense.
1149 @xref{short create}, for more information on this.
1150
1151 In this example, you type the command as shown above: @option{--create}
1152 is the operation which creates the new archive
1153 (@file{collection.tar}), and @option{--file} is the option which lets
1154 you give it the name you chose. The files, @file{blues}, @file{folk},
1155 and @file{jazz}, are now members of the archive, @file{collection.tar}
1156 (they are @dfn{file name arguments} to the @option{--create} operation.
1157 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1158 in the archive, they are called @emph{archive members}, not files.
1159 (@pxref{Definitions,members}).
1160
1161 When you create an archive, you @emph{must} specify which files you
1162 want placed in the archive. If you do not specify any archive
1163 members, @GNUTAR{} will complain.
1164
1165 If you now list the contents of the working directory (@command{ls}), you will
1166 find the archive file listed as well as the files you saw previously:
1167
1168 @smallexample
1169 blues folk jazz collection.tar
1170 @end smallexample
1171
1172 @noindent
1173 Creating the archive @samp{collection.tar} did not destroy the copies of
1174 the files in the directory.
1175
1176 Keep in mind that if you don't indicate an operation, @command{tar} will not
1177 run and will prompt you for one. If you don't name any files, @command{tar}
1178 will complain. You must have write access to the working directory,
1179 or else you will not be able to create an archive in that directory.
1180
1181 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1182 an existing archive; it will delete the archive and write a new one.
1183 Use @option{--append} (@option{-r}) instead. @xref{append}.
1184
1185 @node create verbose
1186 @subsection Running @option{--create} with @option{--verbose}
1187
1188 @xopindex{create, using with @option{--verbose}}
1189 @xopindex{verbose, using with @option{--create}}
1190 If you include the @option{--verbose} (@option{-v}) option on the command line,
1191 @command{tar} will list the files it is acting on as it is working. In
1192 verbose mode, the @code{create} example above would appear as:
1193
1194 @smallexample
1195 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1196 blues
1197 folk
1198 jazz
1199 @end smallexample
1200
1201 This example is just like the example we showed which did not use
1202 @option{--verbose}, except that @command{tar} generated the remaining lines
1203 @iftex
1204 (note the different font styles).
1205 @end iftex
1206 @ifinfo
1207 .
1208 @end ifinfo
1209
1210 In the rest of the examples in this chapter, we will frequently use
1211 @code{verbose} mode so we can show actions or @command{tar} responses that
1212 you would otherwise not see, and which are important for you to
1213 understand.
1214
1215 @node short create
1216 @subsection Short Forms with @samp{create}
1217
1218 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1219 basic uses of @command{tar}, and you will use it countless times.
1220 Eventually, you will probably want to use abbreviated (or ``short'')
1221 forms of options. A full discussion of the three different forms that
1222 options can take appears in @ref{Styles}; for now, here is what the
1223 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1224 using short option forms:
1225
1226 @smallexample
1227 $ @kbd{tar -cvf collection.tar blues folk jazz}
1228 blues
1229 folk
1230 jazz
1231 @end smallexample
1232
1233 @noindent
1234 As you can see, the system responds the same no matter whether you use
1235 long or short option forms.
1236
1237 @FIXME{i don't like how this is worded:} One difference between using
1238 short and long option forms is that, although the exact placement of
1239 arguments following options is no more specific when using short forms,
1240 it is easier to become confused and make a mistake when using short
1241 forms. For example, suppose you attempted the above example in the
1242 following way:
1243
1244 @smallexample
1245 $ @kbd{tar -cfv collection.tar blues folk jazz}
1246 @end smallexample
1247
1248 @noindent
1249 In this case, @command{tar} will make an archive file called @file{v},
1250 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1251 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1252 is thus taken to be the chosen archive file name. @command{tar} will try
1253 to add a file called @file{collection.tar} to the @file{v} archive file;
1254 if the file @file{collection.tar} did not already exist, @command{tar} will
1255 report an error indicating that this file does not exist. If the file
1256 @file{collection.tar} does already exist (e.g., from a previous command
1257 you may have run), then @command{tar} will add this file to the archive.
1258 Because the @option{-v} option did not get registered, @command{tar} will not
1259 run under @samp{verbose} mode, and will not report its progress.
1260
1261 The end result is that you may be quite confused about what happened,
1262 and possibly overwrite a file. To illustrate this further, we will show
1263 you how an example we showed previously would look using short forms.
1264
1265 This example,
1266
1267 @smallexample
1268 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1269 @end smallexample
1270
1271 @noindent
1272 is confusing as it is. When shown using short forms, however, it
1273 becomes much more so:
1274
1275 @smallexample
1276 $ @kbd{tar blues -c folk -f collection.tar jazz}
1277 @end smallexample
1278
1279 @noindent
1280 It would be very easy to put the wrong string of characters
1281 immediately following the @option{-f}, but doing that could sacrifice
1282 valuable data.
1283
1284 For this reason, we recommend that you pay very careful attention to
1285 the order of options and placement of file and archive names,
1286 especially when using short option forms. Not having the option name
1287 written out mnemonically can affect how well you remember which option
1288 does what, and therefore where different names have to be placed.
1289
1290 @node create dir
1291 @subsection Archiving Directories
1292
1293 @cindex Archiving Directories
1294 @cindex Directories, Archiving
1295 You can archive a directory by specifying its directory name as a
1296 file name argument to @command{tar}. The files in the directory will be
1297 archived relative to the working directory, and the directory will be
1298 re-created along with its contents when the archive is extracted.
1299
1300 To archive a directory, first move to its superior directory. If you
1301 have followed the previous instructions in this tutorial, you should
1302 type:
1303
1304 @smallexample
1305 $ @kbd{cd ..}
1306 $
1307 @end smallexample
1308
1309 @noindent
1310 This will put you into the directory which contains @file{practice},
1311 i.e., your home directory. Once in the superior directory, you can
1312 specify the subdirectory, @file{practice}, as a file name argument. To
1313 store @file{practice} in the new archive file @file{music.tar}, type:
1314
1315 @smallexample
1316 $ @kbd{tar --create --verbose --file=music.tar practice}
1317 @end smallexample
1318
1319 @noindent
1320 @command{tar} should output:
1321
1322 @smallexample
1323 practice/
1324 practice/blues
1325 practice/folk
1326 practice/jazz
1327 practice/collection.tar
1328 @end smallexample
1329
1330 Note that the archive thus created is not in the subdirectory
1331 @file{practice}, but rather in the current working directory---the
1332 directory from which @command{tar} was invoked. Before trying to archive a
1333 directory from its superior directory, you should make sure you have
1334 write access to the superior directory itself, not only the directory
1335 you are trying archive with @command{tar}. For example, you will probably
1336 not be able to store your home directory in an archive by invoking
1337 @command{tar} from the root directory; @xref{absolute}. (Note
1338 also that @file{collection.tar}, the original archive file, has itself
1339 been archived. @command{tar} will accept any file as a file to be
1340 archived, regardless of its content. When @file{music.tar} is
1341 extracted, the archive file @file{collection.tar} will be re-written
1342 into the file system).
1343
1344 If you give @command{tar} a command such as
1345
1346 @smallexample
1347 $ @kbd{tar --create --file=foo.tar .}
1348 @end smallexample
1349
1350 @noindent
1351 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1352 dumped}. This happens because @command{tar} creates the archive
1353 @file{foo.tar} in the current directory before putting any files into
1354 it. Then, when @command{tar} attempts to add all the files in the
1355 directory @file{.} to the archive, it notices that the file
1356 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1357 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1358 will continue in this case, and create the archive
1359 normally, except for the exclusion of that one file. (@emph{Please
1360 note:} Other implementations of @command{tar} may not be so clever;
1361 they will enter an infinite loop when this happens, so you should not
1362 depend on this behavior unless you are certain you are running
1363 @GNUTAR{}. In general, it is wise to always place the archive outside
1364 of the directory being dumped.
1365
1366 @node list
1367 @section How to List Archives
1368
1369 @opindex list
1370 Frequently, you will find yourself wanting to determine exactly what a
1371 particular archive contains. You can use the @option{--list}
1372 (@option{-t}) operation to get the member names as they currently
1373 appear in the archive, as well as various attributes of the files at
1374 the time they were archived. For example, you can examine the archive
1375 @file{collection.tar} that you created in the last section with the
1376 command,
1377
1378 @smallexample
1379 $ @kbd{tar --list --file=collection.tar}
1380 @end smallexample
1381
1382 @noindent
1383 The output of @command{tar} would then be:
1384
1385 @smallexample
1386 blues
1387 folk
1388 jazz
1389 @end smallexample
1390
1391 @noindent
1392 The archive @file{bfiles.tar} would list as follows:
1393
1394 @smallexample
1395 ./birds
1396 baboon
1397 ./box
1398 @end smallexample
1399
1400 @noindent
1401 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1402 @var{archive-name}}) option just as with @option{--create}
1403 (@option{-c}) to specify the name of the archive.
1404
1405 @xopindex{list, using with @option{--verbose}}
1406 @xopindex{verbose, using with @option{--list}}
1407 If you use the @option{--verbose} (@option{-v}) option with
1408 @option{--list}, then @command{tar} will print out a listing
1409 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1410 forth. This output is described in detail in @ref{verbose member listing}.
1411
1412 If you had used @option{--verbose} (@option{-v}) mode, the example
1413 above would look like:
1414
1415 @smallexample
1416 $ @kbd{tar --list --verbose --file=collection.tar folk}
1417 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1418 @end smallexample
1419
1420 @cindex listing member and file names
1421 @anchor{listing member and file names}
1422 It is important to notice that the output of @kbd{tar --list
1423 --verbose} does not necessarily match that produced by @kbd{tar
1424 --create --verbose} while creating the archive. It is because
1425 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1426 prefixes from file names before storing them in the archive
1427 (@xref{absolute}, for more information). In other
1428 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1429 an archive and @dfn{member names} when listing it. Consider this
1430 example:
1431
1432 @smallexample
1433 @group
1434 $ @kbd{tar cfv archive /etc/mail}
1435 tar: Removing leading `/' from member names
1436 /etc/mail/
1437 /etc/mail/sendmail.cf
1438 /etc/mail/aliases
1439 $ @kbd{tar tf archive}
1440 etc/mail/
1441 etc/mail/sendmail.cf
1442 etc/mail/aliases
1443 @end group
1444 @end smallexample
1445
1446 @opindex show-stored-names
1447 This default behavior can sometimes be inconvenient. You can force
1448 @GNUTAR{} show member names when creating archive by supplying
1449 @option{--show-stored-names} option.
1450
1451 @table @option
1452 @item --show-stored-names
1453 Print member (as opposed to @emph{file}) names when creating the archive.
1454 @end table
1455
1456 @cindex File name arguments, using @option{--list} with
1457 @xopindex{list, using with file name arguments}
1458 You can specify one or more individual member names as arguments when
1459 using @samp{list}. In this case, @command{tar} will only list the
1460 names of members you identify. For example, @w{@kbd{tar --list
1461 --file=afiles.tar apple}} would only print @file{apple}.
1462
1463 Because @command{tar} preserves file names, these must be specified as
1464 they appear in the archive (i.e., relative to the directory from which
1465 the archive was created). Therefore, it is essential when specifying
1466 member names to @command{tar} that you give the exact member names.
1467 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1468 error message something like @samp{tar: birds: Not found in archive},
1469 because there is no member named @file{birds}, only one named
1470 @file{./birds}. While the names @file{birds} and @file{./birds} name
1471 the same file, @emph{member} names by default are compared verbatim.
1472
1473 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1474 with @file{baboon}, because this exact member name is in the archive file
1475 @file{bfiles.tar}. If you are not sure of the exact file name,
1476 use @dfn{globbing patterns}, for example:
1477
1478 @smallexample
1479 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1480 @end smallexample
1481
1482 @noindent
1483 will list all members whose name contains @samp{b}. @xref{wildcards},
1484 for a detailed discussion of globbing patterns and related
1485 @command{tar} command line options.
1486
1487 @menu
1488 * list dir::
1489 @end menu
1490
1491 @node list dir
1492 @unnumberedsubsec Listing the Contents of a Stored Directory
1493
1494 To get information about the contents of an archived directory,
1495 use the directory name as a file name argument in conjunction with
1496 @option{--list} (@option{-t}). To find out file attributes, include the
1497 @option{--verbose} (@option{-v}) option.
1498
1499 For example, to find out about files in the directory @file{practice}, in
1500 the archive file @file{music.tar}, type:
1501
1502 @smallexample
1503 $ @kbd{tar --list --verbose --file=music.tar practice}
1504 @end smallexample
1505
1506 @command{tar} responds:
1507
1508 @smallexample
1509 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1510 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1511 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1512 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1513 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1514 @end smallexample
1515
1516 When you use a directory name as a file name argument, @command{tar} acts on
1517 all the files (including sub-directories) in that directory.
1518
1519 @node extract
1520 @section How to Extract Members from an Archive
1521 @UNREVISED
1522 @cindex Extraction
1523 @cindex Retrieving files from an archive
1524 @cindex Resurrecting files from an archive
1525
1526 @opindex extract
1527 Creating an archive is only half the job---there is no point in storing
1528 files in an archive if you can't retrieve them. The act of retrieving
1529 members from an archive so they can be used and manipulated as
1530 unarchived files again is called @dfn{extraction}. To extract files
1531 from an archive, use the @option{--extract} (@option{--get} or
1532 @option{-x}) operation. As with @option{--create}, specify the name
1533 of the archive with @option{--file} (@option{-f}) option. Extracting
1534 an archive does not modify the archive in any way; you can extract it
1535 multiple times if you want or need to.
1536
1537 Using @option{--extract}, you can extract an entire archive, or specific
1538 files. The files can be directories containing other files, or not. As
1539 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1540 long form of the operation without affecting the performance.
1541
1542 @menu
1543 * extracting archives::
1544 * extracting files::
1545 * extract dir::
1546 * extracting untrusted archives::
1547 * failing commands::
1548 @end menu
1549
1550 @node extracting archives
1551 @subsection Extracting an Entire Archive
1552
1553 To extract an entire archive, specify the archive file name only, with
1554 no individual file names as arguments. For example,
1555
1556 @smallexample
1557 $ @kbd{tar -xvf collection.tar}
1558 @end smallexample
1559
1560 @noindent
1561 produces this:
1562
1563 @smallexample
1564 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1565 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1566 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1567 @end smallexample
1568
1569 @node extracting files
1570 @subsection Extracting Specific Files
1571
1572 To extract specific archive members, give their exact member names as
1573 arguments, as printed by @option{--list} (@option{-t}). If you had
1574 mistakenly deleted one of the files you had placed in the archive
1575 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1576 from the archive without changing the archive's structure. Its
1577 contents will be identical to the original file @file{blues} that you
1578 deleted.
1579
1580 First, make sure you are in the @file{practice} directory, and list the
1581 files in the directory. Now, delete the file, @samp{blues}, and list
1582 the files in the directory again.
1583
1584 You can now extract the member @file{blues} from the archive file
1585 @file{collection.tar} like this:
1586
1587 @smallexample
1588 $ @kbd{tar --extract --file=collection.tar blues}
1589 @end smallexample
1590
1591 @noindent
1592 If you list the files in the directory again, you will see that the file
1593 @file{blues} has been restored, with its original permissions, data
1594 modification times, and owner.@footnote{This is only accidentally
1595 true, but not in general. Whereas modification times are always
1596 restored, in most cases, one has to be root for restoring the owner,
1597 and use a special option for restoring permissions. Here, it just
1598 happens that the restoring user is also the owner of the archived
1599 members, and that the current @code{umask} is compatible with original
1600 permissions.} (These parameters will be identical to those which
1601 the file had when you originally placed it in the archive; any changes
1602 you may have made before deleting the file from the file system,
1603 however, will @emph{not} have been made to the archive member.) The
1604 archive file, @samp{collection.tar}, is the same as it was before you
1605 extracted @samp{blues}. You can confirm this by running @command{tar} with
1606 @option{--list} (@option{-t}).
1607
1608 Remember that as with other operations, specifying the exact member
1609 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1610 will fail, because there is no member named @file{birds}. To extract
1611 the member named @file{./birds}, you must specify @w{@kbd{tar
1612 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1613 exact member names, use @option{--list} (@option{-t}) option
1614 (@pxref{list}). You can also extract those members that match a
1615 specific @dfn{globbing pattern}. For example, to extract from
1616 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1617 directory prefix, you could type:
1618
1619 @smallexample
1620 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1621 @end smallexample
1622
1623 @noindent
1624 Here, @option{--wildcards} instructs @command{tar} to treat
1625 command line arguments as globbing patterns and @option{--no-anchored}
1626 informs it that the patterns apply to member names after any @samp{/}
1627 delimiter. The use of globbing patterns is discussed in detail in
1628 @xref{wildcards}.
1629
1630 You can extract a file to standard output by combining the above options
1631 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1632 Output}).
1633
1634 If you give the @option{--verbose} option, then @option{--extract}
1635 will print the names of the archive members as it extracts them.
1636
1637 @node extract dir
1638 @subsection Extracting Files that are Directories
1639
1640 Extracting directories which are members of an archive is similar to
1641 extracting other files. The main difference to be aware of is that if
1642 the extracted directory has the same name as any directory already in
1643 the working directory, then files in the extracted directory will be
1644 placed into the directory of the same name. Likewise, if there are
1645 files in the pre-existing directory with the same names as the members
1646 which you extract, the files from the extracted archive will replace
1647 the files already in the working directory (and possible
1648 subdirectories). This will happen regardless of whether or not the
1649 files in the working directory were more recent than those extracted
1650 (there exist, however, special options that alter this behavior
1651 @pxref{Writing}).
1652
1653 However, if a file was stored with a directory name as part of its file
1654 name, and that directory does not exist under the working directory when
1655 the file is extracted, @command{tar} will create the directory.
1656
1657 We can demonstrate how to use @option{--extract} to extract a directory
1658 file with an example. Change to the @file{practice} directory if you
1659 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1660 go back to the parent directory and extract the archive
1661 @file{music.tar}. You may either extract the entire archive, or you may
1662 extract only the files you just deleted. To extract the entire archive,
1663 don't give any file names as arguments after the archive name
1664 @file{music.tar}. To extract only the files you deleted, use the
1665 following command:
1666
1667 @smallexample
1668 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1669 practice/folk
1670 practice/jazz
1671 @end smallexample
1672
1673 @noindent
1674 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1675 would have displayed more detail about the extracted files, as shown
1676 in the example below:
1677
1678 @smallexample
1679 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1680 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1681 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1682 @end smallexample
1683
1684 @noindent
1685 Because you created the directory with @file{practice} as part of the
1686 file names of each of the files by archiving the @file{practice}
1687 directory as @file{practice}, you must give @file{practice} as part
1688 of the file names when you extract those files from the archive.
1689
1690 @node extracting untrusted archives
1691 @subsection Extracting Archives from Untrusted Sources
1692
1693 Extracting files from archives can overwrite files that already exist.
1694 If you receive an archive from an untrusted source, you should make a
1695 new directory and extract into that directory, so that you don't have
1696 to worry about the extraction overwriting one of your existing files.
1697 For example, if @file{untrusted.tar} came from somewhere else on the
1698 Internet, and you don't necessarily trust its contents, you can
1699 extract it as follows:
1700
1701 @smallexample
1702 $ @kbd{mkdir newdir}
1703 $ @kbd{cd newdir}
1704 $ @kbd{tar -xvf ../untrusted.tar}
1705 @end smallexample
1706
1707 It is also a good practice to examine contents of the archive
1708 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1709 with @option{--verbose} (@option{-v}).
1710
1711 @node failing commands
1712 @subsection Commands That Will Fail
1713
1714 Here are some sample commands you might try which will not work, and why
1715 they won't work.
1716
1717 If you try to use this command,
1718
1719 @smallexample
1720 $ @kbd{tar -xvf music.tar folk jazz}
1721 @end smallexample
1722
1723 @noindent
1724 you will get the following response:
1725
1726 @smallexample
1727 tar: folk: Not found in archive
1728 tar: jazz: Not found in archive
1729 $
1730 @end smallexample
1731
1732 @noindent
1733 This is because these files were not originally @emph{in} the parent
1734 directory @file{..}, where the archive is located; they were in the
1735 @file{practice} directory, and their file names reflect this:
1736
1737 @smallexample
1738 $ @kbd{tar -tvf music.tar}
1739 practice/folk
1740 practice/jazz
1741 practice/rock
1742 @end smallexample
1743
1744 @FIXME{make sure the above works when going through the examples in
1745 order...}
1746
1747 @noindent
1748 Likewise, if you try to use this command,
1749
1750 @smallexample
1751 $ @kbd{tar -tvf music.tar folk jazz}
1752 @end smallexample
1753
1754 @noindent
1755 you would get a similar response. Members with those names are not in the
1756 archive. You must use the correct member names, or wildcards, in order
1757 to extract the files from the archive.
1758
1759 If you have forgotten the correct names of the files in the archive,
1760 use @w{@kbd{tar --list --verbose}} to list them correctly.
1761
1762 @FIXME{more examples, here? hag thinks it's a good idea.}
1763
1764 @node going further
1765 @section Going Further Ahead in this Manual
1766
1767 @FIXME{need to write up a node here about the things that are going to
1768 be in the rest of the manual.}
1769
1770 @node tar invocation
1771 @chapter Invoking @GNUTAR{}
1772 @UNREVISED
1773
1774 This chapter is about how one invokes the @GNUTAR{}
1775 command, from the command synopsis (@pxref{Synopsis}). There are
1776 numerous options, and many styles for writing them. One mandatory
1777 option specifies the operation @command{tar} should perform
1778 (@pxref{Operation Summary}), other options are meant to detail how
1779 this operation should be performed (@pxref{Option Summary}).
1780 Non-option arguments are not always interpreted the same way,
1781 depending on what the operation is.
1782
1783 You will find in this chapter everything about option styles and rules for
1784 writing them (@pxref{Styles}). On the other hand, operations and options
1785 are fully described elsewhere, in other chapters. Here, you will find
1786 only synthetic descriptions for operations and options, together with
1787 pointers to other parts of the @command{tar} manual.
1788
1789 Some options are so special they are fully described right in this
1790 chapter. They have the effect of inhibiting the normal operation of
1791 @command{tar} or else, they globally alter the amount of feedback the user
1792 receives about what is going on. These are the @option{--help} and
1793 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1794 and @option{--interactive} options (@pxref{interactive}).
1795
1796 @menu
1797 * Synopsis::
1798 * using tar options::
1799 * Styles::
1800 * All Options::
1801 * help::
1802 * defaults::
1803 * verbose::
1804 * interactive::
1805 @end menu
1806
1807 @node Synopsis
1808 @section General Synopsis of @command{tar}
1809
1810 The @GNUTAR{} program is invoked as either one of:
1811
1812 @smallexample
1813 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1814 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1815 @end smallexample
1816
1817 The second form is for when old options are being used.
1818
1819 You can use @command{tar} to store files in an archive, to extract them from
1820 an archive, and to do other types of archive manipulation. The primary
1821 argument to @command{tar}, which is called the @dfn{operation}, specifies
1822 which action to take. The other arguments to @command{tar} are either
1823 @dfn{options}, which change the way @command{tar} performs an operation,
1824 or file names or archive members, which specify the files or members
1825 @command{tar} is to act on.
1826
1827 You can actually type in arguments in any order, even if in this manual
1828 the options always precede the other arguments, to make examples easier
1829 to understand. Further, the option stating the main operation mode
1830 (the @command{tar} main command) is usually given first.
1831
1832 Each @var{name} in the synopsis above is interpreted as an archive member
1833 name when the main command is one of @option{--compare}
1834 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1835 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1836 @option{--update} (@option{-u}). When naming archive members, you
1837 must give the exact name of the member in the archive, as it is
1838 printed by @option{--list}. For @option{--append} (@option{-r}) and
1839 @option{--create} (@option{-c}), these @var{name} arguments specify
1840 the names of either files or directory hierarchies to place in the archive.
1841 These files or hierarchies should already exist in the file system,
1842 prior to the execution of the @command{tar} command.
1843
1844 @command{tar} interprets relative file names as being relative to the
1845 working directory. @command{tar} will make all file names relative
1846 (by removing leading slashes when archiving or restoring files),
1847 unless you specify otherwise (using the @option{--absolute-names}
1848 option). @xref{absolute}, for more information about
1849 @option{--absolute-names}.
1850
1851 If you give the name of a directory as either a file name or a member
1852 name, then @command{tar} acts recursively on all the files and directories
1853 beneath that directory. For example, the name @file{/} identifies all
1854 the files in the file system to @command{tar}.
1855
1856 The distinction between file names and archive member names is especially
1857 important when shell globbing is used, and sometimes a source of confusion
1858 for newcomers. @xref{wildcards}, for more information about globbing.
1859 The problem is that shells may only glob using existing files in the
1860 file system. Only @command{tar} itself may glob on archive members, so when
1861 needed, you must ensure that wildcard characters reach @command{tar} without
1862 being interpreted by the shell first. Using a backslash before @samp{*}
1863 or @samp{?}, or putting the whole argument between quotes, is usually
1864 sufficient for this.
1865
1866 Even if @var{name}s are often specified on the command line, they
1867 can also be read from a text file in the file system, using the
1868 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1869
1870 If you don't use any file name arguments, @option{--append} (@option{-r}),
1871 @option{--delete} and @option{--concatenate} (@option{--catenate},
1872 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1873 will usually yield a diagnostic and inhibit @command{tar} execution.
1874 The other operations of @command{tar} (@option{--list},
1875 @option{--extract}, @option{--compare}, and @option{--update})
1876 will act on the entire contents of the archive.
1877
1878 @cindex exit status
1879 @cindex return status
1880 Besides successful exits, @GNUTAR{} may fail for
1881 many reasons. Some reasons correspond to bad usage, that is, when the
1882 @command{tar} command is improperly written. Errors may be
1883 encountered later, while encountering an error processing the archive
1884 or the files. Some errors are recoverable, in which case the failure
1885 is delayed until @command{tar} has completed all its work. Some
1886 errors are such that it would not meaningful, or at least risky, to
1887 continue processing: @command{tar} then aborts processing immediately.
1888 All abnormal exits, whether immediate or delayed, should always be
1889 clearly diagnosed on @code{stderr}, after a line stating the nature of
1890 the error.
1891
1892 Possible exit codes of @GNUTAR{} are summarized in the following
1893 table:
1894
1895 @table @asis
1896 @item 0
1897 @samp{Successful termination}.
1898
1899 @item 1
1900 @samp{Some files differ}. If tar was invoked with @option{--compare}
1901 (@option{--diff}, @option{-d}) command line option, this means that
1902 some files in the archive differ from their disk counterparts
1903 (@pxref{compare}). If tar was given @option{--create},
1904 @option{--append} or @option{--update} option, this exit code means
1905 that some files were changed while being archived and so the resulting
1906 archive does not contain the exact copy of the file set.
1907
1908 @item 2
1909 @samp{Fatal error}. This means that some fatal, unrecoverable error
1910 occurred.
1911 @end table
1912
1913 If @command{tar} has invoked a subprocess and that subprocess exited with a
1914 nonzero exit code, @command{tar} exits with that code as well.
1915 This can happen, for example, if @command{tar} was given some
1916 compression option (@pxref{gzip}) and the external compressor program
1917 failed. Another example is @command{rmt} failure during backup to the
1918 remote device (@pxref{Remote Tape Server}).
1919
1920 @node using tar options
1921 @section Using @command{tar} Options
1922
1923 @GNUTAR{} has a total of eight operating modes which
1924 allow you to perform a variety of tasks. You are required to choose
1925 one operating mode each time you employ the @command{tar} program by
1926 specifying one, and only one operation as an argument to the
1927 @command{tar} command (two lists of four operations each may be found
1928 at @ref{frequent operations} and @ref{Operations}). Depending on
1929 circumstances, you may also wish to customize how the chosen operating
1930 mode behaves. For example, you may wish to change the way the output
1931 looks, or the format of the files that you wish to archive may require
1932 you to do something special in order to make the archive look right.
1933
1934 You can customize and control @command{tar}'s performance by running
1935 @command{tar} with one or more options (such as @option{--verbose}
1936 (@option{-v}), which we used in the tutorial). As we said in the
1937 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1938 their name suggests) optional. Depending on the operating mode, you
1939 may specify one or more options. Different options will have different
1940 effects, but in general they all change details of the operation, such
1941 as archive format, archive name, or level of user interaction. Some
1942 options make sense with all operating modes, while others are
1943 meaningful only with particular modes. You will likely use some
1944 options frequently, while you will only use others infrequently, or
1945 not at all. (A full list of options is available in @pxref{All Options}.)
1946
1947 @vrindex TAR_OPTIONS, environment variable
1948 @anchor{TAR_OPTIONS}
1949 The @env{TAR_OPTIONS} environment variable specifies default options to
1950 be placed in front of any explicit options. For example, if
1951 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1952 if the two options @option{-v} and @option{--unlink-first} had been
1953 specified before any explicit options. Option specifications are
1954 separated by whitespace. A backslash escapes the next character, so it
1955 can be used to specify an option containing whitespace or a backslash.
1956
1957 Note that @command{tar} options are case sensitive. For example, the
1958 options @option{-T} and @option{-t} are different; the first requires an
1959 argument for stating the name of a file providing a list of @var{name}s,
1960 while the second does not require an argument and is another way to
1961 write @option{--list} (@option{-t}).
1962
1963 In addition to the eight operations, there are many options to
1964 @command{tar}, and three different styles for writing both: long (mnemonic)
1965 form, short form, and old style. These styles are discussed below.
1966 Both the options and the operations can be written in any of these three
1967 styles.
1968
1969 @FIXME{menu at end of this node. need to think of an actual outline
1970 for this chapter; probably do that after stuff from chapter 4 is
1971 incorporated.}
1972
1973 @node Styles
1974 @section The Three Option Styles
1975
1976 There are three styles for writing operations and options to the command
1977 line invoking @command{tar}. The different styles were developed at
1978 different times during the history of @command{tar}. These styles will be
1979 presented below, from the most recent to the oldest.
1980
1981 Some options must take an argument. (For example, @option{--file}
1982 (@option{-f})) takes the name of an archive file as an argument. If
1983 you do not supply an archive file name, @command{tar} will use a
1984 default, but this can be confusing; thus, we recommend that you always
1985 supply a specific archive file name.) Where you @emph{place} the
1986 arguments generally depends on which style of options you choose. We
1987 will detail specific information relevant to each option style in the
1988 sections on the different option styles, below. The differences are
1989 subtle, yet can often be very important; incorrect option placement
1990 can cause you to overwrite a number of important files. We urge you
1991 to note these differences, and only use the option style(s) which
1992 makes the most sense to you until you feel comfortable with the others.
1993
1994 Some options @emph{may} take an argument. Such options may have at
1995 most long and short forms, they do not have old style equivalent. The
1996 rules for specifying an argument for such options are stricter than
1997 those for specifying mandatory arguments. Please, pay special
1998 attention to them.
1999
2000 @menu
2001 * Long Options:: Long Option Style
2002 * Short Options:: Short Option Style
2003 * Old Options:: Old Option Style
2004 * Mixing:: Mixing Option Styles
2005 @end menu
2006
2007 @node Long Options
2008 @subsection Long Option Style
2009
2010 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2011 dashes in a row, e.g., @option{--list}. The long names are more clear than
2012 their corresponding short or old names. It sometimes happens that a
2013 single long option has many different names which are
2014 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2015 long option names can be given unique abbreviations. For example,
2016 @option{--cre} can be used in place of @option{--create} because there is no
2017 other long option which begins with @samp{cre}. (One way to find
2018 this out is by trying it and seeing what happens; if a particular
2019 abbreviation could represent more than one option, @command{tar} will tell
2020 you that that abbreviation is ambiguous and you'll know that that
2021 abbreviation won't work. You may also choose to run @samp{tar --help}
2022 to see a list of options. Be aware that if you run @command{tar} with a
2023 unique abbreviation for the long name of an option you didn't want to
2024 use, you are stuck; @command{tar} will perform the command as ordered.)
2025
2026 Long options are meant to be obvious and easy to remember, and their
2027 meanings are generally easier to discern than those of their
2028 corresponding short options (see below). For example:
2029
2030 @smallexample
2031 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2032 @end smallexample
2033
2034 @noindent
2035 gives a fairly good set of hints about what the command does, even
2036 for those not fully acquainted with @command{tar}.
2037
2038 Long options which require arguments take those arguments
2039 immediately following the option name. There are two ways of
2040 specifying a mandatory argument. It can be separated from the
2041 option name either by an equal sign, or by any amount of
2042 white space characters. For example, the @option{--file} option (which
2043 tells the name of the @command{tar} archive) is given a file such as
2044 @file{archive.tar} as argument by using any of the following notations:
2045 @option{--file=archive.tar} or @option{--file archive.tar}.
2046
2047 In contrast, optional arguments must always be introduced using
2048 an equal sign. For example, the @option{--backup} option takes
2049 an optional argument specifying backup type. It must be used
2050 as @option{--backup=@var{backup-type}}.
2051
2052 @node Short Options
2053 @subsection Short Option Style
2054
2055 Most options also have a @dfn{short option} name. Short options start with
2056 a single dash, and are followed by a single character, e.g., @option{-t}
2057 (which is equivalent to @option{--list}). The forms are absolutely
2058 identical in function; they are interchangeable.
2059
2060 The short option names are faster to type than long option names.
2061
2062 Short options which require arguments take their arguments immediately
2063 following the option, usually separated by white space. It is also
2064 possible to stick the argument right after the short option name, using
2065 no intervening space. For example, you might write @w{@option{-f
2066 archive.tar}} or @option{-farchive.tar} instead of using
2067 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2068 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2069 specific archive, here named @file{archive.tar}.
2070
2071 Short options which take optional arguments take their arguments
2072 immediately following the option letter, @emph{without any intervening
2073 white space characters}.
2074
2075 Short options' letters may be clumped together, but you are not
2076 required to do this (as compared to old options; see below). When
2077 short options are clumped as a set, use one (single) dash for them
2078 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2079 such a set is allowed to have an argument@footnote{Clustering many
2080 options, the last of which has an argument, is a rather opaque way to
2081 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2082 even be made helpful enough for considering such usages as invalid.}.
2083
2084 When the options are separated, the argument for each option which requires
2085 an argument directly follows that option, as is usual for Unix programs.
2086 For example:
2087
2088 @smallexample
2089 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2090 @end smallexample
2091
2092 If you reorder short options' locations, be sure to move any arguments
2093 that belong to them. If you do not move the arguments properly, you may
2094 end up overwriting files.
2095
2096 @node Old Options
2097 @subsection Old Option Style
2098 @UNREVISED
2099
2100 Like short options, @dfn{old options} are single letters. However, old options
2101 must be written together as a single clumped set, without spaces separating
2102 them or dashes preceding them@footnote{Beware that if you precede options
2103 with a dash, you are announcing the short option style instead of the
2104 old option style; short options are decoded differently.}. This set
2105 of letters must be the first to appear on the command line, after the
2106 @command{tar} program name and some white space; old options cannot appear
2107 anywhere else. The letter of an old option is exactly the same letter as
2108 the corresponding short option. For example, the old option @samp{t} is
2109 the same as the short option @option{-t}, and consequently, the same as the
2110 long option @option{--list}. So for example, the command @w{@samp{tar
2111 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2112
2113 When options that need arguments are given together with the command,
2114 all the associated arguments follow, in the same order as the options.
2115 Thus, the example given previously could also be written in the old
2116 style as follows:
2117
2118 @smallexample
2119 $ @kbd{tar cvbf 20 /dev/rmt0}
2120 @end smallexample
2121
2122 @noindent
2123 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2124 the argument of @option{-f}.
2125
2126 On the other hand, this old style syntax makes it difficult to match
2127 option letters with their corresponding arguments, and is often
2128 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2129 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2130 argument for @option{-f}, and @option{-v} does not have a corresponding
2131 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2132 /dev/rmt0}} is clearer, putting all arguments next to the option they
2133 pertain to.
2134
2135 If you want to reorder the letters in the old option argument, be
2136 sure to reorder any corresponding argument appropriately.
2137
2138 This old way of writing @command{tar} options can surprise even experienced
2139 users. For example, the two commands:
2140
2141 @smallexample
2142 @kbd{tar cfz archive.tar.gz file}
2143 @kbd{tar -cfz archive.tar.gz file}
2144 @end smallexample
2145
2146 @noindent
2147 are quite different. The first example uses @file{archive.tar.gz} as
2148 the value for option @samp{f} and recognizes the option @samp{z}. The
2149 second example, however, uses @file{z} as the value for option
2150 @samp{f} --- probably not what was intended.
2151
2152 Old options are kept for compatibility with old versions of @command{tar}.
2153
2154 This second example could be corrected in many ways, among which the
2155 following are equivalent:
2156
2157 @smallexample
2158 @kbd{tar -czf archive.tar.gz file}
2159 @kbd{tar -cf archive.tar.gz -z file}
2160 @kbd{tar cf archive.tar.gz -z file}
2161 @end smallexample
2162
2163 @cindex option syntax, traditional
2164 As far as we know, all @command{tar} programs, @acronym{GNU} and
2165 non-@acronym{GNU}, support old options. @GNUTAR{}
2166 supports them not only for historical reasons, but also because many
2167 people are used to them. For compatibility with Unix @command{tar},
2168 the first argument is always treated as containing command and option
2169 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2170 equivalent to @w{@samp{tar -c}:} both of them specify the
2171 @option{--create} (@option{-c}) command to create an archive.
2172
2173 @node Mixing
2174 @subsection Mixing Option Styles
2175
2176 All three styles may be intermixed in a single @command{tar} command,
2177 so long as the rules for each style are fully
2178 respected@footnote{Before @GNUTAR{} version 1.11.6,
2179 a bug prevented intermixing old style options with long options in
2180 some cases.}. Old style options and either of the modern styles of
2181 options may be mixed within a single @command{tar} command. However,
2182 old style options must be introduced as the first arguments only,
2183 following the rule for old options (old options must appear directly
2184 after the @command{tar} command and some white space). Modern options
2185 may be given only after all arguments to the old options have been
2186 collected. If this rule is not respected, a modern option might be
2187 falsely interpreted as the value of the argument to one of the old
2188 style options.
2189
2190 For example, all the following commands are wholly equivalent, and
2191 illustrate the many combinations and orderings of option styles.
2192
2193 @smallexample
2194 @kbd{tar --create --file=archive.tar}
2195 @kbd{tar --create -f archive.tar}
2196 @kbd{tar --create -farchive.tar}
2197 @kbd{tar --file=archive.tar --create}
2198 @kbd{tar --file=archive.tar -c}
2199 @kbd{tar -c --file=archive.tar}
2200 @kbd{tar -c -f archive.tar}
2201 @kbd{tar -c -farchive.tar}
2202 @kbd{tar -cf archive.tar}
2203 @kbd{tar -cfarchive.tar}
2204 @kbd{tar -f archive.tar --create}
2205 @kbd{tar -f archive.tar -c}
2206 @kbd{tar -farchive.tar --create}
2207 @kbd{tar -farchive.tar -c}
2208 @kbd{tar c --file=archive.tar}
2209 @kbd{tar c -f archive.tar}
2210 @kbd{tar c -farchive.tar}
2211 @kbd{tar cf archive.tar}
2212 @kbd{tar f archive.tar --create}
2213 @kbd{tar f archive.tar -c}
2214 @kbd{tar fc archive.tar}
2215 @end smallexample
2216
2217 On the other hand, the following commands are @emph{not} equivalent to
2218 the previous set:
2219
2220 @smallexample
2221 @kbd{tar -f -c archive.tar}
2222 @kbd{tar -fc archive.tar}
2223 @kbd{tar -fcarchive.tar}
2224 @kbd{tar -farchive.tarc}
2225 @kbd{tar cfarchive.tar}
2226 @end smallexample
2227
2228 @noindent
2229 These last examples mean something completely different from what the
2230 user intended (judging based on the example in the previous set which
2231 uses long options, whose intent is therefore very clear). The first
2232 four specify that the @command{tar} archive would be a file named
2233 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2234 respectively. The first two examples also specify a single non-option,
2235 @var{name} argument having the value @samp{archive.tar}. The last
2236 example contains only old style option letters (repeating option
2237 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2238 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2239 the first sentence of this paragraph..}
2240
2241 @node All Options
2242 @section All @command{tar} Options
2243
2244 The coming manual sections contain an alphabetical listing of all
2245 @command{tar} operations and options, with brief descriptions and cross
2246 references to more in-depth explanations in the body of the manual.
2247 They also contain an alphabetically arranged table of the short option
2248 forms with their corresponding long option. You can use this table as
2249 a reference for deciphering @command{tar} commands in scripts.
2250
2251 @menu
2252 * Operation Summary::
2253 * Option Summary::
2254 * Short Option Summary::
2255 @end menu
2256
2257 @node Operation Summary
2258 @subsection Operations
2259
2260 @table @option
2261
2262 @opsummary{append}
2263 @item --append
2264 @itemx -r
2265
2266 Appends files to the end of the archive. @xref{append}.
2267
2268 @opsummary{catenate}
2269 @item --catenate
2270 @itemx -A
2271
2272 Same as @option{--concatenate}. @xref{concatenate}.
2273
2274 @opsummary{compare}
2275 @item --compare
2276 @itemx -d
2277
2278 Compares archive members with their counterparts in the file
2279 system, and reports differences in file size, mode, owner,
2280 modification date and contents. @xref{compare}.
2281
2282 @opsummary{concatenate}
2283 @item --concatenate
2284 @itemx -A
2285
2286 Appends other @command{tar} archives to the end of the archive.
2287 @xref{concatenate}.
2288
2289 @opsummary{create}
2290 @item --create
2291 @itemx -c
2292
2293 Creates a new @command{tar} archive. @xref{create}.
2294
2295 @opsummary{delete}
2296 @item --delete
2297
2298 Deletes members from the archive. Don't try this on a archive on a
2299 tape! @xref{delete}.
2300
2301 @opsummary{diff}
2302 @item --diff
2303 @itemx -d
2304
2305 Same @option{--compare}. @xref{compare}.
2306
2307 @opsummary{extract}
2308 @item --extract
2309 @itemx -x
2310
2311 Extracts members from the archive into the file system. @xref{extract}.
2312
2313 @opsummary{get}
2314 @item --get
2315 @itemx -x
2316
2317 Same as @option{--extract}. @xref{extract}.
2318
2319 @opsummary{list}
2320 @item --list
2321 @itemx -t
2322
2323 Lists the members in an archive. @xref{list}.
2324
2325 @opsummary{update}
2326 @item --update
2327 @itemx -u
2328
2329 Adds files to the end of the archive, but only if they are newer than
2330 their counterparts already in the archive, or if they do not already
2331 exist in the archive. @xref{update}.
2332
2333 @end table
2334
2335 @node Option Summary
2336 @subsection @command{tar} Options
2337
2338 @table @option
2339
2340 @opsummary{absolute-names}
2341 @item --absolute-names
2342 @itemx -P
2343
2344 Normally when creating an archive, @command{tar} strips an initial
2345 @samp{/} from member names. This option disables that behavior.
2346 @xref{absolute}.
2347
2348 @opsummary{after-date}
2349 @item --after-date
2350
2351 (See @option{--newer}, @pxref{after})
2352
2353 @opsummary{anchored}
2354 @item --anchored
2355 A pattern must match an initial subsequence of the name's components.
2356 @xref{controlling pattern-matching}.
2357
2358 @opsummary{atime-preserve}
2359 @item --atime-preserve
2360 @itemx --atime-preserve=replace
2361 @itemx --atime-preserve=system
2362
2363 Attempt to preserve the access time of files when reading them. This
2364 option currently is effective only on files that you own, unless you
2365 have superuser privileges.
2366
2367 @option{--atime-preserve=replace} remembers the access time of a file
2368 before reading it, and then restores the access time afterwards. This
2369 may cause problems if other programs are reading the file at the same
2370 time, as the times of their accesses will be lost. On most platforms
2371 restoring the access time also requires @command{tar} to restore the
2372 data modification time too, so this option may also cause problems if
2373 other programs are writing the file at the same time. (Tar attempts
2374 to detect this situation, but cannot do so reliably due to race
2375 conditions.) Worse, on most platforms restoring the access time also
2376 updates the status change time, which means that this option is
2377 incompatible with incremental backups.
2378
2379 @option{--atime-preserve=system} avoids changing time stamps on files,
2380 without interfering with time stamp updates
2381 caused by other programs, so it works better with incremental backups.
2382 However, it requires a special @code{O_NOATIME} option from the
2383 underlying operating and file system implementation, and it also requires
2384 that searching directories does not update their access times. As of
2385 this writing (November 2005) this works only with Linux, and only with
2386 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2387 way to know whether this feature actually works. Sometimes
2388 @command{tar} knows that it does not work, and if you use
2389 @option{--atime-preserve=system} then @command{tar} complains and
2390 exits right away. But other times @command{tar} might think that the
2391 option works when it actually does not.
2392
2393 Currently @option{--atime-preserve} with no operand defaults to
2394 @option{--atime-preserve=replace}, but this may change in the future
2395 as support for @option{--atime-preserve=system} improves.
2396
2397 If your operating system does not support
2398 @option{--atime-preserve=@-system}, you might be able to preserve access
2399 times reliably by by using the @command{mount} command. For example,
2400 you can mount the file system read-only, or access the file system via
2401 a read-only loopback mount, or use the @samp{noatime} mount option
2402 available on some systems. However, mounting typically requires
2403 superuser privileges and can be a pain to manage.
2404
2405 @opsummary{auto-compress}
2406 @item --auto-compress
2407 @itemx -a
2408
2409 During a @option{--create} operation, enables automatic compressed
2410 format recognition based on the archive suffix. @xref{gzip}.
2411
2412 @opsummary{backup}
2413 @item --backup=@var{backup-type}
2414
2415 Rather than deleting files from the file system, @command{tar} will
2416 back them up using simple or numbered backups, depending upon
2417 @var{backup-type}. @xref{backup}.
2418
2419 @opsummary{block-number}
2420 @item --block-number
2421 @itemx -R
2422
2423 With this option present, @command{tar} prints error messages for read errors
2424 with the block number in the archive file. @xref{block-number}.
2425
2426 @opsummary{blocking-factor}
2427 @item --blocking-factor=@var{blocking}
2428 @itemx -b @var{blocking}
2429
2430 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2431 record. @xref{Blocking Factor}.
2432
2433 @opsummary{bzip2}
2434 @item --bzip2
2435 @itemx -j
2436
2437 This option tells @command{tar} to read or write archives through
2438 @code{bzip2}. @xref{gzip}.
2439
2440 @opsummary{checkpoint}
2441 @item --checkpoint[=@var{number}]
2442
2443 This option directs @command{tar} to print periodic checkpoint
2444 messages as it reads through the archive. It is intended for when you
2445 want a visual indication that @command{tar} is still running, but
2446 don't want to see @option{--verbose} output. For a detailed
2447 description, see @ref{Progress information}.
2448
2449 @opsummary{check-links}
2450 @item --check-links
2451 @itemx -l
2452 If this option was given, @command{tar} will check the number of links
2453 dumped for each processed file. If this number does not match the
2454 total number of hard links for the file, a warning message will be
2455 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2456 synonym for @option{--one-file-system}. The current semantics, which
2457 complies to UNIX98, was introduced with version
2458 1.15.91. @xref{Changes}, for more information.}.
2459
2460 @opsummary{compress}
2461 @opsummary{uncompress}
2462 @item --compress
2463 @itemx --uncompress
2464 @itemx -Z
2465
2466 @command{tar} will use the @command{compress} program when reading or
2467 writing the archive. This allows you to directly act on archives
2468 while saving space. @xref{gzip}.
2469
2470 @opsummary{confirmation}
2471 @item --confirmation
2472
2473 (See @option{--interactive}.) @xref{interactive}.
2474
2475 @opsummary{delay-directory-restore}
2476 @item --delay-directory-restore
2477
2478 Delay setting modification times and permissions of extracted
2479 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2480
2481 @opsummary{dereference}
2482 @item --dereference
2483 @itemx -h
2484
2485 When creating a @command{tar} archive, @command{tar} will archive the
2486 file that a symbolic link points to, rather than archiving the
2487 symlink. @xref{dereference}.
2488
2489 @opsummary{directory}
2490 @item --directory=@var{dir}
2491 @itemx -C @var{dir}
2492
2493 When this option is specified, @command{tar} will change its current directory
2494 to @var{dir} before performing any operations. When this option is used
2495 during archive creation, it is order sensitive. @xref{directory}.
2496
2497 @opsummary{exclude}
2498 @item --exclude=@var{pattern}
2499
2500 When performing operations, @command{tar} will skip files that match
2501 @var{pattern}. @xref{exclude}.
2502
2503 @opsummary{exclude-from}
2504 @item --exclude-from=@var{file}
2505 @itemx -X @var{file}
2506
2507 Similar to @option{--exclude}, except @command{tar} will use the list of
2508 patterns in the file @var{file}. @xref{exclude}.
2509
2510 @opsummary{exclude-caches}
2511 @item --exclude-caches
2512
2513 Exclude from dump any directory containing a valid cache directory
2514 tag file, but still dump the directory node and the tag file itself.
2515
2516 @xref{exclude}.
2517
2518 @opsummary{exclude-caches-under}
2519 @item --exclude-caches-under
2520
2521 Exclude from dump any directory containing a valid cache directory
2522 tag file, but still dump the directory node itself.
2523
2524 @xref{exclude}.
2525
2526 @opsummary{exclude-caches-all}
2527 @item --exclude-caches-all
2528
2529 Exclude from dump any directory containing a valid cache directory
2530 tag file. @xref{exclude}.
2531
2532 @opsummary{exclude-tag}
2533 @item --exclude-tag=@var{file}
2534
2535 Exclude from dump any directory containing file named @var{file}, but
2536 dump the directory node and @var{file} itself. @xref{exclude}.
2537
2538 @opsummary{exclude-tag-under}
2539 @item --exclude-tag-under=@var{file}
2540
2541 Exclude from dump the contents of any directory containing file
2542 named @var{file}, but dump the directory node itself. @xref{exclude}.
2543
2544 @opsummary{exclude-tag-all}
2545 @item --exclude-tag-all=@var{file}
2546
2547 Exclude from dump any directory containing file named @var{file}.
2548 @xref{exclude}.
2549
2550 @opsummary{exclude-vcs}
2551 @item --exclude-vcs
2552
2553 Exclude from dump directories and files, that are internal for some
2554 widely used version control systems.
2555
2556 @xref{exclude}.
2557
2558 @opsummary{file}
2559 @item --file=@var{archive}
2560 @itemx -f @var{archive}
2561
2562 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2563 performs operations on, rather than @command{tar}'s compilation dependent
2564 default. @xref{file tutorial}.
2565
2566 @opsummary{files-from}
2567 @item --files-from=@var{file}
2568 @itemx -T @var{file}
2569
2570 @command{tar} will use the contents of @var{file} as a list of archive members
2571 or files to operate on, in addition to those specified on the
2572 command-line. @xref{files}.
2573
2574 @opsummary{force-local}
2575 @item --force-local
2576
2577 Forces @command{tar} to interpret the file name given to @option{--file}
2578 as a local file, even if it looks like a remote tape drive name.
2579 @xref{local and remote archives}.
2580
2581 @opsummary{format}
2582 @item --format=@var{format}
2583 @itemx -H @var{format}
2584
2585 Selects output archive format. @var{Format} may be one of the
2586 following:
2587
2588 @table @samp
2589 @item v7
2590 Creates an archive that is compatible with Unix V7 @command{tar}.
2591
2592 @item oldgnu
2593 Creates an archive that is compatible with GNU @command{tar} version
2594 1.12 or earlier.
2595
2596 @item gnu
2597 Creates archive in GNU tar 1.13 format. Basically it is the same as
2598 @samp{oldgnu} with the only difference in the way it handles long
2599 numeric fields.
2600
2601 @item ustar
2602 Creates a @acronym{POSIX.1-1988} compatible archive.
2603
2604 @item posix
2605 Creates a @acronym{POSIX.1-2001 archive}.
2606
2607 @end table
2608
2609 @xref{Formats}, for a detailed discussion of these formats.
2610
2611 @opsummary{group}
2612 @item --group=@var{group}
2613
2614 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2615 rather than the group from the source file. @var{group} is first decoded
2616 as a group symbolic name, but if this interpretation fails, it has to be
2617 a decimal numeric group @acronym{ID}. @xref{override}.
2618
2619 Also see the comments for the @option{--owner=@var{user}} option.
2620
2621 @opsummary{gzip}
2622 @opsummary{gunzip}
2623 @opsummary{ungzip}
2624 @item --gzip
2625 @itemx --gunzip
2626 @itemx --ungzip
2627 @itemx -z
2628
2629 This option tells @command{tar} to read or write archives through
2630 @command{gzip}, allowing @command{tar} to directly operate on several
2631 kinds of compressed archives transparently. @xref{gzip}.
2632
2633 @opsummary{help}
2634 @item --help
2635 @itemx -?
2636
2637 @command{tar} will print out a short message summarizing the operations and
2638 options to @command{tar} and exit. @xref{help}.
2639
2640 @opsummary{ignore-case}
2641 @item --ignore-case
2642 Ignore case when matching member or file names with
2643 patterns. @xref{controlling pattern-matching}.
2644
2645 @opsummary{ignore-command-error}
2646 @item --ignore-command-error
2647 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2648
2649 @opsummary{ignore-failed-read}
2650 @item --ignore-failed-read
2651
2652 Do not exit unsuccessfully merely because an unreadable file was encountered.
2653 @xref{Reading}.
2654
2655 @opsummary{ignore-zeros}
2656 @item --ignore-zeros
2657 @itemx -i
2658
2659 With this option, @command{tar} will ignore zeroed blocks in the
2660 archive, which normally signals EOF. @xref{Reading}.
2661
2662 @opsummary{incremental}
2663 @item --incremental
2664 @itemx -G
2665
2666 Informs @command{tar} that it is working with an old
2667 @acronym{GNU}-format incremental backup archive. It is intended
2668 primarily for backwards compatibility only. @xref{Incremental Dumps},
2669 for a detailed discussion of incremental archives.
2670
2671 @opsummary{index-file}
2672 @item --index-file=@var{file}
2673
2674 Send verbose output to @var{file} instead of to standard output.
2675
2676 @opsummary{info-script}
2677 @opsummary{new-volume-script}
2678 @item --info-script=@var{script-file}
2679 @itemx --new-volume-script=@var{script-file}
2680 @itemx -F @var{script-file}
2681
2682 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2683 at the end of each tape. If @var{script-file} exits with nonzero status,
2684 @command{tar} fails immediately. @xref{info-script}, for a detailed
2685 discussion of @var{script-file}.
2686
2687 @opsummary{interactive}
2688 @item --interactive
2689 @itemx --confirmation
2690 @itemx -w
2691
2692 Specifies that @command{tar} should ask the user for confirmation before
2693 performing potentially destructive options, such as overwriting files.
2694 @xref{interactive}.
2695
2696 @opsummary{keep-newer-files}
2697 @item --keep-newer-files
2698
2699 Do not replace existing files that are newer than their archive copies
2700 when extracting files from an archive.
2701
2702 @opsummary{keep-old-files}
2703 @item --keep-old-files
2704 @itemx -k
2705
2706 Do not overwrite existing files when extracting files from an archive.
2707 @xref{Keep Old Files}.
2708
2709 @opsummary{label}
2710 @item --label=@var{name}
2711 @itemx -V @var{name}
2712
2713 When creating an archive, instructs @command{tar} to write @var{name}
2714 as a name record in the archive. When extracting or listing archives,
2715 @command{tar} will only operate on archives that have a label matching
2716 the pattern specified in @var{name}. @xref{Tape Files}.
2717
2718 @opsummary{listed-incremental}
2719 @item --listed-incremental=@var{snapshot-file}
2720 @itemx -g @var{snapshot-file}
2721
2722 During a @option{--create} operation, specifies that the archive that
2723 @command{tar} creates is a new @acronym{GNU}-format incremental
2724 backup, using @var{snapshot-file} to determine which files to backup.
2725 With other operations, informs @command{tar} that the archive is in
2726 incremental format. @xref{Incremental Dumps}.
2727
2728 @opsummary{lzma}
2729 @item --lzma
2730
2731 This option tells @command{tar} to read or write archives through
2732 @command{lzma}. @xref{gzip}.
2733
2734 @opsummary{mode}
2735 @item --mode=@var{permissions}
2736
2737 When adding files to an archive, @command{tar} will use
2738 @var{permissions} for the archive members, rather than the permissions
2739 from the files. @var{permissions} can be specified either as an octal
2740 number or as symbolic permissions, like with
2741 @command{chmod}. @xref{override}.
2742
2743 @opsummary{mtime}
2744 @item --mtime=@var{date}
2745
2746 When adding files to an archive, @command{tar} will use @var{date} as
2747 the modification time of members when creating archives, instead of
2748 their actual modification times. The value of @var{date} can be
2749 either a textual date representation (@pxref{Date input formats}) or a
2750 name of the existing file, starting with @samp{/} or @samp{.}. In the
2751 latter case, the modification time of that file is used. @xref{override}.
2752
2753 @opsummary{multi-volume}
2754 @item --multi-volume
2755 @itemx -M
2756
2757 Informs @command{tar} that it should create or otherwise operate on a
2758 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2759
2760 @opsummary{new-volume-script}
2761 @item --new-volume-script
2762
2763 (see --info-script)
2764
2765 @opsummary{newer}
2766 @item --newer=@var{date}
2767 @itemx --after-date=@var{date}
2768 @itemx -N
2769
2770 When creating an archive, @command{tar} will only add files that have changed
2771 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2772 is taken to be the name of a file whose data modification time specifies
2773 the date. @xref{after}.
2774
2775 @opsummary{newer-mtime}
2776 @item --newer-mtime=@var{date}
2777
2778 Like @option{--newer}, but add only files whose
2779 contents have changed (as opposed to just @option{--newer}, which will
2780 also back up files for which any status information has
2781 changed). @xref{after}.
2782
2783 @opsummary{no-anchored}
2784 @item --no-anchored
2785 An exclude pattern can match any subsequence of the name's components.
2786 @xref{controlling pattern-matching}.
2787
2788 @opsummary{no-delay-directory-restore}
2789 @item --no-delay-directory-restore
2790
2791 Modification times and permissions of extracted
2792 directories are set when all files from this directory have been
2793 extracted. This is the default.
2794 @xref{Directory Modification Times and Permissions}.
2795
2796 @opsummary{no-ignore-case}
2797 @item --no-ignore-case
2798 Use case-sensitive matching.
2799 @xref{controlling pattern-matching}.
2800
2801 @opsummary{no-ignore-command-error}
2802 @item --no-ignore-command-error
2803 Print warnings about subprocesses that terminated with a nonzero exit
2804 code. @xref{Writing to an External Program}.
2805
2806 @opsummary{no-overwrite-dir}
2807 @item --no-overwrite-dir
2808
2809 Preserve metadata of existing directories when extracting files
2810 from an archive. @xref{Overwrite Old Files}.
2811
2812 @opsummary{no-quote-chars}
2813 @item --no-quote-chars=@var{string}
2814 Remove characters listed in @var{string} from the list of quoted
2815 characters set by the previous @option{--quote-chars} option
2816 (@pxref{quoting styles}).
2817
2818 @opsummary{no-recursion}
2819 @item --no-recursion
2820
2821 With this option, @command{tar} will not recurse into directories.
2822 @xref{recurse}.
2823
2824 @opsummary{no-same-owner}
2825 @item --no-same-owner
2826 @itemx -o
2827
2828 When extracting an archive, do not attempt to preserve the owner
2829 specified in the @command{tar} archive. This the default behavior
2830 for ordinary users.
2831
2832 @opsummary{no-same-permissions}
2833 @item --no-same-permissions
2834
2835 When extracting an archive, subtract the user's umask from files from
2836 the permissions specified in the archive. This is the default behavior
2837 for ordinary users.
2838
2839 @opsummary{no-unquote}
2840 @item --no-unquote
2841 Treat all input file or member names literally, do not interpret
2842 escape sequences. @xref{input name quoting}.
2843
2844 @opsummary{no-wildcards}
2845 @item --no-wildcards
2846 Do not use wildcards.
2847 @xref{controlling pattern-matching}.
2848
2849 @opsummary{no-wildcards-match-slash}
2850 @item --no-wildcards-match-slash
2851 Wildcards do not match @samp{/}.
2852 @xref{controlling pattern-matching}.
2853
2854 @opsummary{null}
2855 @item --null
2856
2857 When @command{tar} is using the @option{--files-from} option, this option
2858 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
2859 @command{tar} can correctly work with file names that contain newlines.
2860 @xref{nul}.
2861
2862 @opsummary{numeric-owner}
2863 @item --numeric-owner
2864
2865 This option will notify @command{tar} that it should use numeric user
2866 and group IDs when creating a @command{tar} file, rather than names.
2867 @xref{Attributes}.
2868
2869 @item -o
2870 The function of this option depends on the action @command{tar} is
2871 performing. When extracting files, @option{-o} is a synonym for
2872 @option{--no-same-owner}, i.e., it prevents @command{tar} from
2873 restoring ownership of files being extracted.
2874
2875 When creating an archive, it is a synonym for
2876 @option{--old-archive}. This behavior is for compatibility
2877 with previous versions of @GNUTAR{}, and will be
2878 removed in future releases.
2879
2880 @xref{Changes}, for more information.
2881
2882 @opsummary{occurrence}
2883 @item --occurrence[=@var{number}]
2884
2885 This option can be used in conjunction with one of the subcommands
2886 @option{--delete}, @option{--diff}, @option{--extract} or
2887 @option{--list} when a list of files is given either on the command
2888 line or via @option{-T} option.
2889
2890 This option instructs @command{tar} to process only the @var{number}th
2891 occurrence of each named file. @var{Number} defaults to 1, so
2892
2893 @smallexample
2894 tar -x -f archive.tar --occurrence filename
2895 @end smallexample
2896
2897 @noindent
2898 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2899 and will terminate without scanning to the end of the archive.
2900
2901 @opsummary{old-archive}
2902 @item --old-archive
2903 Synonym for @option{--format=v7}.
2904
2905 @opsummary{one-file-system}
2906 @item --one-file-system
2907 Used when creating an archive. Prevents @command{tar} from recursing into
2908 directories that are on different file systems from the current
2909 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2910 synonym for @option{--one-file-system}. This has changed in version
2911 1.15.91. @xref{Changes}, for more information.}.
2912
2913 @opsummary{overwrite}
2914 @item --overwrite
2915
2916 Overwrite existing files and directory metadata when extracting files
2917 from an archive. @xref{Overwrite Old Files}.
2918
2919 @opsummary{overwrite-dir}
2920 @item --overwrite-dir
2921
2922 Overwrite the metadata of existing directories when extracting files
2923 from an archive. @xref{Overwrite Old Files}.
2924
2925 @opsummary{owner}
2926 @item --owner=@var{user}
2927
2928 Specifies that @command{tar} should use @var{user} as the owner of members
2929 when creating archives, instead of the user associated with the source
2930 file. @var{user} is first decoded as a user symbolic name, but if
2931 this interpretation fails, it has to be a decimal numeric user @acronym{ID}.
2932 @xref{override}.
2933
2934 This option does not affect extraction from archives.
2935
2936 @opsummary{pax-option}
2937 @item --pax-option=@var{keyword-list}
2938 This option is meaningful only with @acronym{POSIX.1-2001} archives
2939 (@pxref{posix}). It modifies the way @command{tar} handles the
2940 extended header keywords. @var{Keyword-list} is a comma-separated
2941 list of keyword options. @xref{PAX keywords}, for a detailed
2942 discussion.
2943
2944 @opsummary{portability}
2945 @item --portability
2946 @itemx --old-archive
2947 Synonym for @option{--format=v7}.
2948
2949 @opsummary{posix}
2950 @item --posix
2951 Same as @option{--format=posix}.
2952
2953 @opsummary{preserve}
2954 @item --preserve
2955
2956 Synonymous with specifying both @option{--preserve-permissions} and
2957 @option{--same-order}. @xref{Setting Access Permissions}.
2958
2959 @opsummary{preserve-order}
2960 @item --preserve-order
2961
2962 (See @option{--same-order}; @pxref{Reading}.)
2963
2964 @opsummary{preserve-permissions}
2965 @opsummary{same-permissions}
2966 @item --preserve-permissions
2967 @itemx --same-permissions
2968 @itemx -p
2969
2970 When @command{tar} is extracting an archive, it normally subtracts the
2971 users' umask from the permissions specified in the archive and uses
2972 that number as the permissions to create the destination file.
2973 Specifying this option instructs @command{tar} that it should use the
2974 permissions directly from the archive. @xref{Setting Access Permissions}.
2975
2976 @opsummary{quote-chars}
2977 @item --quote-chars=@var{string}
2978 Always quote characters from @var{string}, even if the selected
2979 quoting style would not quote them (@pxref{quoting styles}).
2980
2981 @opsummary{quoting-style}
2982 @item --quoting-style=@var{style}
2983 Set quoting style to use when printing member and file names
2984 (@pxref{quoting styles}). Valid @var{style} values are:
2985 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2986 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2987 style is @code{escape}, unless overridden while configuring the
2988 package.
2989
2990 @opsummary{read-full-records}
2991 @item --read-full-records
2992 @itemx -B
2993
2994 Specifies that @command{tar} should reblock its input, for reading
2995 from pipes on systems with buggy implementations. @xref{Reading}.
2996
2997 @opsummary{record-size}
2998 @item --record-size=@var{size}
2999
3000 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3001 archive. @xref{Blocking Factor}.
3002
3003 @opsummary{recursion}
3004 @item --recursion
3005
3006 With this option, @command{tar} recurses into directories (default).
3007 @xref{recurse}.
3008
3009 @opsummary{recursive-unlink}
3010 @item --recursive-unlink
3011
3012 Remove existing
3013 directory hierarchies before extracting directories of the same name
3014 from the archive. @xref{Recursive Unlink}.
3015
3016 @opsummary{remove-files}
3017 @item --remove-files
3018
3019 Directs @command{tar} to remove the source file from the file system after
3020 appending it to an archive. @xref{remove files}.
3021
3022 @opsummary{restrict}
3023 @item --restrict
3024
3025 Disable use of some potentially harmful @command{tar} options.
3026 Currently this option disables shell invocation from multi-volume menu
3027 (@pxref{Using Multiple Tapes}).
3028
3029 @opsummary{rmt-command}
3030 @item --rmt-command=@var{cmd}
3031
3032 Notifies @command{tar} that it should use @var{cmd} instead of
3033 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3034
3035 @opsummary{rsh-command}
3036 @item --rsh-command=@var{cmd}
3037
3038 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3039 devices. @xref{Device}.
3040
3041 @opsummary{same-order}
3042 @item --same-order
3043 @itemx --preserve-order
3044 @itemx -s
3045
3046 This option is an optimization for @command{tar} when running on machines with
3047 small amounts of memory. It informs @command{tar} that the list of file
3048 arguments has already been sorted to match the order of files in the
3049 archive. @xref{Reading}.
3050
3051 @opsummary{same-owner}
3052 @item --same-owner
3053
3054 When extracting an archive, @command{tar} will attempt to preserve the owner
3055 specified in the @command{tar} archive with this option present.
3056 This is the default behavior for the superuser; this option has an
3057 effect only for ordinary users. @xref{Attributes}.
3058
3059 @opsummary{same-permissions}
3060 @item --same-permissions
3061
3062 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3063
3064 @opsummary{seek}
3065 @item --seek
3066 @itemx -n
3067
3068 Assume that the archive media supports seeks to arbitrary
3069 locations. Usually @command{tar} determines automatically whether
3070 the archive can be seeked or not. This option is intended for use
3071 in cases when such recognition fails.
3072
3073 @opsummary{show-defaults}
3074 @item --show-defaults
3075
3076 Displays the default options used by @command{tar} and exits
3077 successfully. This option is intended for use in shell scripts.
3078 Here is an example of what you can see using this option:
3079
3080 @smallexample
3081 $ tar --show-defaults
3082 --format=gnu -f- -b20 --quoting-style=escape \
3083 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3084 @end smallexample
3085
3086 @opsummary{show-omitted-dirs}
3087 @item --show-omitted-dirs
3088
3089 Instructs @command{tar} to mention the directories it is skipping when
3090 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3091
3092 @opsummary{show-transformed-names}
3093 @opsummary{show-stored-names}
3094 @item --show-transformed-names
3095 @itemx --show-stored-names
3096
3097 Display file or member names after applying any transformations
3098 (@pxref{transform}). In particular, when used in conjunction with one of
3099 the archive creation operations it instructs @command{tar} to list the
3100 member names stored in the archive, as opposed to the actual file
3101 names. @xref{listing member and file names}.
3102
3103 @opsummary{sparse}
3104 @item --sparse
3105 @itemx -S
3106
3107 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3108 sparse files efficiently. @xref{sparse}.
3109
3110 @opsummary{sparse-version}
3111 @item --sparse-version=@var{version}
3112
3113 Specifies the @dfn{format version} to use when archiving sparse
3114 files. Implies @option{--sparse}. @xref{sparse}. For the description
3115 of the supported sparse formats, @xref{Sparse Formats}.
3116
3117 @opsummary{starting-file}
3118 @item --starting-file=@var{name}
3119 @itemx -K @var{name}
3120
3121 This option affects extraction only; @command{tar} will skip extracting
3122 files in the archive until it finds one that matches @var{name}.
3123 @xref{Scarce}.
3124
3125 @opsummary{strip-components}
3126 @item --strip-components=@var{number}
3127 Strip given @var{number} of leading components from file names before
3128 extraction. For example, if archive @file{archive.tar} contained
3129 @file{/some/file/name}, then running
3130
3131 @smallexample
3132 tar --extract --file archive.tar --strip-components=2
3133 @end smallexample
3134
3135 @noindent
3136 would extract this file to file @file{name}.
3137
3138 @opsummary{suffix}, summary
3139 @item --suffix=@var{suffix}
3140
3141 Alters the suffix @command{tar} uses when backing up files from the default
3142 @samp{~}. @xref{backup}.
3143
3144 @opsummary{tape-length}
3145 @item --tape-length=@var{num}
3146 @itemx -L @var{num}
3147
3148 Specifies the length of tapes that @command{tar} is writing as being
3149 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3150
3151 @opsummary{test-label}
3152 @item --test-label
3153
3154 Reads the volume label. If an argument is specified, test whether it
3155 matches the volume label. @xref{--test-label option}.
3156
3157 @opsummary{to-command}
3158 @item --to-command=@var{command}
3159
3160 During extraction @command{tar} will pipe extracted files to the
3161 standard input of @var{command}. @xref{Writing to an External Program}.
3162
3163 @opsummary{to-stdout}
3164 @item --to-stdout
3165 @itemx -O
3166
3167 During extraction, @command{tar} will extract files to stdout rather
3168 than to the file system. @xref{Writing to Standard Output}.
3169
3170 @opsummary{totals}
3171 @item --totals[=@var{signo}]
3172
3173 Displays the total number of bytes transferred when processing an
3174 archive. If an argument is given, these data are displayed on
3175 request, when signal @var{signo} is delivered to @command{tar}.
3176 @xref{totals}.
3177
3178 @opsummary{touch}
3179 @item --touch
3180 @itemx -m
3181
3182 Sets the data modification time of extracted files to the extraction time,
3183 rather than the data modification time stored in the archive.
3184 @xref{Data Modification Times}.
3185
3186 @opsummary{transform}
3187 @item --transform=@var{sed-expr}
3188
3189 Transform file or member names using @command{sed} replacement expression
3190 @var{sed-expr}. For example,
3191
3192 @smallexample
3193 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3194 @end smallexample
3195
3196 @noindent
3197 will add to @file{archive} files from the current working directory,
3198 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3199 discussion, @xref{transform}.
3200
3201 To see transformed member names in verbose listings, use
3202 @option{--show-transformed-names} option
3203 (@pxref{show-transformed-names}).
3204
3205 @opsummary{uncompress}
3206 @item --uncompress
3207
3208 (See @option{--compress}. @pxref{gzip})
3209
3210 @opsummary{ungzip}
3211 @item --ungzip
3212
3213 (See @option{--gzip}. @pxref{gzip})
3214
3215 @opsummary{unlink-first}
3216 @item --unlink-first
3217 @itemx -U
3218
3219 Directs @command{tar} to remove the corresponding file from the file
3220 system before extracting it from the archive. @xref{Unlink First}.
3221
3222 @opsummary{unquote}
3223 @item --unquote
3224 Enable unquoting input file or member names (default). @xref{input
3225 name quoting}.
3226
3227 @opsummary{use-compress-program}
3228 @item --use-compress-program=@var{prog}
3229
3230 Instructs @command{tar} to access the archive through @var{prog}, which is
3231 presumed to be a compression program of some sort. @xref{gzip}.
3232
3233 @opsummary{utc}
3234 @item --utc
3235
3236 Display file modification dates in @acronym{UTC}. This option implies
3237 @option{--verbose}.
3238
3239 @opsummary{verbose}
3240 @item --verbose
3241 @itemx -v
3242
3243 Specifies that @command{tar} should be more verbose about the
3244 operations it is performing. This option can be specified multiple
3245 times for some operations to increase the amount of information displayed.
3246 @xref{verbose}.
3247
3248 @opsummary{verify}
3249 @item --verify
3250 @itemx -W
3251
3252 Verifies that the archive was correctly written when creating an
3253 archive. @xref{verify}.
3254
3255 @opsummary{version}
3256 @item --version
3257
3258 Print information about the program's name, version, origin and legal
3259 status, all on standard output, and then exit successfully.
3260 @xref{help}.
3261
3262 @opsummary{volno-file}
3263 @item --volno-file=@var{file}
3264
3265 Used in conjunction with @option{--multi-volume}. @command{tar} will
3266 keep track of which volume of a multi-volume archive it is working in
3267 @var{file}. @xref{volno-file}.
3268
3269 @opsummary{wildcards}
3270 @item --wildcards
3271 Use wildcards when matching member names with patterns.
3272 @xref{controlling pattern-matching}.
3273
3274 @opsummary{wildcards-match-slash}
3275 @item --wildcards-match-slash
3276 Wildcards match @samp{/}.
3277 @xref{controlling pattern-matching}.
3278 @end table
3279
3280 @node Short Option Summary
3281 @subsection Short Options Cross Reference
3282
3283 Here is an alphabetized list of all of the short option forms, matching
3284 them with the equivalent long option.
3285
3286 @multitable @columnfractions 0.20 0.80
3287 @headitem Short Option @tab Reference
3288
3289 @item -A @tab @ref{--concatenate}.
3290
3291 @item -B @tab @ref{--read-full-records}.
3292
3293 @item -C @tab @ref{--directory}.
3294
3295 @item -F @tab @ref{--info-script}.
3296
3297 @item -G @tab @ref{--incremental}.
3298
3299 @item -K @tab @ref{--starting-file}.
3300
3301 @item -L @tab @ref{--tape-length}.
3302
3303 @item -M @tab @ref{--multi-volume}.
3304
3305 @item -N @tab @ref{--newer}.
3306
3307 @item -O @tab @ref{--to-stdout}.
3308
3309 @item -P @tab @ref{--absolute-names}.
3310
3311 @item -R @tab @ref{--block-number}.
3312
3313 @item -S @tab @ref{--sparse}.
3314
3315 @item -T @tab @ref{--files-from}.
3316
3317 @item -U @tab @ref{--unlink-first}.
3318
3319 @item -V @tab @ref{--label}.
3320
3321 @item -W @tab @ref{--verify}.
3322
3323 @item -X @tab @ref{--exclude-from}.
3324
3325 @item -Z @tab @ref{--compress}.
3326
3327 @item -b @tab @ref{--blocking-factor}.
3328
3329 @item -c @tab @ref{--create}.
3330
3331 @item -d @tab @ref{--compare}.
3332
3333 @item -f @tab @ref{--file}.
3334
3335 @item -g @tab @ref{--listed-incremental}.
3336
3337 @item -h @tab @ref{--dereference}.
3338
3339 @item -i @tab @ref{--ignore-zeros}.
3340
3341 @item -j @tab @ref{--bzip2}.
3342
3343 @item -k @tab @ref{--keep-old-files}.
3344
3345 @item -l @tab @ref{--check-links}.
3346
3347 @item -m @tab @ref{--touch}.
3348
3349 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3350 @ref{--portability}.
3351
3352 The later usage is deprecated. It is retained for compatibility with
3353 the earlier versions of @GNUTAR{}. In future releases
3354 @option{-o} will be equivalent to @option{--no-same-owner} only.
3355
3356 @item -p @tab @ref{--preserve-permissions}.
3357
3358 @item -r @tab @ref{--append}.
3359
3360 @item -s @tab @ref{--same-order}.
3361
3362 @item -t @tab @ref{--list}.
3363
3364 @item -u @tab @ref{--update}.
3365
3366 @item -v @tab @ref{--verbose}.
3367
3368 @item -w @tab @ref{--interactive}.
3369
3370 @item -x @tab @ref{--extract}.
3371
3372 @item -z @tab @ref{--gzip}.
3373
3374 @end multitable
3375
3376 @node help
3377 @section @GNUTAR{} documentation
3378
3379 @cindex Getting program version number
3380 @opindex version
3381 @cindex Version of the @command{tar} program
3382 Being careful, the first thing is really checking that you are using
3383 @GNUTAR{}, indeed. The @option{--version} option
3384 causes @command{tar} to print information about its name, version,
3385 origin and legal status, all on standard output, and then exit
3386 successfully. For example, @w{@samp{tar --version}} might print:
3387
3388 @smallexample
3389 tar (GNU tar) @value{VERSION}
3390 Copyright (C) 2006 Free Software Foundation, Inc.
3391 This is free software. You may redistribute copies of it under the terms
3392 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3393 There is NO WARRANTY, to the extent permitted by law.
3394
3395 Written by John Gilmore and Jay Fenlason.
3396 @end smallexample
3397
3398 @noindent
3399 The first occurrence of @samp{tar} in the result above is the program
3400 name in the package (for example, @command{rmt} is another program),
3401 while the second occurrence of @samp{tar} is the name of the package
3402 itself, containing possibly many programs. The package is currently
3403 named @samp{tar}, after the name of the main program it
3404 contains@footnote{There are plans to merge the @command{cpio} and
3405 @command{tar} packages into a single one which would be called
3406 @code{paxutils}. So, who knows if, one of this days, the
3407 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3408 paxutils) 3.2}}}.
3409
3410 @cindex Obtaining help
3411 @cindex Listing all @command{tar} options
3412 @xopindex{help, introduction}
3413 Another thing you might want to do is checking the spelling or meaning
3414 of some particular @command{tar} option, without resorting to this
3415 manual, for once you have carefully read it. @GNUTAR{}
3416 has a short help feature, triggerable through the
3417 @option{--help} option. By using this option, @command{tar} will
3418 print a usage message listing all available options on standard
3419 output, then exit successfully, without doing anything else and
3420 ignoring all other options. Even if this is only a brief summary, it
3421 may be several screens long. So, if you are not using some kind of
3422 scrollable window, you might prefer to use something like:
3423
3424 @smallexample
3425 $ @kbd{tar --help | less}
3426 @end smallexample
3427
3428 @noindent
3429 presuming, here, that you like using @command{less} for a pager. Other
3430 popular pagers are @command{more} and @command{pg}. If you know about some
3431 @var{keyword} which interests you and do not want to read all the
3432 @option{--help} output, another common idiom is doing:
3433
3434 @smallexample
3435 tar --help | grep @var{keyword}
3436 @end smallexample
3437
3438 @noindent
3439 for getting only the pertinent lines. Notice, however, that some
3440 @command{tar} options have long description lines and the above
3441 command will list only the first of them.
3442
3443 The exact look of the option summary displayed by @kbd{tar --help} is
3444 configurable. @xref{Configuring Help Summary}, for a detailed description.
3445
3446 @opindex usage
3447 If you only wish to check the spelling of an option, running @kbd{tar
3448 --usage} may be a better choice. This will display a terse list of
3449 @command{tar} option without accompanying explanations.
3450
3451 The short help output is quite succinct, and you might have to get
3452 back to the full documentation for precise points. If you are reading
3453 this paragraph, you already have the @command{tar} manual in some
3454 form. This manual is available in a variety of forms from
3455 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3456 distribution, provided you have @TeX{} already installed somewhere,
3457 and a laser printer around. Just configure the distribution, execute
3458 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3459 usual way (contact your local guru to know how). If @GNUTAR{}
3460 has been conveniently installed at your place, this
3461 manual is also available in interactive, hypertextual form as an Info
3462 file. Just call @w{@samp{info tar}} or, if you do not have the
3463 @command{info} program handy, use the Info reader provided within
3464 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3465
3466 There is currently no @code{man} page for @GNUTAR{}.
3467 If you observe such a @code{man} page on the system you are running,
3468 either it does not belong to @GNUTAR{}, or it has not
3469 been produced by @acronym{GNU}. Some package maintainers convert
3470 @kbd{tar --help} output to a man page, using @command{help2man}. In
3471 any case, please bear in mind that the authoritative source of
3472 information about @GNUTAR{} is this Texinfo documentation.
3473
3474 @node defaults
3475 @section Obtaining @GNUTAR{} default values
3476
3477 @opindex show-defaults
3478 @GNUTAR{} has some predefined defaults that are used when you do not
3479 explicitly specify another values. To obtain a list of such
3480 defaults, use @option{--show-defaults} option. This will output the
3481 values in the form of @command{tar} command line options:
3482
3483 @smallexample
3484 @group
3485 @kbd{tar --show-defaults}
3486 --format=gnu -f- -b20 --quoting-style=escape
3487 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3488 @end group
3489 @end smallexample
3490
3491 @noindent
3492 Notice, that this option outputs only one line. The example output above
3493 has been split to fit page boundaries.
3494
3495 @noindent
3496 The above output shows that this version of @GNUTAR{} defaults to
3497 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3498 output as the archive, if no @option{--file} option has been given
3499 (@pxref{file tutorial}), the default blocking factor is 20
3500 (@pxref{Blocking Factor}). It also shows the default locations where
3501 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3502
3503 @node verbose
3504 @section Checking @command{tar} progress
3505
3506 Typically, @command{tar} performs most operations without reporting any
3507 information to the user except error messages. When using @command{tar}
3508 with many options, particularly ones with complicated or
3509 difficult-to-predict behavior, it is possible to make serious mistakes.
3510 @command{tar} provides several options that make observing @command{tar}
3511 easier. These options cause @command{tar} to print information as it
3512 progresses in its job, and you might want to use them just for being
3513 more careful about what is going on, or merely for entertaining
3514 yourself. If you have encountered a problem when operating on an
3515 archive, however, you may need more information than just an error
3516 message in order to solve the problem. The following options can be
3517 helpful diagnostic tools.
3518
3519 @cindex Verbose operation
3520 @opindex verbose
3521 Normally, the @option{--list} (@option{-t}) command to list an archive
3522 prints just the file names (one per line) and the other commands are
3523 silent. When used with most operations, the @option{--verbose}
3524 (@option{-v}) option causes @command{tar} to print the name of each
3525 file or archive member as it is processed. This and the other options
3526 which make @command{tar} print status information can be useful in
3527 monitoring @command{tar}.
3528
3529 With @option{--create} or @option{--extract}, @option{--verbose} used
3530 once just prints the names of the files or members as they are processed.
3531 Using it twice causes @command{tar} to print a longer listing
3532 (@xref{verbose member listing}, for the description) for each member.
3533 Since @option{--list} already prints the names of the members,
3534 @option{--verbose} used once with @option{--list} causes @command{tar}
3535 to print an @samp{ls -l} type listing of the files in the archive.
3536 The following examples both extract members with long list output:
3537
3538 @smallexample
3539 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3540 $ @kbd{tar xvvf archive.tar}
3541 @end smallexample
3542
3543 Verbose output appears on the standard output except when an archive is
3544 being written to the standard output, as with @samp{tar --create
3545 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3546 installer let standard output be the default archive). In that case
3547 @command{tar} writes verbose output to the standard error stream.
3548
3549 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3550 verbose output to @var{file} rather than to standard output or standard
3551 error.
3552
3553 @anchor{totals}
3554 @cindex Obtaining total status information
3555 @opindex totals
3556 The @option{--totals} option causes @command{tar} to print on the
3557 standard error the total amount of bytes transferred when processing
3558 an archive. When creating or appending to an archive, this option
3559 prints the number of bytes written to the archive and the average
3560 speed at which they have been written, e.g.:
3561
3562 @smallexample
3563 @group
3564 $ @kbd{tar -c -f archive.tar --totals /home}
3565 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3566 @end group
3567 @end smallexample
3568
3569 When reading an archive, this option displays the number of bytes
3570 read:
3571
3572 @smallexample
3573 @group
3574 $ @kbd{tar -x -f archive.tar --totals}
3575 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3576 @end group
3577 @end smallexample
3578
3579 Finally, when deleting from an archive, the @option{--totals} option
3580 displays both numbers plus number of bytes removed from the archive:
3581
3582 @smallexample
3583 @group
3584 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3585 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3586 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3587 Total bytes deleted: 1474048
3588 @end group
3589 @end smallexample
3590
3591 You can also obtain this information on request. When
3592 @option{--totals} is used with an argument, this argument is
3593 interpreted as a symbolic name of a signal, upon delivery of which the
3594 statistics is to be printed:
3595
3596 @table @option
3597 @item --totals=@var{signo}
3598 Print statistics upon delivery of signal @var{signo}. Valid arguments
3599 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3600 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3601 accepted.
3602 @end table
3603
3604 Both forms of @option{--totals} option can be used simultaneously.
3605 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3606 extract all members from its default archive and print statistics
3607 after finishing the extraction, as well as when receiving signal
3608 @code{SIGUSR1}.
3609
3610 @anchor{Progress information}
3611 @cindex Progress information
3612 @opindex checkpoint
3613 The @option{--checkpoint} option prints an occasional message
3614 as @command{tar} reads or writes the archive. It is designed for
3615 those who don't need the more detailed (and voluminous) output of
3616 @option{--block-number} (@option{-R}), but do want visual confirmation
3617 that @command{tar} is actually making forward progress. By default it
3618 prints a message each 10 records read or written. This can be changed
3619 by giving it a numeric argument after an equal sign:
3620
3621 @smallexample
3622 $ @kbd{tar -c --checkpoint=1000} /var
3623 tar: Write checkpoint 1000
3624 tar: Write checkpoint 2000
3625 tar: Write checkpoint 3000
3626 @end smallexample
3627
3628 This example shows the default checkpoint message used by
3629 @command{tar}. If you place a dot immediately after the equal
3630 sign, it will print a @samp{.} at each checkpoint. For example:
3631
3632 @smallexample
3633 $ @kbd{tar -c --checkpoint=.1000} /var
3634 ...
3635 @end smallexample
3636
3637 @opindex show-omitted-dirs
3638 @anchor{show-omitted-dirs}
3639 The @option{--show-omitted-dirs} option, when reading an archive---with
3640 @option{--list} or @option{--extract}, for example---causes a message
3641 to be printed for each directory in the archive which is skipped.
3642 This happens regardless of the reason for skipping: the directory might
3643 not have been named on the command line (implicitly or explicitly),
3644 it might be excluded by the use of the
3645 @option{--exclude=@var{pattern}} option, or some other reason.
3646
3647 @opindex block-number
3648 @cindex Block number where error occurred
3649 @anchor{block-number}
3650 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3651 every message it would normally produce, the block number within the
3652 archive where the message was triggered. Also, supplementary messages
3653 are triggered when reading blocks full of NULs, or when hitting end of
3654 file on the archive. As of now, if the archive if properly terminated
3655 with a NUL block, the reading of the file may stop before end of file
3656 is met, so the position of end of file will not usually show when
3657 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3658 drains the archive before exiting when reading the
3659 archive from a pipe.
3660
3661 @cindex Error message, block number of
3662 This option is especially useful when reading damaged archives, since
3663 it helps pinpoint the damaged sections. It can also be used with
3664 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3665 choose among several backup tapes when retrieving a file later, in
3666 favor of the tape where the file appears earliest (closest to the
3667 front of the tape). @xref{backup}.
3668
3669 @node interactive
3670 @section Asking for Confirmation During Operations
3671 @cindex Interactive operation
3672
3673 Typically, @command{tar} carries out a command without stopping for
3674 further instructions. In some situations however, you may want to
3675 exclude some files and archive members from the operation (for instance
3676 if disk or storage space is tight). You can do this by excluding
3677 certain files automatically (@pxref{Choosing}), or by performing
3678 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3679 @command{tar} also accepts @option{--confirmation} for this option.
3680
3681 @opindex interactive
3682 When the @option{--interactive} (@option{-w}) option is specified, before
3683 reading, writing, or deleting files, @command{tar} first prints a message
3684 for each such file, telling what operation it intends to take, then asks
3685 for confirmation on the terminal. The actions which require
3686 confirmation include adding a file to the archive, extracting a file
3687 from the archive, deleting a file from the archive, and deleting a file
3688 from disk. To confirm the action, you must type a line of input
3689 beginning with @samp{y}. If your input line begins with anything other
3690 than @samp{y}, @command{tar} skips that file.
3691
3692 If @command{tar} is reading the archive from the standard input,
3693 @command{tar} opens the file @file{/dev/tty} to support the interactive
3694 communications.
3695
3696 Verbose output is normally sent to standard output, separate from
3697 other error messages. However, if the archive is produced directly
3698 on standard output, then verbose output is mixed with errors on
3699 @code{stderr}. Producing the archive on standard output may be used
3700 as a way to avoid using disk space, when the archive is soon to be
3701 consumed by another process reading it, say. Some people felt the need
3702 of producing an archive on stdout, still willing to segregate between
3703 verbose output and error output. A possible approach would be using a
3704 named pipe to receive the archive, and having the consumer process to
3705 read from that named pipe. This has the advantage of letting standard
3706 output free to receive verbose output, all separate from errors.
3707
3708 @node operations
3709 @chapter @GNUTAR{} Operations
3710
3711 @menu
3712 * Basic tar::
3713 * Advanced tar::
3714 * create options::
3715 * extract options::
3716 * backup::
3717 * Applications::
3718 * looking ahead::
3719 @end menu
3720
3721 @node Basic tar
3722 @section Basic @GNUTAR{} Operations
3723
3724 The basic @command{tar} operations, @option{--create} (@option{-c}),
3725 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3726 @option{-x}), are currently presented and described in the tutorial
3727 chapter of this manual. This section provides some complementary notes
3728 for these operations.
3729
3730 @table @option
3731 @xopindex{create, complementary notes}
3732 @item --create
3733 @itemx -c
3734
3735 Creating an empty archive would have some kind of elegance. One can
3736 initialize an empty archive and later use @option{--append}
3737 (@option{-r}) for adding all members. Some applications would not
3738 welcome making an exception in the way of adding the first archive
3739 member. On the other hand, many people reported that it is
3740 dangerously too easy for @command{tar} to destroy a magnetic tape with
3741 an empty archive@footnote{This is well described in @cite{Unix-haters
3742 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3743 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3744
3745 @enumerate
3746 @item
3747 Mistakingly using @code{create} instead of @code{extract}, when the
3748 intent was to extract the full contents of an archive. This error
3749 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3750 the QWERTY keyboard. Instead of being unpacked, the archive then
3751 gets wholly destroyed. When users speak about @dfn{exploding} an
3752 archive, they usually mean something else :-).
3753
3754 @item
3755 Forgetting the argument to @code{file}, when the intent was to create
3756 an archive with a single file in it. This error is likely because a
3757 tired user can easily add the @kbd{f} key to the cluster of option
3758 letters, by the mere force of habit, without realizing the full
3759 consequence of doing so. The usual consequence is that the single
3760 file, which was meant to be saved, is rather destroyed.
3761 @end enumerate
3762
3763 So, recognizing the likelihood and the catastrophic nature of these
3764 errors, @GNUTAR{} now takes some distance from elegance, and
3765 cowardly refuses to create an archive when @option{--create} option is
3766 given, there are no arguments besides options, and
3767 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3768 around the cautiousness of @GNUTAR{} and nevertheless create an
3769 archive with nothing in it, one may still use, as the value for the
3770 @option{--files-from} option, a file with no names in it, as shown in
3771 the following commands:
3772
3773 @smallexample
3774 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3775 @kbd{tar cfT empty-archive.tar /dev/null}
3776 @end smallexample
3777
3778 @xopindex{extract, complementary notes}
3779 @item --extract
3780 @itemx --get
3781 @itemx -x
3782
3783 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3784
3785 @item @option{--list} (@option{-t})
3786
3787 @GNUTAR{} now shows dates as @samp{1996-08-30},
3788 while it used to show them as @samp{Aug 30 1996}. Preferably,
3789 people should get used to ISO 8601 dates. Local American dates should
3790 be made available again with full date localization support, once
3791 ready. In the meantime, programs not being localizable for dates
3792 should prefer international dates, that's really the way to go.
3793
3794 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
3795 are curious, it contains a detailed explanation of the ISO 8601 standard.
3796
3797 @end table
3798
3799 @node Advanced tar
3800 @section Advanced @GNUTAR{} Operations
3801
3802 Now that you have learned the basics of using @GNUTAR{}, you may want
3803 to learn about further ways in which @command{tar} can help you.
3804
3805 This chapter presents five, more advanced operations which you probably
3806 won't use on a daily basis, but which serve more specialized functions.
3807 We also explain the different styles of options and why you might want
3808 to use one or another, or a combination of them in your @command{tar}
3809 commands. Additionally, this chapter includes options which allow you to
3810 define the output from @command{tar} more carefully, and provide help and
3811 error correction in special circumstances.
3812
3813 @FIXME{check this after the chapter is actually revised to make sure
3814 it still introduces the info in the chapter correctly : ).}
3815
3816 @menu
3817 * Operations::
3818 * append::
3819 * update::
3820 * concatenate::
3821 * delete::
3822 * compare::
3823 @end menu
3824
3825 @node Operations
3826 @subsection The Five Advanced @command{tar} Operations
3827 @UNREVISED
3828
3829 In the last chapter, you learned about the first three operations to
3830 @command{tar}. This chapter presents the remaining five operations to
3831 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3832 @option{--delete}, and @option{--compare}.
3833
3834 You are not likely to use these operations as frequently as those
3835 covered in the last chapter; however, since they perform specialized
3836 functions, they are quite useful when you do need to use them. We
3837 will give examples using the same directory and files that you created
3838 in the last chapter. As you may recall, the directory is called
3839 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3840 @samp{rock}, and the two archive files you created are
3841 @samp{collection.tar} and @samp{music.tar}.
3842
3843 We will also use the archive files @samp{afiles.tar} and
3844 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
3845 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
3846 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3847
3848 Unless we state otherwise, all practicing you do and examples you follow
3849 in this chapter will take place in the @file{practice} directory that
3850 you created in the previous chapter; see @ref{prepare for examples}.
3851 (Below in this section, we will remind you of the state of the examples
3852 where the last chapter left them.)
3853
3854 The five operations that we will cover in this chapter are:
3855
3856 @table @option
3857 @item --append
3858 @itemx -r
3859 Add new entries to an archive that already exists.
3860 @item --update
3861 @itemx -r
3862 Add more recent copies of archive members to the end of an archive, if
3863 they exist.
3864 @item --concatenate
3865 @itemx --catenate
3866 @itemx -A
3867 Add one or more pre-existing archives to the end of another archive.
3868 @item --delete
3869 Delete items from an archive (does not work on tapes).
3870 @item --compare
3871 @itemx --diff
3872 @itemx -d
3873 Compare archive members to their counterparts in the file system.
3874 @end table
3875
3876 @node append
3877 @subsection How to Add Files to Existing Archives: @option{--append}
3878 @UNREVISED
3879
3880 @opindex append
3881 If you want to add files to an existing archive, you don't need to
3882 create a new archive; you can use @option{--append} (@option{-r}).
3883 The archive must already exist in order to use @option{--append}. (A
3884 related operation is the @option{--update} operation; you can use this
3885 to add newer versions of archive members to an existing archive. To learn how to
3886 do this with @option{--update}, @pxref{update}.)
3887
3888 If you use @option{--append} to add a file that has the same name as an
3889 archive member to an archive containing that archive member, then the
3890 old member is not deleted. What does happen, however, is somewhat
3891 complex. @command{tar} @emph{allows} you to have infinite number of files
3892 with the same name. Some operations treat these same-named members no
3893 differently than any other set of archive members: for example, if you
3894 view an archive with @option{--list} (@option{-t}), you will see all
3895 of those members listed, with their data modification times, owners, etc.
3896
3897 Other operations don't deal with these members as perfectly as you might
3898 prefer; if you were to use @option{--extract} to extract the archive,
3899 only the most recently added copy of a member with the same name as four
3900 other members would end up in the working directory. This is because
3901 @option{--extract} extracts an archive in the order the members appeared
3902 in the archive; the most recently archived members will be extracted
3903 last. Additionally, an extracted member will @emph{replace} a file of
3904 the same name which existed in the directory already, and @command{tar}
3905 will not prompt you about this@footnote{Unless you give it
3906 @option{--keep-old-files} option, or the disk copy is newer than the
3907 the one in the archive and you invoke @command{tar} with
3908 @option{--keep-newer-files} option}. Thus, only the most recently archived
3909 member will end up being extracted, as it will replace the one
3910 extracted before it, and so on.
3911
3912 There exists a special option that allows you to get around this
3913 behavior and extract (or list) only a particular copy of the file.
3914 This is @option{--occurrence} option. If you run @command{tar} with
3915 this option, it will extract only the first copy of the file. You
3916 may also give this option an argument specifying the number of
3917 copy to be extracted. Thus, for example if the archive
3918 @file{archive.tar} contained three copies of file @file{myfile}, then
3919 the command
3920
3921 @smallexample
3922 tar --extract --file archive.tar --occurrence=2 myfile
3923 @end smallexample
3924
3925 @noindent
3926 would extract only the second copy. @xref{Option
3927 Summary,---occurrence}, for the description of @option{--occurrence}
3928 option.
3929
3930 @FIXME{ hag -- you might want to incorporate some of the above into the
3931 MMwtSN node; not sure. i didn't know how to make it simpler...
3932
3933 There are a few ways to get around this. (maybe xref Multiple Members
3934 with the Same Name.}
3935
3936 @cindex Members, replacing with other members
3937 @cindex Replacing members with other members
3938 If you want to replace an archive member, use @option{--delete} to
3939 delete the member you want to remove from the archive, , and then use
3940 @option{--append} to add the member you want to be in the archive. Note
3941 that you can not change the order of the archive; the most recently
3942 added member will still appear last. In this sense, you cannot truly
3943 ``replace'' one member with another. (Replacing one member with another
3944 will not work on certain types of media, such as tapes; see @ref{delete}
3945 and @ref{Media}, for more information.)
3946
3947 @menu
3948 * appending files:: Appending Files to an Archive
3949 * multiple::
3950 @end menu
3951
3952 @node appending files
3953 @subsubsection Appending Files to an Archive
3954 @UNREVISED
3955 @cindex Adding files to an Archive
3956 @cindex Appending files to an Archive
3957 @cindex Archives, Appending files to
3958
3959 The simplest way to add a file to an already existing archive is the
3960 @option{--append} (@option{-r}) operation, which writes specified
3961 files into the archive whether or not they are already among the
3962 archived files.
3963
3964 When you use @option{--append}, you @emph{must} specify file name
3965 arguments, as there is no default. If you specify a file that already
3966 exists in the archive, another copy of the file will be added to the
3967 end of the archive. As with other operations, the member names of the
3968 newly added files will be exactly the same as their names given on the
3969 command line. The @option{--verbose} (@option{-v}) option will print
3970 out the names of the files as they are written into the archive.
3971
3972 @option{--append} cannot be performed on some tape drives, unfortunately,
3973 due to deficiencies in the formats those tape drives use. The archive
3974 must be a valid @command{tar} archive, or else the results of using this
3975 operation will be unpredictable. @xref{Media}.
3976
3977 To demonstrate using @option{--append} to add a file to an archive,
3978 create a file called @file{rock} in the @file{practice} directory.
3979 Make sure you are in the @file{practice} directory. Then, run the
3980 following @command{tar} command to add @file{rock} to
3981 @file{collection.tar}:
3982
3983 @smallexample
3984 $ @kbd{tar --append --file=collection.tar rock}
3985 @end smallexample
3986
3987 @noindent
3988 If you now use the @option{--list} (@option{-t}) operation, you will see that
3989 @file{rock} has been added to the archive:
3990
3991 @smallexample
3992 $ @kbd{tar --list --file=collection.tar}
3993 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3994 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3995 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3996 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3997 @end smallexample
3998
3999 @node multiple
4000 @subsubsection Multiple Members with the Same Name
4001
4002 You can use @option{--append} (@option{-r}) to add copies of files
4003 which have been updated since the archive was created. (However, we
4004 do not recommend doing this since there is another @command{tar}
4005 option called @option{--update}; @xref{update}, for more information.
4006 We describe this use of @option{--append} here for the sake of
4007 completeness.) When you extract the archive, the older version will
4008 be effectively lost. This works because files are extracted from an
4009 archive in the order in which they were archived. Thus, when the
4010 archive is extracted, a file archived later in time will replace a
4011 file of the same name which was archived earlier, even though the
4012 older version of the file will remain in the archive unless you delete
4013 all versions of the file.
4014
4015 Supposing you change the file @file{blues} and then append the changed
4016 version to @file{collection.tar}. As you saw above, the original
4017 @file{blues} is in the archive @file{collection.tar}. If you change the
4018 file and append the new version of the file to the archive, there will
4019 be two copies in the archive. When you extract the archive, the older
4020 version of the file will be extracted first, and then replaced by the
4021 newer version when it is extracted.
4022
4023 You can append the new, changed copy of the file @file{blues} to the
4024 archive in this way:
4025
4026 @smallexample
4027 $ @kbd{tar --append --verbose --file=collection.tar blues}
4028 blues
4029 @end smallexample
4030
4031 @noindent
4032 Because you specified the @option{--verbose} option, @command{tar} has
4033 printed the name of the file being appended as it was acted on. Now
4034 list the contents of the archive:
4035
4036 @smallexample
4037 $ @kbd{tar --list --verbose --file=collection.tar}
4038 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4039 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4040 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4041 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4042 -rw-r--r-- me user 58 1996-10-24 18:30 blues
4043 @end smallexample
4044
4045 @noindent
4046 The newest version of @file{blues} is now at the end of the archive
4047 (note the different creation dates and file sizes). If you extract
4048 the archive, the older version of the file @file{blues} will be
4049 replaced by the newer version. You can confirm this by extracting
4050 the archive and running @samp{ls} on the directory.
4051
4052 If you wish to extract the first occurrence of the file @file{blues}
4053 from the archive, use @option{--occurrence} option, as shown in
4054 the following example:
4055
4056 @smallexample
4057 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4058 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4059 @end smallexample
4060
4061 @xref{Writing}, for more information on @option{--extract} and
4062 @xref{Option Summary, --occurrence}, for the description of
4063 @option{--occurrence} option.
4064
4065 @node update
4066 @subsection Updating an Archive
4067 @UNREVISED
4068 @cindex Updating an archive
4069
4070 @opindex update
4071 In the previous section, you learned how to use @option{--append} to
4072 add a file to an existing archive. A related operation is
4073 @option{--update} (@option{-u}). The @option{--update} operation
4074 updates a @command{tar} archive by comparing the date of the specified
4075 archive members against the date of the file with the same name. If
4076 the file has been modified more recently than the archive member, then
4077 the newer version of the file is added to the archive (as with
4078 @option{--append}).
4079
4080 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4081 The operation will fail.
4082
4083 @FIXME{other examples of media on which --update will fail? need to ask
4084 charles and/or mib/thomas/dave shevett..}
4085
4086 Both @option{--update} and @option{--append} work by adding to the end
4087 of the archive. When you extract a file from the archive, only the
4088 version stored last will wind up in the file system, unless you use
4089 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4090
4091 @menu
4092 * how to update::
4093 @end menu
4094
4095 @node how to update
4096 @subsubsection How to Update an Archive Using @option{--update}
4097
4098 You must use file name arguments with the @option{--update}
4099 (@option{-u}) operation. If you don't specify any files,
4100 @command{tar} won't act on any files and won't tell you that it didn't
4101 do anything (which may end up confusing you).
4102
4103 @c note: the above parenthetical added because in fact, this
4104 @c behavior just confused the author. :-)
4105
4106 To see the @option{--update} option at work, create a new file,
4107 @file{classical}, in your practice directory, and some extra text to the
4108 file @file{blues}, using any text editor. Then invoke @command{tar} with
4109 the @samp{update} operation and the @option{--verbose} (@option{-v})
4110 option specified, using the names of all the files in the practice
4111 directory as file name arguments:
4112
4113 @smallexample
4114 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4115 blues
4116 classical
4117 $
4118 @end smallexample
4119
4120 @noindent
4121 Because we have specified verbose mode, @command{tar} prints out the names
4122 of the files it is working on, which in this case are the names of the
4123 files that needed to be updated. If you run @samp{tar --list} and look
4124 at the archive, you will see @file{blues} and @file{classical} at its
4125 end. There will be a total of two versions of the member @samp{blues};
4126 the one at the end will be newer and larger, since you added text before
4127 updating it.
4128
4129 (The reason @command{tar} does not overwrite the older file when updating
4130 it is because writing to the middle of a section of tape is a difficult
4131 process. Tapes are not designed to go backward. @xref{Media}, for more
4132 information about tapes.
4133
4134 @option{--update} (@option{-u}) is not suitable for performing backups for two
4135 reasons: it does not change directory content entries, and it
4136 lengthens the archive every time it is used. The @GNUTAR{}
4137 options intended specifically for backups are more
4138 efficient. If you need to run backups, please consult @ref{Backups}.
4139
4140 @node concatenate
4141 @subsection Combining Archives with @option{--concatenate}
4142
4143 @cindex Adding archives to an archive
4144 @cindex Concatenating Archives
4145 @opindex concatenate
4146 @opindex catenate
4147 @c @cindex @option{-A} described
4148 Sometimes it may be convenient to add a second archive onto the end of
4149 an archive rather than adding individual files to the archive. To add
4150 one or more archives to the end of another archive, you should use the
4151 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4152
4153 To use @option{--concatenate}, give the first archive with
4154 @option{--file} option and name the rest of archives to be
4155 concatenated on the command line. The members, and their member
4156 names, will be copied verbatim from those archives to the first one.
4157 @footnote{This can cause multiple members to have the same name, for
4158 information on how this affects reading the archive, @ref{multiple}.}
4159 The new, concatenated archive will be called by the same name as the
4160 one given with the @option{--file} option. As usual, if you omit
4161 @option{--file}, @command{tar} will use the value of the environment
4162 variable @env{TAPE}, or, if this has not been set, the default archive name.
4163
4164 @FIXME{There is no way to specify a new name...}
4165
4166 To demonstrate how @option{--concatenate} works, create two small archives
4167 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4168 files from @file{practice}:
4169
4170 @smallexample
4171 $ @kbd{tar -cvf bluesrock.tar blues rock}
4172 blues
4173 rock
4174 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4175 folk
4176 jazz
4177 @end smallexample
4178
4179 @noindent
4180 If you like, You can run @samp{tar --list} to make sure the archives
4181 contain what they are supposed to:
4182
4183 @smallexample
4184 $ @kbd{tar -tvf bluesrock.tar}
4185 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4186 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4187 $ @kbd{tar -tvf jazzfolk.tar}
4188 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4189 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4190 @end smallexample
4191
4192 We can concatenate these two archives with @command{tar}:
4193
4194 @smallexample
4195 $ @kbd{cd ..}
4196 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4197 @end smallexample
4198
4199 If you now list the contents of the @file{bluesrock.tar}, you will see
4200 that now it also contains the archive members of @file{jazzfolk.tar}:
4201
4202 @smallexample
4203 $ @kbd{tar --list --file=bluesrock.tar}
4204 blues
4205 rock
4206 folk
4207 jazz
4208 @end smallexample
4209
4210 When you use @option{--concatenate}, the source and target archives must
4211 already exist and must have been created using compatible format
4212 parameters. Notice, that @command{tar} does not check whether the
4213 archives it concatenates have compatible formats, it does not
4214 even check if the files are really tar archives.
4215
4216 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4217 tape drives, due to deficiencies in the formats those tape drives use.
4218
4219 @cindex @code{concatenate} vs @command{cat}
4220 @cindex @command{cat} vs @code{concatenate}
4221 It may seem more intuitive to you to want or try to use @command{cat} to
4222 concatenate two archives instead of using the @option{--concatenate}
4223 operation; after all, @command{cat} is the utility for combining files.
4224
4225 However, @command{tar} archives incorporate an end-of-file marker which
4226 must be removed if the concatenated archives are to be read properly as
4227 one archive. @option{--concatenate} removes the end-of-archive marker
4228 from the target archive before each new archive is appended. If you use
4229 @command{cat} to combine the archives, the result will not be a valid
4230 @command{tar} format archive. If you need to retrieve files from an
4231 archive that was added to using the @command{cat} utility, use the
4232 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4233 information on dealing with archives improperly combined using the
4234 @command{cat} shell utility.
4235
4236 @node delete
4237 @subsection Removing Archive Members Using @option{--delete}
4238 @UNREVISED
4239 @cindex Deleting files from an archive
4240 @cindex Removing files from an archive
4241
4242 @opindex delete
4243 You can remove members from an archive by using the @option{--delete}
4244 option. Specify the name of the archive with @option{--file}
4245 (@option{-f}) and then specify the names of the members to be deleted;
4246 if you list no member names, nothing will be deleted. The
4247 @option{--verbose} option will cause @command{tar} to print the names
4248 of the members as they are deleted. As with @option{--extract}, you
4249 must give the exact member names when using @samp{tar --delete}.
4250 @option{--delete} will remove all versions of the named file from the
4251 archive. The @option{--delete} operation can run very slowly.
4252
4253 Unlike other operations, @option{--delete} has no short form.
4254
4255 @cindex Tapes, using @option{--delete} and
4256 @cindex Deleting from tape archives
4257 This operation will rewrite the archive. You can only use
4258 @option{--delete} on an archive if the archive device allows you to
4259 write to any point on the media, such as a disk; because of this, it
4260 does not work on magnetic tapes. Do not try to delete an archive member
4261 from a magnetic tape; the action will not succeed, and you will be
4262 likely to scramble the archive and damage your tape. There is no safe
4263 way (except by completely re-writing the archive) to delete files from
4264 most kinds of magnetic tape. @xref{Media}.
4265
4266 To delete all versions of the file @file{blues} from the archive
4267 @file{collection.tar} in the @file{practice} directory, make sure you
4268 are in that directory, and then,
4269
4270 @smallexample
4271 $ @kbd{tar --list --file=collection.tar}
4272 blues
4273 folk
4274 jazz
4275 rock
4276 $ @kbd{tar --delete --file=collection.tar blues}
4277 $ @kbd{tar --list --file=collection.tar}
4278 folk
4279 jazz
4280 rock
4281 $
4282 @end smallexample
4283
4284 @FIXME{Check if the above listing is actually produced after running
4285 all the examples on collection.tar.}
4286
4287 The @option{--delete} option has been reported to work properly when
4288 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4289
4290 @node compare
4291 @subsection Comparing Archive Members with the File System
4292 @cindex Verifying the currency of an archive
4293 @UNREVISED
4294
4295 @opindex compare
4296 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4297 specified archive members against files with the same names, and then
4298 reports differences in file size, mode, owner, modification date and
4299 contents. You should @emph{only} specify archive member names, not file
4300 names. If you do not name any members, then @command{tar} will compare the
4301 entire archive. If a file is represented in the archive but does not
4302 exist in the file system, @command{tar} reports a difference.
4303
4304 You have to specify the record size of the archive when modifying an
4305 archive with a non-default record size.
4306
4307 @command{tar} ignores files in the file system that do not have
4308 corresponding members in the archive.
4309
4310 The following example compares the archive members @file{rock},
4311 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4312 files of the same name in the file system. (Note that there is no file,
4313 @file{funk}; @command{tar} will report an error message.)
4314
4315 @smallexample
4316 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4317 rock
4318 blues
4319 tar: funk not found in archive
4320 @end smallexample
4321
4322 The spirit behind the @option{--compare} (@option{--diff},
4323 @option{-d}) option is to check whether the archive represents the
4324 current state of files on disk, more than validating the integrity of
4325 the archive media. For this later goal, @xref{verify}.
4326
4327 @node create options
4328 @section Options Used by @option{--create}
4329
4330 @xopindex{create, additional options}
4331 The previous chapter described the basics of how to use
4332 @option{--create} (@option{-c}) to create an archive from a set of files.
4333 @xref{create}. This section described advanced options to be used with
4334 @option{--create}.
4335
4336 @menu
4337 * override:: Overriding File Metadata.
4338 * Ignore Failed Read::
4339 @end menu
4340
4341 @node override
4342 @subsection Overriding File Metadata
4343
4344 As described above, a @command{tar} archive keeps, for each member it contains,
4345 its @dfn{metadata}, such as modification time, mode and ownership of
4346 the file. @GNUTAR{} allows to replace these data with other values
4347 when adding files to the archive. The options described in this
4348 section affect creation of archives of any type. For POSIX archives,
4349 see also @ref{PAX keywords}, for additional ways of controlling
4350 metadata, stored in the archive.
4351
4352 @table @option
4353 @opindex mode
4354 @item --mode=@var{permissions}
4355
4356 When adding files to an archive, @command{tar} will use
4357 @var{permissions} for the archive members, rather than the permissions
4358 from the files. @var{permissions} can be specified either as an octal
4359 number or as symbolic permissions, like with
4360 @command{chmod} (@xref{File permissions, Permissions, File
4361 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4362 also has useful information for those not being overly familiar with
4363 the UNIX permission system). Using latter syntax allows for
4364 more flexibility. For example, the value @samp{a+rw} adds read and write
4365 permissions for everybody, while retaining executable bits on directories
4366 or on any other file already marked as executable:
4367
4368 @smallexample
4369 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4370 @end smallexample
4371
4372 @item --mtime=@var{date}
4373 @opindex mtime
4374
4375 When adding files to an archive, @command{tar} will use @var{date} as
4376 the modification time of members when creating archives, instead of
4377 their actual modification times. The argument @var{date} can be
4378 either a textual date representation in almost arbitrary format
4379 (@pxref{Date input formats}) or a name of the existing file, starting
4380 with @samp{/} or @samp{.}. In the latter case, the modification time
4381 of that file will be used.
4382
4383 The following example will set the modification date to 00:00:00 UTC,
4384 January 1, 1970:
4385
4386 @smallexample
4387 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4388 @end smallexample
4389
4390 @noindent
4391 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4392 will try to convert the specified date back to its textual
4393 representation and compare it with the one given with
4394 @option{--mtime} options. If the two dates differ, @command{tar} will
4395 print a warning saying what date it will use. This is to help user
4396 ensure he is using the right date.
4397
4398 For example:
4399
4400 @smallexample
4401 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4402 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4403 13:06:29.152478
4404 @dots{}
4405 @end smallexample
4406
4407 @item --owner=@var{user}
4408 @opindex owner
4409
4410 Specifies that @command{tar} should use @var{user} as the owner of members
4411 when creating archives, instead of the user associated with the source
4412 file. The argument @var{user} can be either an existing user symbolic
4413 name, or a decimal numeric user @acronym{ID}.
4414
4415 There is no value indicating a missing number, and @samp{0} usually means
4416 @code{root}. Some people like to force @samp{0} as the value to offer in
4417 their distributions for the owner of files, because the @code{root} user is
4418 anonymous anyway, so that might as well be the owner of anonymous
4419 archives. For example:
4420
4421 @smallexample
4422 @group
4423 $ @kbd{tar -c -f archive.tar --owner=0 .}
4424 # @r{Or:}
4425 $ @kbd{tar -c -f archive.tar --owner=root .}
4426 @end group
4427 @end smallexample
4428
4429 @item --group=@var{group}
4430 @opindex group
4431
4432 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
4433 rather than the group from the source file. The argument @var{group}
4434 can be either an existing group symbolic name, or a decimal numeric group @acronym{ID}.
4435 @end table
4436
4437 @node Ignore Failed Read
4438 @subsection Ignore Fail Read
4439
4440 @table @option
4441 @item --ignore-failed-read
4442 @opindex ignore-failed-read
4443 Do not exit with nonzero on unreadable files or directories.
4444 @end table
4445
4446 @node extract options
4447 @section Options Used by @option{--extract}
4448 @UNREVISED
4449
4450 @xopindex{extract, additional options}
4451 The previous chapter showed how to use @option{--extract} to extract
4452 an archive into the file system. Various options cause @command{tar} to
4453 extract more information than just file contents, such as the owner,
4454 the permissions, the modification date, and so forth. This section
4455 presents options to be used with @option{--extract} when certain special
4456 considerations arise. You may review the information presented in
4457 @ref{extract} for more basic information about the
4458 @option{--extract} operation.
4459
4460 @menu
4461 * Reading:: Options to Help Read Archives
4462 * Writing:: Changing How @command{tar} Writes Files
4463 * Scarce:: Coping with Scarce Resources
4464 @end menu
4465
4466 @node Reading
4467 @subsection Options to Help Read Archives
4468 @cindex Options when reading archives
4469 @UNREVISED
4470
4471 @cindex Reading incomplete records
4472 @cindex Records, incomplete
4473 @opindex read-full-records
4474 Normally, @command{tar} will request data in full record increments from
4475 an archive storage device. If the device cannot return a full record,
4476 @command{tar} will report an error. However, some devices do not always
4477 return full records, or do not require the last record of an archive to
4478 be padded out to the next record boundary. To keep reading until you
4479 obtain a full record, or to accept an incomplete record if it contains
4480 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4481 in conjunction with the @option{--extract} or @option{--list} operations.
4482 @xref{Blocking}.
4483
4484 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4485 @command{tar} reads an archive from standard input, or from a remote
4486 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
4487 pipe returns however much happens to be in the pipe, even if it is
4488 less than was requested. If this option were not enabled, @command{tar}
4489 would fail as soon as it read an incomplete record from the pipe.
4490
4491 If you're not sure of the blocking factor of an archive, you can
4492 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4493 @option{--blocking-factor=@var{512-size}} (@option{-b
4494 @var{512-size}}), using a blocking factor larger than what the archive
4495 uses. This lets you avoid having to determine the blocking factor
4496 of an archive. @xref{Blocking Factor}.
4497
4498 @menu
4499 * read full records::
4500 * Ignore Zeros::
4501 @end menu
4502
4503 @node read full records
4504 @unnumberedsubsubsec Reading Full Records
4505
4506 @FIXME{need sentence or so of intro here}
4507
4508 @table @option
4509 @opindex read-full-records
4510 @item --read-full-records
4511 @item -B
4512 Use in conjunction with @option{--extract} (@option{--get},
4513 @option{-x}) to read an archive which contains incomplete records, or
4514 one which has a blocking factor less than the one specified.
4515 @end table
4516
4517 @node Ignore Zeros
4518 @unnumberedsubsubsec Ignoring Blocks of Zeros
4519
4520 @cindex End-of-archive blocks, ignoring
4521 @cindex Ignoring end-of-archive blocks
4522 @opindex ignore-zeros
4523 Normally, @command{tar} stops reading when it encounters a block of zeros
4524 between file entries (which usually indicates the end of the archive).
4525 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4526 completely read an archive which contains a block of zeros before the
4527 end (i.e., a damaged archive, or one that was created by concatenating
4528 several archives together).
4529
4530 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4531 versions of @command{tar} write garbage after the end-of-archive entry,
4532 since that part of the media is never supposed to be read. @GNUTAR{}
4533 does not write after the end of an archive, but seeks to
4534 maintain compatibility among archiving utilities.
4535
4536 @table @option
4537 @item --ignore-zeros
4538 @itemx -i
4539 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4540 encountered while reading an archive. Use in conjunction with
4541 @option{--extract} or @option{--list}.
4542 @end table
4543
4544 @node Writing
4545 @subsection Changing How @command{tar} Writes Files
4546 @UNREVISED
4547
4548 @FIXME{Introductory paragraph}
4549
4550 @menu
4551 * Dealing with Old Files::
4552 * Overwrite Old Files::
4553 * Keep Old Files::
4554 * Keep Newer Files::
4555 * Unlink First::
4556 * Recursive Unlink::
4557 * Data Modification Times::
4558 * Setting Access Permissions::
4559 * Directory Modification Times and Permissions::
4560 * Writing to Standard Output::
4561 * Writing to an External Program::
4562 * remove files::
4563 @end menu
4564
4565 @node Dealing with Old Files
4566 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4567
4568 @xopindex{overwrite-dir, introduced}
4569 When extracting files, if @command{tar} discovers that the extracted
4570 file already exists, it normally replaces the file by removing it before
4571 extracting it, to prevent confusion in the presence of hard or symbolic
4572 links. (If the existing file is a symbolic link, it is removed, not
4573 followed.) However, if a directory cannot be removed because it is
4574 nonempty, @command{tar} normally overwrites its metadata (ownership,
4575 permission, etc.). The @option{--overwrite-dir} option enables this
4576 default behavior. To be more cautious and preserve the metadata of
4577 such a directory, use the @option{--no-overwrite-dir} option.
4578
4579 @cindex Overwriting old files, prevention
4580 @xopindex{keep-old-files, introduced}
4581 To be even more cautious and prevent existing files from being replaced, use
4582 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4583 to replace or update a file that already exists, i.e., a file with the
4584 same name as an archive member prevents extraction of that archive
4585 member. Instead, it reports an error.
4586
4587 @xopindex{overwrite, introduced}
4588 To be more aggressive about altering existing files, use the
4589 @option{--overwrite} option. It causes @command{tar} to overwrite
4590 existing files and to follow existing symbolic links when extracting.
4591
4592 @cindex Protecting old files
4593 Some people argue that @GNUTAR{} should not hesitate
4594 to overwrite files with other files when extracting. When extracting
4595 a @command{tar} archive, they expect to see a faithful copy of the
4596 state of the file system when the archive was created. It is debatable
4597 that this would always be a proper behavior. For example, suppose one
4598 has an archive in which @file{usr/local} is a link to
4599 @file{usr/local2}. Since then, maybe the site removed the link and
4600 renamed the whole hierarchy from @file{/usr/local2} to
4601 @file{/usr/local}. Such things happen all the time. I guess it would
4602 not be welcome at all that @GNUTAR{} removes the
4603 whole hierarchy just to make room for the link to be reinstated
4604 (unless it @emph{also} simultaneously restores the full
4605 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4606 able to remove a whole hierarchy to reestablish a symbolic link, for
4607 example, but @emph{only if} @option{--recursive-unlink} is specified
4608 to allow this behavior. In any case, single files are silently
4609 removed.
4610
4611 @xopindex{unlink-first, introduced}
4612 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4613 some cases by causing @command{tar} to remove files unconditionally
4614 before extracting them.
4615
4616 @node Overwrite Old Files
4617 @unnumberedsubsubsec Overwrite Old Files
4618
4619 @table @option
4620 @opindex overwrite
4621 @item --overwrite
4622 Overwrite existing files and directory metadata when extracting files
4623 from an archive.
4624
4625 This causes @command{tar} to write extracted files into the file system without
4626 regard to the files already on the system; i.e., files with the same
4627 names as archive members are overwritten when the archive is extracted.
4628 It also causes @command{tar} to extract the ownership, permissions,
4629 and time stamps onto any preexisting files or directories.
4630 If the name of a corresponding file name is a symbolic link, the file
4631 pointed to by the symbolic link will be overwritten instead of the
4632 symbolic link itself (if this is possible). Moreover, special devices,
4633 empty directories and even symbolic links are automatically removed if
4634 they are in the way of extraction.
4635
4636 Be careful when using the @option{--overwrite} option, particularly when
4637 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4638 can change the contents, ownership or permissions of any file on your
4639 system. Also, many systems do not take kindly to overwriting files that
4640 are currently being executed.
4641
4642 @opindex overwrite-dir
4643 @item --overwrite-dir
4644 Overwrite the metadata of directories when extracting files from an
4645 archive, but remove other files before extracting.
4646 @end table
4647
4648 @node Keep Old Files
4649 @unnumberedsubsubsec Keep Old Files
4650
4651 @table @option
4652 @opindex keep-old-files
4653 @item --keep-old-files
4654 @itemx -k
4655 Do not replace existing files from archive. The
4656 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4657 from replacing existing files with files with the same name from the
4658 archive. The @option{--keep-old-files} option is meaningless with
4659 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4660 files in the file system during extraction.
4661 @end table
4662
4663 @node Keep Newer Files
4664 @unnumberedsubsubsec Keep Newer Files
4665
4666 @table @option
4667 @opindex keep-newer-files
4668 @item --keep-newer-files
4669 Do not replace existing files that are newer than their archive
4670 copies. This option is meaningless with @option{--list} (@option{-t}).
4671 @end table
4672
4673 @node Unlink First
4674 @unnumberedsubsubsec Unlink First
4675
4676 @table @option
4677 @opindex unlink-first
4678 @item --unlink-first
4679 @itemx -U
4680 Remove files before extracting over them.
4681 This can make @command{tar} run a bit faster if you know in advance
4682 that the extracted files all need to be removed. Normally this option
4683 slows @command{tar} down slightly, so it is disabled by default.
4684 @end table
4685
4686 @node Recursive Unlink
4687 @unnumberedsubsubsec Recursive Unlink
4688
4689 @table @option
4690 @opindex recursive-unlink
4691 @item --recursive-unlink
4692 When this option is specified, try removing files and directory hierarchies
4693 before extracting over them. @emph{This is a dangerous option!}
4694 @end table
4695
4696 If you specify the @option{--recursive-unlink} option,
4697 @command{tar} removes @emph{anything} that keeps you from extracting a file
4698 as far as current permissions will allow it. This could include removal
4699 of the contents of a full directory hierarchy.
4700
4701 @node Data Modification Times
4702 @unnumberedsubsubsec Setting Data Modification Times
4703
4704 @cindex Data modification times of extracted files
4705 @cindex Modification times of extracted files
4706 Normally, @command{tar} sets the data modification times of extracted
4707 files to the corresponding times recorded for the files in the archive, but
4708 limits the permissions of extracted files by the current @code{umask}
4709 setting.
4710
4711 To set the data modification times of extracted files to the time when
4712 the files were extracted, use the @option{--touch} (@option{-m}) option in
4713 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4714
4715 @table @option
4716 @opindex touch
4717 @item --touch
4718 @itemx -m
4719 Sets the data modification time of extracted archive members to the time
4720 they were extracted, not the time recorded for them in the archive.
4721 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4722 @end table
4723
4724 @node Setting Access Permissions
4725 @unnumberedsubsubsec Setting Access Permissions
4726
4727 @cindex Permissions of extracted files
4728 @cindex Modes of extracted files
4729 To set the modes (access permissions) of extracted files to those
4730 recorded for those files in the archive, use @option{--same-permissions}
4731 in conjunction with the @option{--extract} (@option{--get},
4732 @option{-x}) operation.
4733
4734 @table @option
4735 @opindex preserve-permissions
4736 @opindex same-permissions
4737 @item --preserve-permissions
4738 @itemx --same-permissions
4739 @c @itemx --ignore-umask
4740 @itemx -p
4741 Set modes of extracted archive members to those recorded in the
4742 archive, instead of current umask settings. Use in conjunction with
4743 @option{--extract} (@option{--get}, @option{-x}).
4744 @end table
4745
4746 @node Directory Modification Times and Permissions
4747 @unnumberedsubsubsec Directory Modification Times and Permissions
4748
4749 After successfully extracting a file member, @GNUTAR{} normally
4750 restores its permissions and modification times, as described in the
4751 previous sections. This cannot be done for directories, because
4752 after extracting a directory @command{tar} will almost certainly
4753 extract files into that directory and this will cause the directory
4754 modification time to be updated. Moreover, restoring that directory
4755 permissions may not permit file creation within it. Thus, restoring
4756 directory permissions and modification times must be delayed at least
4757 until all files have been extracted into that directory. @GNUTAR{}
4758 restores directories using the following approach.
4759
4760 The extracted directories are created with the mode specified in the
4761 archive, as modified by the umask of the user, which gives sufficient
4762 permissions to allow file creation. The meta-information about the
4763 directory is recorded in the temporary list of directories. When
4764 preparing to extract next archive member, @GNUTAR{} checks if the
4765 directory prefix of this file contains the remembered directory. If
4766 it does not, the program assumes that all files have been extracted
4767 into that directory, restores its modification time and permissions
4768 and removes its entry from the internal list. This approach allows
4769 to correctly restore directory meta-information in the majority of
4770 cases, while keeping memory requirements sufficiently small. It is
4771 based on the fact, that most @command{tar} archives use the predefined
4772 order of members: first the directory, then all the files and
4773 subdirectories in that directory.
4774
4775 However, this is not always true. The most important exception are
4776 incremental archives (@pxref{Incremental Dumps}). The member order in
4777 an incremental archive is reversed: first all directory members are
4778 stored, followed by other (non-directory) members. So, when extracting
4779 from incremental archives, @GNUTAR{} alters the above procedure. It
4780 remembers all restored directories, and restores their meta-data
4781 only after the entire archive has been processed. Notice, that you do
4782 not need to specify any special options for that, as @GNUTAR{}
4783 automatically detects archives in incremental format.
4784
4785 There may be cases, when such processing is required for normal archives
4786 too. Consider the following example:
4787
4788 @smallexample
4789 @group
4790 $ @kbd{tar --no-recursion -cvf archive \
4791 foo foo/file1 bar bar/file foo/file2}
4792 foo/
4793 foo/file1
4794 bar/
4795 bar/file
4796 foo/file2
4797 @end group
4798 @end smallexample
4799
4800 During the normal operation, after encountering @file{bar}
4801 @GNUTAR{} will assume that all files from the directory @file{foo}
4802 were already extracted and will therefore restore its timestamp and
4803 permission bits. However, after extracting @file{foo/file2} the
4804 directory timestamp will be offset again.
4805
4806 To correctly restore directory meta-information in such cases, use
4807 @option{delay-directory-restore} command line option:
4808
4809 @table @option
4810 @opindex delay-directory-restore
4811 @item --delay-directory-restore
4812 Delays restoring of the modification times and permissions of extracted
4813 directories until the end of extraction. This way, correct
4814 meta-information is restored even if the archive has unusual member
4815 ordering.
4816
4817 @opindex no-delay-directory-restore
4818 @item --no-delay-directory-restore
4819 Cancel the effect of the previous @option{--delay-directory-restore}.
4820 Use this option if you have used @option{--delay-directory-restore} in
4821 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4822 temporarily disable it.
4823 @end table
4824
4825 @node Writing to Standard Output
4826 @unnumberedsubsubsec Writing to Standard Output
4827
4828 @cindex Writing extracted files to standard output
4829 @cindex Standard output, writing extracted files to
4830 To write the extracted files to the standard output, instead of
4831 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4832 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4833 extracting files to send them through a pipe, and do not need to
4834 preserve them in the file system. If you extract multiple members,
4835 they appear on standard output concatenated, in the order they are
4836 found in the archive.
4837
4838 @table @option
4839 @opindex to-stdout
4840 @item --to-stdout
4841 @itemx -O
4842 Writes files to the standard output. Use only in conjunction with
4843 @option{--extract} (@option{--get}, @option{-x}). When this option is
4844 used, instead of creating the files specified, @command{tar} writes
4845 the contents of the files extracted to its standard output. This may
4846 be useful if you are only extracting the files in order to send them
4847 through a pipe. This option is meaningless with @option{--list}
4848 (@option{-t}).
4849 @end table
4850
4851 This can be useful, for example, if you have a tar archive containing
4852 a big file and don't want to store the file on disk before processing
4853 it. You can use a command like this:
4854
4855 @smallexample
4856 tar -xOzf foo.tgz bigfile | process
4857 @end smallexample
4858
4859 or even like this if you want to process the concatenation of the files:
4860
4861 @smallexample
4862 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4863 @end smallexample
4864
4865 However, @option{--to-command} may be more convenient for use with
4866 multiple files. See the next section.
4867
4868 @node Writing to an External Program
4869 @unnumberedsubsubsec Writing to an External Program
4870
4871 You can instruct @command{tar} to send the contents of each extracted
4872 file to the standard input of an external program:
4873
4874 @table @option
4875 @opindex to-command
4876 @item --to-command=@var{command}
4877 Extract files and pipe their contents to the standard input of
4878 @var{command}. When this option is used, instead of creating the
4879 files specified, @command{tar} invokes @var{command} and pipes the
4880 contents of the files to its standard output. @var{Command} may
4881 contain command line arguments. The program is executed via
4882 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4883 extracted. Non-regular files (directories, etc.) are ignored when this
4884 option is used.
4885 @end table
4886
4887 The command can obtain the information about the file it processes
4888 from the following environment variables:
4889
4890 @table @var
4891 @vrindex TAR_FILETYPE, to-command environment
4892 @item TAR_FILETYPE
4893 Type of the file. It is a single letter with the following meaning:
4894
4895 @multitable @columnfractions 0.10 0.90
4896 @item f @tab Regular file
4897 @item d @tab Directory
4898 @item l @tab Symbolic link
4899 @item h @tab Hard link
4900 @item b @tab Block device
4901 @item c @tab Character device
4902 @end multitable
4903
4904 Currently only regular files are supported.
4905
4906 @vrindex TAR_MODE, to-command environment
4907 @item TAR_MODE
4908 File mode, an octal number.
4909
4910 @vrindex TAR_FILENAME, to-command environment
4911 @item TAR_FILENAME
4912 The name of the file.
4913
4914 @vrindex TAR_REALNAME, to-command environment
4915 @item TAR_REALNAME
4916 Name of the file as stored in the archive.
4917
4918 @vrindex TAR_UNAME, to-command environment
4919 @item TAR_UNAME
4920 Name of the file owner.
4921
4922 @vrindex TAR_GNAME, to-command environment
4923 @item TAR_GNAME
4924 Name of the file owner group.
4925
4926 @vrindex TAR_ATIME, to-command environment
4927 @item TAR_ATIME
4928 Time of last access. It is a decimal number, representing seconds
4929 since the epoch. If the archive provides times with nanosecond
4930 precision, the nanoseconds are appended to the timestamp after a
4931 decimal point.
4932
4933 @vrindex TAR_MTIME, to-command environment
4934 @item TAR_MTIME
4935 Time of last modification.
4936
4937 @vrindex TAR_CTIME, to-command environment
4938 @item TAR_CTIME
4939 Time of last status change.
4940
4941 @vrindex TAR_SIZE, to-command environment
4942 @item TAR_SIZE
4943 Size of the file.
4944
4945 @vrindex TAR_UID, to-command environment
4946 @item TAR_UID
4947 UID of the file owner.
4948
4949 @vrindex TAR_GID, to-command environment
4950 @item TAR_GID
4951 GID of the file owner.
4952 @end table
4953
4954 In addition to these variables, @env{TAR_VERSION} contains the
4955 @GNUTAR{} version number.
4956
4957 If @var{command} exits with a non-0 status, @command{tar} will print
4958 an error message similar to the following:
4959
4960 @smallexample
4961 tar: 2345: Child returned status 1
4962 @end smallexample
4963
4964 Here, @samp{2345} is the PID of the finished process.
4965
4966 If this behavior is not wanted, use @option{--ignore-command-error}:
4967
4968 @table @option
4969 @opindex ignore-command-error
4970 @item --ignore-command-error
4971 Ignore exit codes of subprocesses. Notice that if the program
4972 exits on signal or otherwise terminates abnormally, the error message
4973 will be printed even if this option is used.
4974
4975 @opindex no-ignore-command-error
4976 @item --no-ignore-command-error
4977 Cancel the effect of any previous @option{--ignore-command-error}
4978 option. This option is useful if you have set
4979 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4980 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4981 @end table
4982
4983 @node remove files
4984 @unnumberedsubsubsec Removing Files
4985
4986 @FIXME{The section is too terse. Something more to add? An example,
4987 maybe?}
4988
4989 @table @option
4990 @opindex remove-files
4991 @item --remove-files
4992 Remove files after adding them to the archive.
4993 @end table
4994
4995 @node Scarce
4996 @subsection Coping with Scarce Resources
4997 @UNREVISED
4998
4999 @cindex Small memory
5000 @cindex Running out of space
5001
5002 @menu
5003 * Starting File::
5004 * Same Order::
5005 @end menu
5006
5007 @node Starting File
5008 @unnumberedsubsubsec Starting File
5009
5010 @table @option
5011 @opindex starting-file
5012 @item --starting-file=@var{name}
5013 @itemx -K @var{name}
5014 Starts an operation in the middle of an archive. Use in conjunction
5015 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5016 @end table
5017
5018 @cindex Middle of the archive, starting in the
5019 If a previous attempt to extract files failed due to lack of disk
5020 space, you can use @option{--starting-file=@var{name}} (@option{-K
5021 @var{name}}) to start extracting only after member @var{name} of the
5022 archive. This assumes, of course, that there is now free space, or
5023 that you are now extracting into a different file system. (You could
5024 also choose to suspend @command{tar}, remove unnecessary files from
5025 the file system, and then restart the same @command{tar} operation.
5026 In this case, @option{--starting-file} is not necessary.
5027 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
5028
5029 @node Same Order
5030 @unnumberedsubsubsec Same Order
5031
5032 @table @option
5033 @cindex Large lists of file names on small machines
5034 @opindex same-order
5035 @opindex preserve-order
5036 @item --same-order
5037 @itemx --preserve-order
5038 @itemx -s
5039 To process large lists of file names on machines with small amounts of
5040 memory. Use in conjunction with @option{--compare} (@option{--diff},
5041 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5042 (@option{--get}, @option{-x}).
5043 @end table
5044
5045 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5046 names to be listed or extracted is sorted in the same order as the
5047 files in the archive. This allows a large list of names to be used,
5048 even on a small machine that would not otherwise be able to hold all
5049 the names in memory at the same time. Such a sorted list can easily be
5050 created by running @samp{tar -t} on the archive and editing its output.
5051
5052 This option is probably never needed on modern computer systems.
5053
5054 @node backup
5055 @section Backup options
5056
5057 @cindex backup options
5058
5059 @GNUTAR{} offers options for making backups of files
5060 before writing new versions. These options control the details of
5061 these backups. They may apply to the archive itself before it is
5062 created or rewritten, as well as individual extracted members. Other
5063 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5064 and @command{mv}, for example) offer similar options.
5065
5066 Backup options may prove unexpectedly useful when extracting archives
5067 containing many members having identical name, or when extracting archives
5068 on systems having file name limitations, making different members appear
5069 has having similar names through the side-effect of name truncation.
5070 (This is true only if we have a good scheme for truncated backup names,
5071 which I'm not sure at all: I suspect work is needed in this area.)
5072 When any existing file is backed up before being overwritten by extraction,
5073 then clashing files are automatically be renamed to be unique, and the
5074 true name is kept for only the last file of a series of clashing files.
5075 By using verbose mode, users may track exactly what happens.
5076
5077 At the detail level, some decisions are still experimental, and may
5078 change in the future, we are waiting comments from our users. So, please
5079 do not learn to depend blindly on the details of the backup features.
5080 For example, currently, directories themselves are never renamed through
5081 using these options, so, extracting a file over a directory still has
5082 good chances to fail. Also, backup options apply to created archives,
5083 not only to extracted members. For created archives, backups will not
5084 be attempted when the archive is a block or character device, or when it
5085 refers to a remote file.
5086
5087 For the sake of simplicity and efficiency, backups are made by renaming old
5088 files prior to creation or extraction, and not by copying. The original
5089 name is restored if the file creation fails. If a failure occurs after a
5090 partial extraction of a file, both the backup and the partially extracted
5091 file are kept.
5092
5093 @table @samp
5094 @item --backup[=@var{method}]
5095 @opindex backup
5096 @vindex VERSION_CONTROL
5097 @cindex backups
5098 Back up files that are about to be overwritten or removed.
5099 Without this option, the original versions are destroyed.
5100
5101 Use @var{method} to determine the type of backups made.
5102 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5103 environment variable. And if @env{VERSION_CONTROL} is not set,
5104 use the @samp{existing} method.
5105
5106 @vindex version-control @r{Emacs variable}
5107 This option corresponds to the Emacs variable @samp{version-control};
5108 the same values for @var{method} are accepted as in Emacs. This option
5109 also allows more descriptive names. The valid @var{method}s are:
5110
5111 @table @samp
5112 @item t
5113 @itemx numbered
5114 @cindex numbered @r{backup method}
5115 Always make numbered backups.
5116
5117 @item nil
5118 @itemx existing
5119 @cindex existing @r{backup method}
5120 Make numbered backups of files that already have them, simple backups
5121 of the others.
5122
5123 @item never
5124 @itemx simple
5125 @cindex simple @r{backup method}
5126 Always make simple backups.
5127
5128 @end table
5129
5130 @item --suffix=@var{suffix}
5131 @opindex suffix
5132 @cindex backup suffix
5133 @vindex SIMPLE_BACKUP_SUFFIX
5134 Append @var{suffix} to each backup file made with @option{--backup}. If this
5135 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5136 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5137 set, the default is @samp{~}, just as in Emacs.
5138
5139 @end table
5140
5141 @node Applications
5142 @section Notable @command{tar} Usages
5143 @UNREVISED
5144
5145 @FIXME{Using Unix file linking capability to recreate directory
5146 structures---linking files into one subdirectory and then
5147 @command{tar}ring that directory.}
5148
5149 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5150
5151 @findex uuencode
5152 You can easily use archive files to transport a group of files from
5153 one system to another: put all relevant files into an archive on one
5154 computer system, transfer the archive to another system, and extract
5155 the contents there. The basic transfer medium might be magnetic tape,
5156 Internet FTP, or even electronic mail (though you must encode the
5157 archive with @command{uuencode} in order to transport it properly by
5158 mail). Both machines do not have to use the same operating system, as
5159 long as they both support the @command{tar} program.
5160
5161 For example, here is how you might copy a directory's contents from
5162 one disk to another, while preserving the dates, modes, owners and
5163 link-structure of all the files therein. In this case, the transfer
5164 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5165
5166 @smallexample
5167 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5168 @end smallexample
5169
5170 @noindent
5171 You can avoid subshells by using @option{-C} option:
5172
5173 @smallexample
5174 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5175 @end smallexample
5176
5177 @noindent
5178 The command also works using short option forms:
5179
5180 @smallexample
5181 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5182 | (cd targetdir; tar --extract --file=-)}
5183 # Or:
5184 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5185 | tar --directory targetdir --extract --file=-}
5186 @end smallexample
5187
5188 @noindent
5189 This is one of the easiest methods to transfer a @command{tar} archive.
5190
5191 @node looking ahead
5192 @section Looking Ahead: The Rest of this Manual
5193
5194 You have now seen how to use all eight of the operations available to
5195 @command{tar}, and a number of the possible options. The next chapter
5196 explains how to choose and change file and archive names, how to use
5197 files to store names of other files which you can then call as
5198 arguments to @command{tar} (this can help you save time if you expect to
5199 archive the same list of files a number of times), and so forth.
5200 @FIXME{in case it's not obvious, i'm making this up in some sense
5201 based on my limited memory of what the next chapter *really* does. i
5202 just wanted to flesh out this final section a little bit so i'd
5203 remember to stick it in here. :-)}
5204
5205 If there are too many files to conveniently list on the command line,
5206 you can list the names in a file, and @command{tar} will read that file.
5207 @xref{files}.
5208
5209 There are various ways of causing @command{tar} to skip over some files,
5210 and not archive them. @xref{Choosing}.
5211
5212 @node Backups
5213 @chapter Performing Backups and Restoring Files
5214 @UNREVISED
5215
5216 @GNUTAR{} is distributed along with the scripts
5217 which the Free Software Foundation uses for performing backups. There
5218 is no corresponding scripts available yet for doing restoration of
5219 files. Even if there is a good chance those scripts may be satisfying
5220 to you, they are not the only scripts or methods available for doing
5221 backups and restore. You may well create your own, or use more
5222 sophisticated packages dedicated to that purpose.
5223
5224 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5225 Automatic Network Disk Archiver), a backup system developed by James
5226 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5227 This is free software, and it is available at these places:
5228
5229 @smallexample
5230 http://www.cs.umd.edu/projects/amanda/amanda.html
5231 ftp://ftp.cs.umd.edu/pub/amanda
5232 @end smallexample
5233
5234 @FIXME{
5235
5236 Here is a possible plan for a future documentation about the backuping
5237 scripts which are provided within the @GNUTAR{}
5238 distribution.
5239
5240 @itemize @bullet
5241 @item dumps
5242 @itemize @minus
5243 @item what are dumps
5244 @item different levels of dumps
5245 @itemize +
5246 @item full dump = dump everything
5247 @item level 1, level 2 dumps etc
5248 A level @var{n} dump dumps everything changed since the last level
5249 @var{n}-1 dump (?)
5250 @end itemize
5251 @item how to use scripts for dumps (ie, the concept)
5252 @itemize +
5253 @item scripts to run after editing backup specs (details)
5254 @end itemize
5255 @item Backup Specs, what is it.
5256 @itemize +
5257 @item how to customize
5258 @item actual text of script [/sp/dump/backup-specs]
5259 @end itemize
5260 @item Problems
5261 @itemize +
5262 @item rsh doesn't work
5263 @item rtape isn't installed
5264 @item (others?)
5265 @end itemize
5266 @item the @option{--incremental} option of tar
5267 @item tapes
5268 @itemize +
5269 @item write protection
5270 @item types of media, different sizes and types, useful for different things
5271 @item files and tape marks
5272 one tape mark between files, two at end.
5273 @item positioning the tape
5274 MT writes two at end of write,
5275 backspaces over one when writing again.
5276 @end itemize
5277 @end itemize
5278 @end itemize
5279 }
5280
5281 This chapter documents both the provided shell scripts and @command{tar}
5282 options which are more specific to usage as a backup tool.
5283
5284 To @dfn{back up} a file system means to create archives that contain
5285 all the files in that file system. Those archives can then be used to
5286 restore any or all of those files (for instance if a disk crashes or a
5287 file is accidentally deleted). File system @dfn{backups} are also
5288 called @dfn{dumps}.
5289
5290 @menu
5291 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5292 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5293 * Backup Levels:: Levels of Backups
5294 * Backup Parameters:: Setting Parameters for Backups and Restoration
5295 * Scripted Backups:: Using the Backup Scripts
5296 * Scripted Restoration:: Using the Restore Script
5297 @end menu
5298
5299 @node Full Dumps
5300 @section Using @command{tar} to Perform Full Dumps
5301 @UNREVISED
5302
5303 @cindex full dumps
5304 @cindex dumps, full
5305
5306 @cindex corrupted archives
5307 Full dumps should only be made when no other people or programs
5308 are modifying files in the file system. If files are modified while
5309 @command{tar} is making the backup, they may not be stored properly in
5310 the archive, in which case you won't be able to restore them if you
5311 have to. (Files not being modified are written with no trouble, and do
5312 not corrupt the entire archive.)
5313
5314 You will want to use the @option{--label=@var{archive-label}}
5315 (@option{-V @var{archive-label}}) option to give the archive a
5316 volume label, so you can tell what this archive is even if the label
5317 falls off the tape, or anything like that.
5318
5319 Unless the file system you are dumping is guaranteed to fit on
5320 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5321 Make sure you have enough tapes on hand to complete the backup.
5322
5323 If you want to dump each file system separately you will need to use
5324 the @option{--one-file-system} option to prevent
5325 @command{tar} from crossing file system boundaries when storing
5326 (sub)directories.
5327
5328 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5329 option is not needed, since this is a complete copy of everything in
5330 the file system, and a full restore from this backup would only be
5331 done onto a completely
5332 empty disk.
5333
5334 Unless you are in a hurry, and trust the @command{tar} program (and your
5335 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5336 option, to make sure your files really made it onto the dump properly.
5337 This will also detect cases where the file was modified while (or just
5338 after) it was being archived. Not all media (notably cartridge tapes)
5339 are capable of being verified, unfortunately.
5340
5341 @node Incremental Dumps
5342 @section Using @command{tar} to Perform Incremental Dumps
5343
5344 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5345 stores additional metadata so that exact state of the file system
5346 can be restored when extracting the archive.
5347
5348 @GNUTAR{} currently offers two options for handling incremental
5349 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5350 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5351
5352 @opindex listed-incremental
5353 The option @option{--listed-incremental} instructs tar to operate on
5354 an incremental archive with additional metadata stored in a standalone
5355 file, called a @dfn{snapshot file}. The purpose of this file is to help
5356 determine which files have been changed, added or deleted since the
5357 last backup, so that the next incremental backup will contain only
5358 modified files. The name of the snapshot file is given as an argument
5359 to the option:
5360
5361 @table @option
5362 @item --listed-incremental=@var{file}
5363 @itemx -g @var{file}
5364 Handle incremental backups with snapshot data in @var{file}.
5365 @end table
5366
5367 To create an incremental backup, you would use
5368 @option{--listed-incremental} together with @option{--create}
5369 (@pxref{create}). For example:
5370
5371 @smallexample
5372 $ @kbd{tar --create \
5373 --file=archive.1.tar \
5374 --listed-incremental=/var/log/usr.snar \
5375 /usr}
5376 @end smallexample
5377
5378 This will create in @file{archive.1.tar} an incremental backup of
5379 the @file{/usr} file system, storing additional metadata in the file
5380 @file{/var/log/usr.snar}. If this file does not exist, it will be
5381 created. The created archive will then be a @dfn{level 0 backup};
5382 please see the next section for more on backup levels.
5383
5384 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5385 determines which files are modified. In this case only these files will be
5386 stored in the archive. Suppose, for example, that after running the
5387 above command, you delete file @file{/usr/doc/old} and create
5388 directory @file{/usr/local/db} with the following contents:
5389
5390 @smallexample
5391 $ @kbd{ls /usr/local/db}
5392 /usr/local/db/data
5393 /usr/local/db/index
5394 @end smallexample
5395
5396 Some time later you create another incremental backup. You will
5397 then see:
5398
5399 @smallexample
5400 $ @kbd{tar --create \
5401 --file=archive.2.tar \
5402 --listed-incremental=/var/log/usr.snar \
5403 /usr}
5404 tar: usr/local/db: Directory is new
5405 usr/local/db/
5406 usr/local/db/data
5407 usr/local/db/index
5408 @end smallexample
5409
5410 @noindent
5411 The created archive @file{archive.2.tar} will contain only these
5412 three members. This archive is called a @dfn{level 1 backup}. Notice
5413 that @file{/var/log/usr.snar} will be updated with the new data, so if
5414 you plan to create more @samp{level 1} backups, it is necessary to
5415 create a working copy of the snapshot file before running
5416 @command{tar}. The above example will then be modified as follows:
5417
5418 @smallexample
5419 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5420 $ @kbd{tar --create \
5421 --file=archive.2.tar \
5422 --listed-incremental=/var/log/usr.snar-1 \
5423 /usr}
5424 @end smallexample
5425
5426 Incremental dumps depend crucially on time stamps, so the results are
5427 unreliable if you modify a file's time stamps during dumping (e.g.,
5428 with the @option{--atime-preserve=replace} option), or if you set the clock
5429 backwards.
5430
5431 @cindex Device numbers, using in incremental backups
5432 Metadata stored in snapshot files include device numbers, which,
5433 obviously is supposed to be a non-volatile value. However, it turns
5434 out that NFS devices have undependable values when an automounter
5435 gets in the picture. This can lead to a great deal of spurious
5436 redumping in incremental dumps, so it is somewhat useless to compare
5437 two NFS devices numbers over time. The solution implemented currently
5438 is to considers all NFS devices as being equal when it comes to
5439 comparing directories; this is fairly gross, but there does not seem
5440 to be a better way to go.
5441
5442 If you are using the @i{Linux} kernel, the device numbers can also
5443 change when upgrading to some newer versions of the kernel. This can
5444 cause the next backup to be full backup on the affected filesystems.
5445 @xref{Fixing Snapshot Files}, for the information on how to handle this case.
5446
5447 Note that incremental archives use @command{tar} extensions and may
5448 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5449
5450 @xopindex{listed-incremental, using with @option{--extract}}
5451 @xopindex{extract, using with @option{--listed-incremental}}
5452 To extract from the incremental dumps, use
5453 @option{--listed-incremental} together with @option{--extract}
5454 option (@pxref{extracting files}). In this case, @command{tar} does
5455 not need to access snapshot file, since all the data necessary for
5456 extraction are stored in the archive itself. So, when extracting, you
5457 can give whatever argument to @option{--listed-incremental}, the usual
5458 practice is to use @option{--listed-incremental=/dev/null}.
5459 Alternatively, you can use @option{--incremental}, which needs no
5460 arguments. In general, @option{--incremental} (@option{-G}) can be
5461 used as a shortcut for @option{--listed-incremental} when listing or
5462 extracting incremental backups (for more information, regarding this
5463 option, @pxref{incremental-op}).
5464
5465 When extracting from the incremental backup @GNUTAR{} attempts to
5466 restore the exact state the file system had when the archive was
5467 created. In particular, it will @emph{delete} those files in the file
5468 system that did not exist in their directories when the archive was
5469 created. If you have created several levels of incremental files,
5470 then in order to restore the exact contents the file system had when
5471 the last level was created, you will need to restore from all backups
5472 in turn. Continuing our example, to restore the state of @file{/usr}
5473 file system, one would do@footnote{Notice, that since both archives
5474 were created without @option{-P} option (@pxref{absolute}), these
5475 commands should be run from the root file system.}:
5476
5477 @smallexample
5478 $ @kbd{tar --extract \
5479 --listed-incremental=/dev/null \
5480 --file archive.1.tar}
5481 $ @kbd{tar --extract \
5482 --listed-incremental=/dev/null \
5483 --file archive.2.tar}
5484 @end smallexample
5485
5486 To list the contents of an incremental archive, use @option{--list}
5487 (@pxref{list}), as usual. To obtain more information about the
5488 archive, use @option{--listed-incremental} or @option{--incremental}
5489 combined with two @option{--verbose} options@footnote{Two
5490 @option{--verbose} options were selected to avoid breaking usual
5491 verbose listing output (@option{--list --verbose}) when using in
5492 scripts.
5493
5494 @xopindex{incremental, using with @option{--list}}
5495 @xopindex{listed-incremental, using with @option{--list}}
5496 @xopindex{list, using with @option{--incremental}}
5497 @xopindex{list, using with @option{--listed-incremental}}
5498 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5499 contents of the DUMPDIR header (with terminating nulls) when
5500 @option{--incremental} or @option{--listed-incremental} option was
5501 given, no matter what the verbosity level. This behavior, and,
5502 especially, the binary output it produced were considered inconvenient
5503 and were changed in version 1.16}:
5504
5505 @smallexample
5506 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5507 @end smallexample
5508
5509 This command will print, for each directory in the archive, the list
5510 of files in that directory at the time the archive was created. This
5511 information is put out in a format which is both human-readable and
5512 unambiguous for a program: each file name is printed as
5513
5514 @smallexample
5515 @var{x} @var{file}
5516 @end smallexample
5517
5518 @noindent
5519 where @var{x} is a letter describing the status of the file: @samp{Y}
5520 if the file is present in the archive, @samp{N} if the file is not
5521 included in the archive, or a @samp{D} if the file is a directory (and
5522 is included in the archive). @xref{Dumpdir}, for the detailed
5523 description of dumpdirs and status codes. Each such
5524 line is terminated by a newline character. The last line is followed
5525 by an additional newline to indicate the end of the data.
5526
5527 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5528 gives the same behavior as @option{--listed-incremental} when used
5529 with @option{--list} and @option{--extract} options. When used with
5530 @option{--create} option, it creates an incremental archive without
5531 creating snapshot file. Thus, it is impossible to create several
5532 levels of incremental backups with @option{--incremental} option.
5533
5534 @node Backup Levels
5535 @section Levels of Backups
5536
5537 An archive containing all the files in the file system is called a
5538 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5539 creating a full dump every day. This strategy, however, would waste a
5540 substantial amount of archive media and user time, as unchanged files
5541 are daily re-archived.
5542
5543 It is more efficient to do a full dump only occasionally. To back up
5544 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5545 one} dump archives all the files that have changed since the last full
5546 dump.
5547
5548 A typical dump strategy would be to perform a full dump once a week,
5549 and a level one dump once a day. This means some versions of files
5550 will in fact be archived more than once, but this dump strategy makes
5551 it possible to restore a file system to within one day of accuracy by
5552 only extracting two archives---the last weekly (full) dump and the
5553 last daily (level one) dump. The only information lost would be in
5554 files changed or created since the last daily backup. (Doing dumps
5555 more than once a day is usually not worth the trouble).
5556
5557 @GNUTAR{} comes with scripts you can use to do full
5558 and level-one (actually, even level-two and so on) dumps. Using
5559 scripts (shell programs) to perform backups and restoration is a
5560 convenient and reliable alternative to typing out file name lists
5561 and @command{tar} commands by hand.
5562
5563 Before you use these scripts, you need to edit the file
5564 @file{backup-specs}, which specifies parameters used by the backup
5565 scripts and by the restore script. This file is usually located
5566 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5567 detailed description. Once the backup parameters are set, you can
5568 perform backups or restoration by running the appropriate script.
5569
5570 The name of the backup script is @code{backup}. The name of the
5571 restore script is @code{restore}. The following sections describe
5572 their use in detail.
5573
5574 @emph{Please Note:} The backup and restoration scripts are
5575 designed to be used together. While it is possible to restore files by
5576 hand from an archive which was created using a backup script, and to create
5577 an archive by hand which could then be extracted using the restore script,
5578 it is easier to use the scripts. @xref{Incremental Dumps}, before
5579 making such an attempt.
5580
5581 @node Backup Parameters
5582 @section Setting Parameters for Backups and Restoration
5583
5584 The file @file{backup-specs} specifies backup parameters for the
5585 backup and restoration scripts provided with @command{tar}. You must
5586 edit @file{backup-specs} to fit your system configuration and schedule
5587 before using these scripts.
5588
5589 Syntactically, @file{backup-specs} is a shell script, containing
5590 mainly variable assignments. However, any valid shell construct
5591 is allowed in this file. Particularly, you may wish to define
5592 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5593 For more information about shell script syntax, please refer to
5594 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5595 g_02, the definition of the Shell Command Language}. See also
5596 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5597
5598 The shell variables controlling behavior of @code{backup} and
5599 @code{restore} are described in the following subsections.
5600
5601 @menu
5602 * General-Purpose Variables::
5603 * Magnetic Tape Control::
5604 * User Hooks::
5605 * backup-specs example:: An Example Text of @file{Backup-specs}
5606 @end menu
5607
5608 @node General-Purpose Variables
5609 @subsection General-Purpose Variables
5610
5611 @defvr {Backup variable} ADMINISTRATOR
5612 The user name of the backup administrator. @code{Backup} scripts
5613 sends a backup report to this address.
5614 @end defvr
5615
5616 @defvr {Backup variable} BACKUP_HOUR
5617 The hour at which the backups are done. This can be a number from 0
5618 to 23, or the time specification in form @var{hours}:@var{minutes},
5619 or the string @samp{now}.
5620
5621 This variable is used by @code{backup}. Its value may be overridden
5622 using @option{--time} option (@pxref{Scripted Backups}).
5623 @end defvr
5624
5625 @defvr {Backup variable} TAPE_FILE
5626
5627 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5628 is a remote archive (@pxref{remote-dev}), backup script will suppose
5629 that your @command{mt} is able to access remote devices. If @var{RSH}
5630 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5631 invocations of @command{mt}.
5632 @end defvr
5633
5634 @defvr {Backup variable} BLOCKING
5635
5636 The blocking factor @command{tar} will use when writing the dump archive.
5637 @xref{Blocking Factor}.
5638 @end defvr
5639
5640 @defvr {Backup variable} BACKUP_DIRS
5641
5642 A list of file systems to be dumped (for @code{backup}), or restored
5643 (for @code{restore}). You can include any directory
5644 name in the list --- subdirectories on that file system will be
5645 included, regardless of how they may look to other networked machines.
5646 Subdirectories on other file systems will be ignored.
5647
5648 The host name specifies which host to run @command{tar} on, and should
5649 normally be the host that actually contains the file system. However,
5650 the host machine must have @GNUTAR{} installed, and
5651 must be able to access the directory containing the backup scripts and
5652 their support files using the same file name that is used on the
5653 machine where the scripts are run (i.e., what @command{pwd} will print
5654 when in that directory on that machine). If the host that contains
5655 the file system does not have this capability, you can specify another
5656 host as long as it can access the file system through NFS.
5657
5658 If the list of file systems is very long you may wish to put it
5659 in a separate file. This file is usually named
5660 @file{/etc/backup/dirs}, but this name may be overridden in
5661 @file{backup-specs} using @code{DIRLIST} variable.
5662 @end defvr
5663
5664 @defvr {Backup variable} DIRLIST
5665
5666 The name of the file that contains a list of file systems to backup
5667 or restore. By default it is @file{/etc/backup/dirs}.
5668 @end defvr
5669
5670 @defvr {Backup variable} BACKUP_FILES
5671
5672 A list of individual files to be dumped (for @code{backup}), or restored
5673 (for @code{restore}). These should be accessible from the machine on
5674 which the backup script is run.
5675
5676 If the list of file systems is very long you may wish to store it
5677 in a separate file. This file is usually named
5678 @file{/etc/backup/files}, but this name may be overridden in
5679 @file{backup-specs} using @code{FILELIST} variable.
5680 @end defvr
5681
5682 @defvr {Backup variable} FILELIST
5683
5684 The name of the file that contains a list of individual files to backup
5685 or restore. By default it is @file{/etc/backup/files}.
5686 @end defvr
5687
5688 @defvr {Backup variable} MT
5689
5690 Full file name of @command{mt} binary.
5691 @end defvr
5692
5693 @defvr {Backup variable} RSH
5694 @anchor{RSH}
5695 Full file name of @command{rsh} binary or its equivalent. You may wish to
5696 set it to @code{ssh}, to improve security. In this case you will have
5697 to use public key authentication.
5698 @end defvr
5699
5700 @defvr {Backup variable} RSH_COMMAND
5701
5702 Full file name of @command{rsh} binary on remote machines. This will
5703 be passed via @option{--rsh-command} option to the remote invocation
5704 of @GNUTAR{}.
5705 @end defvr
5706
5707 @defvr {Backup variable} VOLNO_FILE
5708
5709 Name of temporary file to hold volume numbers. This needs to be accessible
5710 by all the machines which have file systems to be dumped.
5711 @end defvr
5712
5713 @defvr {Backup variable} XLIST
5714
5715 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5716 located on the remote machine and containing the list of files to
5717 be excluded from the backup. Exclude file lists are searched in
5718 /etc/tar-backup directory. A common use for exclude file lists
5719 is to exclude files containing security-sensitive information
5720 (e.g., @file{/etc/shadow} from backups).
5721
5722 This variable affects only @code{backup}.
5723 @end defvr
5724
5725 @defvr {Backup variable} SLEEP_TIME
5726
5727 Time to sleep between dumps of any two successive file systems
5728
5729 This variable affects only @code{backup}.
5730 @end defvr
5731
5732 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5733
5734 Script to be run when it's time to insert a new tape in for the next
5735 volume. Administrators may want to tailor this script for their site.
5736 If this variable isn't set, @GNUTAR{} will display its built-in
5737 prompt, and will expect confirmation from the console. For the
5738 description of the default prompt, see @ref{change volume prompt}.
5739
5740 @end defvr
5741
5742 @defvr {Backup variable} SLEEP_MESSAGE
5743
5744 Message to display on the terminal while waiting for dump time. Usually
5745 this will just be some literal text.
5746 @end defvr
5747
5748 @defvr {Backup variable} TAR
5749
5750 Full file name of the @GNUTAR{} executable. If this is not set, backup
5751 scripts will search @command{tar} in the current shell path.
5752 @end defvr
5753
5754 @node Magnetic Tape Control
5755 @subsection Magnetic Tape Control
5756
5757 Backup scripts access tape device using special @dfn{hook functions}.
5758 These functions take a single argument -- the name of the tape
5759 device. Their names are kept in the following variables:
5760
5761 @defvr {Backup variable} MT_BEGIN
5762 The name of @dfn{begin} function. This function is called before
5763 accessing the drive. By default it retensions the tape:
5764
5765 @smallexample
5766 MT_BEGIN=mt_begin
5767
5768 mt_begin() @{
5769 mt -f "$1" retension
5770 @}
5771 @end smallexample
5772 @end defvr
5773
5774 @defvr {Backup variable} MT_REWIND
5775 The name of @dfn{rewind} function. The default definition is as
5776 follows:
5777
5778 @smallexample
5779 MT_REWIND=mt_rewind
5780
5781 mt_rewind() @{
5782 mt -f "$1" rewind
5783 @}
5784 @end smallexample
5785
5786 @end defvr
5787
5788 @defvr {Backup variable} MT_OFFLINE
5789 The name of the function switching the tape off line. By default
5790 it is defined as follows:
5791
5792 @smallexample
5793 MT_OFFLINE=mt_offline
5794
5795 mt_offline() @{
5796 mt -f "$1" offl
5797 @}
5798 @end smallexample
5799 @end defvr
5800
5801 @defvr {Backup variable} MT_STATUS
5802 The name of the function used to obtain the status of the archive device,
5803 including error count. Default definition:
5804
5805 @smallexample
5806 MT_STATUS=mt_status
5807
5808 mt_status() @{
5809 mt -f "$1" status
5810 @}
5811 @end smallexample
5812 @end defvr
5813
5814 @node User Hooks
5815 @subsection User Hooks
5816
5817 @dfn{User hooks} are shell functions executed before and after
5818 each @command{tar} invocation. Thus, there are @dfn{backup
5819 hooks}, which are executed before and after dumping each file
5820 system, and @dfn{restore hooks}, executed before and
5821 after restoring a file system. Each user hook is a shell function
5822 taking four arguments:
5823
5824 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5825 Its arguments are:
5826
5827 @table @var
5828 @item level
5829 Current backup or restore level.
5830
5831 @item host
5832 Name or IP address of the host machine being dumped or restored.
5833
5834 @item fs
5835 Full file name of the file system being dumped or restored.
5836
5837 @item fsname
5838 File system name with directory separators replaced with colons. This
5839 is useful, e.g., for creating unique files.
5840 @end table
5841 @end deffn
5842
5843 Following variables keep the names of user hook functions
5844
5845 @defvr {Backup variable} DUMP_BEGIN
5846 Dump begin function. It is executed before dumping the file system.
5847 @end defvr
5848
5849 @defvr {Backup variable} DUMP_END
5850 Executed after dumping the file system.
5851 @end defvr
5852
5853 @defvr {Backup variable} RESTORE_BEGIN
5854 Executed before restoring the file system.
5855 @end defvr
5856
5857 @defvr {Backup variable} RESTORE_END
5858 Executed after restoring the file system.
5859 @end defvr
5860
5861 @node backup-specs example
5862 @subsection An Example Text of @file{Backup-specs}
5863
5864 The following is an example of @file{backup-specs}:
5865
5866 @smallexample
5867 # site-specific parameters for file system backup.
5868
5869 ADMINISTRATOR=friedman
5870 BACKUP_HOUR=1
5871 TAPE_FILE=/dev/nrsmt0
5872
5873 # Use @code{ssh} instead of the less secure @code{rsh}
5874 RSH=/usr/bin/ssh
5875 RSH_COMMAND=/usr/bin/ssh
5876
5877 # Override MT_STATUS function:
5878 my_status() @{
5879 mts -t $TAPE_FILE
5880 @}
5881 MT_STATUS=my_status
5882
5883 # Disable MT_OFFLINE function
5884 MT_OFFLINE=:
5885
5886 BLOCKING=124
5887 BACKUP_DIRS="
5888 albert:/fs/fsf
5889 apple-gunkies:/gd
5890 albert:/fs/gd2
5891 albert:/fs/gp
5892 geech:/usr/jla
5893 churchy:/usr/roland
5894 albert:/
5895 albert:/usr
5896 apple-gunkies:/
5897 apple-gunkies:/usr
5898 gnu:/hack
5899 gnu:/u
5900 apple-gunkies:/com/mailer/gnu
5901 apple-gunkies:/com/archive/gnu"
5902
5903 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5904
5905 @end smallexample
5906
5907 @node Scripted Backups
5908 @section Using the Backup Scripts
5909
5910 The syntax for running a backup script is:
5911
5912 @smallexample
5913 backup --level=@var{level} --time=@var{time}
5914 @end smallexample
5915
5916 The @option{level} option requests the dump level. Thus, to produce
5917 a full dump, specify @code{--level=0} (this is the default, so
5918 @option{--level} may be omitted if its value is @code{0}).
5919 @footnote{For backward compatibility, the @code{backup} will also
5920 try to deduce the requested dump level from the name of the
5921 script itself. If the name consists of a string @samp{level-}
5922 followed by a single decimal digit, that digit is taken as
5923 the dump level number. Thus, you may create a link from @code{backup}
5924 to @code{level-1} and then run @code{level-1} whenever you need to
5925 create a level one dump.}
5926
5927 The @option{--time} option determines when should the backup be
5928 run. @var{Time} may take three forms:
5929
5930 @table @asis
5931 @item @var{hh}:@var{mm}
5932
5933 The dump must be run at @var{hh} hours @var{mm} minutes.
5934
5935 @item @var{hh}
5936
5937 The dump must be run at @var{hh} hours
5938
5939 @item now
5940
5941 The dump must be run immediately.
5942 @end table
5943
5944 You should start a script with a tape or disk mounted. Once you
5945 start a script, it prompts you for new tapes or disks as it
5946 needs them. Media volumes don't have to correspond to archive
5947 files --- a multi-volume archive can be started in the middle of a
5948 tape that already contains the end of another multi-volume archive.
5949 The @code{restore} script prompts for media by its archive volume,
5950 so to avoid an error message you should keep track of which tape
5951 (or disk) contains which volume of the archive (@pxref{Scripted
5952 Restoration}).
5953
5954 The backup scripts write two files on the file system. The first is a
5955 record file in @file{/etc/tar-backup/}, which is used by the scripts
5956 to store and retrieve information about which files were dumped. This
5957 file is not meant to be read by humans, and should not be deleted by
5958 them. @xref{Snapshot Files}, for a more detailed explanation of this
5959 file.
5960
5961 The second file is a log file containing the names of the file systems
5962 and files dumped, what time the backup was made, and any error
5963 messages that were generated, as well as how much space was left in
5964 the media volume after the last volume of the archive was written.
5965 You should check this log file after every backup. The file name is
5966 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5967 represents current date, and @var{n} represents current dump level number.
5968
5969 The script also prints the name of each system being dumped to the
5970 standard output.
5971
5972 Following is the full list of options accepted by @code{backup}
5973 script:
5974
5975 @table @option
5976 @item -l @var{level}
5977 @itemx --level=@var{level}
5978 Do backup level @var{level} (default 0).
5979
5980 @item -f
5981 @itemx --force
5982 Force backup even if today's log file already exists.
5983
5984 @item -v[@var{level}]
5985 @itemx --verbose[=@var{level}]
5986 Set verbosity level. The higher the level is, the more debugging
5987 information will be output during execution. Default @var{level}
5988 is 100, which means the highest debugging level.
5989
5990 @item -t @var{start-time}
5991 @itemx --time=@var{start-time}
5992 Wait till @var{time}, then do backup.
5993
5994 @item -h
5995 @itemx --help
5996 Display short help message and exit.
5997
5998 @item -V
5999 @itemx --version
6000 Display information about the program's name, version, origin and legal
6001 status, all on standard output, and then exit successfully.
6002 @end table
6003
6004
6005 @node Scripted Restoration
6006 @section Using the Restore Script
6007
6008 To restore files that were archived using a scripted backup, use the
6009 @code{restore} script. Its usage is quite straightforward. In the
6010 simplest form, invoke @code{restore --all}, it will
6011 then restore all the file systems and files specified in
6012 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6013
6014 You may select the file systems (and/or files) to restore by
6015 giving @code{restore} list of @dfn{patterns} in its command
6016 line. For example, running
6017
6018 @smallexample
6019 restore 'albert:*'
6020 @end smallexample
6021
6022 @noindent
6023 will restore all file systems on the machine @samp{albert}. A more
6024 complicated example:
6025
6026 @smallexample
6027 restore 'albert:*' '*:/var'
6028 @end smallexample
6029
6030 @noindent
6031 This command will restore all file systems on the machine @samp{albert}
6032 as well as @file{/var} file system on all machines.
6033
6034 By default @code{restore} will start restoring files from the lowest
6035 available dump level (usually zero) and will continue through
6036 all available dump levels. There may be situations where such a
6037 thorough restore is not necessary. For example, you may wish to
6038 restore only files from the recent level one backup. To do so,
6039 use @option{--level} option, as shown in the example below:
6040
6041 @smallexample
6042 restore --level=1
6043 @end smallexample
6044
6045 The full list of options accepted by @code{restore} follows:
6046
6047 @table @option
6048 @item -a
6049 @itemx --all
6050 Restore all file systems and files specified in @file{backup-specs}
6051
6052 @item -l @var{level}
6053 @itemx --level=@var{level}
6054 Start restoring from the given backup level, instead of the default 0.
6055
6056 @item -v[@var{level}]
6057 @itemx --verbose[=@var{level}]
6058 Set verbosity level. The higher the level is, the more debugging
6059 information will be output during execution. Default @var{level}
6060 is 100, which means the highest debugging level.
6061
6062 @item -h
6063 @itemx --help
6064 Display short help message and exit.
6065
6066 @item -V
6067 @itemx --version
6068 Display information about the program's name, version, origin and legal
6069 status, all on standard output, and then exit successfully.
6070 @end table
6071
6072 You should start the restore script with the media containing the
6073 first volume of the archive mounted. The script will prompt for other
6074 volumes as they are needed. If the archive is on tape, you don't need
6075 to rewind the tape to to its beginning---if the tape head is
6076 positioned past the beginning of the archive, the script will rewind
6077 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6078 positioning.
6079
6080 @quotation
6081 @strong{Warning:} The script will delete files from the active file
6082 system if they were not in the file system when the archive was made.
6083 @end quotation
6084
6085 @xref{Incremental Dumps}, for an explanation of how the script makes
6086 that determination.
6087
6088 @node Choosing
6089 @chapter Choosing Files and Names for @command{tar}
6090 @UNREVISED
6091
6092 Certain options to @command{tar} enable you to specify a name for your
6093 archive. Other options let you decide which files to include or exclude
6094 from the archive, based on when or whether files were modified, whether
6095 the file names do or don't match specified patterns, or whether files
6096 are in specified directories.
6097
6098 This chapter discusses these options in detail.
6099
6100 @menu
6101 * file:: Choosing the Archive's Name
6102 * Selecting Archive Members::
6103 * files:: Reading Names from a File
6104 * exclude:: Excluding Some Files
6105 * wildcards:: Wildcards Patterns and Matching
6106 * quoting styles:: Ways of Quoting Special Characters in Names
6107 * transform:: Modifying File and Member Names
6108 * after:: Operating Only on New Files
6109 * recurse:: Descending into Directories
6110 * one:: Crossing File System Boundaries
6111 @end menu
6112
6113 @node file
6114 @section Choosing and Naming Archive Files
6115 @UNREVISED
6116
6117 @cindex Naming an archive
6118 @cindex Archive Name
6119 @cindex Choosing an archive file
6120 @cindex Where is the archive?
6121 By default, @command{tar} uses an archive file name that was compiled when
6122 it was built on the system; usually this name refers to some physical
6123 tape drive on the machine. However, the person who installed @command{tar}
6124 on the system may not have set the default to a meaningful value as far as
6125 most users are concerned. As a result, you will usually want to tell
6126 @command{tar} where to find (or create) the archive. The
6127 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6128 option allows you to either specify or name a file to use as the archive
6129 instead of the default archive file location.
6130
6131 @table @option
6132 @xopindex{file, short description}
6133 @item --file=@var{archive-name}
6134 @itemx -f @var{archive-name}
6135 Name the archive to create or operate on. Use in conjunction with
6136 any operation.
6137 @end table
6138
6139 For example, in this @command{tar} command,
6140
6141 @smallexample
6142 $ @kbd{tar -cvf collection.tar blues folk jazz}
6143 @end smallexample
6144
6145 @noindent
6146 @file{collection.tar} is the name of the archive. It must directly
6147 follow the @option{-f} option, since whatever directly follows @option{-f}
6148 @emph{will} end up naming the archive. If you neglect to specify an
6149 archive name, you may end up overwriting a file in the working directory
6150 with the archive you create since @command{tar} will use this file's name
6151 for the archive name.
6152
6153 An archive can be saved as a file in the file system, sent through a
6154 pipe or over a network, or written to an I/O device such as a tape,
6155 floppy disk, or CD write drive.
6156
6157 @cindex Writing new archives
6158 @cindex Archive creation
6159 If you do not name the archive, @command{tar} uses the value of the
6160 environment variable @env{TAPE} as the file name for the archive. If
6161 that is not available, @command{tar} uses a default, compiled-in archive
6162 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6163
6164 @cindex Standard input and output
6165 @cindex tar to standard input and output
6166 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6167 archive from standard input (when listing or extracting files), or
6168 writes it to standard output (when creating an archive). If you use
6169 @file{-} as an @var{archive-name} when modifying an archive,
6170 @command{tar} reads the original archive from its standard input and
6171 writes the entire new archive to its standard output.
6172
6173 The following example is a convenient way of copying directory
6174 hierarchy from @file{sourcedir} to @file{targetdir}.
6175
6176 @smallexample
6177 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6178 @end smallexample
6179
6180 The @option{-C} option allows to avoid using subshells:
6181
6182 @smallexample
6183 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6184 @end smallexample
6185
6186 In both examples above, the leftmost @command{tar} invocation archives
6187 the contents of @file{sourcedir} to the standard output, while the
6188 rightmost one reads this archive from its standard input and
6189 extracts it. The @option{-p} option tells it to restore permissions
6190 of the extracted files.
6191
6192 @cindex Remote devices
6193 @cindex tar to a remote device
6194 @anchor{remote-dev}
6195 To specify an archive file on a device attached to a remote machine,
6196 use the following:
6197
6198 @smallexample
6199 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6200 @end smallexample
6201
6202 @noindent
6203 @command{tar} will complete the remote connection, if possible, and
6204 prompt you for a username and password. If you use
6205 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6206 will complete the remote connection, if possible, using your username
6207 as the username on the remote machine.
6208
6209 @cindex Local and remote archives
6210 @anchor{local and remote archives}
6211 If the archive file name includes a colon (@samp{:}), then it is assumed
6212 to be a file on another machine. If the archive file is
6213 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6214 host @var{host}. The remote host is accessed using the @command{rsh}
6215 program, with a username of @var{user}. If the username is omitted
6216 (along with the @samp{@@} sign), then your user name will be used.
6217 (This is the normal @command{rsh} behavior.) It is necessary for the
6218 remote machine, in addition to permitting your @command{rsh} access, to
6219 have the @file{rmt} program installed (This command is included in
6220 the @GNUTAR{} distribution and by default is installed under
6221 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6222 installation prefix). If you need to use a file whose name includes a
6223 colon, then the remote tape drive behavior
6224 can be inhibited by using the @option{--force-local} option.
6225
6226 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6227 tries to minimize input and output operations. The Amanda backup
6228 system, when used with @GNUTAR{}, has an initial sizing pass which
6229 uses this feature.
6230
6231 @node Selecting Archive Members
6232 @section Selecting Archive Members
6233 @cindex Specifying files to act on
6234 @cindex Specifying archive members
6235
6236 @dfn{File Name arguments} specify which files in the file system
6237 @command{tar} operates on, when creating or adding to an archive, or which
6238 archive members @command{tar} operates on, when reading or deleting from
6239 an archive. @xref{Operations}.
6240
6241 To specify file names, you can include them as the last arguments on
6242 the command line, as follows:
6243 @smallexample
6244 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6245 @end smallexample
6246
6247 If a file name begins with dash (@samp{-}), precede it with
6248 @option{--add-file} option to prevent it from being treated as an
6249 option.
6250
6251 @anchor{input name quoting}
6252 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6253 name, replacing @dfn{escape sequences} according to the following
6254 table:
6255
6256 @multitable @columnfractions 0.20 0.60
6257 @headitem Escape @tab Replaced with
6258 @item \a @tab Audible bell (@acronym{ASCII} 7)
6259 @item \b @tab Backspace (@acronym{ASCII} 8)
6260 @item \f @tab Form feed (@acronym{ASCII} 12)
6261 @item \n @tab New line (@acronym{ASCII} 10)
6262 @item \r @tab Carriage return (@acronym{ASCII} 13)
6263 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
6264 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
6265 @item \? @tab @acronym{ASCII} 127
6266 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6267 of up to 3 digits)
6268 @end multitable
6269
6270 A backslash followed by any other symbol is retained.
6271
6272 This default behavior is controlled by the following command line
6273 option:
6274
6275 @table @option
6276 @opindex unquote
6277 @item --unquote
6278 Enable unquoting input file or member names (default).
6279
6280 @opindex no-unquote
6281 @item --no-unquote
6282 Disable unquoting input file or member names.
6283 @end table
6284
6285 If you specify a directory name as a file name argument, all the files
6286 in that directory are operated on by @command{tar}.
6287
6288 If you do not specify files, @command{tar} behavior differs depending
6289 on the operation mode as described below:
6290
6291 When @command{tar} is invoked with @option{--create} (@option{-c}),
6292 @command{tar} will stop immediately, reporting the following:
6293
6294 @smallexample
6295 @group
6296 $ @kbd{tar cf a.tar}
6297 tar: Cowardly refusing to create an empty archive
6298 Try `tar --help' or `tar --usage' for more information.
6299 @end group
6300 @end smallexample
6301
6302 If you specify either @option{--list} (@option{-t}) or
6303 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6304 operates on all the archive members in the archive.
6305
6306 If run with @option{--diff} option, tar will compare the archive with
6307 the contents of the current working directory.
6308
6309 If you specify any other operation, @command{tar} does nothing.
6310
6311 By default, @command{tar} takes file names from the command line. However,
6312 there are other ways to specify file or member names, or to modify the
6313 manner in which @command{tar} selects the files or members upon which to
6314 operate. In general, these methods work both for specifying the names
6315 of files and archive members.
6316
6317 @node files
6318 @section Reading Names from a File
6319
6320 @cindex Reading file names from a file
6321 @cindex Lists of file names
6322 @cindex File Name arguments, alternatives
6323 Instead of giving the names of files or archive members on the command
6324 line, you can put the names into a file, and then use the
6325 @option{--files-from=@var{file-of-names}} (@option{-T
6326 @var{file-of-names}}) option to @command{tar}. Give the name of the
6327 file which contains the list of files to include as the argument to
6328 @option{--files-from}. In the list, the file names should be separated by
6329 newlines. You will frequently use this option when you have generated
6330 the list of files to archive with the @command{find} utility.
6331
6332 @table @option
6333 @opindex files-from
6334 @item --files-from=@var{file-name}
6335 @itemx -T @var{file-name}
6336 Get names to extract or create from file @var{file-name}.
6337 @end table
6338
6339 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6340 you specify either @code{--files-from=-} or @code{-T -}), then the file
6341 names are read from standard input.
6342
6343 Unless you are running @command{tar} with @option{--create}, you can not use
6344 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6345 command.
6346
6347 Any number of @option{-T} options can be given in the command line.
6348
6349 The following example shows how to use @command{find} to generate a list of
6350 files smaller than 400K in length and put that list into a file
6351 called @file{small-files}. You can then use the @option{-T} option to
6352 @command{tar} to specify the files from that file, @file{small-files}, to
6353 create the archive @file{little.tgz}. (The @option{-z} option to
6354 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6355 more information.)
6356
6357 @smallexample
6358 $ @kbd{find . -size -400 -print > small-files}
6359 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6360 @end smallexample
6361
6362 @noindent
6363 In the file list given by @option{-T} option, any file name beginning
6364 with @samp{-} character is considered a @command{tar} option and is
6365 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6366 recognized only @option{-C} option in file lists, and only if the
6367 option and its argument occupied two consecutive lines.} For example,
6368 the common use of this feature is to change to another directory by
6369 specifying @option{-C} option:
6370
6371 @smallexample
6372 @group
6373 $ @kbd{cat list}
6374 -C/etc
6375 passwd
6376 hosts
6377 -C/lib
6378 libc.a
6379 $ @kbd{tar -c -f foo.tar --files-from list}
6380 @end group
6381 @end smallexample
6382
6383 @noindent
6384 In this example, @command{tar} will first switch to @file{/etc}
6385 directory and add files @file{passwd} and @file{hosts} to the
6386 archive. Then it will change to @file{/lib} directory and will archive
6387 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6388 contain:
6389
6390 @smallexample
6391 @group
6392 $ @kbd{tar tf foo.tar}
6393 passwd
6394 hosts
6395 libc.a
6396 @end group
6397 @end smallexample
6398
6399 @noindent
6400 @xopindex{directory, using in @option{--files-from} argument}
6401 Notice that the option parsing algorithm used with @option{-T} is
6402 stricter than the one used by shell. Namely, when specifying option
6403 arguments, you should observe the following rules:
6404
6405 @itemize @bullet
6406 @item
6407 When using short (single-letter) option form, its argument must
6408 immediately follow the option letter, without any intervening
6409 whitespace. For example: @code{-Cdir}.
6410
6411 @item
6412 When using long option form, the option argument must be separated
6413 from the option by a single equal sign. No whitespace is allowed on
6414 any side of the equal sign. For example: @code{--directory=dir}.
6415
6416 @item
6417 For both short and long option forms, the option argument can be given
6418 on the next line after the option name, e.g.:
6419
6420 @smallexample
6421 @group
6422 --directory
6423 dir
6424 @end group
6425 @end smallexample
6426
6427 @noindent
6428 and
6429
6430 @smallexample
6431 @group
6432 -C
6433 dir
6434 @end group
6435 @end smallexample
6436 @end itemize
6437
6438 @opindex add-file
6439 If you happen to have a file whose name starts with @samp{-},
6440 precede it with @option{--add-file} option to prevent it from
6441 being recognized as an option. For example: @code{--add-file=--my-file}.
6442
6443 @menu
6444 * nul::
6445 @end menu
6446
6447 @node nul
6448 @subsection @code{NUL} Terminated File Names
6449
6450 @cindex File names, terminated by @code{NUL}
6451 @cindex @code{NUL} terminated file names
6452 The @option{--null} option causes
6453 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6454 to read file names terminated by a @code{NUL} instead of a newline, so
6455 files whose names contain newlines can be archived using
6456 @option{--files-from}.
6457
6458 @table @option
6459 @opindex null
6460 @item --null
6461 Only consider @code{NUL} terminated file names, instead of files that
6462 terminate in a newline.
6463 @end table
6464
6465 The @option{--null} option is just like the one in @acronym{GNU}
6466 @command{xargs} and @command{cpio}, and is useful with the
6467 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6468 @command{tar}, @option{--null} also disables special handling for
6469 file names that begin with dash.
6470
6471 This example shows how to use @command{find} to generate a list of files
6472 larger than 800K in length and put that list into a file called
6473 @file{long-files}. The @option{-print0} option to @command{find} is just
6474 like @option{-print}, except that it separates files with a @code{NUL}
6475 rather than with a newline. You can then run @command{tar} with both the
6476 @option{--null} and @option{-T} options to specify that @command{tar} get the
6477 files from that file, @file{long-files}, to create the archive
6478 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6479 @command{tar} to recognize the @code{NUL} separator between files.
6480
6481 @smallexample
6482 $ @kbd{find . -size +800 -print0 > long-files}
6483 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6484 @end smallexample
6485
6486 @FIXME{say anything else here to conclude the section?}
6487
6488 @node exclude
6489 @section Excluding Some Files
6490 @UNREVISED
6491
6492 @cindex File names, excluding files by
6493 @cindex Excluding files by name and pattern
6494 @cindex Excluding files by file system
6495 To avoid operating on files whose names match a particular pattern,
6496 use the @option{--exclude} or @option{--exclude-from} options.
6497
6498 @table @option
6499 @opindex exclude
6500 @item --exclude=@var{pattern}
6501 Causes @command{tar} to ignore files that match the @var{pattern}.
6502 @end table
6503
6504 @findex exclude
6505 The @option{--exclude=@var{pattern}} option prevents any file or
6506 member whose name matches the shell wildcard (@var{pattern}) from
6507 being operated on.
6508 For example, to create an archive with all the contents of the directory
6509 @file{src} except for files whose names end in @file{.o}, use the
6510 command @samp{tar -cf src.tar --exclude='*.o' src}.
6511
6512 You may give multiple @option{--exclude} options.
6513
6514 @table @option
6515 @opindex exclude-from
6516 @item --exclude-from=@var{file}
6517 @itemx -X @var{file}
6518 Causes @command{tar} to ignore files that match the patterns listed in
6519 @var{file}.
6520 @end table
6521
6522 @findex exclude-from
6523 Use the @option{--exclude-from} option to read a
6524 list of patterns, one per line, from @var{file}; @command{tar} will
6525 ignore files matching those patterns. Thus if @command{tar} is
6526 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6527 single line @file{*.o}, no files whose names end in @file{.o} will be
6528 added to the archive.
6529
6530 Notice, that lines from @var{file} are read verbatim. One of the
6531 frequent errors is leaving some extra whitespace after a file name,
6532 which is difficult to catch using text editors.
6533
6534 However, empty lines are OK.
6535
6536 @cindex version control system, excluding files
6537 @cindex VCS, excluding files
6538 @cindex SCCS, excluding files
6539 @cindex RCS, excluding files
6540 @cindex CVS, excluding files
6541 @cindex SVN, excluding files
6542 @cindex git, excluding files
6543 @table @option
6544 @opindex exclude-vcs
6545 @item --exclude-vcs
6546 Exclude files and directories used by some version control systems.
6547 @end table
6548
6549 As of version @value{VERSION}, the following files are excluded:
6550
6551 @itemize @bullet
6552 @item @file{CVS/}, and everything under it
6553 @item @file{RCS/}, and everything under it
6554 @item @file{SCCS/}, and everything under it
6555 @item @file{.git/}, and everything under it
6556 @item @file{.gitignore}
6557 @item @file{.cvsignore}
6558 @item @file{.svn/}, and everything under it
6559 @item @file{.arch-ids/}, and everything under it
6560 @item @file{@{arch@}/}, and everything under it
6561 @item @file{=RELEASE-ID}
6562 @item @file{=meta-update}
6563 @item @file{=update}
6564 @end itemize
6565
6566 @findex exclude-caches
6567 When creating an archive, the @option{--exclude-caches} option family
6568 causes @command{tar} to exclude all directories that contain a @dfn{cache
6569 directory tag}. A cache directory tag is a short file with the
6570 well-known name @file{CACHEDIR.TAG} and having a standard header
6571 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6572 Various applications write cache directory tags into directories they
6573 use to hold regenerable, non-precious data, so that such data can be
6574 more easily excluded from backups.
6575
6576 There are three @samp{exclude-caches} options, each providing a different
6577 exclusion semantics:
6578
6579 @table @option
6580 @opindex exclude-caches
6581 @item --exclude-caches
6582 Do not archive the contents of the directory, but archive the
6583 directory itself and the @file{CACHEDIR.TAG} file.
6584
6585 @opindex exclude-caches-under
6586 @item --exclude-caches-under
6587 Do not archive the contents of the directory, nor the
6588 @file{CACHEDIR.TAG} file, archive only the directory itself.
6589
6590 @opindex exclude-caches-all
6591 @item --exclude-caches-all
6592 Omit directories containing @file{CACHEDIR.TAG} file entirely.
6593 @end table
6594
6595 @findex exclude-tag
6596 Another option family, @option{--exclude-tag}, provides a generalization of
6597 this concept. It takes a single argument, a file name to look for.
6598 Any directory that contains this file will be excluded from the dump.
6599 Similarly to @samp{exclude-caches}, there are three options in this
6600 option family:
6601
6602 @table @option
6603 @opindex exclude-tag
6604 @item --exclude-tag=@var{file}
6605 Do not dump the contents of the directory, but dump the
6606 directory itself and the @var{file}.
6607
6608 @opindex exclude-tag-under
6609 @item --exclude-tag-under=@var{file}
6610 Do not dump the contents of the directory, nor the
6611 @var{file}, archive only the directory itself.
6612
6613 @opindex exclude-tag-all
6614 @item --exclude-tag-all=@var{file}
6615 Omit directories containing @var{file} file entirely.
6616 @end table
6617
6618 Multiple @option{--exclude-tag*} options can be given.
6619
6620 For example, given this directory:
6621
6622 @smallexample
6623 @group
6624 $ @kbd{find dir}
6625 dir
6626 dir/blues
6627 dir/jazz
6628 dir/folk
6629 dir/folk/tagfile
6630 dir/folk/sanjuan
6631 dir/folk/trote
6632 @end group
6633 @end smallexample
6634
6635 The @option{--exclude-tag} will produce the following:
6636
6637 @smallexample
6638 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
6639 dir/
6640 dir/blues
6641 dir/jazz
6642 dir/folk/
6643 tar: dir/folk/: contains a cache directory tag tagfile;
6644 contents not dumped
6645 dir/folk/tagfile
6646 @end smallexample
6647
6648 Both the @file{dir/folk} directory and its tagfile are preserved in
6649 the archive, however the rest of files in this directory are not.
6650
6651 Now, using the @option{--exclude-tag-under} option will exclude
6652 @file{tagfile} from the dump, while still preserving the directory
6653 itself, as shown in this example:
6654
6655 @smallexample
6656 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
6657 dir/
6658 dir/blues
6659 dir/jazz
6660 dir/folk/
6661 ./tar: dir/folk/: contains a cache directory tag tagfile;
6662 contents not dumped
6663 @end smallexample
6664
6665 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
6666 directory entirely:
6667
6668 @smallexample
6669 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
6670 dir/
6671 dir/blues
6672 dir/jazz
6673 ./tar: dir/folk/: contains a cache directory tag tagfile;
6674 directory not dumped
6675 @end smallexample
6676
6677 @menu
6678 * problems with exclude::
6679 @end menu
6680
6681 @node problems with exclude
6682 @unnumberedsubsec Problems with Using the @code{exclude} Options
6683
6684 @xopindex{exclude, potential problems with}
6685 Some users find @samp{exclude} options confusing. Here are some common
6686 pitfalls:
6687
6688 @itemize @bullet
6689 @item
6690 The main operating mode of @command{tar} does not act on a file name
6691 explicitly listed on the command line, if one of its file name
6692 components is excluded. In the example above, if
6693 you create an archive and exclude files that end with @samp{*.o}, but
6694 explicitly name the file @samp{dir.o/foo} after all the options have been
6695 listed, @samp{dir.o/foo} will be excluded from the archive.
6696
6697 @item
6698 You can sometimes confuse the meanings of @option{--exclude} and
6699 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6700 to be excluded are given as a pattern on the command line. Use
6701 @option{--exclude-from} to introduce the name of a file which contains
6702 a list of patterns, one per line; each of these patterns can exclude
6703 zero, one, or many files.
6704
6705 @item
6706 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6707 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6708 like @samp{*}. If you do not do this, the shell might expand the
6709 @samp{*} itself using files at hand, so @command{tar} might receive a
6710 list of files instead of one pattern, or none at all, making the
6711 command somewhat illegal. This might not correspond to what you want.
6712
6713 For example, write:
6714
6715 @smallexample
6716 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6717 @end smallexample
6718
6719 @noindent
6720 rather than:
6721
6722 @smallexample
6723 # @emph{Wrong!}
6724 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6725 @end smallexample
6726
6727 @item
6728 You must use use shell syntax, or globbing, rather than @code{regexp}
6729 syntax, when using exclude options in @command{tar}. If you try to use
6730 @code{regexp} syntax to describe files to be excluded, your command
6731 might fail.
6732
6733 @item
6734 @FIXME{The change in semantics must have occurred before 1.11,
6735 so I doubt if it is worth mentioning at all. Anyway, should at
6736 least specify in which version the semantics changed.}
6737 In earlier versions of @command{tar}, what is now the
6738 @option{--exclude-from} option was called @option{--exclude} instead.
6739 Now, @option{--exclude} applies to patterns listed on the command
6740 line and @option{--exclude-from} applies to patterns listed in a
6741 file.
6742
6743 @end itemize
6744
6745 @node wildcards
6746 @section Wildcards Patterns and Matching
6747
6748 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6749 @samp{*} or @samp{?} for example, are replaced and expanded into all
6750 existing files matching the given pattern. @GNUTAR{} can use wildcard
6751 patterns for matching (or globbing) archive members when extracting
6752 from or listing an archive. Wildcard patterns are also used for
6753 verifying volume labels of @command{tar} archives. This section has the
6754 purpose of explaining wildcard syntax for @command{tar}.
6755
6756 @FIXME{the next few paragraphs need work.}
6757
6758 A @var{pattern} should be written according to shell syntax, using wildcard
6759 characters to effect globbing. Most characters in the pattern stand
6760 for themselves in the matched string, and case is significant: @samp{a}
6761 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6762 pattern matches any single character in the matched string. The character
6763 @samp{*} in the pattern matches zero, one, or more single characters in
6764 the matched string. The character @samp{\} says to take the following
6765 character of the pattern @emph{literally}; it is useful when one needs to
6766 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6767
6768 The character @samp{[}, up to the matching @samp{]}, introduces a character
6769 class. A @dfn{character class} is a list of acceptable characters
6770 for the next single character of the matched string. For example,
6771 @samp{[abcde]} would match any of the first five letters of the alphabet.
6772 Note that within a character class, all of the ``special characters''
6773 listed above other than @samp{\} lose their special meaning; for example,
6774 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6775 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6776 the characters @samp{-} and @samp{]} must either come @emph{first} or
6777 @emph{last} in a character class.)
6778
6779 @cindex Excluding characters from a character class
6780 @cindex Character class, excluding characters from
6781 If the first character of the class after the opening @samp{[}
6782 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6783 Rather than listing character to match, it lists those characters which
6784 are @emph{forbidden} as the next single character of the matched string.
6785
6786 Other characters of the class stand for themselves. The special
6787 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6788 letters, is meant to represent all characters between @var{a} and
6789 @var{e}, inclusive.
6790
6791 @FIXME{need to add a sentence or so here to make this clear for those
6792 who don't have dan around.}
6793
6794 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6795 special for wildcard matches. However, if a pattern completely matches
6796 a directory prefix of a matched string, then it matches the full matched
6797 string: thus, excluding a directory also excludes all the files beneath it.
6798
6799 @menu
6800 * controlling pattern-matching::
6801 @end menu
6802
6803 @node controlling pattern-matching
6804 @unnumberedsubsec Controlling Pattern-Matching
6805
6806 For the purposes of this section, we call @dfn{exclusion members} all
6807 member names obtained while processing @option{--exclude} and
6808 @option{--exclude-from} options, and @dfn{inclusion members} those
6809 member names that were given in the command line or read from the file
6810 specified with @option{--files-from} option.
6811
6812 These two pairs of member lists are used in the following operations:
6813 @option{--diff}, @option{--extract}, @option{--list},
6814 @option{--update}.
6815
6816 There are no inclusion members in create mode (@option{--create} and
6817 @option{--append}), since in this mode the names obtained from the
6818 command line refer to @emph{files}, not archive members.
6819
6820 By default, inclusion members are compared with archive members
6821 literally @footnote{Notice that earlier @GNUTAR{} versions used
6822 globbing for inclusion members, which contradicted to UNIX98
6823 specification and was not documented. @xref{Changes}, for more
6824 information on this and other changes.} and exclusion members are
6825 treated as globbing patterns. For example:
6826
6827 @smallexample
6828 @group
6829 $ @kbd{tar tf foo.tar}
6830 a.c
6831 b.c
6832 a.txt
6833 [remarks]
6834 # @i{Member names are used verbatim:}
6835 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6836 [remarks]
6837 # @i{Exclude member names are globbed:}
6838 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6839 a.txt
6840 [remarks]
6841 @end group
6842 @end smallexample
6843
6844 This behavior can be altered by using the following options:
6845
6846 @table @option
6847 @opindex wildcards
6848 @item --wildcards
6849 Treat all member names as wildcards.
6850
6851 @opindex no-wildcards
6852 @item --no-wildcards
6853 Treat all member names as literal strings.
6854 @end table
6855
6856 Thus, to extract files whose names end in @samp{.c}, you can use:
6857
6858 @smallexample
6859 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6860 a.c
6861 b.c
6862 @end smallexample
6863
6864 @noindent
6865 Notice quoting of the pattern to prevent the shell from interpreting
6866 it.
6867
6868 The effect of @option{--wildcards} option is canceled by
6869 @option{--no-wildcards}. This can be used to pass part of
6870 the command line arguments verbatim and other part as globbing
6871 patterns. For example, the following invocation:
6872
6873 @smallexample
6874 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6875 @end smallexample
6876
6877 @noindent
6878 instructs @command{tar} to extract from @file{foo.tar} all files whose
6879 names end in @samp{.txt} and the file named @file{[remarks]}.
6880
6881 Normally, a pattern matches a name if an initial subsequence of the
6882 name's components matches the pattern, where @samp{*}, @samp{?}, and
6883 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6884 and wildcards can match @samp{/}.
6885
6886 Other than optionally stripping leading @samp{/} from names
6887 (@pxref{absolute}), patterns and names are used as-is. For
6888 example, trailing @samp{/} is not trimmed from a user-specified name
6889 before deciding whether to exclude it.
6890
6891 However, this matching procedure can be altered by the options listed
6892 below. These options accumulate. For example:
6893
6894 @smallexample
6895 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6896 @end smallexample
6897
6898 @noindent
6899 ignores case when excluding @samp{makefile}, but not when excluding
6900 @samp{readme}.
6901
6902 @table @option
6903 @opindex anchored
6904 @opindex no-anchored
6905 @item --anchored
6906 @itemx --no-anchored
6907 If anchored, a pattern must match an initial subsequence
6908 of the name's components. Otherwise, the pattern can match any
6909 subsequence. Default is @option{--no-anchored} for exclusion members
6910 and @option{--anchored} inclusion members.
6911
6912 @opindex ignore-case
6913 @opindex no-ignore-case
6914 @item --ignore-case
6915 @itemx --no-ignore-case
6916 When ignoring case, upper-case patterns match lower-case names and vice versa.
6917 When not ignoring case (the default), matching is case-sensitive.
6918
6919 @opindex wildcards-match-slash
6920 @opindex no-wildcards-match-slash
6921 @item --wildcards-match-slash
6922 @itemx --no-wildcards-match-slash
6923 When wildcards match slash (the default for exclusion members), a
6924 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6925 name. Otherwise, @samp{/} is matched only by @samp{/}.
6926
6927 @end table
6928
6929 The @option{--recursion} and @option{--no-recursion} options
6930 (@pxref{recurse}) also affect how member patterns are interpreted. If
6931 recursion is in effect, a pattern matches a name if it matches any of
6932 the name's parent directories.
6933
6934 The following table summarizes pattern-matching default values:
6935
6936 @multitable @columnfractions .3 .7
6937 @headitem Members @tab Default settings
6938 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6939 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6940 @end multitable
6941
6942 @node quoting styles
6943 @section Quoting Member Names
6944
6945 When displaying member names, @command{tar} takes care to avoid
6946 ambiguities caused by certain characters. This is called @dfn{name
6947 quoting}. The characters in question are:
6948
6949 @itemize @bullet
6950 @item Non-printable control characters:
6951
6952 @multitable @columnfractions 0.20 0.10 0.60
6953 @headitem Character @tab @acronym{ASCII} @tab Character name
6954 @item \a @tab 7 @tab Audible bell
6955 @item \b @tab 8 @tab Backspace
6956 @item \f @tab 12 @tab Form feed
6957 @item \n @tab 10 @tab New line
6958 @item \r @tab 13 @tab Carriage return
6959 @item \t @tab 9 @tab Horizontal tabulation
6960 @item \v @tab 11 @tab Vertical tabulation
6961 @end multitable
6962
6963 @item Space (@acronym{ASCII} 32)
6964
6965 @item Single and double quotes (@samp{'} and @samp{"})
6966
6967 @item Backslash (@samp{\})
6968 @end itemize
6969
6970 The exact way @command{tar} uses to quote these characters depends on
6971 the @dfn{quoting style}. The default quoting style, called
6972 @dfn{escape} (see below), uses backslash notation to represent control
6973 characters, space and backslash. Using this quoting style, control
6974 characters are represented as listed in column @samp{Character} in the
6975 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6976
6977 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6978 using @option{--quoting-style} option:
6979
6980 @table @option
6981 @item --quoting-style=@var{style}
6982 @opindex quoting-style
6983
6984 Sets quoting style. Valid values for @var{style} argument are:
6985 literal, shell, shell-always, c, escape, locale, clocale.
6986 @end table
6987
6988 These styles are described in detail below. To illustrate their
6989 effect, we will use an imaginary tar archive @file{arch.tar}
6990 containing the following members:
6991
6992 @smallexample
6993 @group
6994 # 1. Contains horizontal tabulation character.
6995 a tab
6996 # 2. Contains newline character
6997 a
6998 newline
6999 # 3. Contains a space
7000 a space
7001 # 4. Contains double quotes
7002 a"double"quote
7003 # 5. Contains single quotes
7004 a'single'quote
7005 # 6. Contains a backslash character:
7006 a\backslash
7007 @end group
7008 @end smallexample
7009
7010 Here is how usual @command{ls} command would have listed them, if they
7011 had existed in the current working directory:
7012
7013 @smallexample
7014 @group
7015 $ @kbd{ls}
7016 a\ttab
7017 a\nnewline
7018 a\ space
7019 a"double"quote
7020 a'single'quote
7021 a\\backslash
7022 @end group
7023 @end smallexample
7024
7025 Quoting styles:
7026
7027 @table @samp
7028 @item literal
7029 No quoting, display each character as is:
7030
7031 @smallexample
7032 @group
7033 $ @kbd{tar tf arch.tar --quoting-style=literal}
7034 ./
7035 ./a space
7036 ./a'single'quote
7037 ./a"double"quote
7038 ./a\backslash
7039 ./a tab
7040 ./a
7041 newline
7042 @end group
7043 @end smallexample
7044
7045 @item shell
7046 Display characters the same way Bourne shell does:
7047 control characters, except @samp{\t} and @samp{\n}, are printed using
7048 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7049 single quote is printed as @samp{\'}. If a name contains any quoted
7050 characters, it is enclosed in single quotes. In particular, if a name
7051 contains single quotes, it is printed as several single-quoted strings:
7052
7053 @smallexample
7054 @group
7055 $ @kbd{tar tf arch.tar --quoting-style=shell}
7056 ./
7057 './a space'
7058 './a'\''single'\''quote'
7059 './a"double"quote'
7060 './a\backslash'
7061 './a tab'
7062 './a
7063 newline'
7064 @end group
7065 @end smallexample
7066
7067 @item shell-always
7068 Same as @samp{shell}, but the names are always enclosed in single
7069 quotes:
7070
7071 @smallexample
7072 @group
7073 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7074 './'
7075 './a space'
7076 './a'\''single'\''quote'
7077 './a"double"quote'
7078 './a\backslash'
7079 './a tab'
7080 './a
7081 newline'
7082 @end group
7083 @end smallexample
7084
7085 @item c
7086 Use the notation of the C programming language. All names are
7087 enclosed in double quotes. Control characters are quoted using
7088 backslash notations, double quotes are represented as @samp{\"},
7089 backslash characters are represented as @samp{\\}. Single quotes and
7090 spaces are not quoted:
7091
7092 @smallexample
7093 @group
7094 $ @kbd{tar tf arch.tar --quoting-style=c}
7095 "./"
7096 "./a space"
7097 "./a'single'quote"
7098 "./a\"double\"quote"
7099 "./a\\backslash"
7100 "./a\ttab"
7101 "./a\nnewline"
7102 @end group
7103 @end smallexample
7104
7105 @item escape
7106 Control characters are printed using backslash notation, a space is
7107 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7108 default quoting style, unless it was changed when configured the
7109 package.
7110
7111 @smallexample
7112 @group
7113 $ @kbd{tar tf arch.tar --quoting-style=escape}
7114 ./
7115 ./a space
7116 ./a'single'quote
7117 ./a"double"quote
7118 ./a\\backslash
7119 ./a\ttab
7120 ./a\nnewline
7121 @end group
7122 @end smallexample
7123
7124 @item locale
7125 Control characters, single quote and backslash are printed using
7126 backslash notation. All names are quoted using left and right
7127 quotation marks, appropriate to the current locale. If it does not
7128 define quotation marks, use @samp{`} as left and @samp{'} as right
7129 quotation marks. Any occurrences of the right quotation mark in a
7130 name are escaped with @samp{\}, for example:
7131
7132 For example:
7133
7134 @smallexample
7135 @group
7136 $ @kbd{tar tf arch.tar --quoting-style=locale}
7137 `./'
7138 `./a space'
7139 `./a\'single\'quote'
7140 `./a"double"quote'
7141 `./a\\backslash'
7142 `./a\ttab'
7143 `./a\nnewline'
7144 @end group
7145 @end smallexample
7146
7147 @item clocale
7148 Same as @samp{locale}, but @samp{"} is used for both left and right
7149 quotation marks, if not provided by the currently selected locale:
7150
7151 @smallexample
7152 @group
7153 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7154 "./"
7155 "./a space"
7156 "./a'single'quote"
7157 "./a\"double\"quote"
7158 "./a\\backslash"
7159 "./a\ttab"
7160 "./a\nnewline"
7161 @end group
7162 @end smallexample
7163 @end table
7164
7165 You can specify which characters should be quoted in addition to those
7166 implied by the current quoting style:
7167
7168 @table @option
7169 @item --quote-chars=@var{string}
7170 Always quote characters from @var{string}, even if the selected
7171 quoting style would not quote them.
7172 @end table
7173
7174 For example, using @samp{escape} quoting (compare with the usual
7175 escape listing above):
7176
7177 @smallexample
7178 @group
7179 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7180 ./
7181 ./a\ space
7182 ./a'single'quote
7183 ./a\"double\"quote
7184 ./a\\backslash
7185 ./a\ttab
7186 ./a\nnewline
7187 @end group
7188 @end smallexample
7189
7190 To disable quoting of such additional characters, use the following
7191 option:
7192
7193 @table @option
7194 @item --no-quote-chars=@var{string}
7195 Remove characters listed in @var{string} from the list of quoted
7196 characters set by the previous @option{--quote-chars} option.
7197 @end table
7198
7199 This option is particularly useful if you have added
7200 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7201 and wish to disable it for the current invocation.
7202
7203 Note, that @option{--no-quote-chars} does @emph{not} disable those
7204 characters that are quoted by default in the selected quoting style.
7205
7206 @node transform
7207 @section Modifying File and Member Names
7208
7209 @command{Tar} archives contain detailed information about files stored
7210 in them and full file names are part of that information. When
7211 storing file to an archive, its file name is recorded in the archive
7212 along with the actual file contents. When restoring from an archive,
7213 a file is created on disk with exactly the same name as that stored
7214 in the archive. In the majority of cases this is the desired behavior
7215 of a file archiver. However, there are some cases when it is not.
7216
7217 First of all, it is often unsafe to extract archive members with
7218 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7219 takes special precautions when extracting such names and provides a
7220 special option for handling them, which is described in
7221 @ref{absolute}.
7222
7223 Secondly, you may wish to extract file names without some leading
7224 directory components, or with otherwise modified names. In other
7225 cases it is desirable to store files under differing names in the
7226 archive.
7227
7228 @GNUTAR{} provides two options for these needs.
7229
7230 @table @option
7231 @opindex strip-components
7232 @item --strip-components=@var{number}
7233 Strip given @var{number} of leading components from file names before
7234 extraction.
7235 @end table
7236
7237 For example, suppose you have archived whole @file{/usr} hierarchy to
7238 a tar archive named @file{usr.tar}. Among other files, this archive
7239 contains @file{usr/include/stdlib.h}, which you wish to extract to
7240 the current working directory. To do so, you type:
7241
7242 @smallexample
7243 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7244 @end smallexample
7245
7246 The option @option{--strip=2} instructs @command{tar} to strip the
7247 two leading components (@file{usr/} and @file{include/}) off the file
7248 name.
7249
7250 If you add to the above invocation @option{--verbose} (@option{-v})
7251 option, you will note that the verbose listing still contains the
7252 full file name, with the two removed components still in place. This
7253 can be inconvenient, so @command{tar} provides a special option for
7254 altering this behavior:
7255
7256 @anchor{show-transformed-names}
7257 @table @option
7258 @opindex show-transformed-names
7259 @item --show-transformed-names
7260 Display file or member names with all requested transformations
7261 applied.
7262 @end table
7263
7264 @noindent
7265 For example:
7266
7267 @smallexample
7268 @group
7269 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7270 usr/include/stdlib.h
7271 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7272 stdlib.h
7273 @end group
7274 @end smallexample
7275
7276 Notice that in both cases the file is @file{stdlib.h} extracted to the
7277 current working directory, @option{--show-transformed-names} affects
7278 only the way its name is displayed.
7279
7280 This option is especially useful for verifying whether the invocation
7281 will have the desired effect. Thus, before running
7282
7283 @smallexample
7284 $ @kbd{tar -x --strip=@var{n}}
7285 @end smallexample
7286
7287 @noindent
7288 it is often advisable to run
7289
7290 @smallexample
7291 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7292 @end smallexample
7293
7294 @noindent
7295 to make sure the command will produce the intended results.
7296
7297 In case you need to apply more complex modifications to the file name,
7298 @GNUTAR{} provides a general-purpose transformation option:
7299
7300 @table @option
7301 @opindex transform
7302 @item --transform=@var{expression}
7303 Modify file names using supplied @var{expression}.
7304 @end table
7305
7306 @noindent
7307 The @var{expression} is a @command{sed}-like replace expression of the
7308 form:
7309
7310 @smallexample
7311 s/@var{regexp}/@var{replace}/[@var{flags}]
7312 @end smallexample
7313
7314 @noindent
7315 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7316 replacement for each file name part that matches @var{regexp}. Both
7317 @var{regexp} and @var{replace} are described in detail in
7318 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7319
7320 Supported @var{flags} are:
7321
7322 @table @samp
7323 @item g
7324 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7325 just the first.
7326
7327 @item i
7328 Use case-insensitive matching
7329
7330 @item x
7331 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7332 regexps, Extended regular expressions, Extended regular expressions,
7333 sed, GNU sed}).
7334
7335 @item @var{number}
7336 Only replace the @var{number}th match of the @var{regexp}.
7337
7338 Note: the @var{posix} standard does not specify what should happen
7339 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7340 follows the GNU @command{sed} implementation in this regard, so
7341 the interaction is defined to be: ignore matches before the
7342 @var{number}th, and then match and replace all matches from the
7343 @var{number}th on.
7344
7345 @end table
7346
7347 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7348 that it be used consistently throughout the expression. For example,
7349 the following two expressions are equivalent:
7350
7351 @smallexample
7352 @group
7353 s/one/two/
7354 s,one,two,
7355 @end group
7356 @end smallexample
7357
7358 Changing delimiters is often useful when the @var{regex} contains
7359 slashes. For example, it is more convenient to write @code{s,/,-,} than
7360 @code{s/\//-/}.
7361
7362 Here are several examples of @option{--transform} usage:
7363
7364 @enumerate
7365 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7366
7367 @smallexample
7368 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7369 @end smallexample
7370
7371 @item Strip two leading directory components (equivalent to
7372 @option{--strip-components=2}):
7373
7374 @smallexample
7375 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7376 @end smallexample
7377
7378 @item Prepend @file{/prefix/} to each file name:
7379
7380 @smallexample
7381 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7382 @end smallexample
7383
7384 @item Convert each file name to lower case:
7385
7386 @smallexample
7387 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7388 @end smallexample
7389
7390 @end enumerate
7391
7392 Unlike @option{--strip-components}, @option{--transform} can be used
7393 in any @GNUTAR{} operation mode. For example, the following command
7394 adds files to the archive while replacing the leading @file{usr/}
7395 component with @file{var/}:
7396
7397 @smallexample
7398 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7399 @end smallexample
7400
7401 To test @option{--transform} effect we suggest using
7402 @option{--show-transformed-names} option:
7403
7404 @smallexample
7405 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7406 --verbose --show-transformed-names /}
7407 @end smallexample
7408
7409 If both @option{--strip-components} and @option{--transform} are used
7410 together, then @option{--transform} is applied first, and the required
7411 number of components is then stripped from its result.
7412
7413 @node after
7414 @section Operating Only on New Files
7415 @UNREVISED
7416
7417 @cindex Excluding file by age
7418 @cindex Data Modification time, excluding files by
7419 @cindex Modification time, excluding files by
7420 @cindex Age, excluding files by
7421 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7422 @option{-N @var{date}}) option causes @command{tar} to only work on
7423 files whose data modification or status change times are newer than
7424 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7425 it is taken to be a file name; the data modification time of that file
7426 is used as the date. If you use this option when creating or appending
7427 to an archive, the archive will only include new files. If you use
7428 @option{--after-date} when extracting an archive, @command{tar} will
7429 only extract files newer than the @var{date} you specify.
7430
7431 If you only want @command{tar} to make the date comparison based on
7432 modification of the file's data (rather than status
7433 changes), then use the @option{--newer-mtime=@var{date}} option.
7434
7435 You may use these options with any operation. Note that these options
7436 differ from the @option{--update} (@option{-u}) operation in that they
7437 allow you to specify a particular date against which @command{tar} can
7438 compare when deciding whether or not to archive the files.
7439
7440 @table @option
7441 @opindex after-date
7442 @opindex newer
7443 @item --after-date=@var{date}
7444 @itemx --newer=@var{date}
7445 @itemx -N @var{date}
7446 Only store files newer than @var{date}.
7447
7448 Acts on files only if their data modification or status change times are
7449 later than @var{date}. Use in conjunction with any operation.
7450
7451 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7452 name; the data modification time of that file is used as the date.
7453
7454 @opindex newer-mtime
7455 @item --newer-mtime=@var{date}
7456 Acts like @option{--after-date}, but only looks at data modification times.
7457 @end table
7458
7459 These options limit @command{tar} to operate only on files which have
7460 been modified after the date specified. A file's status is considered to have
7461 changed if its contents have been modified, or if its owner,
7462 permissions, and so forth, have been changed. (For more information on
7463 how to specify a date, see @ref{Date input formats}; remember that the
7464 entire date argument must be quoted if it contains any spaces.)
7465
7466 Gurus would say that @option{--after-date} tests both the data
7467 modification time (@code{mtime}, the time the contents of the file
7468 were last modified) and the status change time (@code{ctime}, the time
7469 the file's status was last changed: owner, permissions, etc.@:)
7470 fields, while @option{--newer-mtime} tests only the @code{mtime}
7471 field.
7472
7473 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7474 @code{ctime} and processes the file if either one is more recent than
7475 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7476 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7477 contents of the file were looked at).
7478
7479 Date specifiers can have embedded spaces. Because of this, you may need
7480 to quote date arguments to keep the shell from parsing them as separate
7481 arguments. For example, the following command will add to the archive
7482 all the files modified less than two days ago:
7483
7484 @smallexample
7485 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7486 @end smallexample
7487
7488 When any of these options is used with the option @option{--verbose}
7489 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7490 date back to its textual representation and compare that with the
7491 one given with the option. If the two dates differ, @command{tar} will
7492 print a warning saying what date it will use. This is to help user
7493 ensure he is using the right date. For example:
7494
7495 @smallexample
7496 @group
7497 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7498 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7499 13:19:37.232434
7500 @end group
7501 @end smallexample
7502
7503 @quotation
7504 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7505 should not be used for incremental backups. @xref{Incremental Dumps},
7506 for proper way of creating incremental backups.
7507 @end quotation
7508
7509 @node recurse
7510 @section Descending into Directories
7511 @UNREVISED
7512 @cindex Avoiding recursion in directories
7513 @cindex Descending directories, avoiding
7514 @cindex Directories, avoiding recursion
7515 @cindex Recursion in directories, avoiding
7516
7517 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7518
7519 Usually, @command{tar} will recursively explore all directories (either
7520 those given on the command line or through the @option{--files-from}
7521 option) for the various files they contain. However, you may not always
7522 want @command{tar} to act this way.
7523
7524 @opindex no-recursion
7525 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7526 into specified directories. If you specify @option{--no-recursion}, you can
7527 use the @command{find} utility for hunting through levels of directories to
7528 construct a list of file names which you could then pass to @command{tar}.
7529 @command{find} allows you to be more selective when choosing which files to
7530 archive; see @ref{files}, for more information on using @command{find} with
7531 @command{tar}, or look.
7532
7533 @table @option
7534 @item --no-recursion
7535 Prevents @command{tar} from recursively descending directories.
7536
7537 @opindex recursion
7538 @item --recursion
7539 Requires @command{tar} to recursively descend directories.
7540 This is the default.
7541 @end table
7542
7543 When you use @option{--no-recursion}, @GNUTAR{} grabs
7544 directory entries themselves, but does not descend on them
7545 recursively. Many people use @command{find} for locating files they
7546 want to back up, and since @command{tar} @emph{usually} recursively
7547 descends on directories, they have to use the @samp{@w{-not -type d}}
7548 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7549 find, Finding Files}), as they usually do not want all the files in a
7550 directory. They then use the @option{--files-from} option to archive
7551 the files located via @command{find}.
7552
7553 The problem when restoring files archived in this manner is that the
7554 directories themselves are not in the archive; so the
7555 @option{--same-permissions} (@option{--preserve-permissions},
7556 @option{-p}) option does not affect them---while users might really
7557 like it to. Specifying @option{--no-recursion} is a way to tell
7558 @command{tar} to grab only the directory entries given to it, adding
7559 no new files on its own. To summarize, if you use @command{find} to
7560 create a list of files to be stored in an archive, use it as follows:
7561
7562 @smallexample
7563 @group
7564 $ @kbd{find @var{dir} @var{tests} | \
7565 tar -cf @var{archive} -T - --no-recursion}
7566 @end group
7567 @end smallexample
7568
7569 The @option{--no-recursion} option also applies when extracting: it
7570 causes @command{tar} to extract only the matched directory entries, not
7571 the files under those directories.
7572
7573 The @option{--no-recursion} option also affects how globbing patterns
7574 are interpreted (@pxref{controlling pattern-matching}).
7575
7576 The @option{--no-recursion} and @option{--recursion} options apply to
7577 later options and operands, and can be overridden by later occurrences
7578 of @option{--no-recursion} and @option{--recursion}. For example:
7579
7580 @smallexample
7581 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7582 @end smallexample
7583
7584 @noindent
7585 creates an archive with one entry for @file{grape}, and the recursive
7586 contents of @file{grape/concord}, but no entries under @file{grape}
7587 other than @file{grape/concord}.
7588
7589 @node one
7590 @section Crossing File System Boundaries
7591 @cindex File system boundaries, not crossing
7592 @UNREVISED
7593
7594 @command{tar} will normally automatically cross file system boundaries in
7595 order to archive files which are part of a directory tree. You can
7596 change this behavior by running @command{tar} and specifying
7597 @option{--one-file-system}. This option only affects files that are
7598 archived because they are in a directory that is being archived;
7599 @command{tar} will still archive files explicitly named on the command line
7600 or through @option{--files-from}, regardless of where they reside.
7601
7602 @table @option
7603 @opindex one-file-system
7604 @item --one-file-system
7605 Prevents @command{tar} from crossing file system boundaries when
7606 archiving. Use in conjunction with any write operation.
7607 @end table
7608
7609 The @option{--one-file-system} option causes @command{tar} to modify its
7610 normal behavior in archiving the contents of directories. If a file in
7611 a directory is not on the same file system as the directory itself, then
7612 @command{tar} will not archive that file. If the file is a directory
7613 itself, @command{tar} will not archive anything beneath it; in other words,
7614 @command{tar} will not cross mount points.
7615
7616 This option is useful for making full or incremental archival backups of
7617 a file system. If this option is used in conjunction with
7618 @option{--verbose} (@option{-v}), files that are excluded are
7619 mentioned by name on the standard error.
7620
7621 @menu
7622 * directory:: Changing Directory
7623 * absolute:: Absolute File Names
7624 @end menu
7625
7626 @node directory
7627 @subsection Changing the Working Directory
7628
7629 @FIXME{need to read over this node now for continuity; i've switched
7630 things around some.}
7631
7632 @cindex Changing directory mid-stream
7633 @cindex Directory, changing mid-stream
7634 @cindex Working directory, specifying
7635 To change the working directory in the middle of a list of file names,
7636 either on the command line or in a file specified using
7637 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7638 This will change the working directory to the specified directory
7639 after that point in the list.
7640
7641 @table @option
7642 @opindex directory
7643 @item --directory=@var{directory}
7644 @itemx -C @var{directory}
7645 Changes the working directory in the middle of a command line.
7646 @end table
7647
7648 For example,
7649
7650 @smallexample
7651 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7652 @end smallexample
7653
7654 @noindent
7655 will place the files @file{grape} and @file{prune} from the current
7656 directory into the archive @file{jams.tar}, followed by the file
7657 @file{cherry} from the directory @file{food}. This option is especially
7658 useful when you have several widely separated files that you want to
7659 store in the same archive.
7660
7661 Note that the file @file{cherry} is recorded in the archive under the
7662 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7663 archive will contain three files that all appear to have come from the
7664 same directory; if the archive is extracted with plain @samp{tar
7665 --extract}, all three files will be written in the current directory.
7666
7667 Contrast this with the command,
7668
7669 @smallexample
7670 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7671 @end smallexample
7672
7673 @noindent
7674 which records the third file in the archive under the name
7675 @file{red/cherry} so that, if the archive is extracted using
7676 @samp{tar --extract}, the third file will be written in a subdirectory
7677 named @file{orange-colored}.
7678
7679 You can use the @option{--directory} option to make the archive
7680 independent of the original name of the directory holding the files.
7681 The following command places the files @file{/etc/passwd},
7682 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7683 @file{foo.tar}:
7684
7685 @smallexample
7686 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7687 @end smallexample
7688
7689 @noindent
7690 However, the names of the archive members will be exactly what they were
7691 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7692 They will not appear to be related by file name to the original
7693 directories where those files were located.
7694
7695 Note that @option{--directory} options are interpreted consecutively. If
7696 @option{--directory} specifies a relative file name, it is interpreted
7697 relative to the then current directory, which might not be the same as
7698 the original current working directory of @command{tar}, due to a previous
7699 @option{--directory} option.
7700
7701 When using @option{--files-from} (@pxref{files}), you can put various
7702 @command{tar} options (including @option{-C}) in the file list. Notice,
7703 however, that in this case the option and its argument may not be
7704 separated by whitespace. If you use short option, its argument must
7705 either follow the option letter immediately, without any intervening
7706 whitespace, or occupy the next line. Otherwise, if you use long
7707 option, separate its argument by an equal sign.
7708
7709 For instance, the file list for the above example will be:
7710
7711 @smallexample
7712 @group
7713 -C/etc
7714 passwd
7715 hosts
7716 --directory=/lib
7717 libc.a
7718 @end group
7719 @end smallexample
7720
7721 @noindent
7722 To use it, you would invoke @command{tar} as follows:
7723
7724 @smallexample
7725 $ @kbd{tar -c -f foo.tar --files-from list}
7726 @end smallexample
7727
7728 The interpretation of @option{--directory} is disabled by
7729 @option{--null} option.
7730
7731 @node absolute
7732 @subsection Absolute File Names
7733 @UNREVISED
7734
7735 @table @option
7736 @opindex absolute-names
7737 @item --absolute-names
7738 @itemx -P
7739 Do not strip leading slashes from file names, and permit file names
7740 containing a @file{..} file name component.
7741 @end table
7742
7743 By default, @GNUTAR{} drops a leading @samp{/} on
7744 input or output, and complains about file names containing a @file{..}
7745 component. This option turns off this behavior.
7746
7747 When @command{tar} extracts archive members from an archive, it strips any
7748 leading slashes (@samp{/}) from the member name. This causes absolute
7749 member names in the archive to be treated as relative file names. This
7750 allows you to have such members extracted wherever you want, instead of
7751 being restricted to extracting the member in the exact directory named
7752 in the archive. For example, if the archive member has the name
7753 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7754 really @file{etc/passwd}.
7755
7756 File names containing @file{..} can cause problems when extracting, so
7757 @command{tar} normally warns you about such files when creating an
7758 archive, and rejects attempts to extracts such files.
7759
7760 Other @command{tar} programs do not do this. As a result, if you
7761 create an archive whose member names start with a slash, they will be
7762 difficult for other people with a non-@GNUTAR{}
7763 program to use. Therefore, @GNUTAR{} also strips
7764 leading slashes from member names when putting members into the
7765 archive. For example, if you ask @command{tar} to add the file
7766 @file{/bin/ls} to an archive, it will do so, but the member name will
7767 be @file{bin/ls}.@footnote{A side effect of this is that when
7768 @option{--create} is used with @option{--verbose} the resulting output
7769 is not, generally speaking, the same as the one you'd get running
7770 @kbd{tar --list} command. This may be important if you use some
7771 scripts for comparing both outputs. @xref{listing member and file names},
7772 for the information on how to handle this case.}
7773
7774 If you use the @option{--absolute-names} (@option{-P}) option,
7775 @command{tar} will do none of these transformations.
7776
7777 To archive or extract files relative to the root directory, specify
7778 the @option{--absolute-names} (@option{-P}) option.
7779
7780 Normally, @command{tar} acts on files relative to the working
7781 directory---ignoring superior directory names when archiving, and
7782 ignoring leading slashes when extracting.
7783
7784 When you specify @option{--absolute-names} (@option{-P}),
7785 @command{tar} stores file names including all superior directory
7786 names, and preserves leading slashes. If you only invoked
7787 @command{tar} from the root directory you would never need the
7788 @option{--absolute-names} option, but using this option
7789 may be more convenient than switching to root.
7790
7791 @FIXME{Should be an example in the tutorial/wizardry section using this
7792 to transfer files between systems.}
7793
7794 @FIXME{Is write access an issue?}
7795
7796 @table @option
7797 @item --absolute-names
7798 Preserves full file names (including superior directory names) when
7799 archiving files. Preserves leading slash when extracting files.
7800
7801 @end table
7802
7803 @FIXME{this is still horrible; need to talk with dan on monday.}
7804
7805 @command{tar} prints out a message about removing the @samp{/} from
7806 file names. This message appears once per @GNUTAR{}
7807 invocation. It represents something which ought to be told; ignoring
7808 what it means can cause very serious surprises, later.
7809
7810 Some people, nevertheless, do not want to see this message. Wanting to
7811 play really dangerously, one may of course redirect @command{tar} standard
7812 error to the sink. For example, under @command{sh}:
7813
7814 @smallexample
7815 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7816 @end smallexample
7817
7818 @noindent
7819 Another solution, both nicer and simpler, would be to change to
7820 the @file{/} directory first, and then avoid absolute notation.
7821 For example:
7822
7823 @smallexample
7824 $ @kbd{(cd / && tar -c -f archive.tar home)}
7825 # @i{or}:
7826 $ @kbd{tar -c -f archive.tar -C / home}
7827 @end smallexample
7828
7829 @include getdate.texi
7830
7831 @node Formats
7832 @chapter Controlling the Archive Format
7833
7834 @cindex Tar archive formats
7835 Due to historical reasons, there are several formats of tar archives.
7836 All of them are based on the same principles, but have some subtle
7837 differences that often make them incompatible with each other.
7838
7839 GNU tar is able to create and handle archives in a variety of formats.
7840 The most frequently used formats are (in alphabetical order):
7841
7842 @table @asis
7843 @item gnu
7844 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7845 from an early @acronym{POSIX} standard, adding some improvements such as
7846 sparse file handling and incremental archives. Unfortunately these
7847 features were implemented in a way incompatible with other archive
7848 formats.
7849
7850 Archives in @samp{gnu} format are able to hold file names of unlimited
7851 length.
7852
7853 @item oldgnu
7854 Format used by @GNUTAR{} of versions prior to 1.12.
7855
7856 @item v7
7857 Archive format, compatible with the V7 implementation of tar. This
7858 format imposes a number of limitations. The most important of them
7859 are:
7860
7861 @enumerate
7862 @item The maximum length of a file name is limited to 99 characters.
7863 @item The maximum length of a symbolic link is limited to 99 characters.
7864 @item It is impossible to store special files (block and character
7865 devices, fifos etc.)
7866 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
7867 octal)
7868 @item V7 archives do not contain symbolic ownership information (user
7869 and group name of the file owner).
7870 @end enumerate
7871
7872 This format has traditionally been used by Automake when producing
7873 Makefiles. This practice will change in the future, in the meantime,
7874 however this means that projects containing file names more than 99
7875 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7876 Automake prior to 1.9.
7877
7878 @item ustar
7879 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7880 symbolic ownership information. It is also able to store
7881 special files. However, it imposes several restrictions as well:
7882
7883 @enumerate
7884 @item The maximum length of a file name is limited to 256 characters,
7885 provided that the file name can be split at a directory separator in
7886 two parts, first of them being at most 155 bytes long. So, in most
7887 cases the maximum file name length will be shorter than 256
7888 characters.
7889 @item The maximum length of a symbolic link name is limited to
7890 100 characters.
7891 @item Maximum size of a file the archive is able to accommodate
7892 is 8GB
7893 @item Maximum value of UID/GID is 2097151.
7894 @item Maximum number of bits in device major and minor numbers is 21.
7895 @end enumerate
7896
7897 @item star
7898 Format used by J@"org Schilling @command{star}
7899 implementation. @GNUTAR{} is able to read @samp{star} archives but
7900 currently does not produce them.
7901
7902 @item posix
7903 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7904 most flexible and feature-rich format. It does not impose any
7905 restrictions on file sizes or file name lengths. This format is quite
7906 recent, so not all tar implementations are able to handle it properly.
7907 However, this format is designed in such a way that any tar
7908 implementation able to read @samp{ustar} archives will be able to read
7909 most @samp{posix} archives as well, with the only exception that any
7910 additional information (such as long file names etc.) will in such
7911 case be extracted as plain text files along with the files it refers to.
7912
7913 This archive format will be the default format for future versions
7914 of @GNUTAR{}.
7915
7916 @end table
7917
7918 The following table summarizes the limitations of each of these
7919 formats:
7920
7921 @multitable @columnfractions .10 .20 .20 .20 .20
7922 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
7923 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7924 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7925 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7926 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7927 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7928 @end multitable
7929
7930 The default format for @GNUTAR{} is defined at compilation
7931 time. You may check it by running @command{tar --help}, and examining
7932 the last lines of its output. Usually, @GNUTAR{} is configured
7933 to create archives in @samp{gnu} format, however, future version will
7934 switch to @samp{posix}.
7935
7936 @menu
7937 * Compression:: Using Less Space through Compression
7938 * Attributes:: Handling File Attributes
7939 * Portability:: Making @command{tar} Archives More Portable
7940 * cpio:: Comparison of @command{tar} and @command{cpio}
7941 @end menu
7942
7943 @node Compression
7944 @section Using Less Space through Compression
7945
7946 @menu
7947 * gzip:: Creating and Reading Compressed Archives
7948 * sparse:: Archiving Sparse Files
7949 @end menu
7950
7951 @node gzip
7952 @subsection Creating and Reading Compressed Archives
7953 @cindex Compressed archives
7954 @cindex Storing archives in compressed format
7955
7956 @GNUTAR{} is able to create and read compressed archives. It supports
7957 @command{gzip}, @command{bzip2} and @command{lzma} compression
7958 programs. For backward compatibility, it also supports
7959 @command{compress} command, although we strongly recommend against
7960 using it, because it is by far less effective than other compression
7961 programs@footnote{It also had patent problems in the past.}.
7962
7963 Creating a compressed archive is simple: you just specify a
7964 @dfn{compression option} along with the usual archive creation
7965 commands. The compression option is @option{-z} (@option{--gzip}) to
7966 create a @command{gzip} compressed archive, @option{-j}
7967 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
7968 @command{lzma} to create an @asis{LZMA} compressed archive and
7969 @option{-Z} (@option{--compress}) to use @command{compress} program.
7970 For example:
7971
7972 @smallexample
7973 $ @kbd{tar cfz archive.tar.gz .}
7974 @end smallexample
7975
7976 You can also let @GNUTAR{} select the compression program basing on
7977 the suffix of the archive file name. This is done using
7978 @option{--auto-compress} (@option{-a}) command line option. For
7979 example, the following invocation will use @command{bzip2} for
7980 compression:
7981
7982 @smallexample
7983 $ @kbd{tar cfa archive.tar.bz2 .}
7984 @end smallexample
7985
7986 @noindent
7987 whereas the following one will use @command{lzma}:
7988
7989 @smallexample
7990 $ @kbd{tar cfa archive.tar.lzma .}
7991 @end smallexample
7992
7993 For a complete list of file name suffixes recognized by @GNUTAR{},
7994 @ref{auto-compress}.
7995
7996 Reading compressed archive is even simpler: you don't need to specify
7997 any additional options as @GNUTAR{} recognizes its format
7998 automatically. Thus, the following commands will list and extract the
7999 archive created in previous example:
8000
8001 @smallexample
8002 # List the compressed archive
8003 $ @kbd{tar tf archive.tar.gz}
8004 # Extract the compressed archive
8005 $ @kbd{tar xf archive.tar.gz}
8006 @end smallexample
8007
8008 The only case when you have to specify a decompression option while
8009 reading the archive is when reading from a pipe or from a tape drive
8010 that does not support random access. However, in this case @GNUTAR{}
8011 will indicate which option you should use. For example:
8012
8013 @smallexample
8014 $ @kbd{cat archive.tar.gz | tar tf -}
8015 tar: Archive is compressed. Use -z option
8016 tar: Error is not recoverable: exiting now
8017 @end smallexample
8018
8019 If you see such diagnostics, just add the suggested option to the
8020 invocation of @GNUTAR{}:
8021
8022 @smallexample
8023 $ @kbd{cat archive.tar.gz | tar tfz -}
8024 @end smallexample
8025
8026 Notice also, that there are several restrictions on operations on
8027 compressed archives. First of all, compressed archives cannot be
8028 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8029 (@option{--delete}) members from them. Likewise, you cannot append
8030 another @command{tar} archive to a compressed archive using
8031 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8032 compressed.
8033
8034 The following table summarizes compression options used by @GNUTAR{}.
8035
8036 @table @option
8037 @anchor{auto-compress}
8038 @opindex auto-compress
8039 @item --auto-compress
8040 @itemx -a
8041 Select a compression program to use by the archive file name
8042 suffix. The following suffixes are recognized:
8043
8044 @multitable @columnfractions 0.3 0.6
8045 @headitem Suffix @tab Compression program
8046 @item @samp{.gz} @tab @command{gzip}
8047 @item @samp{.tgz} @tab @command{gzip}
8048 @item @samp{.taz} @tab @command{gzip}
8049 @item @samp{.Z} @tab @command{compress}
8050 @item @samp{.taZ} @tab @command{compress}
8051 @item @samp{.bz2} @tab @command{bzip2}
8052 @item @samp{.tz2} @tab @command{bzip2}
8053 @item @samp{.tbz2} @tab @command{bzip2}
8054 @item @samp{.tbz} @tab @command{bzip2}
8055 @item @samp{.lzma} @tab @command{lzma}
8056 @item @samp{.tlz} @tab @command{lzma}
8057 @end multitable
8058
8059 @opindex gzip
8060 @opindex ungzip
8061 @item -z
8062 @itemx --gzip
8063 @itemx --ungzip
8064 Filter the archive through @command{gzip}.
8065
8066 You can use @option{--gzip} and @option{--gunzip} on physical devices
8067 (tape drives, etc.) and remote files as well as on normal files; data
8068 to or from such devices or remote files is reblocked by another copy
8069 of the @command{tar} program to enforce the specified (or default) record
8070 size. The default compression parameters are used; if you need to
8071 override them, set @env{GZIP} environment variable, e.g.:
8072
8073 @smallexample
8074 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8075 @end smallexample
8076
8077 @noindent
8078 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8079 @command{gzip} explicitly:
8080
8081 @smallexample
8082 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8083 @end smallexample
8084
8085 @cindex corrupted archives
8086 About corrupted compressed archives: @command{gzip}'ed files have no
8087 redundancy, for maximum compression. The adaptive nature of the
8088 compression scheme means that the compression tables are implicitly
8089 spread all over the archive. If you lose a few blocks, the dynamic
8090 construction of the compression tables becomes unsynchronized, and there
8091 is little chance that you could recover later in the archive.
8092
8093 There are pending suggestions for having a per-volume or per-file
8094 compression in @GNUTAR{}. This would allow for viewing the
8095 contents without decompression, and for resynchronizing decompression at
8096 every volume or file, in case of corrupted archives. Doing so, we might
8097 lose some compressibility. But this would have make recovering easier.
8098 So, there are pros and cons. We'll see!
8099
8100 @opindex bzip2
8101 @item -j
8102 @itemx --bzip2
8103 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8104
8105 @opindex lzma
8106 @item --lzma
8107 Filter the archive through @command{lzma}. Otherwise like @option{--gzip}.
8108
8109 @opindex compress
8110 @opindex uncompress
8111 @item -Z
8112 @itemx --compress
8113 @itemx --uncompress
8114 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8115
8116 @opindex use-compress-program
8117 @item --use-compress-program=@var{prog}
8118 Use external compression program @var{prog}. Use this option if you
8119 have a compression program that @GNUTAR{} does not support. There
8120 are two requirements to which @var{prog} should comply:
8121
8122 First, when called without options, it should read data from standard
8123 input, compress it and output it on standard output.
8124
8125 Secondly, if called with @option{-d} argument, it should do exactly
8126 the opposite, i.e., read the compressed data from the standard input
8127 and produce uncompressed data on the standard output.
8128 @end table
8129
8130 @cindex gpg, using with tar
8131 @cindex gnupg, using with tar
8132 @cindex Using encrypted archives
8133 The @option{--use-compress-program} option, in particular, lets you
8134 implement your own filters, not necessarily dealing with
8135 compression/decompression. For example, suppose you wish to implement
8136 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8137 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8138 Manual}). The following script does that:
8139
8140 @smallexample
8141 @group
8142 #! /bin/sh
8143 case $1 in
8144 -d) gpg --decrypt - | gzip -d -c;;
8145 '') gzip -c | gpg -s ;;
8146 *) echo "Unknown option $1">&2; exit 1;;
8147 esac
8148 @end group
8149 @end smallexample
8150
8151 Suppose you name it @file{gpgz} and save it somewhere in your
8152 @env{PATH}. Then the following command will create a compressed
8153 archive signed with your private key:
8154
8155 @smallexample
8156 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8157 @end smallexample
8158
8159 @noindent
8160 Likewise, the following command will list its contents:
8161
8162 @smallexample
8163 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8164 @end smallexample
8165
8166 @ignore
8167 The above is based on the following discussion:
8168
8169 I have one question, or maybe it's a suggestion if there isn't a way
8170 to do it now. I would like to use @option{--gzip}, but I'd also like
8171 the output to be fed through a program like @acronym{GNU}
8172 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8173 to use :-)), basically adding ECC protection on top of compression.
8174 It seems as if this should be quite easy to do, but I can't work out
8175 exactly how to go about it. Of course, I can pipe the standard output
8176 of @command{tar} through @command{ecc}, but then I lose (though I
8177 haven't started using it yet, I confess) the ability to have
8178 @command{tar} use @command{rmt} for it's I/O (I think).
8179
8180 I think the most straightforward thing would be to let me specify a
8181 general set of filters outboard of compression (preferably ordered,
8182 so the order can be automatically reversed on input operations, and
8183 with the options they require specifiable), but beggars shouldn't be
8184 choosers and anything you decide on would be fine with me.
8185
8186 By the way, I like @command{ecc} but if (as the comments say) it can't
8187 deal with loss of block sync, I'm tempted to throw some time at adding
8188 that capability. Supposing I were to actually do such a thing and
8189 get it (apparently) working, do you accept contributed changes to
8190 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8191
8192 Isn't that exactly the role of the
8193 @option{--use-compress-prog=@var{program}} option?
8194 I never tried it myself, but I suspect you may want to write a
8195 @var{prog} script or program able to filter stdin to stdout to
8196 way you want. It should recognize the @option{-d} option, for when
8197 extraction is needed rather than creation.
8198
8199 It has been reported that if one writes compressed data (through the
8200 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8201 the DLT compression mode, the data will actually get bigger and one will
8202 end up with less space on the tape.
8203 @end ignore
8204
8205 @node sparse
8206 @subsection Archiving Sparse Files
8207 @cindex Sparse Files
8208
8209 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
8210 in a file is a section of the file's contents which was never written.
8211 The contents of a hole reads as all zeros. On many operating systems,
8212 actual disk storage is not allocated for holes, but they are counted
8213 in the length of the file. If you archive such a file, @command{tar}
8214 could create an archive longer than the original. To have @command{tar}
8215 attempt to recognize the holes in a file, use @option{--sparse}
8216 (@option{-S}). When you use this option, then, for any file using
8217 less disk space than would be expected from its length, @command{tar}
8218 searches the file for consecutive stretches of zeros. It then records
8219 in the archive for the file where the consecutive stretches of zeros
8220 are, and only archives the ``real contents'' of the file. On
8221 extraction (using @option{--sparse} is not needed on extraction) any
8222 such files have holes created wherever the continuous stretches of zeros
8223 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8224 won't take more space than the original.
8225
8226 @table @option
8227 @opindex sparse
8228 @item -S
8229 @itemx --sparse
8230 This option instructs @command{tar} to test each file for sparseness
8231 before attempting to archive it. If the file is found to be sparse it
8232 is treated specially, thus allowing to decrease the amount of space
8233 used by its image in the archive.
8234
8235 This option is meaningful only when creating or updating archives. It
8236 has no effect on extraction.
8237 @end table
8238
8239 Consider using @option{--sparse} when performing file system backups,
8240 to avoid archiving the expanded forms of files stored sparsely in the
8241 system.
8242
8243 Even if your system has no sparse files currently, some may be
8244 created in the future. If you use @option{--sparse} while making file
8245 system backups as a matter of course, you can be assured the archive
8246 will never take more space on the media than the files take on disk
8247 (otherwise, archiving a disk filled with sparse files might take
8248 hundreds of tapes). @xref{Incremental Dumps}.
8249
8250 However, be aware that @option{--sparse} option presents a serious
8251 drawback. Namely, in order to determine if the file is sparse
8252 @command{tar} has to read it before trying to archive it, so in total
8253 the file is read @strong{twice}. So, always bear in mind that the
8254 time needed to process all files with this option is roughly twice
8255 the time needed to archive them without it.
8256 @FIXME{A technical note:
8257
8258 Programs like @command{dump} do not have to read the entire file; by
8259 examining the file system directly, they can determine in advance
8260 exactly where the holes are and thus avoid reading through them. The
8261 only data it need read are the actual allocated data blocks.
8262 @GNUTAR{} uses a more portable and straightforward
8263 archiving approach, it would be fairly difficult that it does
8264 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8265 1990-12-10:
8266
8267 @quotation
8268 What I did say is that you cannot tell the difference between a hole and an
8269 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8270 best tells you how many holes there are; it doesn't tell you @emph{where}.
8271 Just as programs may, conceivably, care what @code{st_blocks} is (care
8272 to name one that does?), they may also care where the holes are (I have
8273 no examples of this one either, but it's equally imaginable).
8274
8275 I conclude from this that good archivers are not portable. One can
8276 arguably conclude that if you want a portable program, you can in good
8277 conscience restore files with as many holes as possible, since you can't
8278 get it right.
8279 @end quotation
8280 }
8281
8282 @cindex sparse formats, defined
8283 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
8284 sparse files using in three distinct ways, called @dfn{sparse
8285 formats}. A sparse format is identified by its @dfn{number},
8286 consisting, as usual of two decimal numbers, delimited by a dot. By
8287 default, format @samp{1.0} is used. If, for some reason, you wish to
8288 use an earlier format, you can select it using
8289 @option{--sparse-version} option.
8290
8291 @table @option
8292 @opindex sparse-version
8293 @item --sparse-version=@var{version}
8294
8295 Select the format to store sparse files in. Valid @var{version} values
8296 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
8297 for a detailed description of each format.
8298 @end table
8299
8300 Using @option{--sparse-format} option implies @option{--sparse}.
8301
8302 @node Attributes
8303 @section Handling File Attributes
8304 @UNREVISED
8305
8306 When @command{tar} reads files, it updates their access times. To
8307 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8308 reset the access time retroactively or avoid changing it in the first
8309 place.
8310
8311 Handling of file attributes
8312
8313 @table @option
8314 @opindex atime-preserve
8315 @item --atime-preserve
8316 @itemx --atime-preserve=replace
8317 @itemx --atime-preserve=system
8318 Preserve the access times of files that are read. This works only for
8319 files that you own, unless you have superuser privileges.
8320
8321 @option{--atime-preserve=replace} works on most systems, but it also
8322 restores the data modification time and updates the status change
8323 time. Hence it doesn't interact with incremental dumps nicely
8324 (@pxref{Incremental Dumps}), and it can set access or data modification times
8325 incorrectly if other programs access the file while @command{tar} is
8326 running.
8327
8328 @option{--atime-preserve=system} avoids changing the access time in
8329 the first place, if the operating system supports this.
8330 Unfortunately, this may or may not work on any given operating system
8331 or file system. If @command{tar} knows for sure it won't work, it
8332 complains right away.
8333
8334 Currently @option{--atime-preserve} with no operand defaults to
8335 @option{--atime-preserve=replace}, but this is intended to change to
8336 @option{--atime-preserve=system} when the latter is better-supported.
8337
8338 @opindex touch
8339 @item -m
8340 @itemx --touch
8341 Do not extract data modification time.
8342
8343 When this option is used, @command{tar} leaves the data modification times
8344 of the files it extracts as the times when the files were extracted,
8345 instead of setting it to the times recorded in the archive.
8346
8347 This option is meaningless with @option{--list} (@option{-t}).
8348
8349 @opindex same-owner
8350 @item --same-owner
8351 Create extracted files with the same ownership they have in the
8352 archive.
8353
8354 This is the default behavior for the superuser,
8355 so this option is meaningful only for non-root users, when @command{tar}
8356 is executed on those systems able to give files away. This is
8357 considered as a security flaw by many people, at least because it
8358 makes quite difficult to correctly account users for the disk space
8359 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8360 files are easily and silently lost when files are given away.
8361
8362 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
8363 separately. If it can't find a user name (because the user @acronym{ID} is not
8364 in @file{/etc/passwd}), then it does not write one. When restoring,
8365 it tries to look the name (if one was written) up in
8366 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
8367 the archive instead.
8368
8369 @opindex no-same-owner
8370 @item --no-same-owner
8371 @itemx -o
8372 Do not attempt to restore ownership when extracting. This is the
8373 default behavior for ordinary users, so this option has an effect
8374 only for the superuser.
8375
8376 @opindex numeric-owner
8377 @item --numeric-owner
8378 The @option{--numeric-owner} option allows (ANSI) archives to be written
8379 without user/group name information or such information to be ignored
8380 when extracting. It effectively disables the generation and/or use
8381 of user/group name information. This option forces extraction using
8382 the numeric ids from the archive, ignoring the names.
8383
8384 This is useful in certain circumstances, when restoring a backup from
8385 an emergency floppy with different passwd/group files for example.
8386 It is otherwise impossible to extract files with the right ownerships
8387 if the password file in use during the extraction does not match the
8388 one belonging to the file system(s) being extracted. This occurs,
8389 for example, if you are restoring your files after a major crash and
8390 had booted from an emergency floppy with no password file or put your
8391 disk into another machine to do the restore.
8392
8393 The numeric ids are @emph{always} saved into @command{tar} archives.
8394 The identifying names are added at create time when provided by the
8395 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8396 used when moving archives between a collection of machines using
8397 a centralized management for attribution of numeric ids to users
8398 and groups. This is often made through using the NIS capabilities.
8399
8400 When making a @command{tar} file for distribution to other sites, it
8401 is sometimes cleaner to use a single owner for all files in the
8402 distribution, and nicer to specify the write permission bits of the
8403 files as stored in the archive independently of their actual value on
8404 the file system. The way to prepare a clean distribution is usually
8405 to have some Makefile rule creating a directory, copying all needed
8406 files in that directory, then setting ownership and permissions as
8407 wanted (there are a lot of possible schemes), and only then making a
8408 @command{tar} archive out of this directory, before cleaning
8409 everything out. Of course, we could add a lot of options to
8410 @GNUTAR{} for fine tuning permissions and ownership.
8411 This is not the good way, I think. @GNUTAR{} is
8412 already crowded with options and moreover, the approach just explained
8413 gives you a great deal of control already.
8414
8415 @xopindex{same-permissions, short description}
8416 @xopindex{preserve-permissions, short description}
8417 @item -p
8418 @itemx --same-permissions
8419 @itemx --preserve-permissions
8420 Extract all protection information.
8421
8422 This option causes @command{tar} to set the modes (access permissions) of
8423 extracted files exactly as recorded in the archive. If this option
8424 is not used, the current @code{umask} setting limits the permissions
8425 on extracted files. This option is by default enabled when
8426 @command{tar} is executed by a superuser.
8427
8428
8429 This option is meaningless with @option{--list} (@option{-t}).
8430
8431 @opindex preserve
8432 @item --preserve
8433 Same as both @option{--same-permissions} and @option{--same-order}.
8434
8435 The @option{--preserve} option has no equivalent short option name.
8436 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8437
8438 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8439 Neither do I. --Sergey}
8440
8441 @end table
8442
8443 @node Portability
8444 @section Making @command{tar} Archives More Portable
8445
8446 Creating a @command{tar} archive on a particular system that is meant to be
8447 useful later on many other machines and with other versions of @command{tar}
8448 is more challenging than you might think. @command{tar} archive formats
8449 have been evolving since the first versions of Unix. Many such formats
8450 are around, and are not always compatible with each other. This section
8451 discusses a few problems, and gives some advice about making @command{tar}
8452 archives more portable.
8453
8454 One golden rule is simplicity. For example, limit your @command{tar}
8455 archives to contain only regular files and directories, avoiding
8456 other kind of special files. Do not attempt to save sparse files or
8457 contiguous files as such. Let's discuss a few more problems, in turn.
8458
8459 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
8460 archives and archive labels) in GNU and PAX formats.}
8461
8462 @menu
8463 * Portable Names:: Portable Names
8464 * dereference:: Symbolic Links
8465 * old:: Old V7 Archives
8466 * ustar:: Ustar Archives
8467 * gnu:: GNU and old GNU format archives.
8468 * posix:: @acronym{POSIX} archives
8469 * Checksumming:: Checksumming Problems
8470 * Large or Negative Values:: Large files, negative time stamps, etc.
8471 * Other Tars:: How to Extract GNU-Specific Data Using
8472 Other @command{tar} Implementations
8473 @end menu
8474
8475 @node Portable Names
8476 @subsection Portable Names
8477
8478 Use portable file and member names. A name is portable if it contains
8479 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
8480 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
8481 contain @samp{/-}. Avoid deep directory nesting. For portability to
8482 old Unix hosts, limit your file name components to 14 characters or
8483 less.
8484
8485 If you intend to have your @command{tar} archives to be read under
8486 MSDOS, you should not rely on case distinction for file names, and you
8487 might use the @acronym{GNU} @command{doschk} program for helping you
8488 further diagnosing illegal MSDOS names, which are even more limited
8489 than System V's.
8490
8491 @node dereference
8492 @subsection Symbolic Links
8493 @cindex File names, using symbolic links
8494 @cindex Symbolic link as file name
8495
8496 @opindex dereference
8497 Normally, when @command{tar} archives a symbolic link, it writes a
8498 block to the archive naming the target of the link. In that way, the
8499 @command{tar} archive is a faithful record of the file system contents.
8500 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
8501 @command{tar} to archive the files symbolic links point to, instead of
8502 the links themselves. When this option is used, when @command{tar}
8503 encounters a symbolic link, it will archive the linked-to file,
8504 instead of simply recording the presence of a symbolic link.
8505
8506 The name under which the file is stored in the file system is not
8507 recorded in the archive. To record both the symbolic link name and
8508 the file name in the system, archive the file under both names. If
8509 all links were recorded automatically by @command{tar}, an extracted file
8510 might be linked to a file name that no longer exists in the file
8511 system.
8512
8513 If a linked-to file is encountered again by @command{tar} while creating
8514 the same archive, an entire second copy of it will be stored. (This
8515 @emph{might} be considered a bug.)
8516
8517 So, for portable archives, do not archive symbolic links as such,
8518 and use @option{--dereference} (@option{-h}): many systems do not support
8519 symbolic links, and moreover, your distribution might be unusable if
8520 it contains unresolved symbolic links.
8521
8522 @node old
8523 @subsection Old V7 Archives
8524 @cindex Format, old style
8525 @cindex Old style format
8526 @cindex Old style archives
8527 @cindex v7 archive format
8528
8529 Certain old versions of @command{tar} cannot handle additional
8530 information recorded by newer @command{tar} programs. To create an
8531 archive in V7 format (not ANSI), which can be read by these old
8532 versions, specify the @option{--format=v7} option in
8533 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
8534 accepts @option{--portability} or @option{--old-archive} for this
8535 option). When you specify it,
8536 @command{tar} leaves out information about directories, pipes, fifos,
8537 contiguous files, and device files, and specifies file ownership by
8538 group and user IDs instead of group and user names.
8539
8540 When updating an archive, do not use @option{--format=v7}
8541 unless the archive was created using this option.
8542
8543 In most cases, a @emph{new} format archive can be read by an @emph{old}
8544 @command{tar} program without serious trouble, so this option should
8545 seldom be needed. On the other hand, most modern @command{tar}s are
8546 able to read old format archives, so it might be safer for you to
8547 always use @option{--format=v7} for your distributions. Notice,
8548 however, that @samp{ustar} format is a better alternative, as it is
8549 free from many of @samp{v7}'s drawbacks.
8550
8551 @node ustar
8552 @subsection Ustar Archive Format
8553
8554 @cindex ustar archive format
8555 Archive format defined by @acronym{POSIX}.1-1988 specification is called
8556 @code{ustar}. Although it is more flexible than the V7 format, it
8557 still has many restrictions (@xref{Formats,ustar}, for the detailed
8558 description of @code{ustar} format). Along with V7 format,
8559 @code{ustar} format is a good choice for archives intended to be read
8560 with other implementations of @command{tar}.
8561
8562 To create archive in @code{ustar} format, use @option{--format=ustar}
8563 option in conjunction with the @option{--create} (@option{-c}).
8564
8565 @node gnu
8566 @subsection @acronym{GNU} and old @GNUTAR{} format
8567
8568 @cindex GNU archive format
8569 @cindex Old GNU archive format
8570 @GNUTAR{} was based on an early draft of the
8571 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
8572 @command{tar}, such as the support for file names longer than 100
8573 characters, use portions of the @command{tar} header record which were
8574 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
8575 @acronym{POSIX} have allocated the same parts of the header record for
8576 other purposes. As a result, @GNUTAR{} format is
8577 incompatible with the current @acronym{POSIX} specification, and with
8578 @command{tar} programs that follow it.
8579
8580 In the majority of cases, @command{tar} will be configured to create
8581 this format by default. This will change in future releases, since
8582 we plan to make @samp{POSIX} format the default.
8583
8584 To force creation a @GNUTAR{} archive, use option
8585 @option{--format=gnu}.
8586
8587 @node posix
8588 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
8589
8590 @cindex POSIX archive format
8591 @cindex PAX archive format
8592 Starting from version 1.14 @GNUTAR{} features full support for
8593 @acronym{POSIX.1-2001} archives.
8594
8595 A @acronym{POSIX} conformant archive will be created if @command{tar}
8596 was given @option{--format=posix} (@option{--format=pax}) option. No
8597 special option is required to read and extract from a @acronym{POSIX}
8598 archive.
8599
8600 @menu
8601 * PAX keywords:: Controlling Extended Header Keywords.
8602 @end menu
8603
8604 @node PAX keywords
8605 @subsubsection Controlling Extended Header Keywords
8606
8607 @table @option
8608 @opindex pax-option
8609 @item --pax-option=@var{keyword-list}
8610 Handle keywords in @acronym{PAX} extended headers. This option is
8611 equivalent to @option{-o} option of the @command{pax} utility.
8612 @end table
8613
8614 @var{Keyword-list} is a comma-separated
8615 list of keyword options, each keyword option taking one of
8616 the following forms:
8617
8618 @table @code
8619 @item delete=@var{pattern}
8620 When used with one of archive-creation commands,
8621 this option instructs @command{tar} to omit from extended header records
8622 that it produces any keywords matching the string @var{pattern}.
8623
8624 When used in extract or list mode, this option instructs tar
8625 to ignore any keywords matching the given @var{pattern} in the extended
8626 header records. In both cases, matching is performed using the pattern
8627 matching notation described in @acronym{POSIX 1003.2}, 3.13
8628 (@pxref{wildcards}). For example:
8629
8630 @smallexample
8631 --pax-option delete=security.*
8632 @end smallexample
8633
8634 would suppress security-related information.
8635
8636 @item exthdr.name=@var{string}
8637
8638 This keyword allows user control over the name that is written into the
8639 ustar header blocks for the extended headers. The name is obtained
8640 from @var{string} after making the following substitutions:
8641
8642 @multitable @columnfractions .25 .55
8643 @headitem Meta-character @tab Replaced By
8644 @item %d @tab The directory name of the file, equivalent to the
8645 result of the @command{dirname} utility on the translated file name.
8646 @item %f @tab The name of the file with the directory information
8647 stripped, equivalent to the result of the @command{basename} utility
8648 on the translated file name.
8649 @item %p @tab The process @acronym{ID} of the @command{tar} process.
8650 @item %% @tab A @samp{%} character.
8651 @end multitable
8652
8653 Any other @samp{%} characters in @var{string} produce undefined
8654 results.
8655
8656 If no option @samp{exthdr.name=string} is specified, @command{tar}
8657 will use the following default value:
8658
8659 @smallexample
8660 %d/PaxHeaders.%p/%f
8661 @end smallexample
8662
8663 @item globexthdr.name=@var{string}
8664 This keyword allows user control over the name that is written into
8665 the ustar header blocks for global extended header records. The name
8666 is obtained from the contents of @var{string}, after making
8667 the following substitutions:
8668
8669 @multitable @columnfractions .25 .55
8670 @headitem Meta-character @tab Replaced By
8671 @item %n @tab An integer that represents the
8672 sequence number of the global extended header record in the archive,
8673 starting at 1.
8674 @item %p @tab The process @acronym{ID} of the @command{tar} process.
8675 @item %% @tab A @samp{%} character.
8676 @end multitable
8677
8678 Any other @samp{%} characters in @var{string} produce undefined results.
8679
8680 If no option @samp{globexthdr.name=string} is specified, @command{tar}
8681 will use the following default value:
8682
8683 @smallexample
8684 $TMPDIR/GlobalHead.%p.%n
8685 @end smallexample
8686
8687 @noindent
8688 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
8689 environment variable. If @var{TMPDIR} is not set, @command{tar}
8690 uses @samp{/tmp}.
8691
8692 @item @var{keyword}=@var{value}
8693 When used with one of archive-creation commands, these keyword/value pairs
8694 will be included at the beginning of the archive in a global extended
8695 header record. When used with one of archive-reading commands,
8696 @command{tar} will behave as if it has encountered these keyword/value
8697 pairs at the beginning of the archive in a global extended header
8698 record.
8699
8700 @item @var{keyword}:=@var{value}
8701 When used with one of archive-creation commands, these keyword/value pairs
8702 will be included as records at the beginning of an extended header for
8703 each file. This is effectively equivalent to @var{keyword}=@var{value}
8704 form except that it creates no global extended header records.
8705
8706 When used with one of archive-reading commands, @command{tar} will
8707 behave as if these keyword/value pairs were included as records at the
8708 end of each extended header; thus, they will override any global or
8709 file-specific extended header record keywords of the same names.
8710 For example, in the command:
8711
8712 @smallexample
8713 tar --format=posix --create \
8714 --file archive --pax-option gname:=user .
8715 @end smallexample
8716
8717 the group name will be forced to a new value for all files
8718 stored in the archive.
8719 @end table
8720
8721 @node Checksumming
8722 @subsection Checksumming Problems
8723
8724 SunOS and HP-UX @command{tar} fail to accept archives created using
8725 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
8726 is, file names having characters with the eight bit set, because they
8727 use signed checksums, while @GNUTAR{} uses unsigned
8728 checksums while creating archives, as per @acronym{POSIX} standards. On
8729 reading, @GNUTAR{} computes both checksums and
8730 accept any. It is somewhat worrying that a lot of people may go
8731 around doing backup of their files using faulty (or at least
8732 non-standard) software, not learning about it until it's time to
8733 restore their missing files with an incompatible file extractor, or
8734 vice versa.
8735
8736 @GNUTAR{} compute checksums both ways, and accept
8737 any on read, so @acronym{GNU} tar can read Sun tapes even with their
8738 wrong checksums. @GNUTAR{} produces the standard
8739 checksum, however, raising incompatibilities with Sun. That is to
8740 say, @GNUTAR{} has not been modified to
8741 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
8742 I've been told that more recent Sun @command{tar} now read standard
8743 archives, so maybe Sun did a similar patch, after all?
8744
8745 The story seems to be that when Sun first imported @command{tar}
8746 sources on their system, they recompiled it without realizing that
8747 the checksums were computed differently, because of a change in
8748 the default signing of @code{char}'s in their compiler. So they
8749 started computing checksums wrongly. When they later realized their
8750 mistake, they merely decided to stay compatible with it, and with
8751 themselves afterwards. Presumably, but I do not really know, HP-UX
8752 has chosen that their @command{tar} archives to be compatible with Sun's.
8753 The current standards do not favor Sun @command{tar} format. In any
8754 case, it now falls on the shoulders of SunOS and HP-UX users to get
8755 a @command{tar} able to read the good archives they receive.
8756
8757 @node Large or Negative Values
8758 @subsection Large or Negative Values
8759 @cindex large values
8760 @cindex future time stamps
8761 @cindex negative time stamps
8762 @UNREVISED{}
8763
8764 The above sections suggest to use @samp{oldest possible} archive
8765 format if in doubt. However, sometimes it is not possible. If you
8766 attempt to archive a file whose metadata cannot be represented using
8767 required format, @GNUTAR{} will print error message and ignore such a
8768 file. You will than have to switch to a format that is able to
8769 handle such values. The format summary table (@pxref{Formats}) will
8770 help you to do so.
8771
8772 In particular, when trying to archive files larger than 8GB or with
8773 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
8774 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
8775 @acronym{POSIX} archive formats. When considering which format to
8776 choose, bear in mind that the @acronym{GNU} format uses
8777 two's-complement base-256 notation to store values that do not fit
8778 into standard @acronym{ustar} range. Such archives can generally be
8779 read only by a @GNUTAR{} implementation. Moreover, they sometimes
8780 cannot be correctly restored on another hosts even by @GNUTAR{}. For
8781 example, using two's complement representation for negative time
8782 stamps that assumes a signed 32-bit @code{time_t} generates archives
8783 that are not portable to hosts with differing @code{time_t}
8784 representations.
8785
8786 On the other hand, @acronym{POSIX} archives, generally speaking, can
8787 be extracted by any tar implementation that understands older
8788 @acronym{ustar} format. The only exception are files larger than 8GB.
8789
8790 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
8791 POSIX-aware tars.}
8792
8793 @node Other Tars
8794 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
8795
8796 In previous sections you became acquainted with various quirks
8797 necessary to make your archives portable. Sometimes you may need to
8798 extract archives containing GNU-specific members using some
8799 third-party @command{tar} implementation or an older version of
8800 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
8801 but if it is for some reason impossible, this section will explain
8802 how to cope without it.
8803
8804 When we speak about @dfn{GNU-specific} members we mean two classes of
8805 them: members split between the volumes of a multi-volume archive and
8806 sparse members. You will be able to always recover such members if
8807 the archive is in PAX format. In addition split members can be
8808 recovered from archives in old GNU format. The following subsections
8809 describe the required procedures in detail.
8810
8811 @menu
8812 * Split Recovery:: Members Split Between Volumes
8813 * Sparse Recovery:: Sparse Members
8814 @end menu
8815
8816 @node Split Recovery
8817 @subsubsection Extracting Members Split Between Volumes
8818
8819 @cindex Mutli-volume archives, extracting using non-GNU tars
8820 If a member is split between several volumes of an old GNU format archive
8821 most third party @command{tar} implementation will fail to extract
8822 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
8823 This program is available from
8824 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
8825 home page}. It concatenates several archive volumes into a single
8826 valid archive. For example, if you have three volumes named from
8827 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
8828 extract them using a third-party @command{tar}:
8829
8830 @smallexample
8831 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
8832 @end smallexample
8833
8834 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
8835 You could use this approach for most (although not all) PAX
8836 format archives as well. However, extracting split members from a PAX
8837 archive is a much easier task, because PAX volumes are constructed in
8838 such a way that each part of a split member is extracted to a
8839 different file by @command{tar} implementations that are not aware of
8840 GNU extensions. More specifically, the very first part retains its
8841 original name, and all subsequent parts are named using the pattern:
8842
8843 @smallexample
8844 %d/GNUFileParts.%p/%f.%n
8845 @end smallexample
8846
8847 @noindent
8848 where symbols preceeded by @samp{%} are @dfn{macro characters} that
8849 have the following meaning:
8850
8851 @multitable @columnfractions .25 .55
8852 @headitem Meta-character @tab Replaced By
8853 @item %d @tab The directory name of the file, equivalent to the
8854 result of the @command{dirname} utility on its full name.
8855 @item %f @tab The file name of the file, equivalent to the result
8856 of the @command{basename} utility on its full name.
8857 @item %p @tab The process @acronym{ID} of the @command{tar} process that
8858 created the archive.
8859 @item %n @tab Ordinal number of this particular part.
8860 @end multitable
8861
8862 For example, if the file @file{var/longfile} was split during archive
8863 creation between three volumes, and the creator @command{tar} process
8864 had process @acronym{ID} @samp{27962}, then the member names will be:
8865
8866 @smallexample
8867 var/longfile
8868 var/GNUFileParts.27962/longfile.1
8869 var/GNUFileParts.27962/longfile.2
8870 @end smallexample
8871
8872 When you extract your archive using a third-party @command{tar}, these
8873 files will be created on your disk, and the only thing you will need
8874 to do to restore your file in its original form is concatenate them in
8875 the proper order, for example:
8876
8877 @smallexample
8878 @group
8879 $ @kbd{cd var}
8880 $ @kbd{cat GNUFileParts.27962/longfile.1 \
8881 GNUFileParts.27962/longfile.2 >> longfile}
8882 $ rm -f GNUFileParts.27962
8883 @end group
8884 @end smallexample
8885
8886 Notice, that if the @command{tar} implementation you use supports PAX
8887 format archives, it will probably emit warnings about unknown keywords
8888 during extraction. They will look like this:
8889
8890 @smallexample
8891 @group
8892 Tar file too small
8893 Unknown extended header keyword 'GNU.volume.filename' ignored.
8894 Unknown extended header keyword 'GNU.volume.size' ignored.
8895 Unknown extended header keyword 'GNU.volume.offset' ignored.
8896 @end group
8897 @end smallexample
8898
8899 @noindent
8900 You can safely ignore these warnings.
8901
8902 If your @command{tar} implementation is not PAX-aware, you will get
8903 more warnings and more files generated on your disk, e.g.:
8904
8905 @smallexample
8906 @group
8907 $ @kbd{tar xf vol-1.tar}
8908 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
8909 normal file
8910 Unexpected EOF in archive
8911 $ @kbd{tar xf vol-2.tar}
8912 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
8913 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
8914 'x', extracted as normal file
8915 @end group
8916 @end smallexample
8917
8918 Ignore these warnings. The @file{PaxHeaders.*} directories created
8919 will contain files with @dfn{extended header keywords} describing the
8920 extracted files. You can delete them, unless they describe sparse
8921 members. Read further to learn more about them.
8922
8923 @node Sparse Recovery
8924 @subsubsection Extracting Sparse Members
8925
8926 @cindex sparse files, extracting with non-GNU tars
8927 Any @command{tar} implementation will be able to extract sparse members from a
8928 PAX archive. However, the extracted files will be @dfn{condensed},
8929 i.e., any zero blocks will be removed from them. When we restore such
8930 a condensed file to its original form, by adding zero blocks (or
8931 @dfn{holes}) back to their original locations, we call this process
8932 @dfn{expanding} a compressed sparse file.
8933
8934 @pindex xsparse
8935 To expand a file, you will need a simple auxiliary program called
8936 @command{xsparse}. It is available in source form from
8937 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
8938 home page}.
8939
8940 @cindex sparse files v.1.0, extracting with non-GNU tars
8941 Let's begin with archive members in @dfn{sparse format
8942 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
8943 The condensed file will contain both file map and file data, so no
8944 additional data will be needed to restore it. If the original file
8945 name was @file{@var{dir}/@var{name}}, then the condensed file will be
8946 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
8947 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
8948 @dfn{process @acronym{ID}} of the @command{tar} process which created the
8949 archive (@pxref{PAX keywords}).}.
8950
8951 To expand a version 1.0 file, run @command{xsparse} as follows:
8952
8953 @smallexample
8954 $ @kbd{xsparse @file{cond-file}}
8955 @end smallexample
8956
8957 @noindent
8958 where @file{cond-file} is the name of the condensed file. The utility
8959 will deduce the name for the resulting expanded file using the
8960 following algorithm:
8961
8962 @enumerate 1
8963 @item If @file{cond-file} does not contain any directories,
8964 @file{../cond-file} will be used;
8965
8966 @item If @file{cond-file} has the form
8967 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
8968 are simple names, with no @samp{/} characters in them, the output file
8969 name will be @file{@var{dir}/@var{name}}.
8970
8971 @item Otherwise, if @file{cond-file} has the form
8972 @file{@var{dir}/@var{name}}, the output file name will be
8973 @file{@var{name}}.
8974 @end enumerate
8975
8976 In the unlikely case when this algorithm does not suit your needs,
8977 you can explicitly specify output file name as a second argument to
8978 the command:
8979
8980 @smallexample
8981 $ @kbd{xsparse @file{cond-file} @file{out-file}}
8982 @end smallexample
8983
8984 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
8985 first. In this mode, the command does not actually expand the file,
8986 but verbosely lists all actions it would be taking to do so. The dry
8987 run mode is enabled by @option{-n} command line argument:
8988
8989 @smallexample
8990 @group
8991 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
8992 Reading v.1.0 sparse map
8993 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8994 `/home/gray/sparsefile'
8995 Finished dry run
8996 @end group
8997 @end smallexample
8998
8999 To actually expand the file, you would run:
9000
9001 @smallexample
9002 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
9003 @end smallexample
9004
9005 @noindent
9006 The program behaves the same way all UNIX utilities do: it will keep
9007 quiet unless it has simething important to tell you (e.g. an error
9008 condition or something). If you wish it to produce verbose output,
9009 similar to that from the dry run mode, use @option{-v} option:
9010
9011 @smallexample
9012 @group
9013 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
9014 Reading v.1.0 sparse map
9015 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9016 `/home/gray/sparsefile'
9017 Done
9018 @end group
9019 @end smallexample
9020
9021 Additionally, if your @command{tar} implementation has extracted the
9022 @dfn{extended headers} for this file, you can instruct @command{xstar}
9023 to use them in order to verify the integrity of the expanded file.
9024 The option @option{-x} sets the name of the extended header file to
9025 use. Continuing our example:
9026
9027 @smallexample
9028 @group
9029 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
9030 /home/gray/GNUSparseFile.6058/sparsefile}
9031 Reading extended header file
9032 Found variable GNU.sparse.major = 1
9033 Found variable GNU.sparse.minor = 0
9034 Found variable GNU.sparse.name = sparsefile
9035 Found variable GNU.sparse.realsize = 217481216
9036 Reading v.1.0 sparse map
9037 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9038 `/home/gray/sparsefile'
9039 Done
9040 @end group
9041 @end smallexample
9042
9043 @anchor{extracting sparse v.0.x}
9044 @cindex sparse files v.0.1, extracting with non-GNU tars
9045 @cindex sparse files v.0.0, extracting with non-GNU tars
9046 An @dfn{extended header} is a special @command{tar} archive header
9047 that precedes an archive member and contains a set of
9048 @dfn{variables}, describing the member properties that cannot be
9049 stored in the standard @code{ustar} header. While optional for
9050 expanding sparse version 1.0 members, the use of extended headers is
9051 mandatory when expanding sparse members in older sparse formats: v.0.0
9052 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
9053 Formats}.) So, for these formats, the question is: how to obtain
9054 extended headers from the archive?
9055
9056 If you use a @command{tar} implementation that does not support PAX
9057 format, extended headers for each member will be extracted as a
9058 separate file. If we represent the member name as
9059 @file{@var{dir}/@var{name}}, then the extended header file will be
9060 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
9061 @var{n} is an integer number.
9062
9063 Things become more difficult if your @command{tar} implementation
9064 does support PAX headers, because in this case you will have to
9065 manually extract the headers. We recommend the following algorithm:
9066
9067 @enumerate 1
9068 @item
9069 Consult the documentation of your @command{tar} implementation for an
9070 option that prints @dfn{block numbers} along with the archive
9071 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
9072 @command{star} has @option{-block-number}.
9073
9074 @item
9075 Obtain verbose listing using the @samp{block number} option, and
9076 find block numbers of the sparse member in question and the member
9077 immediately following it. For example, running @command{star} on our
9078 archive we obtain:
9079
9080 @smallexample
9081 @group
9082 $ @kbd{star -t -v -block-number -f arc.tar}
9083 @dots{}
9084 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
9085 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
9086 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
9087 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
9088 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
9089 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
9090 @dots{}
9091 @end group
9092 @end smallexample
9093
9094 @noindent
9095 (as usual, ignore the warnings about unknown keywords.)
9096
9097 @item
9098 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
9099 and @var{Bn} be the block number of the next member.
9100 Compute:
9101
9102 @smallexample
9103 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
9104 @end smallexample
9105
9106 @noindent
9107 This number gives the size of the extended header part in tar @dfn{blocks}.
9108 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
9109 = 7}.
9110
9111 @item
9112 Use @command{dd} to extract the headers:
9113
9114 @smallexample
9115 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
9116 @end smallexample
9117
9118 @noindent
9119 where @var{archive} is the archive name, @var{hname} is a name of the
9120 file to store the extended header in, @var{Bs} and @var{N} are
9121 computed in previous steps.
9122
9123 In our example, this command will be
9124
9125 @smallexample
9126 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
9127 @end smallexample
9128 @end enumerate
9129
9130 Finally, you can expand the condensed file, using the obtained header:
9131
9132 @smallexample
9133 @group
9134 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
9135 Reading extended header file
9136 Found variable GNU.sparse.size = 217481216
9137 Found variable GNU.sparse.numblocks = 208
9138 Found variable GNU.sparse.name = sparsefile
9139 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
9140 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
9141 Done
9142 @end group
9143 @end smallexample
9144
9145 @node cpio
9146 @section Comparison of @command{tar} and @command{cpio}
9147 @UNREVISED
9148
9149 @FIXME{Reorganize the following material}
9150
9151 The @command{cpio} archive formats, like @command{tar}, do have maximum
9152 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
9153 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
9154 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
9155 with arbitrary file name lengths, but other @command{cpio} implementations
9156 may crash unexplainedly trying to read them.
9157
9158 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
9159 @command{cpio} doesn't handle symbolic links in the form in which it comes
9160 in System V prior to SVR4, and some vendors may have added symlinks
9161 to their system without enhancing @command{cpio} to know about them.
9162 Others may have enhanced it in a way other than the way I did it
9163 at Sun, and which was adopted by AT&T (and which is, I think, also
9164 present in the @command{cpio} that Berkeley picked up from AT&T and put
9165 into a later @acronym{BSD} release---I think I gave them my changes).
9166
9167 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
9168 can handle @command{tar} format input, and write it on output, and it
9169 probably handles symbolic links. They may not have bothered doing
9170 anything to enhance @command{tar} as a result.)
9171
9172 @command{cpio} handles special files; traditional @command{tar} doesn't.
9173
9174 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
9175 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
9176 (4.3-tahoe and later).
9177
9178 @command{tar}'s way of handling multiple hard links to a file can handle
9179 file systems that support 32-bit inumbers (e.g., the @acronym{BSD} file system);
9180 @command{cpio}s way requires you to play some games (in its ``binary''
9181 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
9182 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
9183 field of the header to make sure that the file system @acronym{ID}/i-number pairs
9184 of different files were always different), and I don't know which
9185 @command{cpio}s, if any, play those games. Those that don't might get
9186 confused and think two files are the same file when they're not, and
9187 make hard links between them.
9188
9189 @command{tar}s way of handling multiple hard links to a file places only
9190 one copy of the link on the tape, but the name attached to that copy
9191 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
9192 way puts one copy for every link, but you can retrieve it using any
9193 of the names.
9194
9195 @quotation
9196 What type of check sum (if any) is used, and how is this calculated.
9197 @end quotation
9198
9199 See the attached manual pages for @command{tar} and @command{cpio} format.
9200 @command{tar} uses a checksum which is the sum of all the bytes in the
9201 @command{tar} header for a file; @command{cpio} uses no checksum.
9202
9203 @quotation
9204 If anyone knows why @command{cpio} was made when @command{tar} was present
9205 at the unix scene,
9206 @end quotation
9207
9208 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
9209 generally-available version of UNIX had @command{tar} at the time. I don't
9210 know whether any version that was generally available @emph{within AT&T}
9211 had @command{tar}, or, if so, whether the people within AT&T who did
9212 @command{cpio} knew about it.
9213
9214 On restore, if there is a corruption on a tape @command{tar} will stop at
9215 that point, while @command{cpio} will skip over it and try to restore the
9216 rest of the files.
9217
9218 The main difference is just in the command syntax and header format.
9219
9220 @command{tar} is a little more tape-oriented in that everything is blocked
9221 to start on a record boundary.
9222
9223 @quotation
9224 Is there any differences between the ability to recover crashed
9225 archives between the two of them. (Is there any chance of recovering
9226 crashed archives at all.)
9227 @end quotation
9228
9229 Theoretically it should be easier under @command{tar} since the blocking
9230 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
9231 However, modern @command{cpio}'s and variations have an option to just
9232 search for the next file header after an error with a reasonable chance
9233 of resyncing. However, lots of tape driver software won't allow you to
9234 continue past a media error which should be the only reason for getting
9235 out of sync unless a file changed sizes while you were writing the
9236 archive.
9237
9238 @quotation
9239 If anyone knows why @command{cpio} was made when @command{tar} was present
9240 at the unix scene, please tell me about this too.
9241 @end quotation
9242
9243 Probably because it is more media efficient (by not blocking everything
9244 and using only the space needed for the headers where @command{tar}
9245 always uses 512 bytes per file header) and it knows how to archive
9246 special files.
9247
9248 You might want to look at the freely available alternatives. The
9249 major ones are @command{afio}, @GNUTAR{}, and
9250 @command{pax}, each of which have their own extensions with some
9251 backwards compatibility.
9252
9253 Sparse files were @command{tar}red as sparse files (which you can
9254 easily test, because the resulting archive gets smaller, and
9255 @acronym{GNU} @command{cpio} can no longer read it).
9256
9257 @node Media
9258 @chapter Tapes and Other Archive Media
9259 @UNREVISED
9260
9261 A few special cases about tape handling warrant more detailed
9262 description. These special cases are discussed below.
9263
9264 Many complexities surround the use of @command{tar} on tape drives. Since
9265 the creation and manipulation of archives located on magnetic tape was
9266 the original purpose of @command{tar}, it contains many features making
9267 such manipulation easier.
9268
9269 Archives are usually written on dismountable media---tape cartridges,
9270 mag tapes, or floppy disks.
9271
9272 The amount of data a tape or disk holds depends not only on its size,
9273 but also on how it is formatted. A 2400 foot long reel of mag tape
9274 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9275 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9276
9277 Magnetic media are re-usable---once the archive on a tape is no longer
9278 needed, the archive can be erased and the tape or disk used over.
9279 Media quality does deteriorate with use, however. Most tapes or disks
9280 should be discarded when they begin to produce data errors. EXABYTE
9281 tape cartridges should be discarded when they generate an @dfn{error
9282 count} (number of non-usable bits) of more than 10k.
9283
9284 Magnetic media are written and erased using magnetic fields, and
9285 should be protected from such fields to avoid damage to stored data.
9286 Sticking a floppy disk to a filing cabinet using a magnet is probably
9287 not a good idea.
9288
9289 @menu
9290 * Device:: Device selection and switching
9291 * Remote Tape Server::
9292 * Common Problems and Solutions::
9293 * Blocking:: Blocking
9294 * Many:: Many archives on one tape
9295 * Using Multiple Tapes:: Using Multiple Tapes
9296 * label:: Including a Label in the Archive
9297 * verify::
9298 * Write Protection::
9299 @end menu
9300
9301 @node Device
9302 @section Device Selection and Switching
9303 @UNREVISED
9304
9305 @table @option
9306 @item -f [@var{hostname}:]@var{file}
9307 @itemx --file=[@var{hostname}:]@var{file}
9308 Use archive file or device @var{file} on @var{hostname}.
9309 @end table
9310
9311 This option is used to specify the file name of the archive @command{tar}
9312 works on.
9313
9314 If the file name is @samp{-}, @command{tar} reads the archive from standard
9315 input (when listing or extracting), or writes it to standard output
9316 (when creating). If the @samp{-} file name is given when updating an
9317 archive, @command{tar} will read the original archive from its standard
9318 input, and will write the entire new archive to its standard output.
9319
9320 If the file name contains a @samp{:}, it is interpreted as
9321 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9322 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9323 either case, @command{tar} will invoke the command @command{rsh} (or
9324 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9325 machine. If you give an alternate login name, it will be given to the
9326 @command{rsh}.
9327 Naturally, the remote machine must have an executable
9328 @command{/usr/libexec/rmt}. This program is free software from the
9329 University of California, and a copy of the source code can be found
9330 with the sources for @command{tar}; it's compiled and installed by default.
9331 The exact path to this utility is determined when configuring the package.
9332 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9333 your installation prefix. This location may also be overridden at
9334 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9335 ---rmt-command}, for detailed description of this option. @xref{Remote
9336 Tape Server}, for the description of @command{rmt} command).
9337
9338 If this option is not given, but the environment variable @env{TAPE}
9339 is set, its value is used; otherwise, old versions of @command{tar}
9340 used a default archive name (which was picked when @command{tar} was
9341 compiled). The default is normally set up to be the @dfn{first} tape
9342 drive or other transportable I/O medium on the system.
9343
9344 Starting with version 1.11.5, @GNUTAR{} uses
9345 standard input and standard output as the default device, and I will
9346 not try anymore supporting automatic device detection at installation
9347 time. This was failing really in too many cases, it was hopeless.
9348 This is now completely left to the installer to override standard
9349 input and standard output for default device, if this seems
9350 preferable. Further, I think @emph{most} actual usages of
9351 @command{tar} are done with pipes or disks, not really tapes,
9352 cartridges or diskettes.
9353
9354 Some users think that using standard input and output is running
9355 after trouble. This could lead to a nasty surprise on your screen if
9356 you forget to specify an output file name---especially if you are going
9357 through a network or terminal server capable of buffering large amounts
9358 of output. We had so many bug reports in that area of configuring
9359 default tapes automatically, and so many contradicting requests, that
9360 we finally consider the problem to be portably intractable. We could
9361 of course use something like @samp{/dev/tape} as a default, but this
9362 is @emph{also} running after various kind of trouble, going from hung
9363 processes to accidental destruction of real tapes. After having seen
9364 all this mess, using standard input and output as a default really
9365 sounds like the only clean choice left, and a very useful one too.
9366
9367 @GNUTAR{} reads and writes archive in records, I
9368 suspect this is the main reason why block devices are preferred over
9369 character devices. Most probably, block devices are more efficient
9370 too. The installer could also check for @samp{DEFTAPE} in
9371 @file{<sys/mtio.h>}.
9372
9373 @table @option
9374 @xopindex{force-local, short description}
9375 @item --force-local
9376 Archive file is local even if it contains a colon.
9377
9378 @opindex rsh-command
9379 @item --rsh-command=@var{command}
9380 Use remote @var{command} instead of @command{rsh}. This option exists
9381 so that people who use something other than the standard @command{rsh}
9382 (e.g., a Kerberized @command{rsh}) can access a remote device.
9383
9384 When this command is not used, the shell command found when
9385 the @command{tar} program was installed is used instead. This is
9386 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9387 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9388 The installer may have overridden this by defining the environment
9389 variable @env{RSH} @emph{at installation time}.
9390
9391 @item -[0-7][lmh]
9392 Specify drive and density.
9393
9394 @xopindex{multi-volume, short description}
9395 @item -M
9396 @itemx --multi-volume
9397 Create/list/extract multi-volume archive.
9398
9399 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9400 that may be larger than will fit on the medium used to hold it.
9401 @xref{Multi-Volume Archives}.
9402
9403 @xopindex{tape-length, short description}
9404 @item -L @var{num}
9405 @itemx --tape-length=@var{num}
9406 Change tape after writing @var{num} x 1024 bytes.
9407
9408 This option might be useful when your tape drivers do not properly
9409 detect end of physical tapes. By being slightly conservative on the
9410 maximum tape length, you might avoid the problem entirely.
9411
9412 @xopindex{info-script, short description}
9413 @xopindex{new-volume-script, short description}
9414 @item -F @var{file}
9415 @itemx --info-script=@var{file}
9416 @itemx --new-volume-script=@var{file}
9417 Execute @file{file} at end of each tape. This implies
9418 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9419 description of this option.
9420 @end table
9421
9422 @node Remote Tape Server
9423 @section The Remote Tape Server
9424
9425 @cindex remote tape drive
9426 @pindex rmt
9427 In order to access the tape drive on a remote machine, @command{tar}
9428 uses the remote tape server written at the University of California at
9429 Berkeley. The remote tape server must be installed as
9430 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9431 want to use. @command{tar} calls @command{rmt} by running an
9432 @command{rsh} or @command{remsh} to the remote machine, optionally
9433 using a different login name if one is supplied.
9434
9435 A copy of the source for the remote tape server is provided. It is
9436 Copyright @copyright{} 1983 by the Regents of the University of
9437 California, but can be freely distributed. It is compiled and
9438 installed by default.
9439
9440 @cindex absolute file names
9441 Unless you use the @option{--absolute-names} (@option{-P}) option,
9442 @GNUTAR{} will not allow you to create an archive that contains
9443 absolute file names (a file name beginning with @samp{/}.) If you try,
9444 @command{tar} will automatically remove the leading @samp{/} from the
9445 file names it stores in the archive. It will also type a warning
9446 message telling you what it is doing.
9447
9448 When reading an archive that was created with a different
9449 @command{tar} program, @GNUTAR{} automatically
9450 extracts entries in the archive which have absolute file names as if
9451 the file names were not absolute. This is an important feature. A
9452 visitor here once gave a @command{tar} tape to an operator to restore;
9453 the operator used Sun @command{tar} instead of @GNUTAR{},
9454 and the result was that it replaced large portions of
9455 our @file{/bin} and friends with versions from the tape; needless to
9456 say, we were unhappy about having to recover the file system from
9457 backup tapes.
9458
9459 For example, if the archive contained a file @file{/usr/bin/computoy},
9460 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9461 relative to the current directory. If you want to extract the files in
9462 an archive to the same absolute names that they had when the archive
9463 was created, you should do a @samp{cd /} before extracting the files
9464 from the archive, or you should either use the @option{--absolute-names}
9465 option, or use the command @samp{tar -C / @dots{}}.
9466
9467 @cindex Ultrix 3.1 and write failure
9468 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9469 can claim that a short write near the end of a tape succeeded,
9470 when it actually failed. This will result in the -M option not
9471 working correctly. The best workaround at the moment is to use a
9472 significantly larger blocking factor than the default 20.
9473
9474 In order to update an archive, @command{tar} must be able to backspace the
9475 archive in order to reread or rewrite a record that was just read (or
9476 written). This is currently possible only on two kinds of files: normal
9477 disk files (or any other file that can be backspaced with @samp{lseek}),
9478 and industry-standard 9-track magnetic tape (or any other kind of tape
9479 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9480
9481 This means that the @option{--append}, @option{--concatenate}, and
9482 @option{--delete} commands will not work on any other kind of file.
9483 Some media simply cannot be backspaced, which means these commands and
9484 options will never be able to work on them. These non-backspacing
9485 media include pipes and cartridge tape drives.
9486
9487 Some other media can be backspaced, and @command{tar} will work on them
9488 once @command{tar} is modified to do so.
9489
9490 Archives created with the @option{--multi-volume}, @option{--label}, and
9491 @option{--incremental} (@option{-G}) options may not be readable by other version
9492 of @command{tar}. In particular, restoring a file that was split over
9493 a volume boundary will require some careful work with @command{dd}, if
9494 it can be done at all. Other versions of @command{tar} may also create
9495 an empty file whose name is that of the volume header. Some versions
9496 of @command{tar} may create normal files instead of directories archived
9497 with the @option{--incremental} (@option{-G}) option.
9498
9499 @node Common Problems and Solutions
9500 @section Some Common Problems and their Solutions
9501
9502 @ifclear PUBLISH
9503
9504 @format
9505 errors from system:
9506 permission denied
9507 no such file or directory
9508 not owner
9509
9510 errors from @command{tar}:
9511 directory checksum error
9512 header format error
9513
9514 errors from media/system:
9515 i/o error
9516 device busy
9517 @end format
9518
9519 @end ifclear
9520
9521 @node Blocking
9522 @section Blocking
9523 @UNREVISED
9524
9525 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9526 is also confusing to the expert reader. On the other hand, readers
9527 who are new to the field have a fresh mind, and they may safely skip
9528 the next two paragraphs, as the remainder of this manual uses those
9529 two terms in a quite consistent way.
9530
9531 John Gilmore, the writer of the public domain @command{tar} from which
9532 @GNUTAR{} was originally derived, wrote (June 1995):
9533
9534 @quotation
9535 The nomenclature of tape drives comes from IBM, where I believe
9536 they were invented for the IBM 650 or so. On IBM mainframes, what
9537 is recorded on tape are tape blocks. The logical organization of
9538 data is into records. There are various ways of putting records into
9539 blocks, including @code{F} (fixed sized records), @code{V} (variable
9540 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9541 to a block), @code{VB} (variable size records, @var{n} to a block),
9542 @code{VSB} (variable spanned blocked: variable sized records that can
9543 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9544 parameter specified this to the operating system.
9545
9546 The Unix man page on @command{tar} was totally confused about this.
9547 When I wrote @code{PD TAR}, I used the historically correct terminology
9548 (@command{tar} writes data records, which are grouped into blocks).
9549 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9550 here), and now Fran@,{c}ois has migrated that terminology back
9551 into the source code too.
9552 @end quotation
9553
9554 The term @dfn{physical block} means the basic transfer chunk from or
9555 to a device, after which reading or writing may stop without anything
9556 being lost. In this manual, the term @dfn{block} usually refers to
9557 a disk physical block, @emph{assuming} that each disk block is 512
9558 bytes in length. It is true that some disk devices have different
9559 physical blocks, but @command{tar} ignore these differences in its own
9560 format, which is meant to be portable, so a @command{tar} block is always
9561 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9562 The term @dfn{logical block} often represents the basic chunk of
9563 allocation of many disk blocks as a single entity, which the operating
9564 system treats somewhat atomically; this concept is only barely used
9565 in @GNUTAR{}.
9566
9567 The term @dfn{physical record} is another way to speak of a physical
9568 block, those two terms are somewhat interchangeable. In this manual,
9569 the term @dfn{record} usually refers to a tape physical block,
9570 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9571 It is true that archives may be put on disk or used with pipes,
9572 but nevertheless, @command{tar} tries to read and write the archive one
9573 @dfn{record} at a time, whatever the medium in use. One record is made
9574 up of an integral number of blocks, and this operation of putting many
9575 disk blocks into a single tape block is called @dfn{reblocking}, or
9576 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9577 the logical organization of many characters into something meaningful
9578 to the application. The term @dfn{unit record} describes a small set
9579 of characters which are transmitted whole to or by the application,
9580 and often refers to a line of text. Those two last terms are unrelated
9581 to what we call a @dfn{record} in @GNUTAR{}.
9582
9583 When writing to tapes, @command{tar} writes the contents of the archive
9584 in chunks known as @dfn{records}. To change the default blocking
9585 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9586 @var{512-size}}) option. Each record will then be composed of
9587 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9588 @xref{Standard}.) Each file written to the archive uses at least one
9589 full record. As a result, using a larger record size can result in
9590 more wasted space for small files. On the other hand, a larger record
9591 size can often be read and written much more efficiently.
9592
9593 Further complicating the problem is that some tape drives ignore the
9594 blocking entirely. For these, a larger record size can still improve
9595 performance (because the software layers above the tape drive still
9596 honor the blocking), but not as dramatically as on tape drives that
9597 honor blocking.
9598
9599 When reading an archive, @command{tar} can usually figure out the
9600 record size on itself. When this is the case, and a non-standard
9601 record size was used when the archive was created, @command{tar} will
9602 print a message about a non-standard blocking factor, and then operate
9603 normally. On some tape devices, however, @command{tar} cannot figure
9604 out the record size itself. On most of those, you can specify a
9605 blocking factor (with @option{--blocking-factor}) larger than the
9606 actual blocking factor, and then use the @option{--read-full-records}
9607 (@option{-B}) option. (If you specify a blocking factor with
9608 @option{--blocking-factor} and don't use the
9609 @option{--read-full-records} option, then @command{tar} will not
9610 attempt to figure out the recording size itself.) On some devices,
9611 you must always specify the record size exactly with
9612 @option{--blocking-factor} when reading, because @command{tar} cannot
9613 figure it out. In any case, use @option{--list} (@option{-t}) before
9614 doing any extractions to see whether @command{tar} is reading the archive
9615 correctly.
9616
9617 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9618 putting them into records is to put a whole number of them (one or
9619 more) into each record. @command{tar} records are all the same size;
9620 at the end of the file there's a block containing all zeros, which
9621 is how you tell that the remainder of the last record(s) are garbage.
9622
9623 In a standard @command{tar} file (no options), the block size is 512
9624 and the record size is 10240, for a blocking factor of 20. What the
9625 @option{--blocking-factor} option does is sets the blocking factor,
9626 changing the record size while leaving the block size at 512 bytes.
9627 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9628 most tape drives these days prefer much bigger records in order to
9629 stream and not waste tape. When writing tapes for myself, some tend
9630 to use a factor of the order of 2048, say, giving a record size of
9631 around one megabyte.
9632
9633 If you use a blocking factor larger than 20, older @command{tar}
9634 programs might not be able to read the archive, so we recommend this
9635 as a limit to use in practice. @GNUTAR{}, however,
9636 will support arbitrarily large record sizes, limited only by the
9637 amount of virtual memory or the physical characteristics of the tape
9638 device.
9639
9640 @menu
9641 * Format Variations:: Format Variations
9642 * Blocking Factor:: The Blocking Factor of an Archive
9643 @end menu
9644
9645 @node Format Variations
9646 @subsection Format Variations
9647 @cindex Format Parameters
9648 @cindex Format Options
9649 @cindex Options, archive format specifying
9650 @cindex Options, format specifying
9651 @UNREVISED
9652
9653 Format parameters specify how an archive is written on the archive
9654 media. The best choice of format parameters will vary depending on
9655 the type and number of files being archived, and on the media used to
9656 store the archive.
9657
9658 To specify format parameters when accessing or creating an archive,
9659 you can use the options described in the following sections.
9660 If you do not specify any format parameters, @command{tar} uses
9661 default parameters. You cannot modify a compressed archive.
9662 If you create an archive with the @option{--blocking-factor} option
9663 specified (@pxref{Blocking Factor}), you must specify that
9664 blocking-factor when operating on the archive. @xref{Formats}, for other
9665 examples of format parameter considerations.
9666
9667 @node Blocking Factor
9668 @subsection The Blocking Factor of an Archive
9669 @cindex Blocking Factor
9670 @cindex Record Size
9671 @cindex Number of blocks per record
9672 @cindex Number of bytes per record
9673 @cindex Bytes per record
9674 @cindex Blocks per record
9675 @UNREVISED
9676
9677 @opindex blocking-factor
9678 The data in an archive is grouped into blocks, which are 512 bytes.
9679 Blocks are read and written in whole number multiples called
9680 @dfn{records}. The number of blocks in a record (i.e., the size of a
9681 record in units of 512 bytes) is called the @dfn{blocking factor}.
9682 The @option{--blocking-factor=@var{512-size}} (@option{-b
9683 @var{512-size}}) option specifies the blocking factor of an archive.
9684 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9685 can be specified at installation. To find out the blocking factor of
9686 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9687 This may not work on some devices.
9688
9689 Records are separated by gaps, which waste space on the archive media.
9690 If you are archiving on magnetic tape, using a larger blocking factor
9691 (and therefore larger records) provides faster throughput and allows you
9692 to fit more data on a tape (because there are fewer gaps). If you are
9693 archiving on cartridge, a very large blocking factor (say 126 or more)
9694 greatly increases performance. A smaller blocking factor, on the other
9695 hand, may be useful when archiving small files, to avoid archiving lots
9696 of nulls as @command{tar} fills out the archive to the end of the record.
9697 In general, the ideal record size depends on the size of the
9698 inter-record gaps on the tape you are using, and the average size of the
9699 files you are archiving. @xref{create}, for information on
9700 writing archives.
9701
9702 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9703
9704 Archives with blocking factors larger than 20 cannot be read
9705 by very old versions of @command{tar}, or by some newer versions
9706 of @command{tar} running on old machines with small address spaces.
9707 With @GNUTAR{}, the blocking factor of an archive is limited
9708 only by the maximum record size of the device containing the archive,
9709 or by the amount of available virtual memory.
9710
9711 Also, on some systems, not using adequate blocking factors, as sometimes
9712 imposed by the device drivers, may yield unexpected diagnostics. For
9713 example, this has been reported:
9714
9715 @smallexample
9716 Cannot write to /dev/dlt: Invalid argument
9717 @end smallexample
9718
9719 @noindent
9720 In such cases, it sometimes happen that the @command{tar} bundled by
9721 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9722 requires an explicit specification for the block size,
9723 which it cannot guess. This yields some people to consider
9724 @GNUTAR{} is misbehaving, because by comparison,
9725 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9726 for example, might resolve the problem.
9727
9728 If you use a non-default blocking factor when you create an archive, you
9729 must specify the same blocking factor when you modify that archive. Some
9730 archive devices will also require you to specify the blocking factor when
9731 reading that archive, however this is not typically the case. Usually, you
9732 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9733 reports a non-default record size and then lists the archive members as
9734 it would normally. To extract files from an archive with a non-standard
9735 blocking factor (particularly if you're not sure what the blocking factor
9736 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9737 specifying a blocking factor larger then the blocking factor of the archive
9738 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
9739 @xref{list}, for more information on the @option{--list} (@option{-t})
9740 operation. @xref{Reading}, for a more detailed explanation of that option.
9741
9742 @table @option
9743 @item --blocking-factor=@var{number}
9744 @itemx -b @var{number}
9745 Specifies the blocking factor of an archive. Can be used with any
9746 operation, but is usually not necessary with @option{--list} (@option{-t}).
9747 @end table
9748
9749 Device blocking
9750
9751 @table @option
9752 @item -b @var{blocks}
9753 @itemx --blocking-factor=@var{blocks}
9754 Set record size to @math{@var{blocks} * 512} bytes.
9755
9756 This option is used to specify a @dfn{blocking factor} for the archive.
9757 When reading or writing the archive, @command{tar}, will do reads and writes
9758 of the archive in records of @math{@var{block}*512} bytes. This is true
9759 even when the archive is compressed. Some devices requires that all
9760 write operations be a multiple of a certain size, and so, @command{tar}
9761 pads the archive out to the next record boundary.
9762
9763 The default blocking factor is set when @command{tar} is compiled, and is
9764 typically 20. Blocking factors larger than 20 cannot be read by very
9765 old versions of @command{tar}, or by some newer versions of @command{tar}
9766 running on old machines with small address spaces.
9767
9768 With a magnetic tape, larger records give faster throughput and fit
9769 more data on a tape (because there are fewer inter-record gaps).
9770 If the archive is in a disk file or a pipe, you may want to specify
9771 a smaller blocking factor, since a large one will result in a large
9772 number of null bytes at the end of the archive.
9773
9774 When writing cartridge or other streaming tapes, a much larger
9775 blocking factor (say 126 or more) will greatly increase performance.
9776 However, you must specify the same blocking factor when reading or
9777 updating the archive.
9778
9779 Apparently, Exabyte drives have a physical block size of 8K bytes.
9780 If we choose our blocksize as a multiple of 8k bytes, then the problem
9781 seems to disappear. Id est, we are using block size of 112 right
9782 now, and we haven't had the problem since we switched@dots{}
9783
9784 With @GNUTAR{} the blocking factor is limited only
9785 by the maximum record size of the device containing the archive, or by
9786 the amount of available virtual memory.
9787
9788 However, deblocking or reblocking is virtually avoided in a special
9789 case which often occurs in practice, but which requires all the
9790 following conditions to be simultaneously true:
9791 @itemize @bullet
9792 @item
9793 the archive is subject to a compression option,
9794 @item
9795 the archive is not handled through standard input or output, nor
9796 redirected nor piped,
9797 @item
9798 the archive is directly handled to a local disk, instead of any special
9799 device,
9800 @item
9801 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9802 invocation.
9803 @end itemize
9804
9805 If the output goes directly to a local disk, and not through
9806 stdout, then the last write is not extended to a full record size.
9807 Otherwise, reblocking occurs. Here are a few other remarks on this
9808 topic:
9809
9810 @itemize @bullet
9811
9812 @item
9813 @command{gzip} will complain about trailing garbage if asked to
9814 uncompress a compressed archive on tape, there is an option to turn
9815 the message off, but it breaks the regularity of simply having to use
9816 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9817 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9818 Gailly, by sending a copy of this message to him.
9819
9820 @item
9821 @command{compress} does not show this problem, but as Jean-loup pointed
9822 out to Michael, @samp{compress -d} silently adds garbage after
9823 the result of decompression, which tar ignores because it already
9824 recognized its end-of-file indicator. So this bug may be safely
9825 ignored.
9826
9827 @item
9828 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9829 but will still return an exit status of 2 which tar reports in turn.
9830 @command{tar} might ignore the exit status returned, but I hate doing
9831 that, as it weakens the protection @command{tar} offers users against
9832 other possible problems at decompression time. If @command{gzip} was
9833 silently skipping trailing zeros @emph{and} also avoiding setting the
9834 exit status in this innocuous case, that would solve this situation.
9835
9836 @item
9837 @command{tar} should become more solid at not stopping to read a pipe at
9838 the first null block encountered. This inelegantly breaks the pipe.
9839 @command{tar} should rather drain the pipe out before exiting itself.
9840 @end itemize
9841
9842 @xopindex{ignore-zeros, short description}
9843 @item -i
9844 @itemx --ignore-zeros
9845 Ignore blocks of zeros in archive (means EOF).
9846
9847 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9848 of zeros in the archive. Normally a block of zeros indicates the
9849 end of the archive, but when reading a damaged archive, or one which
9850 was created by concatenating several archives together, this option
9851 allows @command{tar} to read the entire archive. This option is not on
9852 by default because many versions of @command{tar} write garbage after
9853 the zeroed blocks.
9854
9855 Note that this option causes @command{tar} to read to the end of the
9856 archive file, which may sometimes avoid problems when multiple files
9857 are stored on a single physical tape.
9858
9859 @xopindex{read-full-records, short description}
9860 @item -B
9861 @itemx --read-full-records
9862 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
9863
9864 If @option{--read-full-records} is used, @command{tar}
9865 will not panic if an attempt to read a record from the archive does
9866 not return a full record. Instead, @command{tar} will keep reading
9867 until it has obtained a full
9868 record.
9869
9870 This option is turned on by default when @command{tar} is reading
9871 an archive from standard input, or from a remote machine. This is
9872 because on @acronym{BSD} Unix systems, a read of a pipe will return however
9873 much happens to be in the pipe, even if it is less than @command{tar}
9874 requested. If this option was not used, @command{tar} would fail as
9875 soon as it read an incomplete record from the pipe.
9876
9877 This option is also useful with the commands for updating an archive.
9878
9879 @end table
9880
9881 Tape blocking
9882
9883 @FIXME{Appropriate options should be moved here from elsewhere.}
9884
9885 @cindex blocking factor
9886 @cindex tape blocking
9887
9888 When handling various tapes or cartridges, you have to take care of
9889 selecting a proper blocking, that is, the number of disk blocks you
9890 put together as a single tape block on the tape, without intervening
9891 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9892 with no information on it, used for decelerating the tape to a
9893 full stop, and for later regaining the reading or writing speed.
9894 When the tape driver starts reading a record, the record has to
9895 be read whole without stopping, as a tape gap is needed to stop the
9896 tape motion without loosing information.
9897
9898 @cindex Exabyte blocking
9899 @cindex DAT blocking
9900 Using higher blocking (putting more disk blocks per tape block) will use
9901 the tape more efficiently as there will be less tape gaps. But reading
9902 such tapes may be more difficult for the system, as more memory will be
9903 required to receive at once the whole record. Further, if there is a
9904 reading error on a huge record, this is less likely that the system will
9905 succeed in recovering the information. So, blocking should not be too
9906 low, nor it should be too high. @command{tar} uses by default a blocking of
9907 20 for historical reasons, and it does not really matter when reading or
9908 writing to disk. Current tape technology would easily accommodate higher
9909 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9910 We were told that for some DLT drives, the blocking should be a multiple
9911 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9912 Other manufacturers may use different recommendations for the same tapes.
9913 This might also depends of the buffering techniques used inside modern
9914 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9915 Others request blocking to be some exponent of two.
9916
9917 So, there is no fixed rule for blocking. But blocking at read time
9918 should ideally be the same as blocking used at write time. At one place
9919 I know, with a wide variety of equipment, they found it best to use a
9920 blocking of 32 to guarantee that their tapes are fully interchangeable.
9921
9922 I was also told that, for recycled tapes, prior erasure (by the same
9923 drive unit that will be used to create the archives) sometimes lowers
9924 the error rates observed at rewriting time.
9925
9926 I might also use @option{--number-blocks} instead of
9927 @option{--block-number}, so @option{--block} will then expand to
9928 @option{--blocking-factor} unambiguously.
9929
9930 @node Many
9931 @section Many Archives on One Tape
9932
9933 @FIXME{Appropriate options should be moved here from elsewhere.}
9934
9935 @findex ntape @r{device}
9936 Most tape devices have two entries in the @file{/dev} directory, or
9937 entries that come in pairs, which differ only in the minor number for
9938 this device. Let's take for example @file{/dev/tape}, which often
9939 points to the only or usual tape device of a given system. There might
9940 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9941 name is the @emph{rewinding} version of the device, while the name
9942 having @samp{nr} in it is the @emph{no rewinding} version of the same
9943 device.
9944
9945 A rewinding tape device will bring back the tape to its beginning point
9946 automatically when this device is opened or closed. Since @command{tar}
9947 opens the archive file before using it and closes it afterwards, this
9948 means that a simple:
9949
9950 @smallexample
9951 $ @kbd{tar cf /dev/tape @var{directory}}
9952 @end smallexample
9953
9954 @noindent
9955 will reposition the tape to its beginning both prior and after saving
9956 @var{directory} contents to it, thus erasing prior tape contents and
9957 making it so that any subsequent write operation will destroy what has
9958 just been saved.
9959
9960 @cindex tape positioning
9961 So, a rewinding device is normally meant to hold one and only one file.
9962 If you want to put more than one @command{tar} archive on a given tape, you
9963 will need to avoid using the rewinding version of the tape device. You
9964 will also have to pay special attention to tape positioning. Errors in
9965 positioning may overwrite the valuable data already on your tape. Many
9966 people, burnt by past experiences, will only use rewinding devices and
9967 limit themselves to one file per tape, precisely to avoid the risk of
9968 such errors. Be fully aware that writing at the wrong position on a
9969 tape loses all information past this point and most probably until the
9970 end of the tape, and this destroyed information @emph{cannot} be
9971 recovered.
9972
9973 To save @var{directory-1} as a first archive at the beginning of a
9974 tape, and leave that tape ready for a second archive, you should use:
9975
9976 @smallexample
9977 $ @kbd{mt -f /dev/nrtape rewind}
9978 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9979 @end smallexample
9980
9981 @cindex tape marks
9982 @dfn{Tape marks} are special magnetic patterns written on the tape
9983 media, which are later recognizable by the reading hardware. These
9984 marks are used after each file, when there are many on a single tape.
9985 An empty file (that is to say, two tape marks in a row) signal the
9986 logical end of the tape, after which no file exist. Usually,
9987 non-rewinding tape device drivers will react to the close request issued
9988 by @command{tar} by first writing two tape marks after your archive, and by
9989 backspacing over one of these. So, if you remove the tape at that time
9990 from the tape drive, it is properly terminated. But if you write
9991 another file at the current position, the second tape mark will be
9992 erased by the new information, leaving only one tape mark between files.
9993
9994 So, you may now save @var{directory-2} as a second archive after the
9995 first on the same tape by issuing the command:
9996
9997 @smallexample
9998 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9999 @end smallexample
10000
10001 @noindent
10002 and so on for all the archives you want to put on the same tape.
10003
10004 Another usual case is that you do not write all the archives the same
10005 day, and you need to remove and store the tape between two archive
10006 sessions. In general, you must remember how many files are already
10007 saved on your tape. Suppose your tape already has 16 files on it, and
10008 that you are ready to write the 17th. You have to take care of skipping
10009 the first 16 tape marks before saving @var{directory-17}, say, by using
10010 these commands:
10011
10012 @smallexample
10013 $ @kbd{mt -f /dev/nrtape rewind}
10014 $ @kbd{mt -f /dev/nrtape fsf 16}
10015 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
10016 @end smallexample
10017
10018 In all the previous examples, we put aside blocking considerations, but
10019 you should do the proper things for that as well. @xref{Blocking}.
10020
10021 @menu
10022 * Tape Positioning:: Tape Positions and Tape Marks
10023 * mt:: The @command{mt} Utility
10024 @end menu
10025
10026 @node Tape Positioning
10027 @subsection Tape Positions and Tape Marks
10028 @UNREVISED
10029
10030 Just as archives can store more than one file from the file system,
10031 tapes can store more than one archive file. To keep track of where
10032 archive files (or any other type of file stored on tape) begin and
10033 end, tape archive devices write magnetic @dfn{tape marks} on the
10034 archive media. Tape drives write one tape mark between files,
10035 two at the end of all the file entries.
10036
10037 If you think of data as a series of records "rrrr"'s, and tape marks as
10038 "*"'s, a tape might look like the following:
10039
10040 @smallexample
10041 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
10042 @end smallexample
10043
10044 Tape devices read and write tapes using a read/write @dfn{tape
10045 head}---a physical part of the device which can only access one
10046 point on the tape at a time. When you use @command{tar} to read or
10047 write archive data from a tape device, the device will begin reading
10048 or writing from wherever on the tape the tape head happens to be,
10049 regardless of which archive or what part of the archive the tape
10050 head is on. Before writing an archive, you should make sure that no
10051 data on the tape will be overwritten (unless it is no longer needed).
10052 Before reading an archive, you should make sure the tape head is at
10053 the beginning of the archive you want to read. You can do it manually
10054 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
10055 that automatically (@pxref{Scripted Restoration}).
10056
10057 If you want to add new archive file entries to a tape, you should
10058 advance the tape to the end of the existing file entries, backspace
10059 over the last tape mark, and write the new archive file. If you were
10060 to add two archives to the example above, the tape might look like the
10061 following:
10062
10063 @smallexample
10064 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
10065 @end smallexample
10066
10067 @node mt
10068 @subsection The @command{mt} Utility
10069 @UNREVISED
10070
10071 @FIXME{Is it true that this only works on non-block devices?
10072 should explain the difference, (fixed or variable).}
10073 @xref{Blocking Factor}.
10074
10075 You can use the @command{mt} utility to advance or rewind a tape past a
10076 specified number of archive files on the tape. This will allow you
10077 to move to the beginning of an archive before extracting or reading
10078 it, or to the end of all the archives before writing a new one.
10079 @FIXME{Why isn't there an "advance 'til you find two tape marks
10080 together"?}
10081
10082 The syntax of the @command{mt} command is:
10083
10084 @smallexample
10085 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
10086 @end smallexample
10087
10088 where @var{tapename} is the name of the tape device, @var{number} is
10089 the number of times an operation is performed (with a default of one),
10090 and @var{operation} is one of the following:
10091
10092 @FIXME{is there any use for record operations?}
10093
10094 @table @option
10095 @item eof
10096 @itemx weof
10097 Writes @var{number} tape marks at the current position on the tape.
10098
10099 @item fsf
10100 Moves tape position forward @var{number} files.
10101
10102 @item bsf
10103 Moves tape position back @var{number} files.
10104
10105 @item rewind
10106 Rewinds the tape. (Ignores @var{number}).
10107
10108 @item offline
10109 @itemx rewoff1
10110 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
10111
10112 @item status
10113 Prints status information about the tape unit.
10114
10115 @end table
10116
10117 @FIXME{Is there a better way to frob the spacing on the list?}
10118
10119 If you don't specify a @var{tapename}, @command{mt} uses the environment
10120 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
10121 the default device specified in your @file{sys/mtio.h} file
10122 (@code{DEFTAPE} variable). If this is not defined, the program will
10123 display a descriptive error message and exit with code 1.
10124
10125 @command{mt} returns a 0 exit status when the operation(s) were
10126 successful, 1 if the command was unrecognized, and 2 if an operation
10127 failed.
10128
10129 @node Using Multiple Tapes
10130 @section Using Multiple Tapes
10131
10132 Often you might want to write a large archive, one larger than will fit
10133 on the actual tape you are using. In such a case, you can run multiple
10134 @command{tar} commands, but this can be inconvenient, particularly if you
10135 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
10136 Therefore, @command{tar} provides a special mode for creating
10137 multi-volume archives.
10138
10139 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
10140 on several media volumes of fixed size. Although in this section we will
10141 often call @samp{volume} a @dfn{tape}, there is absolutely no
10142 requirement for multi-volume archives to be stored on tapes. Instead,
10143 they can use whatever media type the user finds convenient, they can
10144 even be located on files.
10145
10146 When creating a multi-volume archive, @GNUTAR{} continues to fill
10147 current volume until it runs out of space, then it switches to
10148 next volume (usually the operator is queried to replace the tape on
10149 this point), and continues working on the new volume. This operation
10150 continues until all requested files are dumped. If @GNUTAR{} detects
10151 end of media while dumping a file, such a file is archived in split
10152 form. Some very big files can even be split across several volumes.
10153
10154 Each volume is itself a valid @GNUTAR{} archive, so it can be read
10155 without any special options. Consequently any file member residing
10156 entirely on one volume can be extracted or otherwise operated upon
10157 without needing the other volume. Sure enough, to extract a split
10158 member you would need all volumes its parts reside on.
10159
10160 Multi-volume archives suffer from several limitations. In particular,
10161 they cannot be compressed.
10162
10163 @GNUTAR{} is able to create multi-volume archives of two formats
10164 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
10165
10166 @menu
10167 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
10168 * Tape Files:: Tape Files
10169 * Tarcat:: Concatenate Volumes into a Single Archive
10170
10171 @end menu
10172
10173 @node Multi-Volume Archives
10174 @subsection Archives Longer than One Tape or Disk
10175 @cindex Multi-volume archives
10176
10177 @opindex multi-volume
10178 To create an archive that is larger than will fit on a single unit of
10179 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
10180 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
10181 archive can be manipulated like any other archive (provided the
10182 @option{--multi-volume} option is specified), but is stored on more
10183 than one tape or disk.
10184
10185 When you specify @option{--multi-volume}, @command{tar} does not report an
10186 error when it comes to the end of an archive volume (when reading), or
10187 the end of the media (when writing). Instead, it prompts you to load
10188 a new storage volume. If the archive is on a magnetic tape, you
10189 should change tapes when you see the prompt; if the archive is on a
10190 floppy disk, you should change disks; etc.
10191
10192 @table @option
10193 @item --multi-volume
10194 @itemx -M
10195 Creates a multi-volume archive, when used in conjunction with
10196 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
10197 archive, specify @option{--multi-volume} in conjunction with that
10198 operation.
10199 For example:
10200
10201 @smallexample
10202 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
10203 @end smallexample
10204 @end table
10205
10206 The method @command{tar} uses to detect end of tape is not perfect, and
10207 fails on some operating systems or on some devices. If @command{tar}
10208 cannot detect the end of the tape itself, you can use
10209 @option{--tape-length} option to inform it about the capacity of the
10210 tape:
10211
10212 @anchor{tape-length}
10213 @table @option
10214 @opindex tape-length
10215 @item --tape-length=@var{size}
10216 @itemx -L @var{size}
10217 Set maximum length of a volume. The @var{size} argument should then
10218 be the usable size of the tape in units of 1024 bytes. This option
10219 selects @option{--multi-volume} automatically. For example:
10220
10221 @smallexample
10222 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
10223 @end smallexample
10224 @end table
10225
10226 @anchor{change volume prompt}
10227 When @GNUTAR{} comes to the end of a storage media, it asks you to
10228 change the volume. The built-in prompt for POSIX locale
10229 is@footnote{If you run @GNUTAR{} under a different locale, the
10230 translation to the locale's language will be used.}:
10231
10232 @smallexample
10233 Prepare volume #@var{n} for `@var{archive}' and hit return:
10234 @end smallexample
10235
10236 @noindent
10237 where @var{n} is the ordinal number of the volume to be created and
10238 @var{archive} is archive file or device name.
10239
10240 When prompting for a new tape, @command{tar} accepts any of the following
10241 responses:
10242
10243 @table @kbd
10244 @item ?
10245 Request @command{tar} to explain possible responses
10246 @item q
10247 Request @command{tar} to exit immediately.
10248 @item n @var{file-name}
10249 Request @command{tar} to write the next volume on the file @var{file-name}.
10250 @item !
10251 Request @command{tar} to run a subshell. This option can be disabled
10252 by giving @option{--restrict} command line option to
10253 @command{tar}@footnote{@xref{--restrict}, for more information about
10254 this option}.
10255 @item y
10256 Request @command{tar} to begin writing the next volume.
10257 @end table
10258
10259 (You should only type @samp{y} after you have changed the tape;
10260 otherwise @command{tar} will write over the volume it just finished.)
10261
10262 @cindex Volume number file
10263 @cindex volno file
10264 @anchor{volno-file}
10265 @opindex volno-file
10266 The volume number used by @command{tar} in its tape-changing prompt
10267 can be changed; if you give the
10268 @option{--volno-file=@var{file-of-number}} option, then
10269 @var{file-of-number} should be an non-existing file to be created, or
10270 else, a file already containing a decimal number. That number will be
10271 used as the volume number of the first volume written. When
10272 @command{tar} is finished, it will rewrite the file with the
10273 now-current volume number. (This does not change the volume number
10274 written on a tape label, as per @ref{label}, it @emph{only} affects
10275 the number used in the prompt.)
10276
10277 @cindex End-of-archive info script
10278 @cindex Info script
10279 @anchor{info-script}
10280 @opindex info-script
10281 @opindex new-volume-script
10282 If you want more elaborate behavior than this, you can write a special
10283 @dfn{new volume script}, that will be responsible for changing the
10284 volume, and instruct @command{tar} to use it instead of its normal
10285 prompting procedure:
10286
10287 @table @option
10288 @item --info-script=@var{script-name}
10289 @itemx --new-volume-script=@var{script-name}
10290 @itemx -F @var{script-name}
10291 Specify the full name of the volume script to use. The script can be
10292 used to eject cassettes, or to broadcast messages such as
10293 @samp{Someone please come change my tape} when performing unattended
10294 backups.
10295 @end table
10296
10297 The @var{script-name} is executed without any command line
10298 arguments. It inherits @command{tar}'s shell environment.
10299 Additional data is passed to it via the following
10300 environment variables:
10301
10302 @table @env
10303 @vrindex TAR_VERSION, info script environment variable
10304 @item TAR_VERSION
10305 @GNUTAR{} version number.
10306
10307 @vrindex TAR_ARCHIVE, info script environment variable
10308 @item TAR_ARCHIVE
10309 The name of the archive @command{tar} is processing.
10310
10311 @vrindex TAR_VOLUME, info script environment variable
10312 @item TAR_VOLUME
10313 Ordinal number of the volume @command{tar} is about to start.
10314
10315 @vrindex TAR_SUBCOMMAND, info script environment variable
10316 @item TAR_SUBCOMMAND
10317 Short option describing the operation @command{tar} is executing
10318 @xref{Operations}, for a complete list of subcommand options.
10319
10320 @vrindex TAR_FORMAT, info script environment variable
10321 @item TAR_FORMAT
10322 Format of the archive being processed. @xref{Formats}, for a complete
10323 list of archive format names.
10324
10325 @vrindex TAR_FD, info script environment variable
10326 @item TAR_FD
10327 File descriptor which can be used to communicate the new volume
10328 name to @command{tar}.
10329 @end table
10330
10331 The volume script can instruct @command{tar} to use new archive name,
10332 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
10333
10334 If the info script fails, @command{tar} exits; otherwise, it begins
10335 writing the next volume.
10336
10337 If you want @command{tar} to cycle through a series of files or tape
10338 drives, there are three approaches to choose from. First of all, you
10339 can give @command{tar} multiple @option{--file} options. In this case
10340 the specified files will be used, in sequence, as the successive
10341 volumes of the archive. Only when the first one in the sequence needs
10342 to be used again will @command{tar} prompt for a tape change (or run
10343 the info script). For example, suppose someone has two tape drives on
10344 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10345 @GNUTAR{} to switch to the second drive when it needs to write the
10346 second tape, and then back to the first tape, etc., just do either of:
10347
10348 @smallexample
10349 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10350 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10351 @end smallexample
10352
10353 The second method is to use the @samp{n} response to the tape-change
10354 prompt.
10355
10356 Finally, the most flexible approach is to use a volume script, that
10357 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
10358 following volume script will create a series of archive files, named
10359 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10360 archive being created (as given by @option{--file} option) and
10361 @var{vol} is the ordinal number of the archive being created:
10362
10363 @smallexample
10364 @group
10365 #! /bin/sh
10366 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10367
10368 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10369 case $TAR_SUBCOMMAND in
10370 -c) ;;
10371 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10372 ;;
10373 *) exit 1
10374 esac
10375
10376 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
10377 @end group
10378 @end smallexample
10379
10380 The same script can be used while listing, comparing or extracting
10381 from the created archive. For example:
10382
10383 @smallexample
10384 @group
10385 # @r{Create a multi-volume archive:}
10386 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10387 # @r{Extract from the created archive:}
10388 $ @kbd{tar -x -f archive.tar -F new-volume .}
10389 @end group
10390 @end smallexample
10391
10392 @noindent
10393 Notice, that the first command had to use @option{-L} option, since
10394 otherwise @GNUTAR{} will end up writing everything to file
10395 @file{archive.tar}.
10396
10397 You can read each individual volume of a multi-volume archive as if it
10398 were an archive by itself. For example, to list the contents of one
10399 volume, use @option{--list}, without @option{--multi-volume} specified.
10400 To extract an archive member from one volume (assuming it is described
10401 that volume), use @option{--extract}, again without
10402 @option{--multi-volume}.
10403
10404 If an archive member is split across volumes (i.e., its entry begins on
10405 one volume of the media and ends on another), you need to specify
10406 @option{--multi-volume} to extract it successfully. In this case, you
10407 should load the volume where the archive member starts, and use
10408 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10409 volumes as it needs them. @xref{extracting archives}, for more
10410 information about extracting archives.
10411
10412 Multi-volume archives can be modified like any other archive. To add
10413 files to a multi-volume archive, you need to only mount the last
10414 volume of the archive media (and new volumes, if needed). For all
10415 other operations, you need to use the entire archive.
10416
10417 If a multi-volume archive was labeled using
10418 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10419 created, @command{tar} will not automatically label volumes which are
10420 added later. To label subsequent volumes, specify
10421 @option{--label=@var{archive-label}} again in conjunction with the
10422 @option{--append}, @option{--update} or @option{--concatenate} operation.
10423
10424 Notice that multi-volume support is a GNU extension and the archives
10425 created in this mode should be read only using @GNUTAR{}. If you
10426 absolutely have to process such archives using a third-party @command{tar}
10427 implementation, read @ref{Split Recovery}.
10428
10429 @node Tape Files
10430 @subsection Tape Files
10431 @UNREVISED
10432
10433 To give the archive a name which will be recorded in it, use the
10434 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10435 option. This will write a special block identifying
10436 @var{volume-label} as the name of the archive to the front of the
10437 archive which will be displayed when the archive is listed with
10438 @option{--list}. If you are creating a multi-volume archive with
10439 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10440 volume label will have @samp{Volume @var{nnn}} appended to the name
10441 you give, where @var{nnn} is the number of the volume of the archive.
10442 (If you use the @option{--label=@var{volume-label}}) option when
10443 reading an archive, it checks to make sure the label on the tape
10444 matches the one you give. @xref{label}.
10445
10446 When @command{tar} writes an archive to tape, it creates a single
10447 tape file. If multiple archives are written to the same tape, one
10448 after the other, they each get written as separate tape files. When
10449 extracting, it is necessary to position the tape at the right place
10450 before running @command{tar}. To do this, use the @command{mt} command.
10451 For more information on the @command{mt} command and on the organization
10452 of tapes into a sequence of tape files, see @ref{mt}.
10453
10454 People seem to often do:
10455
10456 @smallexample
10457 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10458 @end smallexample
10459
10460 or such, for pushing a common date in all volumes or an archive set.
10461
10462 @node Tarcat
10463 @subsection Concatenate Volumes into a Single Archive
10464
10465 @pindex tarcat
10466 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10467 archive to a single @command{tar} archive. Simply concatenating all
10468 volumes into one will not work, since each volume carries an additional
10469 information at the beginning. @GNUTAR{} is shipped with the shell
10470 script @command{tarcat} designed for this purpose.
10471
10472 The script takes a list of files comprising a multi-volume archive
10473 and creates the resulting archive at the standard output. For example:
10474
10475 @smallexample
10476 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10477 @end smallexample
10478
10479 The script implements a simple heuristics to determine the format of
10480 the first volume file and to decide how to process the rest of the
10481 files. However, it makes no attempt to verify whether the files are
10482 given in order or even if they are valid @command{tar} archives.
10483 It uses @command{dd} and does not filter its standard error, so you
10484 will usually see lots of spurious messages.
10485
10486 @FIXME{The script is not installed. Should we install it?}
10487
10488 @node label
10489 @section Including a Label in the Archive
10490 @cindex Labeling an archive
10491 @cindex Labels on the archive media
10492 @cindex Labeling multi-volume archives
10493 @UNREVISED
10494
10495 @opindex label
10496 To avoid problems caused by misplaced paper labels on the archive
10497 media, you can include a @dfn{label} entry---an archive member which
10498 contains the name of the archive---in the archive itself. Use the
10499 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10500 option in conjunction with the @option{--create} operation to include
10501 a label entry in the archive as it is being created.
10502
10503 @table @option
10504 @item --label=@var{archive-label}
10505 @itemx -V @var{archive-label}
10506 Includes an @dfn{archive-label} at the beginning of the archive when
10507 the archive is being created, when used in conjunction with the
10508 @option{--create} operation. Checks to make sure the archive label
10509 matches the one specified (when used in conjunction with any other
10510 operation.
10511 @end table
10512
10513 If you create an archive using both
10514 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10515 and @option{--multi-volume} (@option{-M}), each volume of the archive
10516 will have an archive label of the form @samp{@var{archive-label}
10517 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10518 next, and so on. @xref{Using Multiple Tapes}, for information on
10519 creating multiple volume archives.
10520
10521 @cindex Volume label, listing
10522 @cindex Listing volume label
10523 The volume label will be displayed by @option{--list} along with
10524 the file contents. If verbose display is requested, it will also be
10525 explicitly marked as in the example below:
10526
10527 @smallexample
10528 @group
10529 $ @kbd{tar --verbose --list --file=iamanarchive}
10530 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10531 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10532 @end group
10533 @end smallexample
10534
10535 @opindex test-label
10536 @anchor{--test-label option}
10537 However, @option{--list} option will cause listing entire
10538 contents of the archive, which may be undesirable (for example, if the
10539 archive is stored on a tape). You can request checking only the volume
10540 by specifying @option{--test-label} option. This option reads only the
10541 first block of an archive, so it can be used with slow storage
10542 devices. For example:
10543
10544 @smallexample
10545 @group
10546 $ @kbd{tar --test-label --file=iamanarchive}
10547 iamalabel
10548 @end group
10549 @end smallexample
10550
10551 If @option{--test-label} is used with a single command line
10552 argument, @command{tar} compares the volume label with the
10553 argument. It exits with code 0 if the two strings match, and with code
10554 2 otherwise. In this case no output is displayed. For example:
10555
10556 @smallexample
10557 @group
10558 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10559 @result{} 0
10560 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10561 @result{} 1
10562 @end group
10563 @end smallexample
10564
10565 If you request any operation, other than @option{--create}, along
10566 with using @option{--label} option, @command{tar} will first check if
10567 the archive label matches the one specified and will refuse to proceed
10568 if it does not. Use this as a safety precaution to avoid accidentally
10569 overwriting existing archives. For example, if you wish to add files
10570 to @file{archive}, presumably labeled with string @samp{My volume},
10571 you will get:
10572
10573 @smallexample
10574 @group
10575 $ @kbd{tar -rf archive --label 'My volume' .}
10576 tar: Archive not labeled to match `My volume'
10577 @end group
10578 @end smallexample
10579
10580 @noindent
10581 in case its label does not match. This will work even if
10582 @file{archive} is not labeled at all.
10583
10584 Similarly, @command{tar} will refuse to list or extract the
10585 archive if its label doesn't match the @var{archive-label}
10586 specified. In those cases, @var{archive-label} argument is interpreted
10587 as a globbing-style pattern which must match the actual magnetic
10588 volume label. @xref{exclude}, for a precise description of how match
10589 is attempted@footnote{Previous versions of @command{tar} used full
10590 regular expression matching, or before that, only exact string
10591 matching, instead of wildcard matchers. We decided for the sake of
10592 simplicity to use a uniform matching device through
10593 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10594 the volume label matcher will also suffix @var{archive-label} by
10595 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10596 up. Since the volume numbering is automatically added in labels at
10597 creation time, it sounded logical to equally help the user taking care
10598 of it when the archive is being read.
10599
10600 The @option{--label} was once called @option{--volume}, but is not
10601 available under that name anymore.
10602
10603 You can also use @option{--label} to get a common information on
10604 all tapes of a series. For having this information different in each
10605 series created through a single script used on a regular basis, just
10606 manage to get some date string as part of the label. For example:
10607
10608 @smallexample
10609 @group
10610 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10611 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10612 --volume="Daily backup for `date +%Y-%m-%d`"}
10613 @end group
10614 @end smallexample
10615
10616 Also note that each label has its own date and time, which corresponds
10617 to when @GNUTAR{} initially attempted to write it,
10618 often soon after the operator launches @command{tar} or types the
10619 carriage return telling that the next tape is ready. Comparing date
10620 labels does give an idea of tape throughput only if the delays for
10621 rewinding tapes and the operator switching them were negligible, which
10622 is usually not the case.
10623
10624 @node verify
10625 @section Verifying Data as It is Stored
10626 @cindex Verifying a write operation
10627 @cindex Double-checking a write operation
10628
10629 @table @option
10630 @item -W
10631 @itemx --verify
10632 @opindex verify, short description
10633 Attempt to verify the archive after writing.
10634 @end table
10635
10636 This option causes @command{tar} to verify the archive after writing it.
10637 Each volume is checked after it is written, and any discrepancies
10638 are recorded on the standard error output.
10639
10640 Verification requires that the archive be on a back-space-able medium.
10641 This means pipes, some cartridge tape drives, and some other devices
10642 cannot be verified.
10643
10644 You can insure the accuracy of an archive by comparing files in the
10645 system with archive members. @command{tar} can compare an archive to the
10646 file system as the archive is being written, to verify a write
10647 operation, or can compare a previously written archive, to insure that
10648 it is up to date.
10649
10650 @xopindex{verify, using with @option{--create}}
10651 @xopindex{create, using with @option{--verify}}
10652 To check for discrepancies in an archive immediately after it is
10653 written, use the @option{--verify} (@option{-W}) option in conjunction with
10654 the @option{--create} operation. When this option is
10655 specified, @command{tar} checks archive members against their counterparts
10656 in the file system, and reports discrepancies on the standard error.
10657
10658 To verify an archive, you must be able to read it from before the end
10659 of the last written entry. This option is useful for detecting data
10660 errors on some tapes. Archives written to pipes, some cartridge tape
10661 drives, and some other devices cannot be verified.
10662
10663 One can explicitly compare an already made archive with the file
10664 system by using the @option{--compare} (@option{--diff}, @option{-d})
10665 option, instead of using the more automatic @option{--verify} option.
10666 @xref{compare}.
10667
10668 Note that these two options have a slightly different intent. The
10669 @option{--compare} option checks how identical are the logical contents of some
10670 archive with what is on your disks, while the @option{--verify} option is
10671 really for checking if the physical contents agree and if the recording
10672 media itself is of dependable quality. So, for the @option{--verify}
10673 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10674 the archive, while it lets the speed optimization undisturbed for the
10675 @option{--compare} option. If you nevertheless use @option{--compare} for
10676 media verification, you may have to defeat the in-memory cache yourself,
10677 maybe by opening and reclosing the door latch of your recording unit,
10678 forcing some doubt in your operating system about the fact this is really
10679 the same volume as the one just written or read.
10680
10681 The @option{--verify} option would not be necessary if drivers were indeed
10682 able to detect dependably all write failures. This sometimes require many
10683 magnetic heads, some able to read after the writes occurred. One would
10684 not say that drivers unable to detect all cases are necessarily flawed,
10685 as long as programming is concerned.
10686
10687 The @option{--verify} (@option{-W}) option will not work in
10688 conjunction with the @option{--multi-volume} (@option{-M}) option or
10689 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
10690 and @option{--delete} operations. @xref{Operations}, for more
10691 information on these operations.
10692
10693 Also, since @command{tar} normally strips leading @samp{/} from file
10694 names (@pxref{absolute}), a command like @samp{tar --verify -cf
10695 /tmp/foo.tar /etc} will work as desired only if the working directory is
10696 @file{/}, as @command{tar} uses the archive's relative member names
10697 (e.g., @file{etc/motd}) when verifying the archive.
10698
10699 @node Write Protection
10700 @section Write Protection
10701
10702 Almost all tapes and diskettes, and in a few rare cases, even disks can
10703 be @dfn{write protected}, to protect data on them from being changed.
10704 Once an archive is written, you should write protect the media to prevent
10705 the archive from being accidentally overwritten or deleted. (This will
10706 protect the archive from being changed with a tape or floppy drive---it
10707 will not protect it from magnet fields or other physical hazards).
10708
10709 The write protection device itself is usually an integral part of the
10710 physical media, and can be a two position (write enabled/write
10711 disabled) switch, a notch which can be popped out or covered, a ring
10712 which can be removed from the center of a tape reel, or some other
10713 changeable feature.
10714
10715 @node Changes
10716 @appendix Changes
10717
10718 This appendix lists some important user-visible changes between
10719 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10720 version of this document is available at
10721 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10722 @GNUTAR{} documentation page}.
10723
10724 @table @asis
10725 @item Use of globbing patterns when listing and extracting.
10726
10727 Previous versions of GNU tar assumed shell-style globbing when
10728 extracting from or listing an archive. For example:
10729
10730 @smallexample
10731 $ @kbd{tar xf foo.tar '*.c'}
10732 @end smallexample
10733
10734 would extract all files whose names end in @samp{.c}. This behavior
10735 was not documented and was incompatible with traditional tar
10736 implementations. Therefore, starting from version 1.15.91, GNU tar
10737 no longer uses globbing by default. For example, the above invocation
10738 is now interpreted as a request to extract from the archive the file
10739 named @file{*.c}.
10740
10741 To facilitate transition to the new behavior for those users who got
10742 used to the previous incorrect one, @command{tar} will print a warning
10743 if it finds out that a requested member was not found in the archive
10744 and its name looks like a globbing pattern. For example:
10745
10746 @smallexample
10747 $ @kbd{tar xf foo.tar '*.c'}
10748 tar: Pattern matching characters used in file names. Please,
10749 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10750 tar: suppress this warning.
10751 tar: *.c: Not found in archive
10752 tar: Error exit delayed from previous errors
10753 @end smallexample
10754
10755 To treat member names as globbing patterns, use --wildcards option.
10756 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10757 add this option to your @env{TAR_OPTIONS} variable.
10758
10759 @xref{wildcards}, for the detailed discussion of the use of globbing
10760 patterns by @GNUTAR{}.
10761
10762 @item Use of short option @option{-o}.
10763
10764 Earlier versions of @GNUTAR{} understood @option{-o} command line
10765 option as a synonym for @option{--old-archive}.
10766
10767 @GNUTAR{} starting from version 1.13.90 understands this option as
10768 a synonym for @option{--no-same-owner}. This is compatible with
10769 UNIX98 @command{tar} implementations.
10770
10771 However, to facilitate transition, @option{-o} option retains its
10772 old semantics when it is used with one of archive-creation commands.
10773 Users are encouraged to use @option{--format=oldgnu} instead.
10774
10775 It is especially important, since versions of @acronym{GNU} Automake
10776 up to and including 1.8.4 invoke tar with this option to produce
10777 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10778 of this issue and its implications.
10779
10780 @FIXME{Change the first argument to tar-formats when the new Automake is
10781 out. The proposition to add @anchor{} to the appropriate place of its
10782 docs was accepted by Automake people --Sergey 2006-05-25}.
10783 @xref{Options, tar-v7, Changing Automake's Behavior,
10784 automake, GNU Automake}, for a description on how to use various
10785 archive formats with @command{automake}.
10786
10787 Future versions of @GNUTAR{} will understand @option{-o} only as a
10788 synonym for @option{--no-same-owner}.
10789
10790 @item Use of short option @option{-l}
10791
10792 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10793 synonym for @option{--one-file-system}. Since such usage contradicted
10794 to UNIX98 specification and harmed compatibility with other
10795 implementation, it was declared deprecated in version 1.14. However,
10796 to facilitate transition to its new semantics, it was supported by
10797 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10798 variant of @option{--check-links} was introduced in version 1.15.91.
10799
10800 @item Use of options @option{--portability} and @option{--old-archive}
10801
10802 These options are deprecated. Please use @option{--format=v7} instead.
10803
10804 @item Use of option @option{--posix}
10805
10806 This option is deprecated. Please use @option{--format=posix} instead.
10807 @end table
10808
10809 @node Configuring Help Summary
10810 @appendix Configuring Help Summary
10811
10812 Running @kbd{tar --help} displays the short @command{tar} option
10813 summary (@pxref{help}). This summary is organized by @dfn{groups} of
10814 semantically close options. The options within each group are printed
10815 in the following order: a short option, eventually followed by a list
10816 of corresponding long option names, followed by a short description of
10817 the option. For example, here is an excerpt from the actual @kbd{tar
10818 --help} output:
10819
10820 @verbatim
10821 Main operation mode:
10822
10823 -A, --catenate, --concatenate append tar files to an archive
10824 -c, --create create a new archive
10825 -d, --diff, --compare find differences between archive and
10826 file system
10827 --delete delete from the archive
10828 @end verbatim
10829
10830 @vrindex ARGP_HELP_FMT, environment variable
10831 The exact visual representation of the help output is configurable via
10832 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10833 is a comma-separated list of @dfn{format variable} assignments. There
10834 are two kinds of format variables. An @dfn{offset variable} keeps the
10835 offset of some part of help output text from the leftmost column on
10836 the screen. A @dfn{boolean} variable is a flag that toggles some
10837 output feature on or off. Depending on the type of the corresponding
10838 variable, there are two kinds of assignments:
10839
10840 @table @asis
10841 @item Offset assignment
10842
10843 The assignment to an offset variable has the following syntax:
10844
10845 @smallexample
10846 @var{variable}=@var{value}
10847 @end smallexample
10848
10849 @noindent
10850 where @var{variable} is the variable name, and @var{value} is a
10851 numeric value to be assigned to the variable.
10852
10853 @item Boolean assignment
10854
10855 To assign @code{true} value to a variable, simply put this variable name. To
10856 assign @code{false} value, prefix the variable name with @samp{no-}. For
10857 example:
10858
10859 @smallexample
10860 @group
10861 # Assign @code{true} value:
10862 dup-args
10863 # Assign @code{false} value:
10864 no-dup-args
10865 @end group
10866 @end smallexample
10867 @end table
10868
10869 Following variables are declared:
10870
10871 @deftypevr {Help Output} boolean dup-args
10872 If true, arguments for an option are shown with both short and long
10873 options, even when a given option has both forms, for example:
10874
10875 @smallexample
10876 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10877 @end smallexample
10878
10879 If false, then if an option has both short and long forms, the
10880 argument is only shown with the long one, for example:
10881
10882 @smallexample
10883 -f, --file=ARCHIVE use archive file or device ARCHIVE
10884 @end smallexample
10885
10886 @noindent
10887 and a message indicating that the argument is applicable to both
10888 forms is printed below the options. This message can be disabled
10889 using @code{dup-args-note} (see below).
10890
10891 The default is false.
10892 @end deftypevr
10893
10894 @deftypevr {Help Output} boolean dup-args-note
10895 If this variable is true, which is the default, the following notice
10896 is displayed at the end of the help output:
10897
10898 @quotation
10899 Mandatory or optional arguments to long options are also mandatory or
10900 optional for any corresponding short options.
10901 @end quotation
10902
10903 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10904 variables @code{dup-args} or @code{dup-args-note} should be set.
10905 @end deftypevr
10906
10907 @deftypevr {Help Output} offset short-opt-col
10908 Column in which short options start. Default is 2.
10909
10910 @smallexample
10911 @group
10912 $ @kbd{tar --help|grep ARCHIVE}
10913 -f, --file=ARCHIVE use archive file or device ARCHIVE
10914 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10915 -f, --file=ARCHIVE use archive file or device ARCHIVE
10916 @end group
10917 @end smallexample
10918 @end deftypevr
10919
10920 @deftypevr {Help Output} offset long-opt-col
10921 Column in which long options start. Default is 6. For example:
10922
10923 @smallexample
10924 @group
10925 $ @kbd{tar --help|grep ARCHIVE}
10926 -f, --file=ARCHIVE use archive file or device ARCHIVE
10927 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10928 -f, --file=ARCHIVE use archive file or device ARCHIVE
10929 @end group
10930 @end smallexample
10931 @end deftypevr
10932
10933 @deftypevr {Help Output} offset doc-opt-col
10934 Column in which @dfn{doc options} start. A doc option isn't actually
10935 an option, but rather an arbitrary piece of documentation that is
10936 displayed in much the same manner as the options. For example, in
10937 the description of @option{--format} option:
10938
10939 @smallexample
10940 @group
10941 -H, --format=FORMAT create archive of the given format.
10942
10943 FORMAT is one of the following:
10944
10945 gnu GNU tar 1.13.x format
10946 oldgnu GNU format as per tar <= 1.12
10947 pax POSIX 1003.1-2001 (pax) format
10948 posix same as pax
10949 ustar POSIX 1003.1-1988 (ustar) format
10950 v7 old V7 tar format
10951 @end group
10952 @end smallexample
10953
10954 @noindent
10955 the format names are doc options. Thus, if you set
10956 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10957 will look as follows:
10958
10959 @smallexample
10960 @group
10961 -H, --format=FORMAT create archive of the given format.
10962
10963 FORMAT is one of the following:
10964
10965 gnu GNU tar 1.13.x format
10966 oldgnu GNU format as per tar <= 1.12
10967 pax POSIX 1003.1-2001 (pax) format
10968 posix same as pax
10969 ustar POSIX 1003.1-1988 (ustar) format
10970 v7 old V7 tar format
10971 @end group
10972 @end smallexample
10973 @end deftypevr
10974
10975 @deftypevr {Help Output} offset opt-doc-col
10976 Column in which option description starts. Default is 29.
10977
10978 @smallexample
10979 @group
10980 $ @kbd{tar --help|grep ARCHIVE}
10981 -f, --file=ARCHIVE use archive file or device ARCHIVE
10982 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10983 -f, --file=ARCHIVE use archive file or device ARCHIVE
10984 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10985 -f, --file=ARCHIVE
10986 use archive file or device ARCHIVE
10987 @end group
10988 @end smallexample
10989
10990 @noindent
10991 Notice, that the description starts on a separate line if
10992 @code{opt-doc-col} value is too small.
10993 @end deftypevr
10994
10995 @deftypevr {Help Output} offset header-col
10996 Column in which @dfn{group headers} are printed. A group header is a
10997 descriptive text preceding an option group. For example, in the
10998 following text:
10999
11000 @verbatim
11001 Main operation mode:
11002
11003 -A, --catenate, --concatenate append tar files to
11004 an archive
11005 -c, --create create a new archive
11006 @end verbatim
11007 @noindent
11008 @samp{Main operation mode:} is the group header.
11009
11010 The default value is 1.
11011 @end deftypevr
11012
11013 @deftypevr {Help Output} offset usage-indent
11014 Indentation of wrapped usage lines. Affects @option{--usage}
11015 output. Default is 12.
11016 @end deftypevr
11017
11018 @deftypevr {Help Output} offset rmargin
11019 Right margin of the text output. Used for wrapping.
11020 @end deftypevr
11021
11022 @node Fixing Snapshot Files
11023 @appendix Fixing Snapshot Files
11024 @include tar-snapshot-edit.texi
11025
11026 @node Tar Internals
11027 @appendix Tar Internals
11028 @include intern.texi
11029
11030 @node Genfile
11031 @appendix Genfile
11032 @include genfile.texi
11033
11034 @node Free Software Needs Free Documentation
11035 @appendix Free Software Needs Free Documentation
11036 @include freemanuals.texi
11037
11038 @node Copying This Manual
11039 @appendix Copying This Manual
11040
11041 @menu
11042 * GNU Free Documentation License:: License for copying this manual
11043 @end menu
11044
11045 @include fdl.texi
11046
11047 @node Index of Command Line Options
11048 @appendix Index of Command Line Options
11049
11050 This appendix contains an index of all @GNUTAR{} long command line
11051 options. The options are listed without the preceding double-dash.
11052 For a cross-reference of short command line options, @ref{Short Option Summary}.
11053
11054 @printindex op
11055
11056 @node Index
11057 @appendix Index
11058
11059 @printindex cp
11060
11061 @summarycontents
11062 @contents
11063 @bye
11064
11065 @c Local variables:
11066 @c texinfo-column-for-description: 32
11067 @c End:
This page took 0.544216 seconds and 4 git commands to generate.