]> git.cworth.org Git - tar/blob - doc/tar.texi
Imported Upstream version 1.24
[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 @defcodeindex kw
25
26 @c Put everything in one index (arbitrarily chosen to be the concept index).
27 @syncodeindex fn cp
28 @syncodeindex ky cp
29 @syncodeindex pg cp
30 @syncodeindex vr cp
31 @syncodeindex kw cp
32
33 @copying
34
35 This manual is for @acronym{GNU} @command{tar} (version
36 @value{VERSION}, @value{UPDATED}), which creates and extracts files
37 from archives.
38
39 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
40 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
41
42 @quotation
43 Permission is granted to copy, distribute and/or modify this document
44 under the terms of the GNU Free Documentation License, Version 1.3 or
45 any later version published by the Free Software Foundation; with no
46 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
47 and with the Back-Cover Texts as in (a) below.  A copy of the license
48 is included in the section entitled ``GNU Free Documentation
49 License''.
50
51 (a) The FSF's Back-Cover Text is: ``You have the freedom to
52 copy and modify this GNU manual.  Buying copies from the FSF
53 supports it in developing GNU and promoting software freedom.''
54 @end quotation
55 @end copying
56
57 @dircategory Archiving
58 @direntry
59 * Tar: (tar).                   Making tape (or disk) archives.
60 @end direntry
61
62 @dircategory Individual utilities
63 @direntry
64 * tar: (tar)tar invocation.                     Invoking @GNUTAR{}.
65 @end direntry
66
67 @shorttitlepage @acronym{GNU} @command{tar}
68
69 @titlepage
70 @title @acronym{GNU} tar: an archiver tool
71 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
72 @author John Gilmore, Jay Fenlason et al.
73
74 @page
75 @vskip 0pt plus 1filll
76 @insertcopying
77 @end titlepage
78
79 @ifnottex
80 @node Top
81 @top @acronym{GNU} tar: an archiver tool
82
83 @insertcopying
84
85 @cindex file archival
86 @cindex archiving files
87
88 The first part of this master menu lists the major nodes in this Info
89 document.  The rest of the menu lists all the lower level nodes.
90 @end ifnottex
91
92 @c The master menu goes here.
93 @c
94 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
95 @c loaded and run texinfo-master-menu.
96 @c To update it from the command line, run
97 @c
98 @c    make master-menu
99
100 @menu
101 * Introduction::
102 * Tutorial::
103 * tar invocation::
104 * operations::
105 * Backups::
106 * Choosing::
107 * Date input formats::
108 * Formats::
109 * Media::
110 * Reliability and security::
111
112 Appendices
113
114 * Changes::
115 * Configuring Help Summary::
116 * Fixing Snapshot Files::
117 * Tar Internals::
118 * Genfile::
119 * Free Software Needs Free Documentation::
120 * GNU Free Documentation License::
121 * Index of Command Line Options::
122 * Index::
123
124 @detailmenu
125  --- The Detailed Node Listing ---
126
127 Introduction
128
129 * Book Contents::               What this Book Contains
130 * Definitions::                 Some Definitions
131 * What tar Does::               What @command{tar} Does
132 * Naming tar Archives::         How @command{tar} Archives are Named
133 * Authors::                     @GNUTAR{} Authors
134 * Reports::                     Reporting bugs or suggestions
135
136 Tutorial Introduction to @command{tar}
137
138 * assumptions::
139 * stylistic conventions::
140 * basic tar options::           Basic @command{tar} Operations and Options
141 * frequent operations::
142 * Two Frequent Options::
143 * create::                      How to Create Archives
144 * list::                        How to List Archives
145 * extract::                     How to Extract Members from an Archive
146 * going further::
147
148 Two Frequently Used Options
149
150 * file tutorial::
151 * verbose tutorial::
152 * help tutorial::
153
154 How to Create Archives
155
156 * prepare for examples::
157 * Creating the archive::
158 * create verbose::
159 * short create::
160 * create dir::
161
162 How to List Archives
163
164 * list dir::
165
166 How to Extract Members from an Archive
167
168 * extracting archives::
169 * extracting files::
170 * extract dir::
171 * extracting untrusted archives::
172 * failing commands::
173
174 Invoking @GNUTAR{}
175
176 * Synopsis::
177 * using tar options::
178 * Styles::
179 * All Options::
180 * help::
181 * defaults::
182 * verbose::
183 * checkpoints::
184 * warnings::
185 * interactive::
186
187 The Three Option Styles
188
189 * Long Options::                Long Option Style
190 * Short Options::               Short Option Style
191 * Old Options::                 Old Option Style
192 * Mixing::                      Mixing Option Styles
193
194 All @command{tar} Options
195
196 * Operation Summary::
197 * Option Summary::
198 * Short Option Summary::
199
200 @GNUTAR{} Operations
201
202 * Basic tar::
203 * Advanced tar::
204 * create options::
205 * extract options::
206 * backup::
207 * Applications::
208 * looking ahead::
209
210 Advanced @GNUTAR{} Operations
211
212 * Operations::
213 * append::
214 * update::
215 * concatenate::
216 * delete::
217 * compare::
218
219 How to Add Files to Existing Archives: @option{--append}
220
221 * appending files::             Appending Files to an Archive
222 * multiple::
223
224 Updating an Archive
225
226 * how to update::
227
228 Options Used by @option{--create}
229
230 * override::                  Overriding File Metadata.
231 * Ignore Failed Read::
232
233 Options Used by @option{--extract}
234
235 * Reading::                     Options to Help Read Archives
236 * Writing::                     Changing How @command{tar} Writes Files
237 * Scarce::                      Coping with Scarce Resources
238
239 Options to Help Read Archives
240
241 * read full records::
242 * Ignore Zeros::
243
244 Changing How @command{tar} Writes Files
245
246 * Dealing with Old Files::
247 * Overwrite Old Files::
248 * Keep Old Files::
249 * Keep Newer Files::
250 * Unlink First::
251 * Recursive Unlink::
252 * Data Modification Times::
253 * Setting Access Permissions::
254 * Directory Modification Times and Permissions::
255 * Writing to Standard Output::
256 * Writing to an External Program::
257 * remove files::
258
259 Coping with Scarce Resources
260
261 * Starting File::
262 * Same Order::
263
264 Performing Backups and Restoring Files
265
266 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
267 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
268 * Backup Levels::               Levels of Backups
269 * Backup Parameters::           Setting Parameters for Backups and Restoration
270 * Scripted Backups::            Using the Backup Scripts
271 * Scripted Restoration::        Using the Restore Script
272
273 Setting Parameters for Backups and Restoration
274
275 * General-Purpose Variables::
276 * Magnetic Tape Control::
277 * User Hooks::
278 * backup-specs example::        An Example Text of @file{Backup-specs}
279
280 Choosing Files and Names for @command{tar}
281
282 * file::                        Choosing the Archive's Name
283 * Selecting Archive Members::
284 * files::                       Reading Names from a File
285 * exclude::                     Excluding Some Files
286 * wildcards::                   Wildcards Patterns and Matching
287 * quoting styles::              Ways of Quoting Special Characters in Names
288 * transform::                   Modifying File and Member Names
289 * after::                       Operating Only on New Files
290 * recurse::                     Descending into Directories
291 * one::                         Crossing File System Boundaries
292
293 Reading Names from a File
294
295 * nul::
296
297 Excluding Some Files
298
299 * problems with exclude::
300
301 Wildcards Patterns and Matching
302
303 * controlling pattern-matching::
304
305 Crossing File System Boundaries
306
307 * directory::                   Changing Directory
308 * absolute::                    Absolute File Names
309
310 Date input formats
311
312 * General date syntax::            Common rules.
313 * Calendar date items::            19 Dec 1994.
314 * Time of day items::              9:20pm.
315 * Time zone items::                @sc{est}, @sc{pdt}, @sc{gmt}.
316 * Day of week items::              Monday and others.
317 * Relative items in date strings:: next tuesday, 2 years ago.
318 * Pure numbers in date strings::   19931219, 1440.
319 * Seconds since the Epoch::        @@1078100502.
320 * Specifying time zone rules::     TZ="America/New_York", TZ="UTC0".
321 * Authors of parse_datetime::      Bellovin, Eggert, Salz, Berets, et al.
322
323 Controlling the Archive Format
324
325 * Compression::                 Using Less Space through Compression
326 * Attributes::                  Handling File Attributes
327 * Portability::                 Making @command{tar} Archives More Portable
328 * cpio::                        Comparison of @command{tar} and @command{cpio}
329
330 Using Less Space through Compression
331
332 * gzip::                        Creating and Reading Compressed Archives
333 * sparse::                      Archiving Sparse Files
334
335 Creating and Reading Compressed Archives
336
337 * lbzip2::  Using lbzip2 with @GNUTAR{}.
338
339 Making @command{tar} Archives More Portable
340
341 * Portable Names::              Portable Names
342 * dereference::                 Symbolic Links
343 * hard links::                  Hard Links
344 * old::                         Old V7 Archives
345 * ustar::                       Ustar Archives
346 * gnu::                         GNU and old GNU format archives.
347 * posix::                       @acronym{POSIX} archives
348 * Checksumming::                Checksumming Problems
349 * Large or Negative Values::    Large files, negative time stamps, etc.
350 * Other Tars::                  How to Extract GNU-Specific Data Using
351                                 Other @command{tar} Implementations
352
353 @GNUTAR{} and @acronym{POSIX} @command{tar}
354
355 * PAX keywords:: Controlling Extended Header Keywords.
356
357 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
358
359 * Split Recovery::       Members Split Between Volumes
360 * Sparse Recovery::      Sparse Members
361
362 Tapes and Other Archive Media
363
364 * Device::                      Device selection and switching
365 * Remote Tape Server::
366 * Common Problems and Solutions::
367 * Blocking::                    Blocking
368 * Many::                        Many archives on one tape
369 * Using Multiple Tapes::        Using Multiple Tapes
370 * label::                       Including a Label in the Archive
371 * verify::
372 * Write Protection::
373
374 Blocking
375
376 * Format Variations::           Format Variations
377 * Blocking Factor::             The Blocking Factor of an Archive
378
379 Many Archives on One Tape
380
381 * Tape Positioning::            Tape Positions and Tape Marks
382 * mt::                          The @command{mt} Utility
383
384 Using Multiple Tapes
385
386 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
387 * Tape Files::                  Tape Files
388 * Tarcat::                      Concatenate Volumes into a Single Archive
389
390
391 Tar Internals
392
393 * Standard::           Basic Tar Format
394 * Extensions::         @acronym{GNU} Extensions to the Archive Format
395 * Sparse Formats::     Storing Sparse Files
396 * Snapshot Files::
397 * Dumpdir::
398
399 Storing Sparse Files
400
401 * Old GNU Format::
402 * PAX 0::                PAX Format, Versions 0.0 and 0.1
403 * PAX 1::                PAX Format, Version 1.0
404
405 Genfile
406
407 * Generate Mode::     File Generation Mode.
408 * Status Mode::       File Status Mode.
409 * Exec Mode::         Synchronous Execution mode.
410
411 Copying This Manual
412
413 * GNU Free Documentation License::  License for copying this manual
414
415 @end detailmenu
416 @end menu
417
418 @node Introduction
419 @chapter Introduction
420
421 @GNUTAR{} creates
422 and manipulates @dfn{archives} which are actually collections of
423 many other files; the program provides users with an organized and
424 systematic method for controlling a large amount of data.
425 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
426 archives need not (and these days, typically do not) reside on tapes.
427
428 @menu
429 * Book Contents::               What this Book Contains
430 * Definitions::                 Some Definitions
431 * What tar Does::               What @command{tar} Does
432 * Naming tar Archives::         How @command{tar} Archives are Named
433 * Authors::                     @GNUTAR{} Authors
434 * Reports::                     Reporting bugs or suggestions
435 @end menu
436
437 @node Book Contents
438 @section What this Book Contains
439
440 The first part of this chapter introduces you to various terms that will
441 recur throughout the book.  It also tells you who has worked on @GNUTAR{}
442 and its documentation, and where you should send bug reports
443 or comments.
444
445 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
446 gentle introduction for people who are new to using @command{tar}.  It is
447 meant to be self-contained, not requiring any reading from subsequent
448 chapters to make sense.  It moves from topic to topic in a logical,
449 progressive order, building on information already explained.
450
451 Although the tutorial is paced and structured to allow beginners to
452 learn how to use @command{tar}, it is not intended solely for beginners.
453 The tutorial explains how to use the three most frequently used
454 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
455 two frequently used options (@samp{file} and @samp{verbose}).  The other
456 chapters do not refer to the tutorial frequently; however, if a section
457 discusses something which is a complex variant of a basic concept, there
458 may be a cross-reference to that basic concept.  (The entire book,
459 including the tutorial, assumes that the reader understands some basic
460 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
461
462 The third chapter presents the remaining five operations, and
463 information about using @command{tar} options and option syntax.
464
465 The other chapters are meant to be used as a reference.  Each chapter
466 presents everything that needs to be said about a specific topic.
467
468 One of the chapters (@pxref{Date input formats}) exists in its
469 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
470 In addition, one section of this manual (@pxref{Standard}) contains a
471 big quote which is taken directly from @command{tar} sources.
472
473 In general, we give both long and short (abbreviated) option names
474 at least once in each section where the relevant option is covered, so
475 that novice readers will become familiar with both styles.  (A few
476 options have no short versions, and the relevant sections will
477 indicate this.)
478
479 @node Definitions
480 @section Some Definitions
481
482 @cindex archive
483 @cindex tar archive
484 The @command{tar} program is used to create and manipulate @command{tar}
485 archives.  An @dfn{archive} is a single file which contains the contents
486 of many files, while still identifying the names of the files, their
487 owner(s), and so forth.  (In addition, archives record access
488 permissions, user and group, size in bytes, and data modification time.
489 Some archives also record the file names in each archived directory, as
490 well as other file and directory information.)  You can use @command{tar}
491 to @dfn{create} a new archive in a specified directory.
492
493 @cindex member
494 @cindex archive member
495 @cindex file name
496 @cindex member name
497 The files inside an archive are called @dfn{members}.  Within this
498 manual, we use the term @dfn{file} to refer only to files accessible in
499 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
500 @dfn{member} to refer only to the members of an archive.  Similarly, a
501 @dfn{file name} is the name of a file, as it resides in the file system,
502 and a @dfn{member name} is the name of an archive member within the
503 archive.
504
505 @cindex extraction
506 @cindex unpacking
507 The term @dfn{extraction} refers to the process of copying an archive
508 member (or multiple members) into a file in the file system.  Extracting
509 all the members of an archive is often called @dfn{extracting the
510 archive}.  The term @dfn{unpack} can also be used to refer to the
511 extraction of many or all the members of an archive.  Extracting an
512 archive does not destroy the archive's structure, just as creating an
513 archive does not destroy the copies of the files that exist outside of
514 the archive.  You may also @dfn{list} the members in a given archive
515 (this is often thought of as ``printing'' them to the standard output,
516 or the command line), or @dfn{append} members to a pre-existing archive.
517 All of these operations can be performed using @command{tar}.
518
519 @node What tar Does
520 @section What @command{tar} Does
521
522 @cindex tar
523 The @command{tar} program provides the ability to create @command{tar}
524 archives, as well as various other kinds of manipulation.  For example,
525 you can use @command{tar} on previously created archives to extract files,
526 to store additional files, or to update or list files which were already
527 stored.
528
529 Initially, @command{tar} archives were used to store files conveniently on
530 magnetic tape.  The name @command{tar} comes from this use; it stands for
531 @code{t}ape @code{ar}chiver.  Despite the utility's name, @command{tar} can
532 direct its output to available devices, files, or other programs (using
533 pipes).  @command{tar} may even access remote devices or files (as archives).
534
535 You can use @command{tar} archives in many ways.  We want to stress a few
536 of them: storage, backup, and transportation.
537
538 @FIXME{the following table entries need a bit of work.}
539 @table @asis
540 @item Storage
541 Often, @command{tar} archives are used to store related files for
542 convenient file transfer over a network.  For example, the
543 @acronym{GNU} Project distributes its software bundled into
544 @command{tar} archives, so that all the files relating to a particular
545 program (or set of related programs) can be transferred as a single
546 unit.
547
548 A magnetic tape can store several files in sequence.  However, the tape
549 has no names for these files; it only knows their relative position on
550 the tape.  One way to store several files on one tape and retain their
551 names is by creating a @command{tar} archive.  Even when the basic transfer
552 mechanism can keep track of names, as FTP can, the nuisance of handling
553 multiple files, directories, and multiple links makes @command{tar}
554 archives useful.
555
556 Archive files are also used for long-term storage.  You can think of
557 this as transportation from the present into the future.  (It is a
558 science-fiction idiom that you can move through time as well as in
559 space; the idea here is that @command{tar} can be used to move archives in
560 all dimensions, even time!)
561
562 @item Backup
563 Because the archive created by @command{tar} is capable of preserving
564 file information and directory structure, @command{tar} is commonly
565 used for performing full and incremental backups of disks.  A backup
566 puts a collection of files (possibly pertaining to many users and
567 projects) together on a disk or a tape.  This guards against
568 accidental destruction of the information in those files.
569 @GNUTAR{} has special features that allow it to be
570 used to make incremental and full dumps of all the files in a
571 file system.
572
573 @item Transportation
574 You can create an archive on one system, transfer it to another system,
575 and extract the contents there.  This allows you to transport a group of
576 files from one system to another.
577 @end table
578
579 @node Naming tar Archives
580 @section How @command{tar} Archives are Named
581
582 Conventionally, @command{tar} archives are given names ending with
583 @samp{.tar}.  This is not necessary for @command{tar} to operate properly,
584 but this manual follows that convention in order to accustom readers to
585 it and to make examples more clear.
586
587 @cindex tar file
588 @cindex entry
589 @cindex tar entry
590 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
591 archive members as ``files'' or ``entries''.  For people familiar with
592 the operation of @command{tar}, this causes no difficulty.  However, in
593 this manual, we consistently refer to ``archives'' and ``archive
594 members'' to make learning to use @command{tar} easier for novice users.
595
596 @node Authors
597 @section @GNUTAR{} Authors
598
599 @GNUTAR{} was originally written by John Gilmore,
600 and modified by many people.  The @acronym{GNU} enhancements were
601 written by Jay Fenlason, then Joy Kendall, and the whole package has
602 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
603 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
604 numerous and kind users.
605
606 We wish to stress that @command{tar} is a collective work, and owes much to
607 all those people who reported problems, offered solutions and other
608 insights, or shared their thoughts and suggestions.  An impressive, yet
609 partial list of those contributors can be found in the @file{THANKS}
610 file from the @GNUTAR{} distribution.
611
612 @FIXME{i want all of these names mentioned, Absolutely.  BUT, i'm not
613 sure i want to spell out the history in this detail, at least not for
614 the printed book.  i'm just not sure it needs to be said this way.
615 i'll think about it.}
616
617 @FIXME{History is more important, and surely more interesting, than
618 actual names.  Quoting names without history would be meaningless.  FP}
619
620 Jay Fenlason put together a draft of a @GNUTAR{}
621 manual, borrowing notes from the original man page from John Gilmore.
622 This was withdrawn in version 1.11.  Thomas Bushnell, n/BSG and Amy
623 Gorin worked on a tutorial and manual for @GNUTAR{}.
624 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
625 taking information from all these sources and merging them.  Melissa
626 Weisshaus finally edited and redesigned the book to create version
627 1.12.  The book for versions from 1.14 up to @value{VERSION} were edited
628 by the current maintainer, Sergey Poznyakoff.
629
630 For version 1.12, Daniel Hagerty contributed a great deal of technical
631 consulting.  In particular, he is the primary author of @ref{Backups}.
632
633 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
634 (see @url{http://savannah.gnu.org/projects/tar}), and
635 active development and maintenance work has started
636 again.  Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
637 Poznyakoff and Jeff Bailey.
638
639 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
640
641 @node Reports
642 @section Reporting bugs or suggestions
643
644 @cindex bug reports
645 @cindex reporting bugs
646 If you find problems or have suggestions about this program or manual,
647 please report them to @file{bug-tar@@gnu.org}.
648
649 When reporting a bug, please be sure to include as much detail as
650 possible, in order to reproduce it.  @FIXME{Be more specific, I'd
651 like to make this node as detailed as 'Bug reporting' node in Emacs
652 manual.}
653
654 @node Tutorial
655 @chapter Tutorial Introduction to @command{tar}
656
657 This chapter guides you through some basic examples of three @command{tar}
658 operations: @option{--create}, @option{--list}, and @option{--extract}.  If
659 you already know how to use some other version of @command{tar}, then you
660 may not need to read this chapter.  This chapter omits most complicated
661 details about how @command{tar} works.
662
663 @menu
664 * assumptions::
665 * stylistic conventions::
666 * basic tar options::           Basic @command{tar} Operations and Options
667 * frequent operations::
668 * Two Frequent Options::
669 * create::                      How to Create Archives
670 * list::                        How to List Archives
671 * extract::                     How to Extract Members from an Archive
672 * going further::
673 @end menu
674
675 @node assumptions
676 @section Assumptions this Tutorial Makes
677
678 This chapter is paced to allow beginners to learn about @command{tar}
679 slowly.  At the same time, we will try to cover all the basic aspects of
680 these three operations.  In order to accomplish both of these tasks, we
681 have made certain assumptions about your knowledge before reading this
682 manual, and the hardware you will be using:
683
684 @itemize @bullet
685 @item
686 Before you start to work through this tutorial, you should understand
687 what the terms ``archive'' and ``archive member'' mean
688 (@pxref{Definitions}).  In addition, you should understand something
689 about how Unix-type operating systems work, and you should know how to
690 use some basic utilities.  For example, you should know how to create,
691 list, copy, rename, edit, and delete files and directories; how to
692 change between directories; and how to figure out where you are in the
693 file system.  You should have some basic understanding of directory
694 structure and how files are named according to which directory they are
695 in.  You should understand concepts such as standard output and standard
696 input, what various definitions of the term @samp{argument} mean, and the
697 differences between relative and absolute file names.  @FIXME{and what
698 else?}
699
700 @item
701 This manual assumes that you are working from your own home directory
702 (unless we state otherwise).  In this tutorial, you will create a
703 directory to practice @command{tar} commands in.  When we show file names,
704 we will assume that those names are relative to your home directory.
705 For example, my home directory is @file{/home/fsf/melissa}.  All of
706 my examples are in a subdirectory of the directory named by that file
707 name; the subdirectory is called @file{practice}.
708
709 @item
710 In general, we show examples of archives which exist on (or can be
711 written to, or worked with from) a directory on a hard disk.  In most
712 cases, you could write those archives to, or work with them on any other
713 device, such as a tape drive.  However, some of the later examples in
714 the tutorial and next chapter will not work on tape drives.
715 Additionally, working with tapes is much more complicated than working
716 with hard disks.  For these reasons, the tutorial does not cover working
717 with tape drives.  @xref{Media}, for complete information on using
718 @command{tar} archives with tape drives.
719
720 @FIXME{this is a cop out.  need to add some simple tape drive info.}
721 @end itemize
722
723 @node stylistic conventions
724 @section Stylistic Conventions
725
726 In the examples, @samp{$} represents a typical shell prompt.  It
727 precedes lines you should type; to make this more clear, those lines are
728 shown in @kbd{this font}, as opposed to lines which represent the
729 computer's response; those lines are shown in @code{this font}, or
730 sometimes @samp{like this}.
731
732 @c When we have lines which are too long to be
733 @c displayed in any other way, we will show them like this:
734
735 @node basic tar options
736 @section Basic @command{tar} Operations and Options
737
738 @command{tar} can take a wide variety of arguments which specify and define
739 the actions it will have on the particular set of files or the archive.
740 The main types of arguments to @command{tar} fall into one of two classes:
741 operations, and options.
742
743 Some arguments fall into a class called @dfn{operations}; exactly one of
744 these is both allowed and required for any instance of using @command{tar};
745 you may @emph{not} specify more than one.  People sometimes speak of
746 @dfn{operating modes}.  You are in a particular operating mode when you
747 have specified the operation which specifies it; there are eight
748 operations in total, and thus there are eight operating modes.
749
750 The other arguments fall into the class known as @dfn{options}.  You are
751 not required to specify any options, and you are allowed to specify more
752 than one at a time (depending on the way you are using @command{tar} at
753 that time).  Some options are used so frequently, and are so useful for
754 helping you type commands more carefully that they are effectively
755 ``required''.  We will discuss them in this chapter.
756
757 You can write most of the @command{tar} operations and options in any
758 of three forms: long (mnemonic) form, short form, and old style.  Some
759 of the operations and options have no short or ``old'' forms; however,
760 the operations and options which we will cover in this tutorial have
761 corresponding abbreviations.  We will indicate those abbreviations
762 appropriately to get you used to seeing them.  Note, that the ``old
763 style'' option forms exist in @GNUTAR{} for compatibility with Unix
764 @command{tar}.  In this book we present a full discussion of this way
765 of writing options and operations (@pxref{Old Options}), and we discuss
766 the other two styles of writing options (@xref{Long Options}, and
767 @pxref{Short Options}).
768
769 In the examples and in the text of this tutorial, we usually use the
770 long forms of operations and options; but the ``short'' forms produce
771 the same result and can make typing long @command{tar} commands easier.
772 For example, instead of typing
773
774 @smallexample
775 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
776 @end smallexample
777
778 @noindent
779 you can type
780 @smallexample
781 @kbd{tar -c -v -f afiles.tar apple angst aspic}
782 @end smallexample
783
784 @noindent
785 or even
786 @smallexample
787 @kbd{tar -cvf afiles.tar apple angst aspic}
788 @end smallexample
789
790 @noindent
791 For more information on option syntax, see @ref{Advanced tar}.  In
792 discussions in the text, when we name an option by its long form, we
793 also give the corresponding short option in parentheses.
794
795 The term, ``option'', can be confusing at times, since ``operations''
796 are often lumped in with the actual, @emph{optional} ``options'' in certain
797 general class statements.  For example, we just talked about ``short and
798 long forms of options and operations''.  However, experienced @command{tar}
799 users often refer to these by shorthand terms such as, ``short and long
800 options''.  This term assumes that the ``operations'' are included, also.
801 Context will help you determine which definition of ``options'' to use.
802
803 Similarly, the term ``command'' can be confusing, as it is often used in
804 two different ways.  People sometimes refer to @command{tar} ``commands''.
805 A @command{tar} @dfn{command} is the entire command line of user input
806 which tells @command{tar} what to do --- including the operation, options,
807 and any arguments (file names, pipes, other commands, etc.).  However,
808 you will also sometimes hear the term ``the @command{tar} command''.  When
809 the word ``command'' is used specifically like this, a person is usually
810 referring to the @command{tar} @emph{operation}, not the whole line.
811 Again, use context to figure out which of the meanings the speaker
812 intends.
813
814 @node frequent operations
815 @section The Three Most Frequently Used Operations
816
817 Here are the three most frequently used operations (both short and long
818 forms), as well as a brief description of their meanings.  The rest of
819 this chapter will cover how to use these operations in detail.  We will
820 present the rest of the operations in the next chapter.
821
822 @table @option
823 @item --create
824 @itemx -c
825 Create a new @command{tar} archive.
826 @item --list
827 @itemx -t
828 List the contents of an archive.
829 @item --extract
830 @itemx -x
831 Extract one or more members from an archive.
832 @end table
833
834 @node Two Frequent Options
835 @section Two Frequently Used Options
836
837 To understand how to run @command{tar} in the three operating modes listed
838 previously, you also need to understand how to use two of the options to
839 @command{tar}: @option{--file} (which takes an archive file as an argument)
840 and @option{--verbose}.  (You are usually not @emph{required} to specify
841 either of these options when you run @command{tar}, but they can be very
842 useful in making things more clear and helping you avoid errors.)
843
844 @menu
845 * file tutorial::
846 * verbose tutorial::
847 * help tutorial::
848 @end menu
849
850 @node file tutorial
851 @unnumberedsubsec The @option{--file} Option
852
853 @table @option
854 @xopindex{file, tutorial}
855 @item --file=@var{archive-name}
856 @itemx -f @var{archive-name}
857 Specify the name of an archive file.
858 @end table
859
860 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
861 use @command{tar}; this option determines the name of the archive file
862 that @command{tar} will work on.
863
864 @vrindex TAPE
865 If you don't specify this argument, then @command{tar} will examine
866 the environment variable @env{TAPE}.  If it is set, its value will be
867 used as the archive name.  Otherwise, @command{tar} will use the
868 default archive, determined at compile time. Usually it is
869 standard output or some physical tape drive attached to your machine
870 (you can verify what the default is by running @kbd{tar
871 --show-defaults}, @pxref{defaults}).  If there is no tape drive
872 attached, or the default is not meaningful, then @command{tar} will
873 print an error message.  The error message might look roughly like one
874 of the following:
875
876 @smallexample
877 tar: can't open /dev/rmt8 : No such device or address
878 tar: can't open /dev/rsmt0 : I/O error
879 @end smallexample
880
881 @noindent
882 To avoid confusion, we recommend that you always specify an archive file
883 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
884 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
885 @ref{file}.
886
887 @node verbose tutorial
888 @unnumberedsubsec The @option{--verbose} Option
889
890 @table @option
891 @xopindex{verbose, introduced}
892 @item --verbose
893 @itemx -v
894 Show the files being worked on as @command{tar} is running.
895 @end table
896
897 @option{--verbose} (@option{-v}) shows details about the results of running
898 @command{tar}.  This can be especially useful when the results might not be
899 obvious.  For example, if you want to see the progress of @command{tar} as
900 it writes files into the archive, you can use the @option{--verbose}
901 option.  In the beginning, you may find it useful to use
902 @option{--verbose} at all times; when you are more accustomed to
903 @command{tar}, you will likely want to use it at certain times but not at
904 others.  We will use @option{--verbose} at times to help make something
905 clear, and we will give many examples both using and not using
906 @option{--verbose} to show the differences.
907
908 Each instance of @option{--verbose} on the command line increases the
909 verbosity level by one, so if you need more details on the output,
910 specify it twice.
911
912 When reading archives (@option{--list}, @option{--extract},
913 @option{--diff}), @command{tar} by default prints only the names of
914 the members being extracted.  Using @option{--verbose} will show a full,
915 @command{ls} style member listing.
916
917 In contrast, when writing archives (@option{--create}, @option{--append},
918 @option{--update}), @command{tar} does not print file names by
919 default.  So, a single @option{--verbose} option shows the file names
920 being added to the archive, while two @option{--verbose} options
921 enable the full listing.
922
923 For example, to create an archive in verbose mode:
924
925 @smallexample
926 $ @kbd{tar -cvf afiles.tar apple angst aspic}
927 apple
928 angst
929 aspic
930 @end smallexample
931
932 @noindent
933 Creating the same archive with the verbosity level 2 could give:
934
935 @smallexample
936 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
937 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
938 -rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
939 -rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic
940 @end smallexample
941
942 @noindent
943 This works equally well using short or long forms of options.  Using
944 long forms, you would simply write out the mnemonic form of the option
945 twice, like this:
946
947 @smallexample
948 $ @kbd{tar --create --verbose --verbose @dots{}}
949 @end smallexample
950
951 @noindent
952 Note that you must double the hyphens properly each time.
953
954 Later in the tutorial, we will give examples using @w{@option{--verbose
955 --verbose}}.
956
957 @anchor{verbose member listing}
958 The full output consists of six fields:
959
960 @itemize @bullet
961 @item File type and permissions in symbolic form.
962 These are displayed in the same format as the first column of
963 @command{ls -l} output (@pxref{What information is listed,
964 format=verbose, Verbose listing, fileutils, GNU file utilities}).
965
966 @item Owner name and group separated by a slash character.
967 If these data are not available (for example, when listing a @samp{v7} format
968 archive), numeric @acronym{ID} values are printed instead.
969
970 @item Size of the file, in bytes.
971
972 @item File modification date in ISO 8601 format.
973
974 @item File modification time.
975
976 @item File name.
977 If the name contains any special characters (white space, newlines,
978 etc.) these are displayed in an unambiguous form using so called
979 @dfn{quoting style}.  For the detailed discussion of available styles
980 and on how to use them, see @ref{quoting styles}.
981
982 Depending on the file type, the name can be followed by some
983 additional information, described in the following table:
984
985 @table @samp
986 @item -> @var{link-name}
987 The file or archive member is a @dfn{symbolic link} and
988 @var{link-name} is the name of file it links to.
989
990 @item link to @var{link-name}
991 The file or archive member is a @dfn{hard link} and @var{link-name} is
992 the name of file it links to.
993
994 @item --Long Link--
995 The archive member is an old GNU format long link.  You will normally
996 not encounter this.
997
998 @item --Long Name--
999 The archive member is an old GNU format long name.  You will normally
1000 not encounter this.
1001
1002 @item --Volume Header--
1003 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1004
1005 @item --Continued at byte @var{n}--
1006 Encountered only at the beginning of a multi-volume archive
1007 (@pxref{Using Multiple Tapes}).  This archive member is a continuation
1008 from the previous volume. The number @var{n} gives the offset where
1009 the original file was split.
1010
1011 @item  unknown file type @var{c}
1012 An archive member of unknown type. @var{c} is the type character from
1013 the archive header.  If you encounter such a message, it means that
1014 either your archive contains proprietary member types @GNUTAR{} is not
1015 able to handle, or the archive is corrupted.
1016 @end table
1017
1018 @end itemize
1019
1020 For example, here is an archive listing containing most of the special
1021 suffixes explained above:
1022
1023 @smallexample
1024 @group
1025 V--------- 0/0          1536 2006-06-09 13:07 MyVolume--Volume Header--
1026 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1027 byte 32456--
1028 -rw-r--r-- gray/staff  62373 2006-06-09 12:06 apple
1029 lrwxrwxrwx gray/staff      0 2006-06-09 13:01 angst -> apple
1030 -rw-r--r-- gray/staff  35793 2006-06-09 12:06 blues
1031 hrw-r--r-- gray/staff      0 2006-06-09 12:06 music link to blues
1032 @end group
1033 @end smallexample
1034
1035 @smallexample
1036 @end smallexample
1037
1038 @node help tutorial
1039 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1040
1041 @table @option
1042 @opindex help
1043 @item --help
1044
1045 The @option{--help} option to @command{tar} prints out a very brief list of
1046 all operations and option available for the current version of
1047 @command{tar} available on your system.
1048 @end table
1049
1050 @node create
1051 @section How to Create Archives
1052 @UNREVISED
1053
1054 @cindex Creation of the archive
1055 @cindex Archive, creation of
1056 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1057 you use to create a @command{tar} archive.  We will explain
1058 @option{--create} first because, in order to learn about the other
1059 operations, you will find it useful to have an archive available to
1060 practice on.
1061
1062 To make this easier, in this section you will first create a directory
1063 containing three files.  Then, we will show you how to create an
1064 @emph{archive} (inside the new directory).  Both the directory, and
1065 the archive are specifically for you to practice on.  The rest of this
1066 chapter and the next chapter will show many examples using this
1067 directory and the files you will create: some of those files may be
1068 other directories and other archives.
1069
1070 The three files you will archive in this example are called
1071 @file{blues}, @file{folk}, and @file{jazz}.  The archive is called
1072 @file{collection.tar}.
1073
1074 This section will proceed slowly, detailing how to use @option{--create}
1075 in @code{verbose} mode, and showing examples using both short and long
1076 forms.  In the rest of the tutorial, and in the examples in the next
1077 chapter, we will proceed at a slightly quicker pace.  This section
1078 moves more slowly to allow beginning users to understand how
1079 @command{tar} works.
1080
1081 @menu
1082 * prepare for examples::
1083 * Creating the archive::
1084 * create verbose::
1085 * short create::
1086 * create dir::
1087 @end menu
1088
1089 @node prepare for examples
1090 @subsection Preparing a Practice Directory for Examples
1091
1092 To follow along with this and future examples, create a new directory
1093 called @file{practice} containing files called @file{blues}, @file{folk}
1094 and @file{jazz}.  The files can contain any information you like:
1095 ideally, they should contain information which relates to their names,
1096 and be of different lengths.  Our examples assume that @file{practice}
1097 is a subdirectory of your home directory.
1098
1099 Now @command{cd} to the directory named @file{practice}; @file{practice}
1100 is now your @dfn{working directory}.  (@emph{Please note}: Although
1101 the full file name of this directory is
1102 @file{/@var{homedir}/practice}, in our examples we will refer to
1103 this directory as @file{practice}; the @var{homedir} is presumed.)
1104
1105 In general, you should check that the files to be archived exist where
1106 you think they do (in the working directory) by running @command{ls}.
1107 Because you just created the directory and the files and have changed to
1108 that directory, you probably don't need to do that this time.
1109
1110 It is very important to make sure there isn't already a file in the
1111 working directory with the archive name you intend to use (in this case,
1112 @samp{collection.tar}), or that you don't care about its contents.
1113 Whenever you use @samp{create}, @command{tar} will erase the current
1114 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists.  @command{tar}
1115 will not tell you if you are about to overwrite an archive unless you
1116 specify an option which does this (@pxref{backup}, for the
1117 information on how to do so).  To add files to an existing archive,
1118 you need to use a different option, such as @option{--append} (@option{-r}); see
1119 @ref{append} for information on how to do this.
1120
1121 @node Creating the archive
1122 @subsection Creating the Archive
1123
1124 @xopindex{create, introduced}
1125 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1126 archive named @file{collection.tar}, use the following command:
1127
1128 @smallexample
1129 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1130 @end smallexample
1131
1132 The order of the arguments is not very important, @emph{when using long
1133 option forms}.  You could also say:
1134
1135 @smallexample
1136 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1137 @end smallexample
1138
1139 @noindent
1140 However, you can see that this order is harder to understand; this is
1141 why we will list the arguments in the order that makes the commands
1142 easiest to understand (and we encourage you to do the same when you use
1143 @command{tar}, to avoid errors).
1144
1145 Note that the sequence
1146 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1147 If you substituted any other string of characters for
1148 @kbd{collection.tar},  then that string would become the name of the
1149 archive file you create.
1150
1151 The order of the options becomes more important when you begin to use
1152 short forms.  With short forms, if you type commands in the wrong order
1153 (even if you type them correctly in all other ways), you may end up with
1154 results you don't expect.  For this reason, it is a good idea to get
1155 into the habit of typing options in the order that makes inherent sense.
1156 @xref{short create}, for more information on this.
1157
1158 In this example, you type the command as shown above: @option{--create}
1159 is the operation which creates the new archive
1160 (@file{collection.tar}), and @option{--file} is the option which lets
1161 you give it the name you chose.  The files, @file{blues}, @file{folk},
1162 and @file{jazz}, are now members of the archive, @file{collection.tar}
1163 (they are @dfn{file name arguments} to the @option{--create} operation.
1164 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1165 in the archive, they are called @emph{archive members}, not files.
1166 (@pxref{Definitions,members}).
1167
1168 When you create an archive, you @emph{must} specify which files you
1169 want placed in the archive.  If you do not specify any archive
1170 members, @GNUTAR{} will complain.
1171
1172 If you now list the contents of the working directory (@command{ls}), you will
1173 find the archive file listed as well as the files you saw previously:
1174
1175 @smallexample
1176 blues   folk   jazz   collection.tar
1177 @end smallexample
1178
1179 @noindent
1180 Creating the archive @samp{collection.tar} did not destroy the copies of
1181 the files in the directory.
1182
1183 Keep in mind that if you don't indicate an operation, @command{tar} will not
1184 run and will prompt you for one.  If you don't name any files, @command{tar}
1185 will complain.  You must have write access to the working directory,
1186 or else you will not be able to create an archive in that directory.
1187
1188 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1189 an existing archive; it will delete the archive and write a new one.
1190 Use @option{--append} (@option{-r}) instead.  @xref{append}.
1191
1192 @node create verbose
1193 @subsection Running @option{--create} with @option{--verbose}
1194
1195 @xopindex{create, using with @option{--verbose}}
1196 @xopindex{verbose, using with @option{--create}}
1197 If you include the @option{--verbose} (@option{-v}) option on the command line,
1198 @command{tar} will list the files it is acting on as it is working.  In
1199 verbose mode, the @code{create} example above would appear as:
1200
1201 @smallexample
1202 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1203 blues
1204 folk
1205 jazz
1206 @end smallexample
1207
1208 This example is just like the example we showed which did not use
1209 @option{--verbose}, except that @command{tar} generated the remaining
1210 @iftex
1211 lines (note the different font styles).
1212 @end iftex
1213 @ifinfo
1214 lines.
1215 @end ifinfo
1216
1217 In the rest of the examples in this chapter, we will frequently use
1218 @code{verbose} mode so we can show actions or @command{tar} responses that
1219 you would otherwise not see, and which are important for you to
1220 understand.
1221
1222 @node short create
1223 @subsection Short Forms with @samp{create}
1224
1225 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1226 basic uses of @command{tar}, and you will use it countless times.
1227 Eventually, you will probably want to use abbreviated (or ``short'')
1228 forms of options.  A full discussion of the three different forms that
1229 options can take appears in @ref{Styles}; for now, here is what the
1230 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1231 using short option forms:
1232
1233 @smallexample
1234 $ @kbd{tar -cvf collection.tar blues folk jazz}
1235 blues
1236 folk
1237 jazz
1238 @end smallexample
1239
1240 @noindent
1241 As you can see, the system responds the same no matter whether you use
1242 long or short option forms.
1243
1244 @FIXME{i don't like how this is worded:} One difference between using
1245 short and long option forms is that, although the exact placement of
1246 arguments following options is no more specific when using short forms,
1247 it is easier to become confused and make a mistake when using short
1248 forms.  For example, suppose you attempted the above example in the
1249 following way:
1250
1251 @smallexample
1252 $ @kbd{tar -cfv collection.tar blues folk jazz}
1253 @end smallexample
1254
1255 @noindent
1256 In this case, @command{tar} will make an archive file called @file{v},
1257 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1258 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1259 is thus taken to be the chosen archive file name.  @command{tar} will try
1260 to add a file called @file{collection.tar} to the @file{v} archive file;
1261 if the file @file{collection.tar} did not already exist, @command{tar} will
1262 report an error indicating that this file does not exist.  If the file
1263 @file{collection.tar} does already exist (e.g., from a previous command
1264 you may have run), then @command{tar} will add this file to the archive.
1265 Because the @option{-v} option did not get registered, @command{tar} will not
1266 run under @samp{verbose} mode, and will not report its progress.
1267
1268 The end result is that you may be quite confused about what happened,
1269 and possibly overwrite a file.  To illustrate this further, we will show
1270 you how an example we showed previously would look using short forms.
1271
1272 This example,
1273
1274 @smallexample
1275 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1276 @end smallexample
1277
1278 @noindent
1279 is confusing as it is.  When shown using short forms, however, it
1280 becomes much more so:
1281
1282 @smallexample
1283 $ @kbd{tar blues -c folk -f collection.tar jazz}
1284 @end smallexample
1285
1286 @noindent
1287 It would be very easy to put the wrong string of characters
1288 immediately following the @option{-f}, but doing that could sacrifice
1289 valuable data.
1290
1291 For this reason, we recommend that you pay very careful attention to
1292 the order of options and placement of file and archive names,
1293 especially when using short option forms.  Not having the option name
1294 written out mnemonically can affect how well you remember which option
1295 does what, and therefore where different names have to be placed.
1296
1297 @node create dir
1298 @subsection Archiving Directories
1299
1300 @cindex Archiving Directories
1301 @cindex Directories, Archiving
1302 You can archive a directory by specifying its directory name as a
1303 file name argument to @command{tar}.  The files in the directory will be
1304 archived relative to the working directory, and the directory will be
1305 re-created along with its contents when the archive is extracted.
1306
1307 To archive a directory, first move to its superior directory.  If you
1308 have followed the previous instructions in this tutorial, you should
1309 type:
1310
1311 @smallexample
1312 $ @kbd{cd ..}
1313 $
1314 @end smallexample
1315
1316 @noindent
1317 This will put you into the directory which contains @file{practice},
1318 i.e., your home directory.  Once in the superior directory, you can
1319 specify the subdirectory, @file{practice}, as a file name argument.  To
1320 store @file{practice} in the new archive file @file{music.tar}, type:
1321
1322 @smallexample
1323 $ @kbd{tar --create --verbose --file=music.tar practice}
1324 @end smallexample
1325
1326 @noindent
1327 @command{tar} should output:
1328
1329 @smallexample
1330 practice/
1331 practice/blues
1332 practice/folk
1333 practice/jazz
1334 practice/collection.tar
1335 @end smallexample
1336
1337 Note that the archive thus created is not in the subdirectory
1338 @file{practice}, but rather in the current working directory---the
1339 directory from which @command{tar} was invoked.  Before trying to archive a
1340 directory from its superior directory, you should make sure you have
1341 write access to the superior directory itself, not only the directory
1342 you are trying archive with @command{tar}.  For example, you will probably
1343 not be able to store your home directory in an archive by invoking
1344 @command{tar} from the root directory; @xref{absolute}.  (Note
1345 also that @file{collection.tar}, the original archive file, has itself
1346 been archived.  @command{tar} will accept any file as a file to be
1347 archived, regardless of its content.  When @file{music.tar} is
1348 extracted, the archive file @file{collection.tar} will be re-written
1349 into the file system).
1350
1351 If you give @command{tar} a command such as
1352
1353 @smallexample
1354 $ @kbd{tar --create --file=foo.tar .}
1355 @end smallexample
1356
1357 @noindent
1358 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1359 dumped}.  This happens because @command{tar} creates the archive
1360 @file{foo.tar} in the current directory before putting any files into
1361 it.  Then, when @command{tar} attempts to add all the files in the
1362 directory @file{.} to the archive, it notices that the file
1363 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1364 it.  (It makes no sense to put an archive into itself.)  @GNUTAR{}
1365 will continue in this case, and create the archive
1366 normally, except for the exclusion of that one file.  (@emph{Please
1367 note:} Other implementations of @command{tar} may not be so clever;
1368 they will enter an infinite loop when this happens, so you should not
1369 depend on this behavior unless you are certain you are running
1370 @GNUTAR{}.  In general, it is wise to always place the archive outside
1371 of the directory being dumped.)
1372
1373 @node list
1374 @section How to List Archives
1375
1376 @opindex list
1377 Frequently, you will find yourself wanting to determine exactly what a
1378 particular archive contains.  You can use the @option{--list}
1379 (@option{-t}) operation to get the member names as they currently
1380 appear in the archive, as well as various attributes of the files at
1381 the time they were archived.  For example, you can examine the archive
1382 @file{collection.tar} that you created in the last section with the
1383 command,
1384
1385 @smallexample
1386 $ @kbd{tar --list --file=collection.tar}
1387 @end smallexample
1388
1389 @noindent
1390 The output of @command{tar} would then be:
1391
1392 @smallexample
1393 blues
1394 folk
1395 jazz
1396 @end smallexample
1397
1398 @noindent
1399 The archive @file{bfiles.tar} would list as follows:
1400
1401 @smallexample
1402 ./birds
1403 baboon
1404 ./box
1405 @end smallexample
1406
1407 @noindent
1408 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1409 @var{archive-name}}) option just as with @option{--create}
1410 (@option{-c}) to specify the name of the archive.
1411
1412 @xopindex{list, using with @option{--verbose}}
1413 @xopindex{verbose, using with @option{--list}}
1414 If you use the @option{--verbose} (@option{-v}) option with
1415 @option{--list}, then @command{tar} will print out a listing
1416 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1417 forth.  This output is described in detail in @ref{verbose member listing}.
1418
1419 If you had used @option{--verbose} (@option{-v}) mode, the example
1420 above would look like:
1421
1422 @smallexample
1423 $ @kbd{tar --list --verbose --file=collection.tar folk}
1424 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1425 @end smallexample
1426
1427 @cindex listing member and file names
1428 @anchor{listing member and file names}
1429 It is important to notice that the output of @kbd{tar --list
1430 --verbose} does not necessarily match that produced by @kbd{tar
1431 --create --verbose} while creating the archive.  It is because
1432 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1433 prefixes from file names before storing them in the archive
1434 (@xref{absolute}, for more information).  In other
1435 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1436 an archive and @dfn{member names} when listing it.  Consider this
1437 example:
1438
1439 @smallexample
1440 @group
1441 $ @kbd{tar --create --verbose --file archive /etc/mail}
1442 tar: Removing leading `/' from member names
1443 /etc/mail/
1444 /etc/mail/sendmail.cf
1445 /etc/mail/aliases
1446 $ @kbd{tar --test --file archive}
1447 etc/mail/
1448 etc/mail/sendmail.cf
1449 etc/mail/aliases
1450 @end group
1451 @end smallexample
1452
1453 @opindex show-stored-names
1454   This default behavior can sometimes be inconvenient.  You can force
1455 @GNUTAR{} show member names when creating archive by supplying
1456 @option{--show-stored-names} option.
1457
1458 @table @option
1459 @item --show-stored-names
1460 Print member (as opposed to @emph{file}) names when creating the archive.
1461 @end table
1462
1463 @cindex File name arguments, using @option{--list} with
1464 @xopindex{list, using with file name arguments}
1465 You can specify one or more individual member names as arguments when
1466 using @samp{list}.  In this case, @command{tar} will only list the
1467 names of members you identify.  For example, @w{@kbd{tar --list
1468 --file=afiles.tar apple}} would only print @file{apple}.
1469
1470 Because @command{tar} preserves file names, these must be specified as
1471 they appear in the archive (i.e., relative to the directory from which
1472 the archive was created).  Therefore, it is essential when specifying
1473 member names to @command{tar} that you give the exact member names.
1474 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1475 error message something like @samp{tar: birds: Not found in archive},
1476 because there is no member named @file{birds}, only one named
1477 @file{./birds}.  While the names @file{birds} and @file{./birds} name
1478 the same file, @emph{member} names by default are compared verbatim.
1479
1480 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1481 with @file{baboon}, because this exact member name is in the archive file
1482 @file{bfiles.tar}.  If you are not sure of the exact file name,
1483 use @dfn{globbing patterns}, for example:
1484
1485 @smallexample
1486 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1487 @end smallexample
1488
1489 @noindent
1490 will list all members whose name contains @samp{b}.  @xref{wildcards},
1491 for a detailed discussion of globbing patterns and related
1492 @command{tar} command line options.
1493
1494 @menu
1495 * list dir::
1496 @end menu
1497
1498 @node list dir
1499 @unnumberedsubsec Listing the Contents of a Stored Directory
1500
1501 To get information about the contents of an archived directory,
1502 use the directory name as a file name argument in conjunction with
1503 @option{--list} (@option{-t}).  To find out file attributes, include the
1504 @option{--verbose} (@option{-v}) option.
1505
1506 For example, to find out about files in the directory @file{practice}, in
1507 the archive file @file{music.tar}, type:
1508
1509 @smallexample
1510 $ @kbd{tar --list --verbose --file=music.tar practice}
1511 @end smallexample
1512
1513 @command{tar} responds:
1514
1515 @smallexample
1516 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1517 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1518 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1519 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1520 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1521 @end smallexample
1522
1523 When you use a directory name as a file name argument, @command{tar} acts on
1524 all the files (including sub-directories) in that directory.
1525
1526 @node extract
1527 @section How to Extract Members from an Archive
1528 @cindex Extraction
1529 @cindex Retrieving files from an archive
1530 @cindex Resurrecting files from an archive
1531
1532 @opindex extract
1533 Creating an archive is only half the job---there is no point in storing
1534 files in an archive if you can't retrieve them.  The act of retrieving
1535 members from an archive so they can be used and manipulated as
1536 unarchived files again is called @dfn{extraction}.  To extract files
1537 from an archive, use the @option{--extract} (@option{--get} or
1538 @option{-x}) operation.  As with @option{--create}, specify the name
1539 of the archive with @option{--file} (@option{-f}) option. Extracting
1540 an archive does not modify the archive in any way; you can extract it
1541 multiple times if you want or need to.
1542
1543 Using @option{--extract}, you can extract an entire archive, or specific
1544 files.  The files can be directories containing other files, or not.  As
1545 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1546 long form of the operation without affecting the performance.
1547
1548 @menu
1549 * extracting archives::
1550 * extracting files::
1551 * extract dir::
1552 * extracting untrusted archives::
1553 * failing commands::
1554 @end menu
1555
1556 @node extracting archives
1557 @subsection Extracting an Entire Archive
1558
1559 To extract an entire archive, specify the archive file name only, with
1560 no individual file names as arguments.  For example,
1561
1562 @smallexample
1563 $ @kbd{tar -xvf collection.tar}
1564 @end smallexample
1565
1566 @noindent
1567 produces this:
1568
1569 @smallexample
1570 -rw-r--r-- me user     28 1996-10-18 16:31 jazz
1571 -rw-r--r-- me user     21 1996-09-23 16:44 blues
1572 -rw-r--r-- me user     20 1996-09-23 16:44 folk
1573 @end smallexample
1574
1575 @node extracting files
1576 @subsection Extracting Specific Files
1577
1578 To extract specific archive members, give their exact member names as
1579 arguments, as printed by @option{--list} (@option{-t}).  If you had
1580 mistakenly deleted one of the files you had placed in the archive
1581 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1582 from the archive without changing the archive's structure.  Its
1583 contents will be identical to the original file @file{blues} that you
1584 deleted.
1585
1586 First, make sure you are in the @file{practice} directory, and list the
1587 files in the directory.  Now, delete the file, @samp{blues}, and list
1588 the files in the directory again.
1589
1590 You can now extract the member @file{blues} from the archive file
1591 @file{collection.tar} like this:
1592
1593 @smallexample
1594 $ @kbd{tar --extract --file=collection.tar blues}
1595 @end smallexample
1596
1597 @noindent
1598 If you list the files in the directory again, you will see that the file
1599 @file{blues} has been restored, with its original permissions, data
1600 modification times, and owner.@footnote{This is only accidentally
1601 true, but not in general.  Whereas modification times are always
1602 restored, in most cases, one has to be root for restoring the owner,
1603 and use a special option for restoring permissions.  Here, it just
1604 happens that the restoring user is also the owner of the archived
1605 members, and that the current @code{umask} is compatible with original
1606 permissions.}  (These parameters will be identical to those which
1607 the file had when you originally placed it in the archive; any changes
1608 you may have made before deleting the file from the file system,
1609 however, will @emph{not} have been made to the archive member.)  The
1610 archive file, @samp{collection.tar}, is the same as it was before you
1611 extracted @samp{blues}.  You can confirm this by running @command{tar} with
1612 @option{--list} (@option{-t}).
1613
1614 Remember that as with other operations, specifying the exact member
1615 name is important.  @w{@kbd{tar --extract --file=bfiles.tar birds}}
1616 will fail, because there is no member named @file{birds}.  To extract
1617 the member named @file{./birds}, you must specify @w{@kbd{tar
1618 --extract --file=bfiles.tar ./birds}}.  If you don't remember the
1619 exact member names, use @option{--list} (@option{-t}) option
1620 (@pxref{list}).  You can also extract those members that match a
1621 specific @dfn{globbing pattern}.  For example, to extract from
1622 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1623 directory prefix, you could type:
1624
1625 @smallexample
1626 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1627 @end smallexample
1628
1629 @noindent
1630 Here, @option{--wildcards} instructs @command{tar} to treat
1631 command line arguments as globbing patterns and @option{--no-anchored}
1632 informs it that the patterns apply to member names after any @samp{/}
1633 delimiter.  The use of globbing patterns is discussed in detail in
1634 @xref{wildcards}.
1635
1636 You can extract a file to standard output by combining the above options
1637 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1638 Output}).
1639
1640 If you give the @option{--verbose} option, then @option{--extract}
1641 will print the names of the archive members as it extracts them.
1642
1643 @node extract dir
1644 @subsection Extracting Files that are Directories
1645
1646 Extracting directories which are members of an archive is similar to
1647 extracting other files.  The main difference to be aware of is that if
1648 the extracted directory has the same name as any directory already in
1649 the working directory, then files in the extracted directory will be
1650 placed into the directory of the same name.  Likewise, if there are
1651 files in the pre-existing directory with the same names as the members
1652 which you extract, the files from the extracted archive will replace
1653 the files already in the working directory (and possible
1654 subdirectories).  This will happen regardless of whether or not the
1655 files in the working directory were more recent than those extracted
1656 (there exist, however, special options that alter this behavior
1657 @pxref{Writing}).
1658
1659 However, if a file was stored with a directory name as part of its file
1660 name, and that directory does not exist under the working directory when
1661 the file is extracted, @command{tar} will create the directory.
1662
1663 We can demonstrate how to use @option{--extract} to extract a directory
1664 file with an example.  Change to the @file{practice} directory if you
1665 weren't there, and remove the files @file{folk} and @file{jazz}.  Then,
1666 go back to the parent directory and extract the archive
1667 @file{music.tar}.  You may either extract the entire archive, or you may
1668 extract only the files you just deleted.  To extract the entire archive,
1669 don't give any file names as arguments after the archive name
1670 @file{music.tar}.  To extract only the files you deleted, use the
1671 following command:
1672
1673 @smallexample
1674 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1675 practice/folk
1676 practice/jazz
1677 @end smallexample
1678
1679 @noindent
1680 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1681 would have displayed more detail about the extracted files, as shown
1682 in the example below:
1683
1684 @smallexample
1685 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1686 -rw-r--r-- me user     28 1996-10-18 16:31 practice/jazz
1687 -rw-r--r-- me user     20 1996-09-23 16:44 practice/folk
1688 @end smallexample
1689
1690 @noindent
1691 Because you created the directory with @file{practice} as part of the
1692 file names of each of the files by archiving the @file{practice}
1693 directory as @file{practice}, you must give @file{practice} as part
1694 of the file names when you extract those files from the archive.
1695
1696 @node extracting untrusted archives
1697 @subsection Extracting Archives from Untrusted Sources
1698
1699 Extracting files from archives can overwrite files that already exist.
1700 If you receive an archive from an untrusted source, you should make a
1701 new directory and extract into that directory, so that you don't have
1702 to worry about the extraction overwriting one of your existing files.
1703 For example, if @file{untrusted.tar} came from somewhere else on the
1704 Internet, and you don't necessarily trust its contents, you can
1705 extract it as follows:
1706
1707 @smallexample
1708 $ @kbd{mkdir newdir}
1709 $ @kbd{cd newdir}
1710 $ @kbd{tar -xvf ../untrusted.tar}
1711 @end smallexample
1712
1713 It is also a good practice to examine contents of the archive
1714 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1715 with @option{--verbose} (@option{-v}).
1716
1717 @node failing commands
1718 @subsection Commands That Will Fail
1719
1720 Here are some sample commands you might try which will not work, and why
1721 they won't work.
1722
1723 If you try to use this command,
1724
1725 @smallexample
1726 $ @kbd{tar -xvf music.tar folk jazz}
1727 @end smallexample
1728
1729 @noindent
1730 you will get the following response:
1731
1732 @smallexample
1733 tar: folk: Not found in archive
1734 tar: jazz: Not found in archive
1735 @end smallexample
1736
1737 @noindent
1738 This is because these files were not originally @emph{in} the parent
1739 directory @file{..}, where the archive is located; they were in the
1740 @file{practice} directory, and their file names reflect this:
1741
1742 @smallexample
1743 $ @kbd{tar -tvf music.tar}
1744 practice/blues
1745 practice/folk
1746 practice/jazz
1747 @end smallexample
1748
1749 @FIXME{make sure the above works when going through the examples in
1750 order...}
1751
1752 @noindent
1753 Likewise, if you try to use this command,
1754
1755 @smallexample
1756 $ @kbd{tar -tvf music.tar folk jazz}
1757 @end smallexample
1758
1759 @noindent
1760 you would get a similar response.  Members with those names are not in the
1761 archive.  You must use the correct member names, or wildcards, in order
1762 to extract the files from the archive.
1763
1764 If you have forgotten the correct names of the files in the archive,
1765 use @w{@kbd{tar --list --verbose}} to list them correctly.
1766
1767 @FIXME{more examples, here?  hag thinks it's a good idea.}
1768
1769 @node going further
1770 @section Going Further Ahead in this Manual
1771 @UNREVISED
1772
1773 @FIXME{need to write up a node here about the things that are going to
1774 be in the rest of the manual.}
1775
1776 @node tar invocation
1777 @chapter Invoking @GNUTAR{}
1778
1779 This chapter is about how one invokes the @GNUTAR{}
1780 command, from the command synopsis (@pxref{Synopsis}).  There are
1781 numerous options, and many styles for writing them.  One mandatory
1782 option specifies the operation @command{tar} should perform
1783 (@pxref{Operation Summary}), other options are meant to detail how
1784 this operation should be performed (@pxref{Option Summary}).
1785 Non-option arguments are not always interpreted the same way,
1786 depending on what the operation is.
1787
1788 You will find in this chapter everything about option styles and rules for
1789 writing them (@pxref{Styles}).  On the other hand, operations and options
1790 are fully described elsewhere, in other chapters.  Here, you will find
1791 only synthetic descriptions for operations and options, together with
1792 pointers to other parts of the @command{tar} manual.
1793
1794 Some options are so special they are fully described right in this
1795 chapter.  They have the effect of inhibiting the normal operation of
1796 @command{tar} or else, they globally alter the amount of feedback the user
1797 receives about what is going on.  These are the @option{--help} and
1798 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1799 and @option{--interactive} options (@pxref{interactive}).
1800
1801 @menu
1802 * Synopsis::
1803 * using tar options::
1804 * Styles::
1805 * All Options::
1806 * help::
1807 * defaults::
1808 * verbose::
1809 * checkpoints::
1810 * warnings::
1811 * interactive::
1812 @end menu
1813
1814 @node Synopsis
1815 @section General Synopsis of @command{tar}
1816
1817 The @GNUTAR{} program is invoked as either one of:
1818
1819 @smallexample
1820 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1821 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1822 @end smallexample
1823
1824 The second form is for when old options are being used.
1825
1826 You can use @command{tar} to store files in an archive, to extract them from
1827 an archive, and to do other types of archive manipulation.  The primary
1828 argument to @command{tar}, which is called the @dfn{operation}, specifies
1829 which action to take.  The other arguments to @command{tar} are either
1830 @dfn{options}, which change the way @command{tar} performs an operation,
1831 or file names or archive members, which specify the files or members
1832 @command{tar} is to act on.
1833
1834 You can actually type in arguments in any order, even if in this manual
1835 the options always precede the other arguments, to make examples easier
1836 to understand.  Further, the option stating the main operation mode
1837 (the @command{tar} main command) is usually given first.
1838
1839 Each @var{name} in the synopsis above is interpreted as an archive member
1840 name when the main command is one of @option{--compare}
1841 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1842 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1843 @option{--update} (@option{-u}).  When naming archive members, you
1844 must give the exact name of the member in the archive, as it is
1845 printed by @option{--list}.  For @option{--append} (@option{-r}) and
1846 @option{--create} (@option{-c}), these @var{name} arguments specify
1847 the names of either files or directory hierarchies to place in the archive.
1848 These files or hierarchies should already exist in the file system,
1849 prior to the execution of the @command{tar} command.
1850
1851 @command{tar} interprets relative file names as being relative to the
1852 working directory.  @command{tar} will make all file names relative
1853 (by removing leading slashes when archiving or restoring files),
1854 unless you specify otherwise (using the @option{--absolute-names}
1855 option).  @xref{absolute}, for more information about
1856 @option{--absolute-names}.
1857
1858 If you give the name of a directory as either a file name or a member
1859 name, then @command{tar} acts recursively on all the files and directories
1860 beneath that directory.  For example, the name @file{/} identifies all
1861 the files in the file system to @command{tar}.
1862
1863 The distinction between file names and archive member names is especially
1864 important when shell globbing is used, and sometimes a source of confusion
1865 for newcomers.  @xref{wildcards}, for more information about globbing.
1866 The problem is that shells may only glob using existing files in the
1867 file system.  Only @command{tar} itself may glob on archive members, so when
1868 needed, you must ensure that wildcard characters reach @command{tar} without
1869 being interpreted by the shell first.  Using a backslash before @samp{*}
1870 or @samp{?}, or putting the whole argument between quotes, is usually
1871 sufficient for this.
1872
1873 Even if @var{name}s are often specified on the command line, they
1874 can also be read from a text file in the file system, using the
1875 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1876
1877 If you don't use any file name arguments, @option{--append} (@option{-r}),
1878 @option{--delete} and @option{--concatenate} (@option{--catenate},
1879 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1880 will usually yield a diagnostic and inhibit @command{tar} execution.
1881 The other operations of @command{tar} (@option{--list},
1882 @option{--extract}, @option{--compare}, and @option{--update})
1883 will act on the entire contents of the archive.
1884
1885 @cindex exit status
1886 @cindex return status
1887 Besides successful exits, @GNUTAR{} may fail for
1888 many reasons.  Some reasons correspond to bad usage, that is, when the
1889 @command{tar} command line is improperly written.  Errors may be
1890 encountered later, while processing the archive or the files.  Some
1891 errors are recoverable, in which case the failure is delayed until
1892 @command{tar} has completed all its work.  Some errors are such that
1893 it would be not meaningful, or at least risky, to continue processing:
1894 @command{tar} then aborts processing immediately.  All abnormal exits,
1895 whether immediate or delayed, should always be clearly diagnosed on
1896 @code{stderr}, after a line stating the nature of the error.
1897
1898 Possible exit codes of @GNUTAR{} are summarized in the following
1899 table:
1900
1901 @table @asis
1902 @item 0
1903 @samp{Successful termination}.
1904
1905 @item 1
1906 @samp{Some files differ}.  If tar was invoked with @option{--compare}
1907 (@option{--diff}, @option{-d}) command line option, this means that
1908 some files in the archive differ from their disk counterparts
1909 (@pxref{compare}).  If tar was given @option{--create},
1910 @option{--append} or @option{--update} option, this exit code means
1911 that some files were changed while being archived and so the resulting
1912 archive does not contain the exact copy of the file set.
1913
1914 @item 2
1915 @samp{Fatal error}.  This means that some fatal, unrecoverable error
1916 occurred.
1917 @end table
1918
1919 If @command{tar} has invoked a subprocess and that subprocess exited with a
1920 nonzero exit code, @command{tar} exits with that code as well.
1921 This can happen, for example, if @command{tar} was given some
1922 compression option (@pxref{gzip}) and the external compressor program
1923 failed.  Another example is @command{rmt} failure during backup to the
1924 remote device (@pxref{Remote Tape Server}).
1925
1926 @node using tar options
1927 @section Using @command{tar} Options
1928
1929 @GNUTAR{} has a total of eight operating modes which
1930 allow you to perform a variety of tasks.  You are required to choose
1931 one operating mode each time you employ the @command{tar} program by
1932 specifying one, and only one operation as an argument to the
1933 @command{tar} command (the corresponding options may be found
1934 at @ref{frequent operations} and @ref{Operations}).  Depending on
1935 circumstances, you may also wish to customize how the chosen operating
1936 mode behaves.  For example, you may wish to change the way the output
1937 looks, or the format of the files that you wish to archive may require
1938 you to do something special in order to make the archive look right.
1939
1940 You can customize and control @command{tar}'s performance by running
1941 @command{tar} with one or more options (such as @option{--verbose}
1942 (@option{-v}), which we used in the tutorial).  As we said in the
1943 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1944 their name suggests) optional. Depending on the operating mode, you
1945 may specify one or more options. Different options will have different
1946 effects, but in general they all change details of the operation, such
1947 as archive format, archive name, or level of user interaction.  Some
1948 options make sense with all operating modes, while others are
1949 meaningful only with particular modes. You will likely use some
1950 options frequently, while you will only use others infrequently, or
1951 not at all.  (A full list of options is available in @pxref{All Options}.)
1952
1953 @vrindex TAR_OPTIONS, environment variable
1954 @anchor{TAR_OPTIONS}
1955 The @env{TAR_OPTIONS} environment variable specifies default options to
1956 be placed in front of any explicit options.  For example, if
1957 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1958 if the two options @option{-v} and @option{--unlink-first} had been
1959 specified before any explicit options.  Option specifications are
1960 separated by whitespace.  A backslash escapes the next character, so it
1961 can be used to specify an option containing whitespace or a backslash.
1962
1963 Note that @command{tar} options are case sensitive.  For example, the
1964 options @option{-T} and @option{-t} are different; the first requires an
1965 argument for stating the name of a file providing a list of @var{name}s,
1966 while the second does not require an argument and is another way to
1967 write @option{--list} (@option{-t}).
1968
1969 In addition to the eight operations, there are many options to
1970 @command{tar}, and three different styles for writing both: long (mnemonic)
1971 form, short form, and old style.  These styles are discussed below.
1972 Both the options and the operations can be written in any of these three
1973 styles.
1974
1975 @FIXME{menu at end of this node.  need to think of an actual outline
1976 for this chapter; probably do that after stuff from chapter 4 is
1977 incorporated.}
1978
1979 @node Styles
1980 @section The Three Option Styles
1981
1982 There are three styles for writing operations and options to the command
1983 line invoking @command{tar}.  The different styles were developed at
1984 different times during the history of @command{tar}.  These styles will be
1985 presented below, from the most recent to the oldest.
1986
1987 Some options must take an argument@footnote{For example, @option{--file}
1988 (@option{-f}) takes the name of an archive file as an argument.  If
1989 you do not supply an archive file name, @command{tar} will use a
1990 default, but this can be confusing; thus, we recommend that you always
1991 supply a specific archive file name.}.  Where you @emph{place} the
1992 arguments generally depends on which style of options you choose.  We
1993 will detail specific information relevant to each option style in the
1994 sections on the different option styles, below.  The differences are
1995 subtle, yet can often be very important; incorrect option placement
1996 can cause you to overwrite a number of important files.  We urge you
1997 to note these differences, and only use the option style(s) which
1998 makes the most sense to you until you feel comfortable with the others.
1999
2000 Some options @emph{may} take an argument.  Such options may have at
2001 most long and short forms, they do not have old style equivalent.  The
2002 rules for specifying an argument for such options are stricter than
2003 those for specifying mandatory arguments.  Please, pay special
2004 attention to them.
2005
2006 @menu
2007 * Long Options::                Long Option Style
2008 * Short Options::               Short Option Style
2009 * Old Options::                 Old Option Style
2010 * Mixing::                      Mixing Option Styles
2011 @end menu
2012
2013 @node Long Options
2014 @subsection Long Option Style
2015
2016 @cindex long options
2017 @cindex options, long style
2018 @cindex options, GNU style
2019 @cindex options, mnemonic names
2020 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2021 dashes in a row, e.g., @option{--list}.  The long names are more clear than
2022 their corresponding short or old names.  It sometimes happens that a
2023 single long option has many different names which are
2024 synonymous, such as @option{--compare} and @option{--diff}.  In addition,
2025 long option names can be given unique abbreviations.  For example,
2026 @option{--cre} can be used in place of @option{--create} because there is no
2027 other long option which begins with @samp{cre}.  (One way to find
2028 this out is by trying it and seeing what happens; if a particular
2029 abbreviation could represent more than one option, @command{tar} will tell
2030 you that that abbreviation is ambiguous and you'll know that that
2031 abbreviation won't work.  You may also choose to run @samp{tar --help}
2032 to see a list of options.  Be aware that if you run @command{tar} with a
2033 unique abbreviation for the long name of an option you didn't want to
2034 use, you are stuck; @command{tar} will perform the command as ordered.)
2035
2036 Long options are meant to be obvious and easy to remember, and their
2037 meanings are generally easier to discern than those of their
2038 corresponding short options (see below).  For example:
2039
2040 @smallexample
2041 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2042 @end smallexample
2043
2044 @noindent
2045 gives a fairly good set of hints about what the command does, even
2046 for those not fully acquainted with @command{tar}.
2047
2048 @cindex arguments to long options
2049 @cindex long options with mandatory arguments
2050 Long options which require arguments take those arguments
2051 immediately following the option name.  There are two ways of
2052 specifying a mandatory argument.  It can be separated from the
2053 option name either by an equal sign, or by any amount of
2054 white space characters.  For example, the @option{--file} option (which
2055 tells the name of the @command{tar} archive) is given a file such as
2056 @file{archive.tar} as argument by using any of the following notations:
2057 @option{--file=archive.tar} or @option{--file archive.tar}.
2058
2059 @cindex optional arguments to long options
2060 @cindex long options with optional arguments
2061 In contrast, optional arguments must always be introduced using
2062 an equal sign.  For example, the @option{--backup} option takes
2063 an optional argument specifying backup type.  It must be used
2064 as @option{--backup=@var{backup-type}}.
2065
2066 @node Short Options
2067 @subsection Short Option Style
2068
2069 @cindex short options
2070 @cindex options, short style
2071 @cindex options, traditional
2072 Most options also have a @dfn{short option} name.  Short options start with
2073 a single dash, and are followed by a single character, e.g., @option{-t}
2074 (which is equivalent to @option{--list}).  The forms are absolutely
2075 identical in function; they are interchangeable.
2076
2077 The short option names are faster to type than long option names.
2078
2079 @cindex arguments to short options
2080 @cindex short options with mandatory arguments
2081 Short options which require arguments take their arguments immediately
2082 following the option, usually separated by white space.  It is also
2083 possible to stick the argument right after the short option name, using
2084 no intervening space.  For example, you might write @w{@option{-f
2085 archive.tar}} or @option{-farchive.tar} instead of using
2086 @option{--file=archive.tar}.  Both @option{--file=@var{archive-name}} and
2087 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2088 specific archive, here named @file{archive.tar}.
2089
2090 @cindex optional arguments to short options
2091 @cindex short options with optional arguments
2092 Short options which take optional arguments take their arguments
2093 immediately following the option letter, @emph{without any intervening
2094 white space characters}.
2095
2096 Short options' letters may be clumped together, but you are not
2097 required to do this (as compared to old options; see below).  When
2098 short options are clumped as a set, use one (single) dash for them
2099 all, e.g., @w{@samp{@command{tar} -cvf}}.  Only the last option in
2100 such a set is allowed to have an argument@footnote{Clustering many
2101 options, the last of which has an argument, is a rather opaque way to
2102 write options.  Some wonder if @acronym{GNU} @code{getopt} should not
2103 even be made helpful enough for considering such usages as invalid.}.
2104
2105 When the options are separated, the argument for each option which requires
2106 an argument directly follows that option, as is usual for Unix programs.
2107 For example:
2108
2109 @smallexample
2110 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2111 @end smallexample
2112
2113 If you reorder short options' locations, be sure to move any arguments
2114 that belong to them.  If you do not move the arguments properly, you may
2115 end up overwriting files.
2116
2117 @node Old Options
2118 @subsection Old Option Style
2119 @cindex options, old style
2120 @cindex old option style
2121
2122 Like short options, @dfn{old options} are single letters.  However, old options
2123 must be written together as a single clumped set, without spaces separating
2124 them or dashes preceding them@footnote{Beware that if you precede options
2125 with a dash, you are announcing the short option style instead of the
2126 old option style; short options are decoded differently.}.  This set
2127 of letters must be the first to appear on the command line, after the
2128 @command{tar} program name and some white space; old options cannot appear
2129 anywhere else.  The letter of an old option is exactly the same letter as
2130 the corresponding short option.  For example, the old option @samp{t} is
2131 the same as the short option @option{-t}, and consequently, the same as the
2132 long option @option{--list}.  So for example, the command @w{@samp{tar
2133 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2134
2135 @cindex arguments to old options
2136 @cindex old options with mandatory arguments
2137 When options that need arguments are given together with the command,
2138 all the associated arguments follow, in the same order as the options.
2139 Thus, the example given previously could also be written in the old
2140 style as follows:
2141
2142 @smallexample
2143 $ @kbd{tar cvbf 20 /dev/rmt0}
2144 @end smallexample
2145
2146 @noindent
2147 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2148 the argument of @option{-f}.
2149
2150 On the other hand, this old style syntax makes it difficult to match
2151 option letters with their corresponding arguments, and is often
2152 confusing.  In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2153 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2154 argument for @option{-f}, and @option{-v} does not have a corresponding
2155 argument.  Even using short options like in @w{@samp{tar -c -v -b 20 -f
2156 /dev/rmt0}} is clearer, putting all arguments next to the option they
2157 pertain to.
2158
2159 If you want to reorder the letters in the old option argument, be
2160 sure to reorder any corresponding argument appropriately.
2161
2162 This old way of writing @command{tar} options can surprise even experienced
2163 users.  For example, the two commands:
2164
2165 @smallexample
2166 @kbd{tar cfz archive.tar.gz file}
2167 @kbd{tar -cfz archive.tar.gz file}
2168 @end smallexample
2169
2170 @noindent
2171 are quite different.  The first example uses @file{archive.tar.gz} as
2172 the value for option @samp{f} and recognizes the option @samp{z}.  The
2173 second example, however, uses @file{z} as the value for option
2174 @samp{f} --- probably not what was intended.
2175
2176 Old options are kept for compatibility with old versions of @command{tar}.
2177
2178 This second example could be corrected in many ways, among which the
2179 following are equivalent:
2180
2181 @smallexample
2182 @kbd{tar -czf archive.tar.gz file}
2183 @kbd{tar -cf archive.tar.gz -z file}
2184 @kbd{tar cf archive.tar.gz -z file}
2185 @end smallexample
2186
2187 @cindex option syntax, traditional
2188 As far as we know, all @command{tar} programs, @acronym{GNU} and
2189 non-@acronym{GNU}, support old options.  @GNUTAR{}
2190 supports them not only for historical reasons, but also because many
2191 people are used to them.  For compatibility with Unix @command{tar},
2192 the first argument is always treated as containing command and option
2193 letters even if it doesn't start with @samp{-}.  Thus, @samp{tar c} is
2194 equivalent to @w{@samp{tar -c}:} both of them specify the
2195 @option{--create} (@option{-c}) command to create an archive.
2196
2197 @node Mixing
2198 @subsection Mixing Option Styles
2199
2200 @cindex options, mixing different styles
2201 All three styles may be intermixed in a single @command{tar} command,
2202 so long as the rules for each style are fully
2203 respected@footnote{Before @GNUTAR{} version 1.11.6,
2204 a bug prevented intermixing old style options with long options in
2205 some cases.}.  Old style options and either of the modern styles of
2206 options may be mixed within a single @command{tar} command.  However,
2207 old style options must be introduced as the first arguments only,
2208 following the rule for old options (old options must appear directly
2209 after the @command{tar} command and some white space).  Modern options
2210 may be given only after all arguments to the old options have been
2211 collected.  If this rule is not respected, a modern option might be
2212 falsely interpreted as the value of the argument to one of the old
2213 style options.
2214
2215 For example, all the following commands are wholly equivalent, and
2216 illustrate the many combinations and orderings of option styles.
2217
2218 @smallexample
2219 @kbd{tar --create --file=archive.tar}
2220 @kbd{tar --create -f archive.tar}
2221 @kbd{tar --create -farchive.tar}
2222 @kbd{tar --file=archive.tar --create}
2223 @kbd{tar --file=archive.tar -c}
2224 @kbd{tar -c --file=archive.tar}
2225 @kbd{tar -c -f archive.tar}
2226 @kbd{tar -c -farchive.tar}
2227 @kbd{tar -cf archive.tar}
2228 @kbd{tar -cfarchive.tar}
2229 @kbd{tar -f archive.tar --create}
2230 @kbd{tar -f archive.tar -c}
2231 @kbd{tar -farchive.tar --create}
2232 @kbd{tar -farchive.tar -c}
2233 @kbd{tar c --file=archive.tar}
2234 @kbd{tar c -f archive.tar}
2235 @kbd{tar c -farchive.tar}
2236 @kbd{tar cf archive.tar}
2237 @kbd{tar f archive.tar --create}
2238 @kbd{tar f archive.tar -c}
2239 @kbd{tar fc archive.tar}
2240 @end smallexample
2241
2242 On the other hand, the following commands are @emph{not} equivalent to
2243 the previous set:
2244
2245 @smallexample
2246 @kbd{tar -f -c archive.tar}
2247 @kbd{tar -fc archive.tar}
2248 @kbd{tar -fcarchive.tar}
2249 @kbd{tar -farchive.tarc}
2250 @kbd{tar cfarchive.tar}
2251 @end smallexample
2252
2253 @noindent
2254 These last examples mean something completely different from what the
2255 user intended (judging based on the example in the previous set which
2256 uses long options, whose intent is therefore very clear).  The first
2257 four specify that the @command{tar} archive would be a file named
2258 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2259 respectively.  The first two examples also specify a single non-option,
2260 @var{name} argument having the value @samp{archive.tar}.  The last
2261 example contains only old style option letters (repeating option
2262 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2263 @samp{h}, or @samp{i}), with no argument value.  @FIXME{not sure i liked
2264 the first sentence of this paragraph..}
2265
2266 @node All Options
2267 @section All @command{tar} Options
2268
2269 The coming manual sections contain an alphabetical listing of all
2270 @command{tar} operations and options, with brief descriptions and
2271 cross-references to more in-depth explanations in the body of the manual.
2272 They also contain an alphabetically arranged table of the short option
2273 forms with their corresponding long option.  You can use this table as
2274 a reference for deciphering @command{tar} commands in scripts.
2275
2276 @menu
2277 * Operation Summary::
2278 * Option Summary::
2279 * Short Option Summary::
2280 @end menu
2281
2282 @node Operation Summary
2283 @subsection Operations
2284
2285 @table @option
2286
2287 @opsummary{append}
2288 @item --append
2289 @itemx -r
2290
2291 Appends files to the end of the archive.  @xref{append}.
2292
2293 @opsummary{catenate}
2294 @item --catenate
2295 @itemx -A
2296
2297 Same as @option{--concatenate}.  @xref{concatenate}.
2298
2299 @opsummary{compare}
2300 @item --compare
2301 @itemx -d
2302
2303 Compares archive members with their counterparts in the file
2304 system, and reports differences in file size, mode, owner,
2305 modification date and contents.  @xref{compare}.
2306
2307 @opsummary{concatenate}
2308 @item --concatenate
2309 @itemx -A
2310
2311 Appends other @command{tar} archives to the end of the archive.
2312 @xref{concatenate}.
2313
2314 @opsummary{create}
2315 @item --create
2316 @itemx -c
2317
2318 Creates a new @command{tar} archive.  @xref{create}.
2319
2320 @opsummary{delete}
2321 @item --delete
2322
2323 Deletes members from the archive.  Don't try this on an archive on a
2324 tape!  @xref{delete}.
2325
2326 @opsummary{diff}
2327 @item --diff
2328 @itemx -d
2329
2330 Same @option{--compare}.  @xref{compare}.
2331
2332 @opsummary{extract}
2333 @item --extract
2334 @itemx -x
2335
2336 Extracts members from the archive into the file system.  @xref{extract}.
2337
2338 @opsummary{get}
2339 @item --get
2340 @itemx -x
2341
2342 Same as @option{--extract}.  @xref{extract}.
2343
2344 @opsummary{list}
2345 @item --list
2346 @itemx -t
2347
2348 Lists the members in an archive.  @xref{list}.
2349
2350 @opsummary{update}
2351 @item --update
2352 @itemx -u
2353
2354 Adds files to the end of the archive, but only if they are newer than
2355 their counterparts already in the archive, or if they do not already
2356 exist in the archive. @xref{update}.
2357
2358 @end table
2359
2360 @node Option Summary
2361 @subsection @command{tar} Options
2362
2363 @table @option
2364
2365 @opsummary{absolute-names}
2366 @item --absolute-names
2367 @itemx -P
2368
2369 Normally when creating an archive, @command{tar} strips an initial
2370 @samp{/} from member names.  This option disables that behavior.
2371 @xref{absolute}.
2372
2373 @opsummary{after-date}
2374 @item --after-date
2375
2376 (See @option{--newer}, @pxref{after})
2377
2378 @opsummary{anchored}
2379 @item --anchored
2380 A pattern must match an initial subsequence of the name's components.
2381 @xref{controlling pattern-matching}.
2382
2383 @opsummary{atime-preserve}
2384 @item --atime-preserve
2385 @itemx --atime-preserve=replace
2386 @itemx --atime-preserve=system
2387
2388 Attempt to preserve the access time of files when reading them.  This
2389 option currently is effective only on files that you own, unless you
2390 have superuser privileges.
2391
2392 @option{--atime-preserve=replace} remembers the access time of a file
2393 before reading it, and then restores the access time afterwards.  This
2394 may cause problems if other programs are reading the file at the same
2395 time, as the times of their accesses will be lost.  On most platforms
2396 restoring the access time also requires @command{tar} to restore the
2397 data modification time too, so this option may also cause problems if
2398 other programs are writing the file at the same time (@command{tar} attempts
2399 to detect this situation, but cannot do so reliably due to race
2400 conditions).  Worse, on most platforms restoring the access time also
2401 updates the status change time, which means that this option is
2402 incompatible with incremental backups.
2403
2404 @option{--atime-preserve=system} avoids changing time stamps on files,
2405 without interfering with time stamp updates
2406 caused by other programs, so it works better with incremental backups.
2407 However, it requires a special @code{O_NOATIME} option from the
2408 underlying operating and file system implementation, and it also requires
2409 that searching directories does not update their access times.  As of
2410 this writing (November 2005) this works only with Linux, and only with
2411 Linux kernels 2.6.8 and later.  Worse, there is currently no reliable
2412 way to know whether this feature actually works.  Sometimes
2413 @command{tar} knows that it does not work, and if you use
2414 @option{--atime-preserve=system} then @command{tar} complains and
2415 exits right away.  But other times @command{tar} might think that the
2416 option works when it actually does not.
2417
2418 Currently @option{--atime-preserve} with no operand defaults to
2419 @option{--atime-preserve=replace}, but this may change in the future
2420 as support for @option{--atime-preserve=system} improves.
2421
2422 If your operating or file system does not support
2423 @option{--atime-preserve=@-system}, you might be able to preserve access
2424 times reliably by using the @command{mount} command.  For example,
2425 you can mount the file system read-only, or access the file system via
2426 a read-only loopback mount, or use the @samp{noatime} mount option
2427 available on some systems.  However, mounting typically requires
2428 superuser privileges and can be a pain to manage.
2429
2430 @opsummary{auto-compress}
2431 @item --auto-compress
2432 @itemx -a
2433
2434 During a @option{--create} operation, enables automatic compressed
2435 format recognition based on the archive suffix.  The effect of this
2436 option is cancelled by @option{--no-auto-compress}.  @xref{gzip}.
2437
2438 @opsummary{backup}
2439 @item --backup=@var{backup-type}
2440
2441 Rather than deleting files from the file system, @command{tar} will
2442 back them up using simple or numbered backups, depending upon
2443 @var{backup-type}.  @xref{backup}.
2444
2445 @opsummary{block-number}
2446 @item --block-number
2447 @itemx -R
2448
2449 With this option present, @command{tar} prints error messages for read errors
2450 with the block number in the archive file.  @xref{block-number}.
2451
2452 @opsummary{blocking-factor}
2453 @item --blocking-factor=@var{blocking}
2454 @itemx -b @var{blocking}
2455
2456 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2457 record.  @xref{Blocking Factor}.
2458
2459 @opsummary{bzip2}
2460 @item --bzip2
2461 @itemx -j
2462
2463 This option tells @command{tar} to read or write archives through
2464 @code{bzip2}.  @xref{gzip}.
2465
2466 @opsummary{check-device}
2467 @item --check-device
2468 Check device numbers when creating a list of modified files for
2469 incremental archiving.  This is the default.  @xref{device numbers},
2470 for a detailed description.
2471
2472 @opsummary{checkpoint}
2473 @item --checkpoint[=@var{number}]
2474
2475 This option directs @command{tar} to print periodic checkpoint
2476 messages as it reads through the archive.  It is intended for when you
2477 want a visual indication that @command{tar} is still running, but
2478 don't want to see @option{--verbose} output.  You can also instruct
2479 @command{tar} to execute a list of actions on each checkpoint, see
2480 @option{--checkpoint-action} below.  For a detailed description, see
2481 @ref{checkpoints}.
2482
2483 @opsummary{checkpoint-action}
2484 @item --checkpoint-action=@var{action}
2485 Instruct @command{tar} to execute an action upon hitting a
2486 breakpoint.  Here we give only a brief outline.  @xref{checkpoints},
2487 for a complete description.
2488
2489 The @var{action} argument can be one of the following:
2490
2491 @table @asis
2492 @item bell
2493 Produce an audible bell on the console.
2494
2495 @item dot
2496 @itemx .
2497 Print a single dot on the standard listing stream.
2498
2499 @item echo
2500 Display a textual message on the standard error, with the status and
2501 number of the checkpoint.  This is the default.
2502
2503 @item echo=@var{string}
2504 Display @var{string} on the standard error.  Before output, the string
2505 is subject to meta-character expansion.
2506
2507 @item exec=@var{command}
2508 Execute the given @var{command}.
2509
2510 @item sleep=@var{time}
2511 Wait for @var{time} seconds.
2512
2513 @item ttyout=@var{string}
2514 Output @var{string} on the current console (@file{/dev/tty}).
2515 @end table
2516
2517 Several @option{--checkpoint-action} options can be specified.  The
2518 supplied actions will be executed in order of their appearance in the
2519 command line.
2520
2521 Using @option{--checkpoint-action} without @option{--checkpoint}
2522 assumes default checkpoint frequency of one checkpoint per 10 records.
2523
2524 @opsummary{check-links}
2525 @item --check-links
2526 @itemx -l
2527 If this option was given, @command{tar} will check the number of links
2528 dumped for each processed file.  If this number does not match the
2529 total number of hard links for the file, a warning message will be
2530 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2531 synonym for @option{--one-file-system}.  The current semantics, which
2532 complies to UNIX98, was introduced with version
2533 1.15.91. @xref{Changes}, for more information.}.
2534
2535 @xref{hard links}.
2536
2537 @opsummary{compress}
2538 @opsummary{uncompress}
2539 @item --compress
2540 @itemx --uncompress
2541 @itemx -Z
2542
2543 @command{tar} will use the @command{compress} program when reading or
2544 writing the archive.  This allows you to directly act on archives
2545 while saving space.  @xref{gzip}.
2546
2547 @opsummary{confirmation}
2548 @item --confirmation
2549
2550 (See @option{--interactive}.)  @xref{interactive}.
2551
2552 @opsummary{delay-directory-restore}
2553 @item --delay-directory-restore
2554
2555 Delay setting modification times and permissions of extracted
2556 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2557
2558 @opsummary{dereference}
2559 @item --dereference
2560 @itemx -h
2561
2562 When reading or writing a file to be archived, @command{tar} accesses
2563 the file that a symbolic link points to, rather than the symlink
2564 itself.  @xref{dereference}.
2565
2566 @opsummary{directory}
2567 @item --directory=@var{dir}
2568 @itemx -C @var{dir}
2569
2570 When this option is specified, @command{tar} will change its current directory
2571 to @var{dir} before performing any operations.  When this option is used
2572 during archive creation, it is order sensitive.  @xref{directory}.
2573
2574 @opsummary{exclude}
2575 @item --exclude=@var{pattern}
2576
2577 When performing operations, @command{tar} will skip files that match
2578 @var{pattern}.  @xref{exclude}.
2579
2580 @opsummary{exclude-backups}
2581 @item --exclude-backups
2582 Exclude backup and lock files.  @xref{exclude,, exclude-backups}.
2583
2584 @opsummary{exclude-from}
2585 @item --exclude-from=@var{file}
2586 @itemx -X @var{file}
2587
2588 Similar to @option{--exclude}, except @command{tar} will use the list of
2589 patterns in the file @var{file}.  @xref{exclude}.
2590
2591 @opsummary{exclude-caches}
2592 @item --exclude-caches
2593
2594 Exclude from dump any directory containing a valid cache directory
2595 tag file, but still dump the directory node and the tag file itself.
2596
2597 @xref{exclude,, exclude-caches}.
2598
2599 @opsummary{exclude-caches-under}
2600 @item --exclude-caches-under
2601
2602 Exclude from dump any directory containing a valid cache directory
2603 tag file, but still dump the directory node itself.
2604
2605 @xref{exclude}.
2606
2607 @opsummary{exclude-caches-all}
2608 @item --exclude-caches-all
2609
2610 Exclude from dump any directory containing a valid cache directory
2611 tag file.  @xref{exclude}.
2612
2613 @opsummary{exclude-tag}
2614 @item --exclude-tag=@var{file}
2615
2616 Exclude from dump any directory containing file named @var{file}, but
2617 dump the directory node and @var{file} itself.  @xref{exclude,, exclude-tag}.
2618
2619 @opsummary{exclude-tag-under}
2620 @item --exclude-tag-under=@var{file}
2621
2622 Exclude from dump the contents of any directory containing file
2623 named @var{file}, but dump the directory node itself.  @xref{exclude,,
2624 exclude-tag-under}.
2625
2626 @opsummary{exclude-tag-all}
2627 @item --exclude-tag-all=@var{file}
2628
2629 Exclude from dump any directory containing file named @var{file}.
2630 @xref{exclude,,exclude-tag-all}.
2631
2632 @opsummary{exclude-vcs}
2633 @item --exclude-vcs
2634
2635 Exclude from dump directories and files, that are internal for some
2636 widely used version control systems.
2637
2638 @xref{exclude,,exclude-vcs}.
2639
2640 @opsummary{file}
2641 @item --file=@var{archive}
2642 @itemx -f @var{archive}
2643
2644 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2645 performs operations on, rather than @command{tar}'s compilation dependent
2646 default.  @xref{file tutorial}.
2647
2648 @opsummary{files-from}
2649 @item --files-from=@var{file}
2650 @itemx -T @var{file}
2651
2652 @command{tar} will use the contents of @var{file} as a list of archive members
2653 or files to operate on, in addition to those specified on the
2654 command-line.  @xref{files}.
2655
2656 @opsummary{force-local}
2657 @item --force-local
2658
2659 Forces @command{tar} to interpret the file name given to @option{--file}
2660 as a local file, even if it looks like a remote tape drive name.
2661 @xref{local and remote archives}.
2662
2663 @opsummary{format}
2664 @item --format=@var{format}
2665 @itemx -H @var{format}
2666
2667 Selects output archive format.  @var{Format} may be one of the
2668 following:
2669
2670 @table @samp
2671 @item v7
2672 Creates an archive that is compatible with Unix V7 @command{tar}.
2673
2674 @item oldgnu
2675 Creates an archive that is compatible with GNU @command{tar} version
2676 1.12 or earlier.
2677
2678 @item gnu
2679 Creates archive in GNU tar 1.13 format.  Basically it is the same as
2680 @samp{oldgnu} with the only difference in the way it handles long
2681 numeric fields.
2682
2683 @item ustar
2684 Creates a @acronym{POSIX.1-1988} compatible archive.
2685
2686 @item posix
2687 Creates a @acronym{POSIX.1-2001 archive}.
2688
2689 @end table
2690
2691 @xref{Formats}, for a detailed discussion of these formats.
2692
2693 @opsummary{full-time}
2694 @item --full-time
2695 This option instructs @command{tar} to print file times to their full
2696 resolution.  Usually this means 1-second resolution, but that depends
2697 on the underlying file system.  The @option{--full-time} option takes
2698 effect only when detailed output (verbosity level 2 or higher) has
2699 been requested using the @option{--verbose} option, e.g., when listing
2700 or extracting archives:
2701
2702 @smallexample
2703 $ @kbd{tar -t -v --full-time -f archive.tar}
2704 @end smallexample
2705
2706 @noindent
2707 or, when creating an archive:
2708
2709 @smallexample
2710 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2711 @end smallexample
2712
2713 Notice, thar when creating the archive you need to specify
2714 @option{--verbose} twice to get a detailed output (@pxref{verbose
2715 tutorial}).
2716
2717 @opsummary{group}
2718 @item --group=@var{group}
2719
2720 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2721 rather than the group from the source file.  @var{group} is first decoded
2722 as a group symbolic name, but if this interpretation fails, it has to be
2723 a decimal numeric group @acronym{ID}.  @xref{override}.
2724
2725 Also see the comments for the @option{--owner=@var{user}} option.
2726
2727 @opsummary{gzip}
2728 @opsummary{gunzip}
2729 @opsummary{ungzip}
2730 @item --gzip
2731 @itemx --gunzip
2732 @itemx --ungzip
2733 @itemx -z
2734
2735 This option tells @command{tar} to read or write archives through
2736 @command{gzip}, allowing @command{tar} to directly operate on several
2737 kinds of compressed archives transparently.  @xref{gzip}.
2738
2739 @opsummary{hard-dereference}
2740 @item --hard-dereference
2741 When creating an archive, dereference hard links and store the files
2742 they refer to, instead of creating usual hard link members.
2743
2744 @xref{hard links}.
2745
2746 @opsummary{help}
2747 @item --help
2748 @itemx -?
2749
2750 @command{tar} will print out a short message summarizing the operations and
2751 options to @command{tar} and exit. @xref{help}.
2752
2753 @opsummary{ignore-case}
2754 @item --ignore-case
2755 Ignore case when matching member or file names with
2756 patterns. @xref{controlling pattern-matching}.
2757
2758 @opsummary{ignore-command-error}
2759 @item --ignore-command-error
2760 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2761
2762 @opsummary{ignore-failed-read}
2763 @item --ignore-failed-read
2764
2765 Do not exit unsuccessfully merely because an unreadable file was encountered.
2766 @xref{Reading}.
2767
2768 @opsummary{ignore-zeros}
2769 @item --ignore-zeros
2770 @itemx -i
2771
2772 With this option, @command{tar} will ignore zeroed blocks in the
2773 archive, which normally signals EOF.  @xref{Reading}.
2774
2775 @opsummary{incremental}
2776 @item --incremental
2777 @itemx -G
2778
2779 Informs @command{tar} that it is working with an old
2780 @acronym{GNU}-format incremental backup archive.  It is intended
2781 primarily for backwards compatibility only.  @xref{Incremental Dumps},
2782 for a detailed discussion of incremental archives.
2783
2784 @opsummary{index-file}
2785 @item --index-file=@var{file}
2786
2787 Send verbose output to @var{file} instead of to standard output.
2788
2789 @opsummary{info-script}
2790 @opsummary{new-volume-script}
2791 @item --info-script=@var{script-file}
2792 @itemx --new-volume-script=@var{script-file}
2793 @itemx -F @var{script-file}
2794
2795 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2796 at the end of each tape.  If @var{script-file} exits with nonzero status,
2797 @command{tar} fails immediately.  @xref{info-script}, for a detailed
2798 discussion of @var{script-file}.
2799
2800 @opsummary{interactive}
2801 @item --interactive
2802 @itemx --confirmation
2803 @itemx -w
2804
2805 Specifies that @command{tar} should ask the user for confirmation before
2806 performing potentially destructive options, such as overwriting files.
2807 @xref{interactive}.
2808
2809 @opsummary{keep-newer-files}
2810 @item --keep-newer-files
2811
2812 Do not replace existing files that are newer than their archive copies
2813 when extracting files from an archive.
2814
2815 @opsummary{keep-old-files}
2816 @item --keep-old-files
2817 @itemx -k
2818
2819 Do not overwrite existing files when extracting files from an archive.
2820 @xref{Keep Old Files}.
2821
2822 @opsummary{label}
2823 @item --label=@var{name}
2824 @itemx -V @var{name}
2825
2826 When creating an archive, instructs @command{tar} to write @var{name}
2827 as a name record in the archive.  When extracting or listing archives,
2828 @command{tar} will only operate on archives that have a label matching
2829 the pattern specified in @var{name}.  @xref{Tape Files}.
2830
2831 @opsummary{level}
2832 @item --level=@var{n}
2833 Force incremental backup of level @var{n}.  As of @GNUTAR version
2834 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2835 file, thereby forcing the level 0 dump.  Other values of @var{n} are
2836 effectively ignored.  @xref{--level=0}, for details and examples.
2837
2838 The use of this option is valid only in conjunction with the
2839 @option{--listed-incremental} option.  @xref{Incremental Dumps},
2840 for a detailed description.
2841
2842 @opsummary{listed-incremental}
2843 @item --listed-incremental=@var{snapshot-file}
2844 @itemx -g @var{snapshot-file}
2845
2846 During a @option{--create} operation, specifies that the archive that
2847 @command{tar} creates is a new @acronym{GNU}-format incremental
2848 backup, using @var{snapshot-file} to determine which files to backup.
2849 With other operations, informs @command{tar} that the archive is in
2850 incremental format.  @xref{Incremental Dumps}.
2851
2852 @opsummary{lzip}
2853 @item --lzip
2854
2855 This option tells @command{tar} to read or write archives through
2856 @command{lzip}.  @xref{gzip}.
2857
2858 @opsummary{lzma}
2859 @item --lzma
2860
2861 This option tells @command{tar} to read or write archives through
2862 @command{lzma}.  @xref{gzip}.
2863
2864 @item --lzop
2865
2866 This option tells @command{tar} to read or write archives through
2867 @command{lzop}.  @xref{gzip}.
2868
2869 @opsummary{mode}
2870 @item --mode=@var{permissions}
2871
2872 When adding files to an archive, @command{tar} will use
2873 @var{permissions} for the archive members, rather than the permissions
2874 from the files.  @var{permissions} can be specified either as an octal
2875 number or as symbolic permissions, like with
2876 @command{chmod}. @xref{override}.
2877
2878 @opsummary{mtime}
2879 @item --mtime=@var{date}
2880
2881 When adding files to an archive, @command{tar} will use @var{date} as
2882 the modification time of members when creating archives, instead of
2883 their actual modification times.  The value of @var{date} can be
2884 either a textual date representation (@pxref{Date input formats}) or a
2885 name of the existing file, starting with @samp{/} or @samp{.}.  In the
2886 latter case, the modification time of that file is used. @xref{override}.
2887
2888 @opsummary{multi-volume}
2889 @item --multi-volume
2890 @itemx -M
2891
2892 Informs @command{tar} that it should create or otherwise operate on a
2893 multi-volume @command{tar} archive.  @xref{Using Multiple Tapes}.
2894
2895 @opsummary{new-volume-script}
2896 @item --new-volume-script
2897
2898 (see @option{--info-script})
2899
2900 @opsummary{newer}
2901 @item --newer=@var{date}
2902 @itemx --after-date=@var{date}
2903 @itemx -N
2904
2905 When creating an archive, @command{tar} will only add files that have changed
2906 since @var{date}.  If @var{date} begins with @samp{/} or @samp{.}, it
2907 is taken to be the name of a file whose data modification time specifies
2908 the date.  @xref{after}.
2909
2910 @opsummary{newer-mtime}
2911 @item --newer-mtime=@var{date}
2912
2913 Like @option{--newer}, but add only files whose
2914 contents have changed (as opposed to just @option{--newer}, which will
2915 also back up files for which any status information has
2916 changed).  @xref{after}.
2917
2918 @opsummary{no-anchored}
2919 @item --no-anchored
2920 An exclude pattern can match any subsequence of the name's components.
2921 @xref{controlling pattern-matching}.
2922
2923 @opsummary{no-auto-compress}
2924 @item --no-auto-compress
2925
2926 Disables automatic compressed format recognition based on the archive
2927 suffix.  @xref{--auto-compress}.  @xref{gzip}.
2928
2929 @opsummary{no-check-device}
2930 @item --no-check-device
2931 Do not check device numbers when creating a list of modified files
2932 for incremental archiving.  @xref{device numbers}, for
2933 a detailed description.
2934
2935 @opsummary{no-delay-directory-restore}
2936 @item --no-delay-directory-restore
2937
2938 Modification times and permissions of extracted
2939 directories are set when all files from this directory have been
2940 extracted.  This is the default.
2941 @xref{Directory Modification Times and Permissions}.
2942
2943 @opsummary{no-ignore-case}
2944 @item --no-ignore-case
2945 Use case-sensitive matching.
2946 @xref{controlling pattern-matching}.
2947
2948 @opsummary{no-ignore-command-error}
2949 @item --no-ignore-command-error
2950 Print warnings about subprocesses that terminated with a nonzero exit
2951 code. @xref{Writing to an External Program}.
2952
2953 @opsummary{no-null}
2954 @item --no-null
2955
2956 If the @option{--null} option was given previously, this option
2957 cancels its effect, so that any following @option{--files-from}
2958 options will expect their file lists to be newline-terminated.
2959
2960 @opsummary{no-overwrite-dir}
2961 @item --no-overwrite-dir
2962
2963 Preserve metadata of existing directories when extracting files
2964 from an archive.  @xref{Overwrite Old Files}.
2965
2966 @opsummary{no-quote-chars}
2967 @item --no-quote-chars=@var{string}
2968 Remove characters listed in @var{string} from the list of quoted
2969 characters set by the previous @option{--quote-chars} option
2970 (@pxref{quoting styles}).
2971
2972 @opsummary{no-recursion}
2973 @item --no-recursion
2974
2975 With this option, @command{tar} will not recurse into directories.
2976 @xref{recurse}.
2977
2978 @opsummary{no-same-owner}
2979 @item --no-same-owner
2980 @itemx -o
2981
2982 When extracting an archive, do not attempt to preserve the owner
2983 specified in the @command{tar} archive.  This the default behavior
2984 for ordinary users.
2985
2986 @opsummary{no-same-permissions}
2987 @item --no-same-permissions
2988
2989 When extracting an archive, subtract the user's umask from files from
2990 the permissions specified in the archive.  This is the default behavior
2991 for ordinary users.
2992
2993 @opsummary{no-seek}
2994 @item --no-seek
2995
2996 The archive media does not support seeks to arbitrary
2997 locations.  Usually @command{tar} determines automatically whether
2998 the archive can be seeked or not.  Use this option to disable this
2999 mechanism.
3000
3001 @opsummary{no-unquote}
3002 @item --no-unquote
3003 Treat all input file or member names literally, do not interpret
3004 escape sequences.  @xref{input name quoting}.
3005
3006 @opsummary{no-wildcards}
3007 @item --no-wildcards
3008 Do not use wildcards.
3009 @xref{controlling pattern-matching}.
3010
3011 @opsummary{no-wildcards-match-slash}
3012 @item --no-wildcards-match-slash
3013 Wildcards do not match @samp{/}.
3014 @xref{controlling pattern-matching}.
3015
3016 @opsummary{null}
3017 @item --null
3018
3019 When @command{tar} is using the @option{--files-from} option, this option
3020 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
3021 @command{tar} can correctly work with file names that contain newlines.
3022 @xref{nul}.
3023
3024 @opsummary{numeric-owner}
3025 @item --numeric-owner
3026
3027 This option will notify @command{tar} that it should use numeric user
3028 and group IDs when creating a @command{tar} file, rather than names.
3029 @xref{Attributes}.
3030
3031 @item -o
3032 The function of this option depends on the action @command{tar} is
3033 performing.  When extracting files, @option{-o} is a synonym for
3034 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3035 restoring ownership of files being extracted.
3036
3037 When creating an archive, it is a synonym for
3038 @option{--old-archive}.  This behavior is for compatibility
3039 with previous versions of @GNUTAR{}, and will be
3040 removed in future releases.
3041
3042 @xref{Changes}, for more information.
3043
3044 @opsummary{occurrence}
3045 @item --occurrence[=@var{number}]
3046
3047 This option can be used in conjunction with one of the subcommands
3048 @option{--delete}, @option{--diff}, @option{--extract} or
3049 @option{--list} when a list of files is given either on the command
3050 line or via @option{-T} option.
3051
3052 This option instructs @command{tar} to process only the @var{number}th
3053 occurrence of each named file.  @var{Number} defaults to 1, so
3054
3055 @smallexample
3056 tar -x -f archive.tar --occurrence filename
3057 @end smallexample
3058
3059 @noindent
3060 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3061 and will terminate without scanning to the end of the archive.
3062
3063 @opsummary{old-archive}
3064 @item --old-archive
3065 Synonym for @option{--format=v7}.
3066
3067 @opsummary{one-file-system}
3068 @item --one-file-system
3069 Used when creating an archive.  Prevents @command{tar} from recursing into
3070 directories that are on different file systems from the current
3071 directory.
3072
3073 @opsummary{overwrite}
3074 @item --overwrite
3075
3076 Overwrite existing files and directory metadata when extracting files
3077 from an archive.  @xref{Overwrite Old Files}.
3078
3079 @opsummary{overwrite-dir}
3080 @item --overwrite-dir
3081
3082 Overwrite the metadata of existing directories when extracting files
3083 from an archive.  @xref{Overwrite Old Files}.
3084
3085 @opsummary{owner}
3086 @item --owner=@var{user}
3087
3088 Specifies that @command{tar} should use @var{user} as the owner of members
3089 when creating archives, instead of the user associated with the source
3090 file.  @var{user} is first decoded as a user symbolic name, but if
3091 this interpretation fails, it has to be a decimal numeric user @acronym{ID}.
3092 @xref{override}.
3093
3094 This option does not affect extraction from archives.
3095
3096 @opsummary{pax-option}
3097 @item --pax-option=@var{keyword-list}
3098 This option enables creation of the archive in @acronym{POSIX.1-2001}
3099 format (@pxref{posix}) and modifies the way @command{tar} handles the
3100 extended header keywords.  @var{Keyword-list} is a comma-separated
3101 list of keyword options.  @xref{PAX keywords}, for a detailed
3102 discussion.
3103
3104 @opsummary{portability}
3105 @item --portability
3106 @itemx --old-archive
3107 Synonym for @option{--format=v7}.
3108
3109 @opsummary{posix}
3110 @item --posix
3111 Same as @option{--format=posix}.
3112
3113 @opsummary{preserve}
3114 @item --preserve
3115
3116 Synonymous with specifying both @option{--preserve-permissions} and
3117 @option{--same-order}.  @xref{Setting Access Permissions}.
3118
3119 @opsummary{preserve-order}
3120 @item --preserve-order
3121
3122 (See @option{--same-order}; @pxref{Reading}.)
3123
3124 @opsummary{preserve-permissions}
3125 @opsummary{same-permissions}
3126 @item --preserve-permissions
3127 @itemx --same-permissions
3128 @itemx -p
3129
3130 When @command{tar} is extracting an archive, it normally subtracts the
3131 users' umask from the permissions specified in the archive and uses
3132 that number as the permissions to create the destination file.
3133 Specifying this option instructs @command{tar} that it should use the
3134 permissions directly from the archive.  @xref{Setting Access Permissions}.
3135
3136 @opsummary{quote-chars}
3137 @item --quote-chars=@var{string}
3138 Always quote characters from @var{string}, even if the selected
3139 quoting style would not quote them (@pxref{quoting styles}).
3140
3141 @opsummary{quoting-style}
3142 @item --quoting-style=@var{style}
3143 Set quoting style to use when printing member and file names
3144 (@pxref{quoting styles}). Valid @var{style} values are:
3145 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3146 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3147 style is @code{escape}, unless overridden while configuring the
3148 package.
3149
3150 @opsummary{read-full-records}
3151 @item --read-full-records
3152 @itemx -B
3153
3154 Specifies that @command{tar} should reblock its input, for reading
3155 from pipes on systems with buggy implementations.  @xref{Reading}.
3156
3157 @opsummary{record-size}
3158 @item --record-size=@var{size}[@var{suf}]
3159
3160 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3161 archive.  The argument can be suffixed with a @dfn{size suffix}, e.g.
3162 @option{--record-size=10K} for 10 Kilobytes.  @xref{size-suffixes},
3163 for a list of valid suffixes.   @xref{Blocking Factor}, for a detailed
3164 description of this option.
3165
3166 @opsummary{recursion}
3167 @item --recursion
3168
3169 With this option, @command{tar} recurses into directories (default).
3170 @xref{recurse}.
3171
3172 @opsummary{recursive-unlink}
3173 @item --recursive-unlink
3174
3175 Remove existing
3176 directory hierarchies before extracting directories of the same name
3177 from the archive.  @xref{Recursive Unlink}.
3178
3179 @opsummary{remove-files}
3180 @item --remove-files
3181
3182 Directs @command{tar} to remove the source file from the file system after
3183 appending it to an archive.  @xref{remove files}.
3184
3185 @opsummary{restrict}
3186 @item --restrict
3187
3188 Disable use of some potentially harmful @command{tar} options.
3189 Currently this option disables shell invocation from multi-volume menu
3190 (@pxref{Using Multiple Tapes}).
3191
3192 @opsummary{rmt-command}
3193 @item --rmt-command=@var{cmd}
3194
3195 Notifies @command{tar} that it should use @var{cmd} instead of
3196 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3197
3198 @opsummary{rsh-command}
3199 @item --rsh-command=@var{cmd}
3200
3201 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3202 devices.  @xref{Device}.
3203
3204 @opsummary{same-order}
3205 @item --same-order
3206 @itemx --preserve-order
3207 @itemx -s
3208
3209 This option is an optimization for @command{tar} when running on machines with
3210 small amounts of memory.  It informs @command{tar} that the list of file
3211 arguments has already been sorted to match the order of files in the
3212 archive.  @xref{Reading}.
3213
3214 @opsummary{same-owner}
3215 @item --same-owner
3216
3217 When extracting an archive, @command{tar} will attempt to preserve the owner
3218 specified in the @command{tar} archive with this option present.
3219 This is the default behavior for the superuser; this option has an
3220 effect only for ordinary users.  @xref{Attributes}.
3221
3222 @opsummary{same-permissions}
3223 @item --same-permissions
3224
3225 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3226
3227 @opsummary{seek}
3228 @item --seek
3229 @itemx -n
3230
3231 Assume that the archive media supports seeks to arbitrary
3232 locations.  Usually @command{tar} determines automatically whether
3233 the archive can be seeked or not.  This option is intended for use
3234 in cases when such recognition fails.  It takes effect only if the
3235 archive is open for reading (e.g. with @option{--list} or
3236 @option{--extract} options).
3237
3238 @opsummary{show-defaults}
3239 @item --show-defaults
3240
3241 Displays the default options used by @command{tar} and exits
3242 successfully.  This option is intended for use in shell scripts.
3243 Here is an example of what you can see using this option:
3244
3245 @smallexample
3246 $ @kbd{tar --show-defaults}
3247 --format=gnu -f- -b20 --quoting-style=escape
3248 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3249 @end smallexample
3250
3251 @noindent
3252 Notice, that this option outputs only one line.  The example output
3253 above has been split to fit page boundaries.
3254
3255 @opsummary{show-omitted-dirs}
3256 @item --show-omitted-dirs
3257
3258 Instructs @command{tar} to mention the directories it is skipping when
3259 operating on a @command{tar} archive.  @xref{show-omitted-dirs}.
3260
3261 @opsummary{show-transformed-names}
3262 @opsummary{show-stored-names}
3263 @item --show-transformed-names
3264 @itemx --show-stored-names
3265
3266 Display file or member names after applying any transformations
3267 (@pxref{transform}).  In particular, when used in conjunction with one of
3268 the archive creation operations it instructs @command{tar} to list the
3269 member names stored in the archive, as opposed to the actual file
3270 names.  @xref{listing member and file names}.
3271
3272 @opsummary{sparse}
3273 @item --sparse
3274 @itemx -S
3275
3276 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3277 sparse files efficiently.  @xref{sparse}.
3278
3279 @opsummary{sparse-version}
3280 @item --sparse-version=@var{version}
3281
3282 Specifies the @dfn{format version} to use when archiving sparse
3283 files.  Implies @option{--sparse}.  @xref{sparse}. For the description
3284 of the supported sparse formats, @xref{Sparse Formats}.
3285
3286 @opsummary{starting-file}
3287 @item --starting-file=@var{name}
3288 @itemx -K @var{name}
3289
3290 This option affects extraction only; @command{tar} will skip extracting
3291 files in the archive until it finds one that matches @var{name}.
3292 @xref{Scarce}.
3293
3294 @opsummary{strip-components}
3295 @item --strip-components=@var{number}
3296 Strip given @var{number} of leading components from file names before
3297 extraction.  For example, if archive @file{archive.tar} contained
3298 @file{/some/file/name}, then running
3299
3300 @smallexample
3301 tar --extract --file archive.tar --strip-components=2
3302 @end smallexample
3303
3304 @noindent
3305 would extract this file to file @file{name}.
3306
3307 @opsummary{suffix}
3308 @item --suffix=@var{suffix}
3309
3310 Alters the suffix @command{tar} uses when backing up files from the default
3311 @samp{~}.  @xref{backup}.
3312
3313 @opsummary{tape-length}
3314 @item --tape-length=@var{num}[@var{suf}]
3315 @itemx -L @var{num}[@var{suf}]
3316
3317 Specifies the length of tapes that @command{tar} is writing as being
3318 @w{@var{num} x 1024} bytes long.  If optional @var{suf} is given, it
3319 specifies a multiplicative factor to be used instead of 1024.  For
3320 example, @samp{-L2M} means 2 megabytes.  @xref{size-suffixes}, for a
3321 list of allowed suffixes.  @xref{Using Multiple Tapes}, for a detailed
3322 discussion of this option.
3323
3324 @opsummary{test-label}
3325 @item --test-label
3326
3327 Reads the volume label.  If an argument is specified, test whether it
3328 matches the volume label.  @xref{--test-label option}.
3329
3330 @opsummary{to-command}
3331 @item --to-command=@var{command}
3332
3333 During extraction @command{tar} will pipe extracted files to the
3334 standard input of @var{command}.  @xref{Writing to an External Program}.
3335
3336 @opsummary{to-stdout}
3337 @item --to-stdout
3338 @itemx -O
3339
3340 During extraction, @command{tar} will extract files to stdout rather
3341 than to the file system.  @xref{Writing to Standard Output}.
3342
3343 @opsummary{totals}
3344 @item --totals[=@var{signo}]
3345
3346 Displays the total number of bytes transferred when processing an
3347 archive.  If an argument is given, these data are displayed on
3348 request, when signal @var{signo} is delivered to @command{tar}.
3349 @xref{totals}.
3350
3351 @opsummary{touch}
3352 @item --touch
3353 @itemx -m
3354
3355 Sets the data modification time of extracted files to the extraction time,
3356 rather than the data modification time stored in the archive.
3357 @xref{Data Modification Times}.
3358
3359 @opsummary{transform}
3360 @opsummary{xform}
3361 @item --transform=@var{sed-expr}
3362 @itemx --xform=@var{sed-expr}
3363 Transform file or member names using @command{sed} replacement expression
3364 @var{sed-expr}.  For example,
3365
3366 @smallexample
3367 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3368 @end smallexample
3369
3370 @noindent
3371 will add to @file{archive} files from the current working directory,
3372 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3373 discussion, @xref{transform}.
3374
3375 To see transformed member names in verbose listings, use
3376 @option{--show-transformed-names} option
3377 (@pxref{show-transformed-names}).
3378
3379 @opsummary{uncompress}
3380 @item --uncompress
3381
3382 (See @option{--compress}, @pxref{gzip})
3383
3384 @opsummary{ungzip}
3385 @item --ungzip
3386
3387 (See @option{--gzip}, @pxref{gzip})
3388
3389 @opsummary{unlink-first}
3390 @item --unlink-first
3391 @itemx -U
3392
3393 Directs @command{tar} to remove the corresponding file from the file
3394 system before extracting it from the archive.  @xref{Unlink First}.
3395
3396 @opsummary{unquote}
3397 @item --unquote
3398 Enable unquoting input file or member names (default).  @xref{input
3399 name quoting}.
3400
3401 @opsummary{use-compress-program}
3402 @item --use-compress-program=@var{prog}
3403 @itemx -I=@var{prog}
3404
3405 Instructs @command{tar} to access the archive through @var{prog}, which is
3406 presumed to be a compression program of some sort.  @xref{gzip}.
3407
3408 @opsummary{utc}
3409 @item --utc
3410
3411 Display file modification dates in @acronym{UTC}.  This option implies
3412 @option{--verbose}.
3413
3414 @opsummary{verbose}
3415 @item --verbose
3416 @itemx -v
3417
3418 Specifies that @command{tar} should be more verbose about the
3419 operations it is performing.  This option can be specified multiple
3420 times for some operations to increase the amount of information displayed.
3421 @xref{verbose}.
3422
3423 @opsummary{verify}
3424 @item --verify
3425 @itemx -W
3426
3427 Verifies that the archive was correctly written when creating an
3428 archive.  @xref{verify}.
3429
3430 @opsummary{version}
3431 @item --version
3432
3433 Print information about the program's name, version, origin and legal
3434 status, all on standard output, and then exit successfully.
3435 @xref{help}.
3436
3437 @opsummary{volno-file}
3438 @item --volno-file=@var{file}
3439
3440 Used in conjunction with @option{--multi-volume}.  @command{tar} will
3441 keep track of which volume of a multi-volume archive it is working in
3442 @var{file}.  @xref{volno-file}.
3443
3444 @opsummary{warning}
3445 @item --warning=@var{keyword}
3446
3447 Enable or disable warning messages identified by @var{keyword}.  The
3448 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3449 @xref{warnings}.
3450
3451 @opsummary{wildcards}
3452 @item --wildcards
3453 Use wildcards when matching member names with patterns.
3454 @xref{controlling pattern-matching}.
3455
3456 @opsummary{wildcards-match-slash}
3457 @item --wildcards-match-slash
3458 Wildcards match @samp{/}.
3459 @xref{controlling pattern-matching}.
3460
3461 @opsummary{xz}
3462 @item --xz
3463 @itemx -J
3464 Use @command{xz} for compressing or decompressing the archives.  @xref{gzip}.
3465
3466 @end table
3467
3468 @node Short Option Summary
3469 @subsection Short Options Cross Reference
3470
3471 Here is an alphabetized list of all of the short option forms, matching
3472 them with the equivalent long option.
3473
3474 @multitable @columnfractions 0.20 0.80
3475 @headitem Short Option  @tab Reference
3476
3477 @item -A @tab @ref{--concatenate}.
3478
3479 @item -B @tab @ref{--read-full-records}.
3480
3481 @item -C @tab @ref{--directory}.
3482
3483 @item -F @tab @ref{--info-script}.
3484
3485 @item -G @tab @ref{--incremental}.
3486
3487 @item -J @tab @ref{--xz}.
3488
3489 @item -K @tab @ref{--starting-file}.
3490
3491 @item -L @tab @ref{--tape-length}.
3492
3493 @item -M @tab @ref{--multi-volume}.
3494
3495 @item -N @tab @ref{--newer}.
3496
3497 @item -O @tab @ref{--to-stdout}.
3498
3499 @item -P @tab @ref{--absolute-names}.
3500
3501 @item -R @tab @ref{--block-number}.
3502
3503 @item -S @tab @ref{--sparse}.
3504
3505 @item -T @tab @ref{--files-from}.
3506
3507 @item -U @tab @ref{--unlink-first}.
3508
3509 @item -V @tab @ref{--label}.
3510
3511 @item -W @tab @ref{--verify}.
3512
3513 @item -X @tab @ref{--exclude-from}.
3514
3515 @item -Z @tab @ref{--compress}.
3516
3517 @item -b @tab @ref{--blocking-factor}.
3518
3519 @item -c @tab @ref{--create}.
3520
3521 @item -d @tab @ref{--compare}.
3522
3523 @item -f @tab @ref{--file}.
3524
3525 @item -g @tab @ref{--listed-incremental}.
3526
3527 @item -h @tab @ref{--dereference}.
3528
3529 @item -i @tab @ref{--ignore-zeros}.
3530
3531 @item -j @tab @ref{--bzip2}.
3532
3533 @item -k @tab @ref{--keep-old-files}.
3534
3535 @item -l @tab @ref{--check-links}.
3536
3537 @item -m @tab @ref{--touch}.
3538
3539 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3540 @ref{--portability}.
3541
3542 The latter usage is deprecated.  It is retained for compatibility with
3543 the earlier versions of @GNUTAR{}.  In future releases
3544 @option{-o} will be equivalent to @option{--no-same-owner} only.
3545
3546 @item -p @tab @ref{--preserve-permissions}.
3547
3548 @item -r @tab @ref{--append}.
3549
3550 @item -s @tab @ref{--same-order}.
3551
3552 @item -t @tab @ref{--list}.
3553
3554 @item -u @tab @ref{--update}.
3555
3556 @item -v @tab @ref{--verbose}.
3557
3558 @item -w @tab @ref{--interactive}.
3559
3560 @item -x @tab @ref{--extract}.
3561
3562 @item -z @tab @ref{--gzip}.
3563
3564 @end multitable
3565
3566 @node help
3567 @section @GNUTAR{} documentation
3568
3569 @cindex Getting program version number
3570 @opindex version
3571 @cindex Version of the @command{tar} program
3572 Being careful, the first thing is really checking that you are using
3573 @GNUTAR{}, indeed.  The @option{--version} option
3574 causes @command{tar} to print information about its name, version,
3575 origin and legal status, all on standard output, and then exit
3576 successfully.  For example, @w{@samp{tar --version}} might print:
3577
3578 @smallexample
3579 tar (GNU tar) @value{VERSION}
3580 Copyright (C) 2010 Free Software Foundation, Inc.
3581 Copyright (C) 2010 Free Software Foundation, Inc.
3582 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3583 This is free software: you are free to change and redistribute it.
3584 There is NO WARRANTY, to the extent permitted by law.
3585
3586 Written by John Gilmore and Jay Fenlason.
3587 @end smallexample
3588
3589 @noindent
3590 The first occurrence of @samp{tar} in the result above is the program
3591 name in the package (for example, @command{rmt} is another program),
3592 while the second occurrence of @samp{tar} is the name of the package
3593 itself, containing possibly many programs.  The package is currently
3594 named @samp{tar}, after the name of the main program it
3595 contains@footnote{There are plans to merge the @command{cpio} and
3596 @command{tar} packages into a single one which would be called
3597 @code{paxutils}.  So, who knows if, one of this days, the
3598 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3599 paxutils) 3.2}}.}.
3600
3601 @cindex Obtaining help
3602 @cindex Listing all @command{tar} options
3603 @xopindex{help, introduction}
3604 Another thing you might want to do is checking the spelling or meaning
3605 of some particular @command{tar} option, without resorting to this
3606 manual, for once you have carefully read it.  @GNUTAR{}
3607 has a short help feature, triggerable through the
3608 @option{--help} option.  By using this option, @command{tar} will
3609 print a usage message listing all available options on standard
3610 output, then exit successfully, without doing anything else and
3611 ignoring all other options.  Even if this is only a brief summary, it
3612 may be several screens long.  So, if you are not using some kind of
3613 scrollable window, you might prefer to use something like:
3614
3615 @smallexample
3616 $ @kbd{tar --help | less}
3617 @end smallexample
3618
3619 @noindent
3620 presuming, here, that you like using @command{less} for a pager.  Other
3621 popular pagers are @command{more} and @command{pg}.  If you know about some
3622 @var{keyword} which interests you and do not want to read all the
3623 @option{--help} output, another common idiom is doing:
3624
3625 @smallexample
3626 tar --help | grep @var{keyword}
3627 @end smallexample
3628
3629 @noindent
3630 for getting only the pertinent lines.  Notice, however, that some
3631 @command{tar} options have long description lines and the above
3632 command will list only the first of them.
3633
3634 The exact look of the option summary displayed by @kbd{tar --help} is
3635 configurable. @xref{Configuring Help Summary}, for a detailed description.
3636
3637 @opindex usage
3638 If you only wish to check the spelling of an option, running @kbd{tar
3639 --usage} may be a better choice.  This will display a terse list of
3640 @command{tar} options without accompanying explanations.
3641
3642 The short help output is quite succinct, and you might have to get
3643 back to the full documentation for precise points.  If you are reading
3644 this paragraph, you already have the @command{tar} manual in some
3645 form.  This manual is available in a variety of forms from
3646 @url{http://www.gnu.org/software/tar/manual}.  It may be printed out of the @GNUTAR{}
3647 distribution, provided you have @TeX{} already installed somewhere,
3648 and a laser printer around.  Just configure the distribution, execute
3649 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3650 usual way (contact your local guru to know how).  If @GNUTAR{}
3651 has been conveniently installed at your place, this
3652 manual is also available in interactive, hypertextual form as an Info
3653 file.  Just call @w{@samp{info tar}} or, if you do not have the
3654 @command{info} program handy, use the Info reader provided within
3655 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3656
3657 There is currently no @code{man} page for @GNUTAR{}.
3658 If you observe such a @code{man} page on the system you are running,
3659 either it does not belong to @GNUTAR{}, or it has not
3660 been produced by @acronym{GNU}.  Some package maintainers convert
3661 @kbd{tar --help} output to a man page, using @command{help2man}.  In
3662 any case, please bear in mind that the authoritative source of
3663 information about @GNUTAR{} is this Texinfo documentation.
3664
3665 @node defaults
3666 @section Obtaining @GNUTAR{} default values
3667
3668 @opindex show-defaults
3669 @GNUTAR{} has some predefined defaults that are used when you do not
3670 explicitly specify another values.  To obtain a list of such
3671 defaults, use @option{--show-defaults} option.  This will output the
3672 values in the form of @command{tar} command line options:
3673
3674 @smallexample
3675 @group
3676 $ @kbd{tar --show-defaults}
3677 --format=gnu -f- -b20 --quoting-style=escape
3678 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3679 @end group
3680 @end smallexample
3681
3682 @noindent
3683 Notice, that this option outputs only one line.  The example output above
3684 has been split to fit page boundaries.
3685
3686 @noindent
3687 The above output shows that this version of @GNUTAR{} defaults to
3688 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3689 output as the archive, if no @option{--file} option has been given
3690 (@pxref{file tutorial}), the default blocking factor is 20
3691 (@pxref{Blocking Factor}).  It also shows the default locations where
3692 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3693
3694 @node verbose
3695 @section Checking @command{tar} progress
3696
3697 Typically, @command{tar} performs most operations without reporting any
3698 information to the user except error messages.  When using @command{tar}
3699 with many options, particularly ones with complicated or
3700 difficult-to-predict behavior, it is possible to make serious mistakes.
3701 @command{tar} provides several options that make observing @command{tar}
3702 easier.  These options cause @command{tar} to print information as it
3703 progresses in its job, and you might want to use them just for being
3704 more careful about what is going on, or merely for entertaining
3705 yourself.  If you have encountered a problem when operating on an
3706 archive, however, you may need more information than just an error
3707 message in order to solve the problem.  The following options can be
3708 helpful diagnostic tools.
3709
3710 @cindex Verbose operation
3711 @opindex verbose
3712 Normally, the @option{--list} (@option{-t}) command to list an archive
3713 prints just the file names (one per line) and the other commands are
3714 silent. When used with most operations, the @option{--verbose}
3715 (@option{-v}) option causes @command{tar} to print the name of each
3716 file or archive member as it is processed.  This and the other options
3717 which make @command{tar} print status information can be useful in
3718 monitoring @command{tar}.
3719
3720 With @option{--create} or @option{--extract}, @option{--verbose} used
3721 once just prints the names of the files or members as they are processed.
3722 Using it twice causes @command{tar} to print a longer listing
3723 (@xref{verbose member listing}, for the description) for each member.
3724 Since @option{--list} already prints  the names of the members,
3725 @option{--verbose} used once with @option{--list} causes @command{tar}
3726 to print an @samp{ls -l} type listing of the files in the archive.
3727 The following examples both extract members with long list output:
3728
3729 @smallexample
3730 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3731 $ @kbd{tar xvvf archive.tar}
3732 @end smallexample
3733
3734 Verbose output appears on the standard output except when an archive is
3735 being written to the standard output, as with @samp{tar --create
3736 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3737 installer let standard output be the default archive).  In that case
3738 @command{tar} writes verbose output to the standard error stream.
3739
3740 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3741 verbose output to @var{file} rather than to standard output or standard
3742 error.
3743
3744 @anchor{totals}
3745 @cindex Obtaining total status information
3746 @opindex totals
3747 The @option{--totals} option causes @command{tar} to print on the
3748 standard error the total amount of bytes transferred when processing
3749 an archive.  When creating or appending to an archive, this option
3750 prints the number of bytes written to the archive and the average
3751 speed at which they have been written, e.g.:
3752
3753 @smallexample
3754 @group
3755 $ @kbd{tar -c -f archive.tar --totals /home}
3756 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3757 @end group
3758 @end smallexample
3759
3760 When reading an archive, this option displays the number of bytes
3761 read:
3762
3763 @smallexample
3764 @group
3765 $ @kbd{tar -x -f archive.tar --totals}
3766 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3767 @end group
3768 @end smallexample
3769
3770 Finally, when deleting from an archive, the @option{--totals} option
3771 displays both numbers plus number of bytes removed from the archive:
3772
3773 @smallexample
3774 @group
3775 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3776 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3777 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3778 Total bytes deleted: 1474048
3779 @end group
3780 @end smallexample
3781
3782 You can also obtain this information on request.  When
3783 @option{--totals} is used with an argument, this argument is
3784 interpreted as a symbolic name of a signal, upon delivery of which the
3785 statistics is to be printed:
3786
3787 @table @option
3788 @item --totals=@var{signo}
3789 Print statistics upon delivery of signal @var{signo}.  Valid arguments
3790 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3791 @code{SIGUSR2}.  Shortened names without @samp{SIG} prefix are also
3792 accepted.
3793 @end table
3794
3795 Both forms of @option{--totals} option can be used simultaneously.
3796 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3797 extract all members from its default archive and print statistics
3798 after finishing the extraction, as well as when receiving signal
3799 @code{SIGUSR1}.
3800
3801 @anchor{Progress information}
3802 @cindex Progress information
3803 The @option{--checkpoint} option prints an occasional message
3804 as @command{tar} reads or writes the archive.  It is designed for
3805 those who don't need the more detailed (and voluminous) output of
3806 @option{--block-number} (@option{-R}), but do want visual confirmation
3807 that @command{tar} is actually making forward progress.  By default it
3808 prints a message each 10 records read or written.  This can be changed
3809 by giving it a numeric argument after an equal sign:
3810
3811 @smallexample
3812 $ @kbd{tar -c --checkpoint=1000} /var
3813 tar: Write checkpoint 1000
3814 tar: Write checkpoint 2000
3815 tar: Write checkpoint 3000
3816 @end smallexample
3817
3818 This example shows the default checkpoint message used by
3819 @command{tar}.  If you place a dot immediately after the equal
3820 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3821 actually a shortcut for @option{--checkpoint=@var{n}
3822 --checkpoint-action=dot}.  @xref{checkpoints, dot}.}.  For example:
3823
3824 @smallexample
3825 $ @kbd{tar -c --checkpoint=.1000} /var
3826 ...
3827 @end smallexample
3828
3829 The @option{--checkpoint} option provides a flexible mechanism for
3830 executing arbitrary actions upon hitting checkpoints, see the next
3831 section (@pxref{checkpoints}), for more information on it.
3832
3833 @opindex show-omitted-dirs
3834 @anchor{show-omitted-dirs}
3835 The @option{--show-omitted-dirs} option, when reading an archive---with
3836 @option{--list} or @option{--extract}, for example---causes a message
3837 to be printed for each directory in the archive which is skipped.
3838 This happens regardless of the reason for skipping: the directory might
3839 not have been named on the command line (implicitly or explicitly),
3840 it might be excluded by the use of the
3841 @option{--exclude=@var{pattern}} option, or some other reason.
3842
3843 @opindex block-number
3844 @cindex Block number where error occurred
3845 @anchor{block-number}
3846 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3847 every message it would normally produce, the block number within the
3848 archive where the message was triggered.  Also, supplementary messages
3849 are triggered when reading blocks full of NULs, or when hitting end of
3850 file on the archive.  As of now, if the archive is properly terminated
3851 with a NUL block, the reading of the file may stop before end of file
3852 is met, so the position of end of file will not usually show when
3853 @option{--block-number} (@option{-R}) is used.  Note that @GNUTAR{}
3854 drains the archive before exiting when reading the
3855 archive from a pipe.
3856
3857 @cindex Error message, block number of
3858 This option is especially useful when reading damaged archives, since
3859 it helps pinpoint the damaged sections.  It can also be used with
3860 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3861 choose among several backup tapes when retrieving a file later, in
3862 favor of the tape where the file appears earliest (closest to the
3863 front of the tape).  @xref{backup}.
3864
3865 @node checkpoints
3866 @section Checkpoints
3867 @cindex checkpoints, defined
3868 @opindex checkpoint
3869 @opindex checkpoint-action
3870
3871 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3872 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3873 from the archive (a @dfn{read checkpoint}).  Checkpoints allow to
3874 periodically execute arbitrary actions.
3875
3876 The checkpoint facility is enabled using the following option:
3877
3878 @table @option
3879 @xopindex{checkpoint, defined}
3880 @item --checkpoint[=@var{n}]
3881 Schedule checkpoints before writing or reading each @var{n}th record.
3882 The default value for @var{n} is 10.
3883 @end table
3884
3885 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3886 These actions include: pausing, displaying textual messages, and
3887 executing arbitrary external programs.  Actions are defined using
3888 the @option{--checkpoint-action} option.
3889
3890 @table @option
3891 @xopindex{checkpoint-action, defined}
3892 @item --checkpoint-action=@var{action}
3893 Execute an @var{action} at each checkpoint.
3894 @end table
3895
3896 @cindex @code{echo}, checkpoint action
3897 The simplest value of @var{action} is @samp{echo}.  It instructs
3898 @command{tar} to display the default message on the standard error
3899 stream upon arriving at each checkpoint.  The default message is (in
3900 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3901 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3902 Here, @var{n} represents ordinal number of the checkpoint.
3903
3904 In another locales, translated versions of this message are used.
3905
3906 This is the default action, so running:
3907
3908 @smallexample
3909 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3910 @end smallexample
3911
3912 @noindent
3913 is equivalent to:
3914
3915 @smallexample
3916 $ @kbd{tar -c --checkpoint=1000} /var
3917 @end smallexample
3918
3919 The @samp{echo} action also allows to supply a customized message.
3920 You do so by placing an equals sign and the message right after it,
3921 e.g.:
3922
3923 @smallexample
3924 --checkpoint-action="echo=Hit %s checkpoint #%u"
3925 @end smallexample
3926
3927 The @samp{%s} and @samp{%u} in the above example are
3928 @dfn{meta-characters}.  The @samp{%s} meta-character is replaced with
3929 the @dfn{type} of the checkpoint: @samp{write} or
3930 @samp{read} (or a corresponding translated version in locales other
3931 than @acronym{POSIX}).  The @samp{%u} meta-character is replaced with
3932 the ordinal number of the checkpoint.  Thus, the above example could
3933 produce the following output when used with the @option{--create}
3934 option:
3935
3936 @smallexample
3937 tar: Hit write checkpoint #10
3938 tar: Hit write checkpoint #20
3939 tar: Hit write checkpoint #30
3940 @end smallexample
3941
3942 Aside from meta-character expansion, the message string is subject to
3943 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3944 replaced with their corresponding @acronym{ASCII} characters
3945 (@pxref{escape sequences}).  E.g. the following action will produce an
3946 audible bell and the message described above at each checkpoint:
3947
3948 @smallexample
3949 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3950 @end smallexample
3951
3952 @cindex @code{bell}, checkpoint action
3953 There is also a special action which produces an audible signal:
3954 @samp{bell}.  It is not equivalent to @samp{echo='\a'}, because
3955 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
3956 whereas @samp{echo='\a'} sends it to the standard error.
3957
3958 @cindex @code{ttyout}, checkpoint action
3959 The @samp{ttyout=@var{string}} action outputs @var{string} to
3960 @file{/dev/tty}, so it can be used even if the standard output is
3961 redirected elsewhere.  The @var{string} is subject to the same
3962 modifications as with @samp{echo} action.  In contrast to the latter,
3963 @samp{ttyout} does not prepend @command{tar} executable name to the
3964 string, nor does it output a newline after it.  For example, the
3965 following action will print the checkpoint message at the same screen
3966 line, overwriting any previous message:
3967
3968 @smallexample
3969 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3970 @end smallexample
3971
3972 @cindex @code{dot}, checkpoint action
3973 Another available checkpoint action is @samp{dot} (or @samp{.}).  It
3974 instructs @command{tar} to print a single dot on the standard listing
3975 stream, e.g.:
3976
3977 @smallexample
3978 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
3979 ...
3980 @end smallexample
3981
3982 For compatibility with previous @GNUTAR{} versions, this action can
3983 be abbreviated by placing a dot in front of the checkpoint frequency,
3984 as shown in the previous section.
3985
3986 @cindex @code{sleep}, checkpoint action
3987 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
3988 amount of seconds.  The following example will stop for 30 seconds at each
3989 checkpoint:
3990
3991 @smallexample
3992 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
3993 @end smallexample
3994
3995 @cindex @code{exec}, checkpoint action
3996 Finally, the @code{exec} action executes a given external program.
3997 For example:
3998
3999 @smallexample
4000 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4001 @end smallexample
4002
4003 This program is executed using @command{/bin/sh -c}, with no
4004 additional arguments.  Its exit code is ignored.  It gets a copy of
4005 @command{tar}'s environment plus the following variables:
4006
4007 @table @env
4008 @vrindex TAR_VERSION, checkpoint script environment
4009 @item TAR_VERSION
4010 @GNUTAR{} version number.
4011
4012 @vrindex TAR_ARCHIVE, checkpoint script environment
4013 @item TAR_ARCHIVE
4014 The name of the archive @command{tar} is processing.
4015
4016 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4017 @item TAR_BLOCKING_FACTOR
4018 Current blocking factor (@pxref{Blocking}).
4019
4020 @vrindex TAR_CHECKPOINT, checkpoint script environment
4021 @item TAR_CHECKPOINT
4022 Number of the checkpoint.
4023
4024 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4025 @item TAR_SUBCOMMAND
4026 A short option describing the operation @command{tar} is executing.
4027 @xref{Operations}, for a complete list of subcommand options.
4028
4029 @vrindex TAR_FORMAT, checkpoint script environment
4030 @item TAR_FORMAT
4031 Format of the archive being processed. @xref{Formats}, for a complete
4032 list of archive format names.
4033 @end table
4034
4035 Any number of actions can be defined, by supplying several
4036 @option{--checkpoint-action} options in the command line.  For
4037 example, the command below displays two messages, pauses
4038 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4039
4040 @example
4041 @group
4042 $ @kbd{tar -c -f arc.tar \
4043        --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4044        --checkpoint-action='echo=Sleeping for 30 seconds' \
4045        --checkpoint-action='sleep=30' \
4046        --checkpoint-action='exec=/sbin/cpoint'}
4047 @end group
4048 @end example
4049
4050 This example also illustrates the fact that
4051 @option{--checkpoint-action} can be used without
4052 @option{--checkpoint}.  In this case, the default checkpoint frequency
4053 (at each 10th record) is assumed.
4054
4055 @node warnings
4056 @section Controlling Warning Messages
4057
4058 Sometimes, while performing the requested task, @GNUTAR{} notices
4059 some conditions that are not exactly errors, but which the user
4060 should be aware of.  When this happens, @command{tar} issues a
4061 @dfn{warning message} describing the condition.  Warning messages
4062 are output to the standard error and they do not affect the exit
4063 code of @command{tar} command.
4064
4065 @xopindex{warning, explained}
4066 @GNUTAR{} allows the user to suppress some or all of its warning
4067 messages:
4068
4069 @table @option
4070 @item --warning=@var{keyword}
4071 Control display of the warning messages identified by @var{keyword}.
4072 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4073 suppressed.  Otherwise, they are enabled.
4074
4075 Multiple @option{--warning} messages accumulate.
4076
4077 The tables below list allowed values for @var{keyword} along with the
4078 warning messages they control.
4079 @end table
4080
4081 @subheading Keywords controlling @command{tar} operation
4082 @table @asis
4083 @kwindex all
4084 @item all
4085 Enable all warning messages.  This is the default.
4086 @kwindex none
4087 @item none
4088 Disable all warning messages.
4089 @kwindex filename-with-nuls
4090 @cindex @samp{file name read contains nul character}, warning message
4091 @item filename-with-nuls
4092 @samp{%s: file name read contains nul character}
4093 @kwindex alone-zero-block
4094 @cindex @samp{A lone zero block at}, warning message
4095 @item alone-zero-block
4096 @samp{A lone zero block at %s}
4097 @end table
4098
4099 @subheading Keywords applicable for @command{tar --create}
4100 @table @asis
4101 @kwindex cachedir
4102 @cindex @samp{contains a cache directory tag}, warning message
4103 @item cachedir
4104 @samp{%s: contains a cache directory tag %s; %s}
4105 @kwindex file-shrank
4106 @cindex @samp{File shrank by %s bytes}, warning message
4107 @item file-shrank
4108 @samp{%s: File shrank by %s bytes; padding with zeros}
4109 @kwindex xdev
4110 @cindex @samp{file is on a different filesystem}, warning message
4111 @item xdev
4112 @samp{%s: file is on a different filesystem; not dumped}
4113 @kwindex file-ignored
4114 @cindex @samp{Unknown file type; file ignored}, warning message
4115 @cindex @samp{socket ignored}, warning message
4116 @cindex @samp{door ignored}, warning message
4117 @item file-ignored
4118 @samp{%s: Unknown file type; file ignored}
4119 @*@samp{%s: socket ignored}
4120 @*@samp{%s: door ignored}
4121 @kwindex file-unchanged
4122 @cindex @samp{file is unchanged; not dumped}, warning message
4123 @item file-unchanged
4124 @samp{%s: file is unchanged; not dumped}
4125 @kwindex ignore-archive
4126 @cindex @samp{file is the archive; not dumped}, warning message
4127 @kwindex ignore-archive
4128 @cindex @samp{file is the archive; not dumped}, warning message
4129 @item ignore-archive
4130 @samp{%s: file is the archive; not dumped}
4131 @kwindex file-removed
4132 @cindex @samp{File removed before we read it}, warning message
4133 @item file-removed
4134 @samp{%s: File removed before we read it}
4135 @kwindex file-changed
4136 @cindex @samp{file changed as we read it}, warning message
4137 @item file-changed
4138 @samp{%s: file changed as we read it}
4139 @end table
4140
4141 @subheading Keywords applicable for @command{tar --extract}
4142 @table @asis
4143 @kwindex timestamp
4144 @cindex @samp{implausibly old time stamp %s}, warning message
4145 @cindex @samp{time stamp %s is %s s in the future}, warning message
4146 @item timestamp
4147 @samp{%s: implausibly old time stamp %s}
4148 @*@samp{%s: time stamp %s is %s s in the future}
4149 @kwindex contiguous-cast
4150 @cindex @samp{Extracting contiguous files as regular files}, warning message
4151 @item contiguous-cast
4152 @samp{Extracting contiguous files as regular files}
4153 @kwindex symlink-cast
4154 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4155 @item symlink-cast
4156 @samp{Attempting extraction of symbolic links as hard links}
4157 @kwindex unknown-cast
4158 @cindex @samp{Unknown file type `%c', extracted as normal file}, warning message
4159 @item unknown-cast
4160 @samp{%s: Unknown file type `%c', extracted as normal file}
4161 @kwindex ignore-newer
4162 @cindex @samp{Current %s is newer or same age}, warning message
4163 @item ignore-newer
4164 @samp{Current %s is newer or same age}
4165 @kwindex unknown-keyword
4166 @cindex @samp{Ignoring unknown extended header keyword `%s'}, warning message
4167 @item unknown-keyword
4168 @samp{Ignoring unknown extended header keyword `%s'}
4169 @end table
4170
4171 @subheading Keywords controlling incremental extraction:
4172 @table @asis
4173 @kwindex rename-directory
4174 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4175 @cindex @samp{%s: Directory has been renamed}, warning message
4176 @item rename-directory
4177 @samp{%s: Directory has been renamed from %s}
4178 @*@samp{%s: Directory has been renamed}
4179 @kwindex new-directory
4180 @cindex @samp{%s: Directory is new}, warning message
4181 @item new-directory
4182 @samp{%s: Directory is new}
4183 @kwindex xdev
4184 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4185 @item xdev
4186 @samp{%s: directory is on a different device: not purging}
4187 @kwindex bad-dumpdir
4188 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4189 @item bad-dumpdir
4190 @samp{Malformed dumpdir: 'X' never used}
4191 @end table
4192
4193 @node interactive
4194 @section Asking for Confirmation During Operations
4195 @cindex Interactive operation
4196
4197 Typically, @command{tar} carries out a command without stopping for
4198 further instructions.  In some situations however, you may want to
4199 exclude some files and archive members from the operation (for instance
4200 if disk or storage space is tight).  You can do this by excluding
4201 certain files automatically (@pxref{Choosing}), or by performing
4202 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4203 @command{tar} also accepts @option{--confirmation} for this option.
4204
4205 @opindex interactive
4206 When the @option{--interactive} (@option{-w}) option is specified, before
4207 reading, writing, or deleting files, @command{tar} first prints a message
4208 for each such file, telling what operation it intends to take, then asks
4209 for confirmation on the terminal.  The actions which require
4210 confirmation include adding a file to the archive, extracting a file
4211 from the archive, deleting a file from the archive, and deleting a file
4212 from disk.  To confirm the action, you must type a line of input
4213 beginning with @samp{y}.  If your input line begins with anything other
4214 than @samp{y}, @command{tar} skips that file.
4215
4216 If @command{tar} is reading the archive from the standard input,
4217 @command{tar} opens the file @file{/dev/tty} to support the interactive
4218 communications.
4219
4220 Verbose output is normally sent to standard output, separate from
4221 other error messages.  However, if the archive is produced directly
4222 on standard output, then verbose output is mixed with errors on
4223 @code{stderr}.  Producing the archive on standard output may be used
4224 as a way to avoid using disk space, when the archive is soon to be
4225 consumed by another process reading it, say.  Some people felt the need
4226 of producing an archive on stdout, still willing to segregate between
4227 verbose output and error output.  A possible approach would be using a
4228 named pipe to receive the archive, and having the consumer process to
4229 read from that named pipe.  This has the advantage of letting standard
4230 output free to receive verbose output, all separate from errors.
4231
4232 @node operations
4233 @chapter @GNUTAR{} Operations
4234
4235 @menu
4236 * Basic tar::
4237 * Advanced tar::
4238 * create options::
4239 * extract options::
4240 * backup::
4241 * Applications::
4242 * looking ahead::
4243 @end menu
4244
4245 @node Basic tar
4246 @section Basic @GNUTAR{} Operations
4247
4248 The basic @command{tar} operations, @option{--create} (@option{-c}),
4249 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4250 @option{-x}), are currently presented and described in the tutorial
4251 chapter of this manual.  This section provides some complementary notes
4252 for these operations.
4253
4254 @table @option
4255 @xopindex{create, complementary notes}
4256 @item --create
4257 @itemx -c
4258
4259 Creating an empty archive would have some kind of elegance.  One can
4260 initialize an empty archive and later use @option{--append}
4261 (@option{-r}) for adding all members.  Some applications would not
4262 welcome making an exception in the way of adding the first archive
4263 member.  On the other hand, many people reported that it is
4264 dangerously too easy for @command{tar} to destroy a magnetic tape with
4265 an empty archive@footnote{This is well described in @cite{Unix-haters
4266 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4267 Books, ISBN 1-56884-203-1.}.  The two most common errors are:
4268
4269 @enumerate
4270 @item
4271 Mistakingly using @code{create} instead of @code{extract}, when the
4272 intent was to extract the full contents of an archive.  This error
4273 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4274 the QWERTY keyboard.  Instead of being unpacked, the archive then
4275 gets wholly destroyed.  When users speak about @dfn{exploding} an
4276 archive, they usually mean something else :-).
4277
4278 @item
4279 Forgetting the argument to @code{file}, when the intent was to create
4280 an archive with a single file in it.  This error is likely because a
4281 tired user can easily add the @kbd{f} key to the cluster of option
4282 letters, by the mere force of habit, without realizing the full
4283 consequence of doing so.  The usual consequence is that the single
4284 file, which was meant to be saved, is rather destroyed.
4285 @end enumerate
4286
4287 So, recognizing the likelihood and the catastrophic nature of these
4288 errors, @GNUTAR{} now takes some distance from elegance, and
4289 cowardly refuses to create an archive when @option{--create} option is
4290 given, there are no arguments besides options, and
4291 @option{--files-from} (@option{-T}) option is @emph{not} used.  To get
4292 around the cautiousness of @GNUTAR{} and nevertheless create an
4293 archive with nothing in it, one may still use, as the value for the
4294 @option{--files-from} option, a file with no names in it, as shown in
4295 the following commands:
4296
4297 @smallexample
4298 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4299 @kbd{tar cfT empty-archive.tar /dev/null}
4300 @end smallexample
4301
4302 @xopindex{extract, complementary notes}
4303 @item --extract
4304 @itemx --get
4305 @itemx -x
4306
4307 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4308
4309 @item @option{--list} (@option{-t})
4310
4311 @GNUTAR{} now shows dates as @samp{1996-08-30},
4312 while it used to show them as @samp{Aug 30 1996}. Preferably,
4313 people should get used to ISO 8601 dates.  Local American dates should
4314 be made available again with full date localization support, once
4315 ready.  In the meantime, programs not being localizable for dates
4316 should prefer international dates, that's really the way to go.
4317
4318 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4319 are curious, it contains a detailed explanation of the ISO 8601 standard.
4320
4321 @end table
4322
4323 @node Advanced tar
4324 @section Advanced @GNUTAR{} Operations
4325
4326 Now that you have learned the basics of using @GNUTAR{}, you may want
4327 to learn about further ways in which @command{tar} can help you.
4328
4329 This chapter presents five, more advanced operations which you probably
4330 won't use on a daily basis, but which serve more specialized functions.
4331 We also explain the different styles of options and why you might want
4332 to use one or another, or a combination of them in your @command{tar}
4333 commands.  Additionally, this chapter includes options which allow you to
4334 define the output from @command{tar} more carefully, and provide help and
4335 error correction in special circumstances.
4336
4337 @FIXME{check this after the chapter is actually revised to make sure
4338 it still introduces the info in the chapter correctly : ).}
4339
4340 @menu
4341 * Operations::
4342 * append::
4343 * update::
4344 * concatenate::
4345 * delete::
4346 * compare::
4347 @end menu
4348
4349 @node Operations
4350 @subsection The Five Advanced @command{tar} Operations
4351
4352 @cindex basic operations
4353 In the last chapter, you learned about the first three operations to
4354 @command{tar}.  This chapter presents the remaining five operations to
4355 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4356 @option{--delete}, and @option{--compare}.
4357
4358 You are not likely to use these operations as frequently as those
4359 covered in the last chapter; however, since they perform specialized
4360 functions, they are quite useful when you do need to use them.  We
4361 will give examples using the same directory and files that you created
4362 in the last chapter.  As you may recall, the directory is called
4363 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4364 and the two archive files you created are
4365 @samp{collection.tar} and @samp{music.tar}.
4366
4367 We will also use the archive files @samp{afiles.tar} and
4368 @samp{bfiles.tar}.  The archive @samp{afiles.tar} contains the members @samp{apple},
4369 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4370 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4371
4372 Unless we state otherwise, all practicing you do and examples you follow
4373 in this chapter will take place in the @file{practice} directory that
4374 you created in the previous chapter; see @ref{prepare for examples}.
4375 (Below in this section, we will remind you of the state of the examples
4376 where the last chapter left them.)
4377
4378 The five operations that we will cover in this chapter are:
4379
4380 @table @option
4381 @item --append
4382 @itemx -r
4383 Add new entries to an archive that already exists.
4384 @item --update
4385 @itemx -u
4386 Add more recent copies of archive members to the end of an archive, if
4387 they exist.
4388 @item --concatenate
4389 @itemx --catenate
4390 @itemx -A
4391 Add one or more pre-existing archives to the end of another archive.
4392 @item --delete
4393 Delete items from an archive (does not work on tapes).
4394 @item --compare
4395 @itemx --diff
4396 @itemx -d
4397 Compare archive members to their counterparts in the file system.
4398 @end table
4399
4400 @node append
4401 @subsection How to Add Files to Existing Archives: @option{--append}
4402
4403 @cindex appending files to existing archive
4404 @opindex append
4405 If you want to add files to an existing archive, you don't need to
4406 create a new archive; you can use @option{--append} (@option{-r}).
4407 The archive must already exist in order to use @option{--append}.  (A
4408 related operation is the @option{--update} operation; you can use this
4409 to add newer versions of archive members to an existing archive.  To learn how to
4410 do this with @option{--update}, @pxref{update}.)
4411
4412 If you use @option{--append} to add a file that has the same name as an
4413 archive member to an archive containing that archive member, then the
4414 old member is not deleted.  What does happen, however, is somewhat
4415 complex.  @command{tar} @emph{allows} you to have infinite number of files
4416 with the same name.  Some operations treat these same-named members no
4417 differently than any other set of archive members: for example, if you
4418 view an archive with @option{--list} (@option{-t}), you will see all
4419 of those members listed, with their data modification times, owners, etc.
4420
4421 Other operations don't deal with these members as perfectly as you might
4422 prefer; if you were to use @option{--extract} to extract the archive,
4423 only the most recently added copy of a member with the same name as
4424 other members would end up in the working directory.  This is because
4425 @option{--extract} extracts an archive in the order the members appeared
4426 in the archive; the most recently archived members will be extracted
4427 last.  Additionally, an extracted member will @emph{replace} a file of
4428 the same name which existed in the directory already, and @command{tar}
4429 will not prompt you about this@footnote{Unless you give it
4430 @option{--keep-old-files} option, or the disk copy is newer than
4431 the one in the archive and you invoke @command{tar} with
4432 @option{--keep-newer-files} option.}.  Thus, only the most recently archived
4433 member will end up being extracted, as it will replace the one
4434 extracted before it, and so on.
4435
4436 @cindex extracting @var{n}th copy of the file
4437 @xopindex{occurrence, described}
4438 There exists a special option that allows you to get around this
4439 behavior and extract (or list) only a particular copy of the file.
4440 This is @option{--occurrence} option.  If you run @command{tar} with
4441 this option, it will extract only the first copy of the file.  You
4442 may also give this option an argument specifying the number of
4443 copy to be extracted.  Thus, for example if the archive
4444 @file{archive.tar} contained three copies of file @file{myfile}, then
4445 the command
4446
4447 @smallexample
4448 tar --extract --file archive.tar --occurrence=2 myfile
4449 @end smallexample
4450
4451 @noindent
4452 would extract only the second copy.  @xref{Option
4453 Summary,---occurrence}, for the description of @option{--occurrence}
4454 option.
4455
4456 @FIXME{ hag -- you might want to incorporate some of the above into the
4457 MMwtSN node; not sure.  i didn't know how to make it simpler...
4458
4459 There are a few ways to get around this.  Xref to Multiple Members
4460 with the Same Name, maybe.}
4461
4462 @cindex Members, replacing with other members
4463 @cindex Replacing members with other members
4464 @xopindex{delete, using before --append}
4465 If you want to replace an archive member, use @option{--delete} to
4466 delete the member you want to remove from the archive, and then use
4467 @option{--append} to add the member you want to be in the archive.  Note
4468 that you can not change the order of the archive; the most recently
4469 added member will still appear last.  In this sense, you cannot truly
4470 ``replace'' one member with another.  (Replacing one member with another
4471 will not work on certain types of media, such as tapes; see @ref{delete}
4472 and @ref{Media}, for more information.)
4473
4474 @menu
4475 * appending files::             Appending Files to an Archive
4476 * multiple::
4477 @end menu
4478
4479 @node appending files
4480 @subsubsection Appending Files to an Archive
4481 @cindex Adding files to an Archive
4482 @cindex Appending files to an Archive
4483 @cindex Archives, Appending files to
4484 @opindex append
4485
4486 The simplest way to add a file to an already existing archive is the
4487 @option{--append} (@option{-r}) operation, which writes specified
4488 files into the archive whether or not they are already among the
4489 archived files.
4490
4491 When you use @option{--append}, you @emph{must} specify file name
4492 arguments, as there is no default.  If you specify a file that already
4493 exists in the archive, another copy of the file will be added to the
4494 end of the archive.  As with other operations, the member names of the
4495 newly added files will be exactly the same as their names given on the
4496 command line.  The @option{--verbose} (@option{-v}) option will print
4497 out the names of the files as they are written into the archive.
4498
4499 @option{--append} cannot be performed on some tape drives, unfortunately,
4500 due to deficiencies in the formats those tape drives use.  The archive
4501 must be a valid @command{tar} archive, or else the results of using this
4502 operation will be unpredictable.  @xref{Media}.
4503
4504 To demonstrate using @option{--append} to add a file to an archive,
4505 create a file called @file{rock} in the @file{practice} directory.
4506 Make sure you are in the @file{practice} directory.  Then, run the
4507 following @command{tar} command to add @file{rock} to
4508 @file{collection.tar}:
4509
4510 @smallexample
4511 $ @kbd{tar --append --file=collection.tar rock}
4512 @end smallexample
4513
4514 @noindent
4515 If you now use the @option{--list} (@option{-t}) operation, you will see that
4516 @file{rock} has been added to the archive:
4517
4518 @smallexample
4519 $ @kbd{tar --list --file=collection.tar}
4520 -rw-r--r-- me user     28 1996-10-18 16:31 jazz
4521 -rw-r--r-- me user     21 1996-09-23 16:44 blues
4522 -rw-r--r-- me user     20 1996-09-23 16:44 folk
4523 -rw-r--r-- me user     20 1996-09-23 16:44 rock
4524 @end smallexample
4525
4526 @node multiple
4527 @subsubsection Multiple Members with the Same Name
4528 @cindex members, multiple
4529 @cindex multiple members
4530
4531 You can use @option{--append} (@option{-r}) to add copies of files
4532 which have been updated since the archive was created.  (However, we
4533 do not recommend doing this since there is another @command{tar}
4534 option called @option{--update}; @xref{update}, for more information.
4535 We describe this use of @option{--append} here for the sake of
4536 completeness.)  When you extract the archive, the older version will
4537 be effectively lost.  This works because files are extracted from an
4538 archive in the order in which they were archived.  Thus, when the
4539 archive is extracted, a file archived later in time will replace a
4540 file of the same name which was archived earlier, even though the
4541 older version of the file will remain in the archive unless you delete
4542 all versions of the file.
4543
4544 Supposing you change the file @file{blues} and then append the changed
4545 version to @file{collection.tar}.  As you saw above, the original
4546 @file{blues} is in the archive @file{collection.tar}.  If you change the
4547 file and append the new version of the file to the archive, there will
4548 be two copies in the archive.  When you extract the archive, the older
4549 version of the file will be extracted first, and then replaced by the
4550 newer version when it is extracted.
4551
4552 You can append the new, changed copy of the file @file{blues} to the
4553 archive in this way:
4554
4555 @smallexample
4556 $ @kbd{tar --append --verbose --file=collection.tar blues}
4557 blues
4558 @end smallexample
4559
4560 @noindent
4561 Because you specified the @option{--verbose} option, @command{tar} has
4562 printed the name of the file being appended as it was acted on.  Now
4563 list the contents of the archive:
4564
4565 @smallexample
4566 $ @kbd{tar --list --verbose --file=collection.tar}
4567 -rw-r--r-- me user     28 1996-10-18 16:31 jazz
4568 -rw-r--r-- me user     21 1996-09-23 16:44 blues
4569 -rw-r--r-- me user     20 1996-09-23 16:44 folk
4570 -rw-r--r-- me user     20 1996-09-23 16:44 rock
4571 -rw-r--r-- me user     58 1996-10-24 18:30 blues
4572 @end smallexample
4573
4574 @noindent
4575 The newest version of @file{blues} is now at the end of the archive
4576 (note the different creation dates and file sizes).  If you extract
4577 the archive, the older version of the file @file{blues} will be
4578 replaced by the newer version.  You can confirm this by extracting
4579 the archive and running @samp{ls} on the directory.
4580
4581 If you wish to extract the first occurrence of the file @file{blues}
4582 from the archive, use @option{--occurrence} option, as shown in
4583 the following example:
4584
4585 @smallexample
4586 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4587 -rw-r--r-- me user     21 1996-09-23 16:44 blues
4588 @end smallexample
4589
4590 @xref{Writing}, for more information on @option{--extract} and
4591 see @ref{Option Summary, --occurrence}, for a description of
4592 @option{--occurrence} option.
4593
4594 @node update
4595 @subsection Updating an Archive
4596 @cindex Updating an archive
4597 @opindex update
4598
4599 In the previous section, you learned how to use @option{--append} to
4600 add a file to an existing archive.  A related operation is
4601 @option{--update} (@option{-u}).  The @option{--update} operation
4602 updates a @command{tar} archive by comparing the date of the specified
4603 archive members against the date of the file with the same name.  If
4604 the file has been modified more recently than the archive member, then
4605 the newer version of the file is added to the archive (as with
4606 @option{--append}).
4607
4608 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4609 The operation will fail.
4610
4611 @FIXME{other examples of media on which --update will fail?  need to ask
4612 charles and/or mib/thomas/dave shevett..}
4613
4614 Both @option{--update} and @option{--append} work by adding to the end
4615 of the archive.  When you extract a file from the archive, only the
4616 version stored last will wind up in the file system, unless you use
4617 the @option{--backup} option.  @xref{multiple}, for a detailed discussion.
4618
4619 @menu
4620 * how to update::
4621 @end menu
4622
4623 @node how to update
4624 @subsubsection How to Update an Archive Using @option{--update}
4625 @opindex update
4626
4627 You must use file name arguments with the @option{--update}
4628 (@option{-u}) operation.  If you don't specify any files,
4629 @command{tar} won't act on any files and won't tell you that it didn't
4630 do anything (which may end up confusing you).
4631
4632 @c note: the above parenthetical added because in fact, this
4633 @c behavior just confused the author. :-)
4634
4635 To see the @option{--update} option at work, create a new file,
4636 @file{classical}, in your practice directory, and some extra text to the
4637 file @file{blues}, using any text editor.  Then invoke @command{tar} with
4638 the @samp{update} operation and the @option{--verbose} (@option{-v})
4639 option specified, using the names of all the files in the @file{practice}
4640 directory as file name arguments:
4641
4642 @smallexample
4643 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4644 blues
4645 classical
4646 $
4647 @end smallexample
4648
4649 @noindent
4650 Because we have specified verbose mode, @command{tar} prints out the names
4651 of the files it is working on, which in this case are the names of the
4652 files that needed to be updated.  If you run @samp{tar --list} and look
4653 at the archive, you will see @file{blues} and @file{classical} at its
4654 end.  There will be a total of two versions of the member @samp{blues};
4655 the one at the end will be newer and larger, since you added text before
4656 updating it.
4657
4658 The reason @command{tar} does not overwrite the older file when updating
4659 it is because writing to the middle of a section of tape is a difficult
4660 process.  Tapes are not designed to go backward.  @xref{Media}, for more
4661 information about tapes.
4662
4663 @option{--update} (@option{-u}) is not suitable for performing backups for two
4664 reasons: it does not change directory content entries, and it
4665 lengthens the archive every time it is used.  The @GNUTAR{}
4666 options intended specifically for backups are more
4667 efficient.  If you need to run backups, please consult @ref{Backups}.
4668
4669 @node concatenate
4670 @subsection Combining Archives with @option{--concatenate}
4671
4672 @cindex Adding archives to an archive
4673 @cindex Concatenating Archives
4674 @opindex concatenate
4675 @opindex catenate
4676 @c @cindex @option{-A} described
4677 Sometimes it may be convenient to add a second archive onto the end of
4678 an archive rather than adding individual files to the archive.  To add
4679 one or more archives to the end of another archive, you should use the
4680 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4681
4682 To use @option{--concatenate}, give the first archive with
4683 @option{--file} option and name the rest of archives to be
4684 concatenated on the command line.  The members, and their member
4685 names, will be copied verbatim from those archives to the first
4686 one@footnote{This can cause multiple members to have the same name.  For
4687 information on how this affects reading the archive, see @ref{multiple}.}.
4688 The new, concatenated archive will be called by the same name as the
4689 one given with the @option{--file} option.  As usual, if you omit
4690 @option{--file}, @command{tar} will use the value of the environment
4691 variable @env{TAPE}, or, if this has not been set, the default archive name.
4692
4693 @FIXME{There is no way to specify a new name...}
4694
4695 To demonstrate how @option{--concatenate} works, create two small archives
4696 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4697 files from @file{practice}:
4698
4699 @smallexample
4700 $ @kbd{tar -cvf bluesrock.tar blues rock}
4701 blues
4702 rock
4703 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4704 folk
4705 jazz
4706 @end smallexample
4707
4708 @noindent
4709 If you like, You can run @samp{tar --list} to make sure the archives
4710 contain what they are supposed to:
4711
4712 @smallexample
4713 $ @kbd{tar -tvf bluesrock.tar}
4714 -rw-r--r-- melissa user    105 1997-01-21 19:42 blues
4715 -rw-r--r-- melissa user     33 1997-01-20 15:34 rock
4716 $ @kbd{tar -tvf jazzfolk.tar}
4717 -rw-r--r-- melissa user     20 1996-09-23 16:44 folk
4718 -rw-r--r-- melissa user     65 1997-01-30 14:15 jazz
4719 @end smallexample
4720
4721 We can concatenate these two archives with @command{tar}:
4722
4723 @smallexample
4724 $ @kbd{cd ..}
4725 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4726 @end smallexample
4727
4728 If you now list the contents of the @file{bluesrock.tar}, you will see
4729 that now it also contains the archive members of @file{jazzfolk.tar}:
4730
4731 @smallexample
4732 $ @kbd{tar --list --file=bluesrock.tar}
4733 blues
4734 rock
4735 folk
4736 jazz
4737 @end smallexample
4738
4739 When you use @option{--concatenate}, the source and target archives must
4740 already exist and must have been created using compatible format
4741 parameters.  Notice, that @command{tar} does not check whether the
4742 archives it concatenates have compatible formats, it does not
4743 even check if the files are really tar archives.
4744
4745 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4746 tape drives, due to deficiencies in the formats those tape drives use.
4747
4748 @cindex @code{concatenate} vs @command{cat}
4749 @cindex @command{cat} vs @code{concatenate}
4750 It may seem more intuitive to you to want or try to use @command{cat} to
4751 concatenate two archives instead of using the @option{--concatenate}
4752 operation; after all, @command{cat} is the utility for combining files.
4753
4754 However, @command{tar} archives incorporate an end-of-file marker which
4755 must be removed if the concatenated archives are to be read properly as
4756 one archive.  @option{--concatenate} removes the end-of-archive marker
4757 from the target archive before each new archive is appended.  If you use
4758 @command{cat} to combine the archives, the result will not be a valid
4759 @command{tar} format archive.  If you need to retrieve files from an
4760 archive that was added to using the @command{cat} utility, use the
4761 @option{--ignore-zeros} (@option{-i}) option.  @xref{Ignore Zeros}, for further
4762 information on dealing with archives improperly combined using the
4763 @command{cat} shell utility.
4764
4765 @node delete
4766 @subsection Removing Archive Members Using @option{--delete}
4767 @cindex Deleting files from an archive
4768 @cindex Removing files from an archive
4769
4770 @opindex delete
4771 You can remove members from an archive by using the @option{--delete}
4772 option.  Specify the name of the archive with @option{--file}
4773 (@option{-f}) and then specify the names of the members to be deleted;
4774 if you list no member names, nothing will be deleted.  The
4775 @option{--verbose} option will cause @command{tar} to print the names
4776 of the members as they are deleted. As with @option{--extract}, you
4777 must give the exact member names when using @samp{tar --delete}.
4778 @option{--delete} will remove all versions of the named file from the
4779 archive.  The @option{--delete} operation can run very slowly.
4780
4781 Unlike other operations, @option{--delete} has no short form.
4782
4783 @cindex Tapes, using @option{--delete} and
4784 @cindex Deleting from tape archives
4785 This operation will rewrite the archive.  You can only use
4786 @option{--delete} on an archive if the archive device allows you to
4787 write to any point on the media, such as a disk; because of this, it
4788 does not work on magnetic tapes.  Do not try to delete an archive member
4789 from a magnetic tape; the action will not succeed, and you will be
4790 likely to scramble the archive and damage your tape.  There is no safe
4791 way (except by completely re-writing the archive) to delete files from
4792 most kinds of magnetic tape.  @xref{Media}.
4793
4794 To delete all versions of the file @file{blues} from the archive
4795 @file{collection.tar} in the @file{practice} directory, make sure you
4796 are in that directory, and then,
4797
4798 @smallexample
4799 $ @kbd{tar --list --file=collection.tar}
4800 blues
4801 folk
4802 jazz
4803 rock
4804 $ @kbd{tar --delete --file=collection.tar blues}
4805 $ @kbd{tar --list --file=collection.tar}
4806 folk
4807 jazz
4808 rock
4809 @end smallexample
4810
4811 @FIXME{Check if the above listing is actually produced after running
4812 all the examples on collection.tar.}
4813
4814 The @option{--delete} option has been reported to work properly when
4815 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4816
4817 @node compare
4818 @subsection Comparing Archive Members with the File System
4819 @cindex Verifying the currency of an archive
4820
4821 @opindex compare
4822 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4823 specified archive members against files with the same names, and then
4824 reports differences in file size, mode, owner, modification date and
4825 contents.  You should @emph{only} specify archive member names, not file
4826 names.  If you do not name any members, then @command{tar} will compare the
4827 entire archive.  If a file is represented in the archive but does not
4828 exist in the file system, @command{tar} reports a difference.
4829
4830 You have to specify the record size of the archive when modifying an
4831 archive with a non-default record size.
4832
4833 @command{tar} ignores files in the file system that do not have
4834 corresponding members in the archive.
4835
4836 The following example compares the archive members @file{rock},
4837 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4838 files of the same name in the file system.  (Note that there is no file,
4839 @file{funk}; @command{tar} will report an error message.)
4840
4841 @smallexample
4842 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4843 rock
4844 blues
4845 tar: funk not found in archive
4846 @end smallexample
4847
4848 The spirit behind the @option{--compare} (@option{--diff},
4849 @option{-d}) option is to check whether the archive represents the
4850 current state of files on disk, more than validating the integrity of
4851 the archive media.  For this latter goal, see @ref{verify}.
4852
4853 @node create options
4854 @section Options Used by @option{--create}
4855
4856 @xopindex{create, additional options}
4857 The previous chapter described the basics of how to use
4858 @option{--create} (@option{-c}) to create an archive from a set of files.
4859 @xref{create}.  This section described advanced options to be used with
4860 @option{--create}.
4861
4862 @menu
4863 * override::                  Overriding File Metadata.
4864 * Ignore Failed Read::
4865 @end menu
4866
4867 @node override
4868 @subsection Overriding File Metadata
4869
4870 As described above, a @command{tar} archive keeps, for each member it contains,
4871 its @dfn{metadata}, such as modification time, mode and ownership of
4872 the file.  @GNUTAR{} allows to replace these data with other values
4873 when adding files to the archive.  The options described in this
4874 section affect creation of archives of any type.  For POSIX archives,
4875 see also @ref{PAX keywords}, for additional ways of controlling
4876 metadata, stored in the archive.
4877
4878 @table @option
4879 @opindex mode
4880 @item --mode=@var{permissions}
4881
4882 When adding files to an archive, @command{tar} will use
4883 @var{permissions} for the archive members, rather than the permissions
4884 from the files.  @var{permissions} can be specified either as an octal
4885 number or as symbolic permissions, like with
4886 @command{chmod} (@xref{File permissions, Permissions, File
4887 permissions, fileutils, @acronym{GNU} file utilities}.  This reference
4888 also has useful information for those not being overly familiar with
4889 the UNIX permission system).  Using latter syntax allows for
4890 more flexibility.  For example, the value @samp{a+rw} adds read and write
4891 permissions for everybody, while retaining executable bits on directories
4892 or on any other file already marked as executable:
4893
4894 @smallexample
4895 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4896 @end smallexample
4897
4898 @item --mtime=@var{date}
4899 @opindex mtime
4900
4901 When adding files to an archive, @command{tar} will use @var{date} as
4902 the modification time of members when creating archives, instead of
4903 their actual modification times.  The argument @var{date} can be
4904 either a textual date representation in almost arbitrary format
4905 (@pxref{Date input formats}) or a name of an existing file, starting
4906 with @samp{/} or @samp{.}.  In the latter case, the modification time
4907 of that file will be used.
4908
4909 The following example will set the modification date to 00:00:00,
4910 January 1, 1970:
4911
4912 @smallexample
4913 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4914 @end smallexample
4915
4916 @noindent
4917 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4918 will try to convert the specified date back to its textual
4919 representation and compare it with the one given with
4920 @option{--mtime} options.  If the two dates differ, @command{tar} will
4921 print a warning saying what date it will use.  This is to help user
4922 ensure he is using the right date.
4923
4924 For example:
4925
4926 @smallexample
4927 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4928 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4929 13:06:29.152478
4930 @dots{}
4931 @end smallexample
4932
4933 @item --owner=@var{user}
4934 @opindex owner
4935
4936 Specifies that @command{tar} should use @var{user} as the owner of members
4937 when creating archives, instead of the user associated with the source
4938 file.  The argument @var{user} can be either an existing user symbolic
4939 name, or a decimal numeric user @acronym{ID}.
4940
4941 There is no value indicating a missing number, and @samp{0} usually means
4942 @code{root}.  Some people like to force @samp{0} as the value to offer in
4943 their distributions for the owner of files, because the @code{root} user is
4944 anonymous anyway, so that might as well be the owner of anonymous
4945 archives.  For example:
4946
4947 @smallexample
4948 $ @kbd{tar -c -f archive.tar --owner=0 .}
4949 @end smallexample
4950
4951 @noindent
4952 or:
4953
4954 @smallexample
4955 $ @kbd{tar -c -f archive.tar --owner=root .}
4956 @end smallexample
4957
4958 @item --group=@var{group}
4959 @opindex group
4960
4961 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
4962 rather than the group from the source file.  The argument @var{group}
4963 can be either an existing group symbolic name, or a decimal numeric group @acronym{ID}.
4964 @end table
4965
4966 @node Ignore Failed Read
4967 @subsection Ignore Fail Read
4968
4969 @table @option
4970 @item --ignore-failed-read
4971 @opindex ignore-failed-read
4972 Do not exit with nonzero on unreadable files or directories.
4973 @end table
4974
4975 @node extract options
4976 @section Options Used by @option{--extract}
4977 @cindex options for use with @option{--extract}
4978
4979 @xopindex{extract, additional options}
4980 The previous chapter showed how to use @option{--extract} to extract
4981 an archive into the file system.  Various options cause @command{tar} to
4982 extract more information than just file contents, such as the owner,
4983 the permissions, the modification date, and so forth.  This section
4984 presents options to be used with @option{--extract} when certain special
4985 considerations arise.  You may review the information presented in
4986 @ref{extract} for more basic information about the
4987 @option{--extract} operation.
4988
4989 @menu
4990 * Reading::                     Options to Help Read Archives
4991 * Writing::                     Changing How @command{tar} Writes Files
4992 * Scarce::                      Coping with Scarce Resources
4993 @end menu
4994
4995 @node Reading
4996 @subsection Options to Help Read Archives
4997 @cindex Options when reading archives
4998
4999 @cindex Reading incomplete records
5000 @cindex Records, incomplete
5001 @opindex read-full-records
5002 Normally, @command{tar} will request data in full record increments from
5003 an archive storage device.  If the device cannot return a full record,
5004 @command{tar} will report an error.  However, some devices do not always
5005 return full records, or do not require the last record of an archive to
5006 be padded out to the next record boundary.  To keep reading until you
5007 obtain a full record, or to accept an incomplete record if it contains
5008 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5009 in conjunction with the @option{--extract} or @option{--list} operations.
5010 @xref{Blocking}.
5011
5012 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5013 @command{tar} reads an archive from standard input, or from a remote
5014 machine.  This is because on @acronym{BSD} Unix systems, attempting to read a
5015 pipe returns however much happens to be in the pipe, even if it is
5016 less than was requested.  If this option were not enabled, @command{tar}
5017 would fail as soon as it read an incomplete record from the pipe.
5018
5019 If you're not sure of the blocking factor of an archive, you can
5020 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5021 @option{--blocking-factor=@var{512-size}} (@option{-b
5022 @var{512-size}}), using a blocking factor larger than what the archive
5023 uses.  This lets you avoid having to determine the blocking factor
5024 of an archive.  @xref{Blocking Factor}.
5025
5026 @menu
5027 * read full records::
5028 * Ignore Zeros::
5029 @end menu
5030
5031 @node read full records
5032 @unnumberedsubsubsec Reading Full Records
5033
5034 @FIXME{need sentence or so of intro here}
5035
5036 @table @option
5037 @opindex read-full-records
5038 @item --read-full-records
5039 @item -B
5040 Use in conjunction with @option{--extract} (@option{--get},
5041 @option{-x}) to read an archive which contains incomplete records, or
5042 one which has a blocking factor less than the one specified.
5043 @end table
5044
5045 @node Ignore Zeros
5046 @unnumberedsubsubsec Ignoring Blocks of Zeros
5047
5048 @cindex End-of-archive blocks, ignoring
5049 @cindex Ignoring end-of-archive blocks
5050 @opindex ignore-zeros
5051 Normally, @command{tar} stops reading when it encounters a block of zeros
5052 between file entries (which usually indicates the end of the archive).
5053 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5054 completely read an archive which contains a block of zeros before the
5055 end (i.e., a damaged archive, or one that was created by concatenating
5056 several archives together).
5057
5058 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5059 versions of @command{tar} write garbage after the end-of-archive entry,
5060 since that part of the media is never supposed to be read.  @GNUTAR{}
5061 does not write after the end of an archive, but seeks to
5062 maintain compatibility among archiving utilities.
5063
5064 @table @option
5065 @item --ignore-zeros
5066 @itemx -i
5067 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5068 encountered while reading an archive.  Use in conjunction with
5069 @option{--extract} or @option{--list}.
5070 @end table
5071
5072 @node Writing
5073 @subsection Changing How @command{tar} Writes Files
5074 @UNREVISED
5075
5076 @FIXME{Introductory paragraph}
5077
5078 @menu
5079 * Dealing with Old Files::
5080 * Overwrite Old Files::
5081 * Keep Old Files::
5082 * Keep Newer Files::
5083 * Unlink First::
5084 * Recursive Unlink::
5085 * Data Modification Times::
5086 * Setting Access Permissions::
5087 * Directory Modification Times and Permissions::
5088 * Writing to Standard Output::
5089 * Writing to an External Program::
5090 * remove files::
5091 @end menu
5092
5093 @node Dealing with Old Files
5094 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5095
5096 @xopindex{overwrite-dir, introduced}
5097 When extracting files, if @command{tar} discovers that the extracted
5098 file already exists, it normally replaces the file by removing it before
5099 extracting it, to prevent confusion in the presence of hard or symbolic
5100 links.  (If the existing file is a symbolic link, it is removed, not
5101 followed.)  However, if a directory cannot be removed because it is
5102 nonempty, @command{tar} normally overwrites its metadata (ownership,
5103 permission, etc.).  The @option{--overwrite-dir} option enables this
5104 default behavior.  To be more cautious and preserve the metadata of
5105 such a directory, use the @option{--no-overwrite-dir} option.
5106
5107 @cindex Overwriting old files, prevention
5108 @xopindex{keep-old-files, introduced}
5109 To be even more cautious and prevent existing files from being replaced, use
5110 the @option{--keep-old-files} (@option{-k}) option.  It causes @command{tar} to refuse
5111 to replace or update a file that already exists, i.e., a file with the
5112 same name as an archive member prevents extraction of that archive
5113 member.  Instead, it reports an error.
5114
5115 @xopindex{overwrite, introduced}
5116 To be more aggressive about altering existing files, use the
5117 @option{--overwrite} option.  It causes @command{tar} to overwrite
5118 existing files and to follow existing symbolic links when extracting.
5119
5120 @cindex Protecting old files
5121 Some people argue that @GNUTAR{} should not hesitate
5122 to overwrite files with other files when extracting.  When extracting
5123 a @command{tar} archive, they expect to see a faithful copy of the
5124 state of the file system when the archive was created.  It is debatable
5125 that this would always be a proper behavior.  For example, suppose one
5126 has an archive in which @file{usr/local} is a link to
5127 @file{usr/local2}.  Since then, maybe the site removed the link and
5128 renamed the whole hierarchy from @file{/usr/local2} to
5129 @file{/usr/local}.  Such things happen all the time.  I guess it would
5130 not be welcome at all that @GNUTAR{} removes the
5131 whole hierarchy just to make room for the link to be reinstated
5132 (unless it @emph{also} simultaneously restores the full
5133 @file{/usr/local2}, of course!)  @GNUTAR{} is indeed
5134 able to remove a whole hierarchy to reestablish a symbolic link, for
5135 example, but @emph{only if} @option{--recursive-unlink} is specified
5136 to allow this behavior.  In any case, single files are silently
5137 removed.
5138
5139 @xopindex{unlink-first, introduced}
5140 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5141 some cases by causing @command{tar} to remove files unconditionally
5142 before extracting them.
5143
5144 @node Overwrite Old Files
5145 @unnumberedsubsubsec Overwrite Old Files
5146
5147 @table @option
5148 @opindex overwrite
5149 @item --overwrite
5150 Overwrite existing files and directory metadata when extracting files
5151 from an archive.
5152
5153 This causes @command{tar} to write extracted files into the file system without
5154 regard to the files already on the system; i.e., files with the same
5155 names as archive members are overwritten when the archive is extracted.
5156 It also causes @command{tar} to extract the ownership, permissions,
5157 and time stamps onto any preexisting files or directories.
5158 If the name of a corresponding file name is a symbolic link, the file
5159 pointed to by the symbolic link will be overwritten instead of the
5160 symbolic link itself (if this is possible).  Moreover, special devices,
5161 empty directories and even symbolic links are automatically removed if
5162 they are in the way of extraction.
5163
5164 Be careful when using the @option{--overwrite} option, particularly when
5165 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5166 can change the contents, ownership or permissions of any file on your
5167 system.  Also, many systems do not take kindly to overwriting files that
5168 are currently being executed.
5169
5170 @opindex overwrite-dir
5171 @item --overwrite-dir
5172 Overwrite the metadata of directories when extracting files from an
5173 archive, but remove other files before extracting.
5174 @end table
5175
5176 @node Keep Old Files
5177 @unnumberedsubsubsec Keep Old Files
5178
5179 @table @option
5180 @opindex keep-old-files
5181 @item --keep-old-files
5182 @itemx -k
5183 Do not replace existing files from archive.  The
5184 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
5185 from replacing existing files with files with the same name from the
5186 archive. The @option{--keep-old-files} option is meaningless with
5187 @option{--list} (@option{-t}).  Prevents @command{tar} from replacing
5188 files in the file system during extraction.
5189 @end table
5190
5191 @node Keep Newer Files
5192 @unnumberedsubsubsec Keep Newer Files
5193
5194 @table @option
5195 @opindex keep-newer-files
5196 @item --keep-newer-files
5197 Do not replace existing files that are newer than their archive
5198 copies.  This option is meaningless with @option{--list} (@option{-t}).
5199 @end table
5200
5201 @node Unlink First
5202 @unnumberedsubsubsec Unlink First
5203
5204 @table @option
5205 @opindex unlink-first
5206 @item --unlink-first
5207 @itemx -U
5208 Remove files before extracting over them.
5209 This can make @command{tar} run a bit faster if you know in advance
5210 that the extracted files all need to be removed.  Normally this option
5211 slows @command{tar} down slightly, so it is disabled by default.
5212 @end table
5213
5214 @node Recursive Unlink
5215 @unnumberedsubsubsec Recursive Unlink
5216
5217 @table @option
5218 @opindex recursive-unlink
5219 @item --recursive-unlink
5220 When this option is specified, try removing files and directory hierarchies
5221 before extracting over them.  @emph{This is a dangerous option!}
5222 @end table
5223
5224 If you specify the @option{--recursive-unlink} option,
5225 @command{tar} removes @emph{anything} that keeps you from extracting a file
5226 as far as current permissions will allow it.  This could include removal
5227 of the contents of a full directory hierarchy.
5228
5229 @node Data Modification Times
5230 @unnumberedsubsubsec Setting Data Modification Times
5231
5232 @cindex Data modification times of extracted files
5233 @cindex Modification times of extracted files
5234 Normally, @command{tar} sets the data modification times of extracted
5235 files to the corresponding times recorded for the files in the archive, but
5236 limits the permissions of extracted files by the current @code{umask}
5237 setting.
5238
5239 To set the data modification times of extracted files to the time when
5240 the files were extracted, use the @option{--touch} (@option{-m}) option in
5241 conjunction with @option{--extract} (@option{--get}, @option{-x}).
5242
5243 @table @option
5244 @opindex touch
5245 @item --touch
5246 @itemx -m
5247 Sets the data modification time of extracted archive members to the time
5248 they were extracted, not the time recorded for them in the archive.
5249 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
5250 @end table
5251
5252 @node Setting Access Permissions
5253 @unnumberedsubsubsec Setting Access Permissions
5254
5255 @cindex Permissions of extracted files
5256 @cindex Modes of extracted files
5257 To set the modes (access permissions) of extracted files to those
5258 recorded for those files in the archive, use @option{--same-permissions}
5259 in conjunction with the @option{--extract} (@option{--get},
5260 @option{-x}) operation.
5261
5262 @table @option
5263 @opindex preserve-permissions
5264 @opindex same-permissions
5265 @item --preserve-permissions
5266 @itemx --same-permissions
5267 @c @itemx --ignore-umask
5268 @itemx -p
5269 Set modes of extracted archive members to those recorded in the
5270 archive, instead of current umask settings.  Use in conjunction with
5271 @option{--extract} (@option{--get}, @option{-x}).
5272 @end table
5273
5274 @node Directory Modification Times and Permissions
5275 @unnumberedsubsubsec Directory Modification Times and Permissions
5276
5277 After successfully extracting a file member, @GNUTAR{} normally
5278 restores its permissions and modification times, as described in the
5279 previous sections.  This cannot be done for directories, because
5280 after extracting a directory @command{tar} will almost certainly
5281 extract files into that directory and this will cause the directory
5282 modification time to be updated.  Moreover, restoring that directory
5283 permissions may not permit file creation within it.  Thus, restoring
5284 directory permissions and modification times must be delayed at least
5285 until all files have been extracted into that directory.  @GNUTAR{}
5286 restores directories using the following approach.
5287
5288 The extracted directories are created with the mode specified in the
5289 archive, as modified by the umask of the user, which gives sufficient
5290 permissions to allow file creation.  The meta-information about the
5291 directory is recorded in the temporary list of directories.  When
5292 preparing to extract next archive member, @GNUTAR{} checks if the
5293 directory prefix of this file contains the remembered directory.  If
5294 it does not, the program assumes that all files have been extracted
5295 into that directory, restores its modification time and permissions
5296 and removes its entry from the internal list.  This approach allows
5297 to correctly restore directory meta-information in the majority of
5298 cases, while keeping memory requirements sufficiently small.  It is
5299 based on the fact, that most @command{tar} archives use the predefined
5300 order of members: first the directory, then all the files and
5301 subdirectories in that directory.
5302
5303 However, this is not always true.  The most important exception are
5304 incremental archives (@pxref{Incremental Dumps}).  The member order in
5305 an incremental archive is reversed: first all directory members are
5306 stored, followed by other (non-directory) members.  So, when extracting
5307 from incremental archives, @GNUTAR{} alters the above procedure.  It
5308 remembers all restored directories, and restores their meta-data
5309 only after the entire archive has been processed.  Notice, that you do
5310 not need to specify any special options for that, as @GNUTAR{}
5311 automatically detects archives in incremental format.
5312
5313 There may be cases, when such processing is required for normal archives
5314 too.  Consider the following example:
5315
5316 @smallexample
5317 @group
5318 $ @kbd{tar --no-recursion -cvf archive \
5319     foo foo/file1 bar bar/file foo/file2}
5320 foo/
5321 foo/file1
5322 bar/
5323 bar/file
5324 foo/file2
5325 @end group
5326 @end smallexample
5327
5328 During the normal operation, after encountering @file{bar}
5329 @GNUTAR{} will assume that all files from the directory @file{foo}
5330 were already extracted and will therefore restore its timestamp and
5331 permission bits.  However, after extracting @file{foo/file2} the
5332 directory timestamp will be offset again.
5333
5334 To correctly restore directory meta-information in such cases, use
5335 the @option{--delay-directory-restore} command line option:
5336
5337 @table @option
5338 @opindex delay-directory-restore
5339 @item --delay-directory-restore
5340 Delays restoring of the modification times and permissions of extracted
5341 directories until the end of extraction.  This way, correct
5342 meta-information is restored even if the archive has unusual member
5343 ordering.
5344
5345 @opindex no-delay-directory-restore
5346 @item --no-delay-directory-restore
5347 Cancel the effect of the previous @option{--delay-directory-restore}.
5348 Use this option if you have used @option{--delay-directory-restore} in
5349 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5350 temporarily disable it.
5351 @end table
5352
5353 @node Writing to Standard Output
5354 @unnumberedsubsubsec Writing to Standard Output
5355
5356 @cindex Writing extracted files to standard output
5357 @cindex Standard output, writing extracted files to
5358 To write the extracted files to the standard output, instead of
5359 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5360 conjunction with @option{--extract} (@option{--get}, @option{-x}).  This option is useful if you are
5361 extracting files to send them through a pipe, and do not need to
5362 preserve them in the file system.  If you extract multiple members,
5363 they appear on standard output concatenated, in the order they are
5364 found in the archive.
5365
5366 @table @option
5367 @opindex to-stdout
5368 @item --to-stdout
5369 @itemx -O
5370 Writes files to the standard output.  Use only in conjunction with
5371 @option{--extract} (@option{--get}, @option{-x}).  When this option is
5372 used, instead of creating the files specified, @command{tar} writes
5373 the contents of the files extracted to its standard output.  This may
5374 be useful if you are only extracting the files in order to send them
5375 through a pipe.  This option is meaningless with @option{--list}
5376 (@option{-t}).
5377 @end table
5378
5379 This can be useful, for example, if you have a tar archive containing
5380 a big file and don't want to store the file on disk before processing
5381 it.  You can use a command like this:
5382
5383 @smallexample
5384 tar -xOzf foo.tgz bigfile | process
5385 @end smallexample
5386
5387 or even like this if you want to process the concatenation of the files:
5388
5389 @smallexample
5390 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5391 @end smallexample
5392
5393 However, @option{--to-command} may be more convenient for use with
5394 multiple files. See the next section.
5395
5396 @node Writing to an External Program
5397 @unnumberedsubsubsec Writing to an External Program
5398
5399 You can instruct @command{tar} to send the contents of each extracted
5400 file to the standard input of an external program:
5401
5402 @table @option
5403 @opindex to-command
5404 @item --to-command=@var{command}
5405 Extract files and pipe their contents to the standard input of
5406 @var{command}. When this option is used, instead of creating the
5407 files specified, @command{tar} invokes @var{command} and pipes the
5408 contents of the files to its standard output. The @var{command} may
5409 contain command line arguments. The program is executed via
5410 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
5411 extracted. Non-regular files (directories, etc.) are ignored when this
5412 option is used.
5413 @end table
5414
5415 The command can obtain the information about the file it processes
5416 from the following environment variables:
5417
5418 @table @env
5419 @vrindex TAR_FILETYPE, to-command environment
5420 @item TAR_FILETYPE
5421 Type of the file. It is a single letter with the following meaning:
5422
5423 @multitable @columnfractions 0.10 0.90
5424 @item f @tab Regular file
5425 @item d @tab Directory
5426 @item l @tab Symbolic link
5427 @item h @tab Hard link
5428 @item b @tab Block device
5429 @item c @tab Character device
5430 @end multitable
5431
5432 Currently only regular files are supported.
5433
5434 @vrindex TAR_MODE, to-command environment
5435 @item TAR_MODE
5436 File mode, an octal number.
5437
5438 @vrindex TAR_FILENAME, to-command environment
5439 @item TAR_FILENAME
5440 The name of the file.
5441
5442 @vrindex TAR_REALNAME, to-command environment
5443 @item TAR_REALNAME
5444 Name of the file as stored in the archive.
5445
5446 @vrindex TAR_UNAME, to-command environment
5447 @item TAR_UNAME
5448 Name of the file owner.
5449
5450 @vrindex TAR_GNAME, to-command environment
5451 @item TAR_GNAME
5452 Name of the file owner group.
5453
5454 @vrindex TAR_ATIME, to-command environment
5455 @item TAR_ATIME
5456 Time of last access. It is a decimal number, representing seconds
5457 since the Epoch.  If the archive provides times with nanosecond
5458 precision, the nanoseconds are appended to the timestamp after a
5459 decimal point.
5460
5461 @vrindex TAR_MTIME, to-command environment
5462 @item TAR_MTIME
5463 Time of last modification.
5464
5465 @vrindex TAR_CTIME, to-command environment
5466 @item TAR_CTIME
5467 Time of last status change.
5468
5469 @vrindex TAR_SIZE, to-command environment
5470 @item TAR_SIZE
5471 Size of the file.
5472
5473 @vrindex TAR_UID, to-command environment
5474 @item TAR_UID
5475 UID of the file owner.
5476
5477 @vrindex TAR_GID, to-command environment
5478 @item TAR_GID
5479 GID of the file owner.
5480 @end table
5481
5482 Additionally, the following variables contain information about
5483 tar mode and the archive being processed:
5484
5485 @table @env
5486 @vrindex TAR_VERSION, to-command environment
5487 @item TAR_VERSION
5488 @GNUTAR{} version number.
5489
5490 @vrindex TAR_ARCHIVE, to-command environment
5491 @item TAR_ARCHIVE
5492 The name of the archive @command{tar} is processing.
5493
5494 @vrindex TAR_BLOCKING_FACTOR, to-command environment
5495 @item TAR_BLOCKING_FACTOR
5496 Current blocking factor (@pxref{Blocking}).
5497
5498 @vrindex TAR_VOLUME, to-command environment
5499 @item TAR_VOLUME
5500 Ordinal number of the volume @command{tar} is processing.
5501
5502 @vrindex TAR_FORMAT, to-command environment
5503 @item TAR_FORMAT
5504 Format of the archive being processed. @xref{Formats}, for a complete
5505 list of archive format names.
5506 @end table
5507
5508 If @var{command} exits with a non-0 status, @command{tar} will print
5509 an error message similar to the following:
5510
5511 @smallexample
5512 tar: 2345: Child returned status 1
5513 @end smallexample
5514
5515 Here, @samp{2345} is the PID of the finished process.
5516
5517 If this behavior is not wanted, use @option{--ignore-command-error}:
5518
5519 @table @option
5520 @opindex ignore-command-error
5521 @item --ignore-command-error
5522 Ignore exit codes of subprocesses.  Notice that if the program
5523 exits on signal or otherwise terminates abnormally, the error message
5524 will be printed even if this option is used.
5525
5526 @opindex no-ignore-command-error
5527 @item --no-ignore-command-error
5528 Cancel the effect of any previous @option{--ignore-command-error}
5529 option. This option is useful if you have set
5530 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5531 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5532 @end table
5533
5534 @node remove files
5535 @unnumberedsubsubsec Removing Files
5536
5537 @FIXME{The section is too terse. Something more to add? An example,
5538 maybe?}
5539
5540 @table @option
5541 @opindex remove-files
5542 @item --remove-files
5543 Remove files after adding them to the archive.
5544 @end table
5545
5546 @node Scarce
5547 @subsection Coping with Scarce Resources
5548 @UNREVISED
5549
5550 @cindex Small memory
5551 @cindex Running out of space
5552
5553 @menu
5554 * Starting File::
5555 * Same Order::
5556 @end menu
5557
5558 @node Starting File
5559 @unnumberedsubsubsec Starting File
5560
5561 @table @option
5562 @opindex starting-file
5563 @item --starting-file=@var{name}
5564 @itemx -K @var{name}
5565 Starts an operation in the middle of an archive.  Use in conjunction
5566 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5567 @end table
5568
5569 @cindex Middle of the archive, starting in the
5570 If a previous attempt to extract files failed due to lack of disk
5571 space, you can use @option{--starting-file=@var{name}} (@option{-K
5572 @var{name}}) to start extracting only after member @var{name} of the
5573 archive.  This assumes, of course, that there is now free space, or
5574 that you are now extracting into a different file system.  (You could
5575 also choose to suspend @command{tar}, remove unnecessary files from
5576 the file system, and then resume the same @command{tar} operation.
5577 In this case, @option{--starting-file} is not necessary.)  See also
5578 @ref{interactive}, and @ref{exclude}.
5579
5580 @node Same Order
5581 @unnumberedsubsubsec Same Order
5582
5583 @table @option
5584 @cindex Large lists of file names on small machines
5585 @opindex same-order
5586 @opindex preserve-order
5587 @item --same-order
5588 @itemx --preserve-order
5589 @itemx -s
5590 To process large lists of file names on machines with small amounts of
5591 memory.  Use in conjunction with @option{--compare} (@option{--diff},
5592 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5593 (@option{--get}, @option{-x}).
5594 @end table
5595
5596 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5597 names to be listed or extracted is sorted in the same order as the
5598 files in the archive.  This allows a large list of names to be used,
5599 even on a small machine that would not otherwise be able to hold all
5600 the names in memory at the same time.  Such a sorted list can easily be
5601 created by running @samp{tar -t} on the archive and editing its output.
5602
5603 This option is probably never needed on modern computer systems.
5604
5605 @node backup
5606 @section Backup options
5607
5608 @cindex backup options
5609
5610 @GNUTAR{} offers options for making backups of files
5611 before writing new versions.  These options control the details of
5612 these backups.  They may apply to the archive itself before it is
5613 created or rewritten, as well as individual extracted members.  Other
5614 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5615 and @command{mv}, for example) offer similar options.
5616
5617 Backup options may prove unexpectedly useful when extracting archives
5618 containing many members having identical name, or when extracting archives
5619 on systems having file name limitations, making different members appear
5620 as having similar names through the side-effect of name truncation.
5621 @FIXME{This is true only if we have a good scheme for truncated backup names,
5622 which I'm not sure at all: I suspect work is needed in this area.}
5623 When any existing file is backed up before being overwritten by extraction,
5624 then clashing files are automatically be renamed to be unique, and the
5625 true name is kept for only the last file of a series of clashing files.
5626 By using verbose mode, users may track exactly what happens.
5627
5628 At the detail level, some decisions are still experimental, and may
5629 change in the future, we are waiting comments from our users.  So, please
5630 do not learn to depend blindly on the details of the backup features.
5631 For example, currently, directories themselves are never renamed through
5632 using these options, so, extracting a file over a directory still has
5633 good chances to fail.  Also, backup options apply to created archives,
5634 not only to extracted members.  For created archives, backups will not
5635 be attempted when the archive is a block or character device, or when it
5636 refers to a remote file.
5637
5638 For the sake of simplicity and efficiency, backups are made by renaming old
5639 files prior to creation or extraction, and not by copying.  The original
5640 name is restored if the file creation fails.  If a failure occurs after a
5641 partial extraction of a file, both the backup and the partially extracted
5642 file are kept.
5643
5644 @table @samp
5645 @item --backup[=@var{method}]
5646 @opindex backup
5647 @vindex VERSION_CONTROL
5648 @cindex backups
5649 Back up files that are about to be overwritten or removed.
5650 Without this option, the original versions are destroyed.
5651
5652 Use @var{method} to determine the type of backups made.
5653 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5654 environment variable.  And if @env{VERSION_CONTROL} is not set,
5655 use the @samp{existing} method.
5656
5657 @vindex version-control @r{Emacs variable}
5658 This option corresponds to the Emacs variable @samp{version-control};
5659 the same values for @var{method} are accepted as in Emacs.  This option
5660 also allows more descriptive names.  The valid @var{method}s are:
5661
5662 @table @samp
5663 @item t
5664 @itemx numbered
5665 @cindex numbered @r{backup method}
5666 Always make numbered backups.
5667
5668 @item nil
5669 @itemx existing
5670 @cindex existing @r{backup method}
5671 Make numbered backups of files that already have them, simple backups
5672 of the others.
5673
5674 @item never
5675 @itemx simple
5676 @cindex simple @r{backup method}
5677 Always make simple backups.
5678
5679 @end table
5680
5681 @item --suffix=@var{suffix}
5682 @opindex suffix
5683 @cindex backup suffix
5684 @vindex SIMPLE_BACKUP_SUFFIX
5685 Append @var{suffix} to each backup file made with @option{--backup}.  If this
5686 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5687 environment variable is used.  And if @env{SIMPLE_BACKUP_SUFFIX} is not
5688 set, the default is @samp{~}, just as in Emacs.
5689
5690 @end table
5691
5692 @node Applications
5693 @section Notable @command{tar} Usages
5694 @UNREVISED
5695
5696 @FIXME{Using Unix file linking capability to recreate directory
5697 structures---linking files into one subdirectory and then
5698 @command{tar}ring that directory.}
5699
5700 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5701
5702 @findex uuencode
5703 You can easily use archive files to transport a group of files from
5704 one system to another: put all relevant files into an archive on one
5705 computer system, transfer the archive to another system, and extract
5706 the contents there.  The basic transfer medium might be magnetic tape,
5707 Internet FTP, or even electronic mail (though you must encode the
5708 archive with @command{uuencode} in order to transport it properly by
5709 mail).  Both machines do not have to use the same operating system, as
5710 long as they both support the @command{tar} program.
5711
5712 For example, here is how you might copy a directory's contents from
5713 one disk to another, while preserving the dates, modes, owners and
5714 link-structure of all the files therein.  In this case, the transfer
5715 medium is a @dfn{pipe}:
5716
5717 @smallexample
5718 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5719 @end smallexample
5720
5721 @noindent
5722 You can avoid subshells by using @option{-C} option:
5723
5724 @smallexample
5725 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5726 @end smallexample
5727
5728 @noindent
5729 The command also works using long option forms:
5730
5731 @smallexample
5732 @group
5733 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5734        | (cd targetdir; tar --extract --file=-)}
5735 @end group
5736 @end smallexample
5737
5738 @noindent
5739 or
5740
5741 @smallexample
5742 @group
5743 $ @kbd{tar --directory sourcedir --create --file=- . \
5744        | tar --directory targetdir --extract --file=-}
5745 @end group
5746 @end smallexample
5747
5748 @noindent
5749 This is one of the easiest methods to transfer a @command{tar} archive.
5750
5751 @node looking ahead
5752 @section Looking Ahead: The Rest of this Manual
5753
5754 You have now seen how to use all eight of the operations available to
5755 @command{tar}, and a number of the possible options.  The next chapter
5756 explains how to choose and change file and archive names, how to use
5757 files to store names of other files which you can then call as
5758 arguments to @command{tar} (this can help you save time if you expect to
5759 archive the same list of files a number of times), and so forth.
5760 @FIXME{in case it's not obvious, i'm making this up in some sense
5761 based on my limited memory of what the next chapter *really* does.  i
5762 just wanted to flesh out this final section a little bit so i'd
5763 remember to stick it in here. :-)}
5764
5765 If there are too many files to conveniently list on the command line,
5766 you can list the names in a file, and @command{tar} will read that file.
5767 @xref{files}.
5768
5769 There are various ways of causing @command{tar} to skip over some files,
5770 and not archive them.  @xref{Choosing}.
5771
5772 @node Backups
5773 @chapter Performing Backups and Restoring Files
5774 @cindex backups
5775
5776 @GNUTAR{} is distributed along with the scripts for performing backups
5777 and restores.  Even if there is a good chance those scripts may be
5778 satisfying to you, they are not the only scripts or methods available for doing
5779 backups and restore.  You may well create your own, or use more
5780 sophisticated packages dedicated to that purpose.
5781
5782 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5783 Automatic Network Disk Archiver), a backup system developed by James
5784 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5785 This is free software, and it is available from @uref{http://www.amanda.org}.
5786
5787 @FIXME{
5788
5789 Here is a possible plan for a future documentation about the backuping
5790 scripts which are provided within the @GNUTAR{}
5791 distribution.
5792
5793 @itemize @bullet
5794 @item dumps
5795  @itemize @minus
5796  @item what are dumps
5797  @item different levels of dumps
5798   @itemize +
5799   @item full dump = dump everything
5800   @item level 1, level 2 dumps etc
5801         A level @var{n} dump dumps everything changed since the last level
5802         @var{n}-1 dump (?)
5803   @end itemize
5804  @item how to use scripts for dumps  (ie, the concept)
5805   @itemize +
5806   @item scripts to run after editing backup specs (details)
5807   @end itemize
5808  @item Backup Specs, what is it.
5809   @itemize +
5810   @item how to customize
5811   @item actual text of script  [/sp/dump/backup-specs]
5812   @end itemize
5813  @item Problems
5814   @itemize +
5815    @item rsh doesn't work
5816    @item rtape isn't installed
5817    @item (others?)
5818   @end itemize
5819  @item the @option{--incremental} option of tar
5820  @item tapes
5821   @itemize +
5822   @item write protection
5823   @item types of media, different sizes and types, useful for different things
5824   @item files and tape marks
5825      one tape mark between files, two at end.
5826   @item positioning the tape
5827      MT writes two at end of write,
5828      backspaces over one when writing again.
5829   @end itemize
5830  @end itemize
5831 @end itemize
5832 }
5833
5834 This chapter documents both the provided shell scripts and @command{tar}
5835 options which are more specific to usage as a backup tool.
5836
5837 To @dfn{back up} a file system means to create archives that contain
5838 all the files in that file system.  Those archives can then be used to
5839 restore any or all of those files (for instance if a disk crashes or a
5840 file is accidentally deleted).  File system @dfn{backups} are also
5841 called @dfn{dumps}.
5842
5843 @menu
5844 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
5845 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
5846 * Backup Levels::               Levels of Backups
5847 * Backup Parameters::           Setting Parameters for Backups and Restoration
5848 * Scripted Backups::            Using the Backup Scripts
5849 * Scripted Restoration::        Using the Restore Script
5850 @end menu
5851
5852 @node Full Dumps
5853 @section Using @command{tar} to Perform Full Dumps
5854 @UNREVISED
5855
5856 @cindex full dumps
5857 @cindex dumps, full
5858
5859 @cindex corrupted archives
5860 Full dumps should only be made when no other people or programs
5861 are modifying files in the file system.  If files are modified while
5862 @command{tar} is making the backup, they may not be stored properly in
5863 the archive, in which case you won't be able to restore them if you
5864 have to.  (Files not being modified are written with no trouble, and do
5865 not corrupt the entire archive.)
5866
5867 You will want to use the @option{--label=@var{archive-label}}
5868 (@option{-V @var{archive-label}}) option to give the archive a
5869 volume label, so you can tell what this archive is even if the label
5870 falls off the tape, or anything like that.
5871
5872 Unless the file system you are dumping is guaranteed to fit on
5873 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5874 Make sure you have enough tapes on hand to complete the backup.
5875
5876 If you want to dump each file system separately you will need to use
5877 the @option{--one-file-system} option to prevent
5878 @command{tar} from crossing file system boundaries when storing
5879 (sub)directories.
5880
5881 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5882 option is not needed, since this is a complete copy of everything in
5883 the file system, and a full restore from this backup would only be
5884 done onto a completely
5885 empty disk.
5886
5887 Unless you are in a hurry, and trust the @command{tar} program (and your
5888 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5889 option, to make sure your files really made it onto the dump properly.
5890 This will also detect cases where the file was modified while (or just
5891 after) it was being archived.  Not all media (notably cartridge tapes)
5892 are capable of being verified, unfortunately.
5893
5894 @node Incremental Dumps
5895 @section Using @command{tar} to Perform Incremental Dumps
5896
5897 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5898 stores additional metadata so that exact state of the file system
5899 can be restored when extracting the archive.
5900
5901 @GNUTAR{} currently offers two options for handling incremental
5902 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5903 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5904
5905 @xopindex{listed-incremental, described}
5906 The option @option{--listed-incremental} instructs tar to operate on
5907 an incremental archive with additional metadata stored in a standalone
5908 file, called a @dfn{snapshot file}.  The purpose of this file is to help
5909 determine which files have been changed, added or deleted since the
5910 last backup, so that the next incremental backup will contain only
5911 modified files.  The name of the snapshot file is given as an argument
5912 to the option:
5913
5914 @table @option
5915 @item --listed-incremental=@var{file}
5916 @itemx -g @var{file}
5917   Handle incremental backups with snapshot data in @var{file}.
5918 @end table
5919
5920 To create an incremental backup, you would use
5921 @option{--listed-incremental} together with @option{--create}
5922 (@pxref{create}).  For example:
5923
5924 @smallexample
5925 $ @kbd{tar --create \
5926            --file=archive.1.tar \
5927            --listed-incremental=/var/log/usr.snar \
5928            /usr}
5929 @end smallexample
5930
5931 This will create in @file{archive.1.tar} an incremental backup of
5932 the @file{/usr} file system, storing additional metadata in the file
5933 @file{/var/log/usr.snar}.  If this file does not exist, it will be
5934 created.  The created archive will then be a @dfn{level 0 backup};
5935 please see the next section for more on backup levels.
5936
5937 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5938 determines which files are modified.  In this case only these files will be
5939 stored in the archive.  Suppose, for example, that after running the
5940 above command, you delete file @file{/usr/doc/old} and create
5941 directory @file{/usr/local/db} with the following contents:
5942
5943 @smallexample
5944 $ @kbd{ls /usr/local/db}
5945 /usr/local/db/data
5946 /usr/local/db/index
5947 @end smallexample
5948
5949 Some time later you create another incremental backup.  You will
5950 then see:
5951
5952 @smallexample
5953 $ @kbd{tar --create \
5954            --file=archive.2.tar \
5955            --listed-incremental=/var/log/usr.snar \
5956            /usr}
5957 tar: usr/local/db: Directory is new
5958 usr/local/db/
5959 usr/local/db/data
5960 usr/local/db/index
5961 @end smallexample
5962
5963 @noindent
5964 The created archive @file{archive.2.tar} will contain only these
5965 three members.  This archive is called a @dfn{level 1 backup}.  Notice
5966 that @file{/var/log/usr.snar} will be updated with the new data, so if
5967 you plan to create more @samp{level 1} backups, it is necessary to
5968 create a working copy of the snapshot file before running
5969 @command{tar}.  The above example will then be modified as follows:
5970
5971 @smallexample
5972 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5973 $ @kbd{tar --create \
5974            --file=archive.2.tar \
5975            --listed-incremental=/var/log/usr.snar-1 \
5976            /usr}
5977 @end smallexample
5978
5979 @anchor{--level=0}
5980 @xopindex{level, described}
5981 You can force @samp{level 0} backups either by removing the snapshot
5982 file before running @command{tar}, or by supplying the
5983 @option{--level=0} option, e.g.:
5984
5985 @smallexample
5986 $ @kbd{tar --create \
5987            --file=archive.2.tar \
5988            --listed-incremental=/var/log/usr.snar-0 \
5989            --level=0 \
5990            /usr}
5991 @end smallexample
5992
5993 Incremental dumps depend crucially on time stamps, so the results are
5994 unreliable if you modify a file's time stamps during dumping (e.g.,
5995 with the @option{--atime-preserve=replace} option), or if you set the clock
5996 backwards.
5997
5998 @anchor{device numbers}
5999 @cindex Device numbers, using in incremental backups
6000 Metadata stored in snapshot files include device numbers, which,
6001 obviously are supposed to be non-volatile values.  However, it turns
6002 out that @acronym{NFS} devices have undependable values when an automounter
6003 gets in the picture.  This can lead to a great deal of spurious
6004 redumping in incremental dumps, so it is somewhat useless to compare
6005 two @acronym{NFS} devices numbers over time.  The solution implemented
6006 currently is to consider all @acronym{NFS} devices as being equal
6007 when it comes to comparing directories; this is fairly gross, but
6008 there does not seem to be a better way to go.
6009
6010 Apart from using @acronym{NFS}, there are a number of cases where
6011 relying on device numbers can cause spurious redumping of unmodified
6012 files.  For example, this occurs when archiving @acronym{LVM} snapshot
6013 volumes.  To avoid this, use @option{--no-check-device} option:
6014
6015 @table @option
6016 @xopindex{no-check-device, described}
6017 @item --no-check-device
6018 Do not rely on device numbers when preparing a list of changed files
6019 for an incremental dump.
6020
6021 @xopindex{check-device, described}
6022 @item --check-device
6023 Use device numbers when preparing a list of changed files
6024 for an incremental dump.  This is the default behavior.  The purpose
6025 of this option is to undo the effect of the @option{--no-check-device}
6026 if it was given in @env{TAR_OPTIONS} environment variable
6027 (@pxref{TAR_OPTIONS}).
6028 @end table
6029
6030 There is also another way to cope with changing device numbers.  It is
6031 described in detail in @ref{Fixing Snapshot Files}.
6032
6033 Note that incremental archives use @command{tar} extensions and may
6034 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6035
6036 @xopindex{listed-incremental, using with @option{--extract}}
6037 @xopindex{extract, using with @option{--listed-incremental}}
6038 To extract from the incremental dumps, use
6039 @option{--listed-incremental} together with @option{--extract}
6040 option (@pxref{extracting files}).  In this case, @command{tar} does
6041 not need to access snapshot file, since all the data necessary for
6042 extraction are stored in the archive itself.  So, when extracting, you
6043 can give whatever argument to @option{--listed-incremental}, the usual
6044 practice is to use @option{--listed-incremental=/dev/null}.
6045 Alternatively, you can use @option{--incremental}, which needs no
6046 arguments.  In general, @option{--incremental} (@option{-G}) can be
6047 used as a shortcut for @option{--listed-incremental} when listing or
6048 extracting incremental backups (for more information regarding this
6049 option, @pxref{incremental-op}).
6050
6051 When extracting from the incremental backup @GNUTAR{} attempts to
6052 restore the exact state the file system had when the archive was
6053 created.  In particular, it will @emph{delete} those files in the file
6054 system that did not exist in their directories when the archive was
6055 created.  If you have created several levels of incremental files,
6056 then in order to restore the exact contents the file system  had when
6057 the last level was created, you will need to restore from all backups
6058 in turn.  Continuing our example, to restore the state of @file{/usr}
6059 file system, one would do@footnote{Notice, that since both archives
6060 were created without @option{-P} option (@pxref{absolute}), these
6061 commands should be run from the root file system.}:
6062
6063 @smallexample
6064 $ @kbd{tar --extract \
6065            --listed-incremental=/dev/null \
6066            --file archive.1.tar}
6067 $ @kbd{tar --extract \
6068            --listed-incremental=/dev/null \
6069            --file archive.2.tar}
6070 @end smallexample
6071
6072 To list the contents of an incremental archive, use @option{--list}
6073 (@pxref{list}), as usual.  To obtain more information about the
6074 archive, use @option{--listed-incremental} or @option{--incremental}
6075 combined with two @option{--verbose} options@footnote{Two
6076 @option{--verbose} options were selected to avoid breaking usual
6077 verbose listing output (@option{--list --verbose}) when using in
6078 scripts.
6079
6080 @xopindex{incremental, using with @option{--list}}
6081 @xopindex{listed-incremental, using with @option{--list}}
6082 @xopindex{list, using with @option{--incremental}}
6083 @xopindex{list, using with @option{--listed-incremental}}
6084 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6085 contents of the DUMPDIR header (with terminating nulls) when
6086 @option{--incremental} or @option{--listed-incremental} option was
6087 given, no matter what the verbosity level.  This behavior, and,
6088 especially, the binary output it produced were considered inconvenient
6089 and were changed in version 1.16.}:
6090
6091 @smallexample
6092 @kbd{tar --list --incremental --verbose --verbose archive.tar}
6093 @end smallexample
6094
6095 This command will print, for each directory in the archive, the list
6096 of files in that directory at the time the archive was created.  This
6097 information is put out in a format which is both human-readable and
6098 unambiguous for a program: each file name is printed as
6099
6100 @smallexample
6101 @var{x} @var{file}
6102 @end smallexample
6103
6104 @noindent
6105 where @var{x} is a letter describing the status of the file: @samp{Y}
6106 if the file  is present in the archive, @samp{N} if the file is not
6107 included in the archive, or a @samp{D} if the file is a directory (and
6108 is included in the archive).  @xref{Dumpdir}, for the detailed
6109 description of dumpdirs and status codes.  Each such
6110 line is terminated by a newline character.  The last line is followed
6111 by an additional newline to indicate the end of the data.
6112
6113 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6114 gives the same behavior as @option{--listed-incremental} when used
6115 with @option{--list} and @option{--extract} options.  When used with
6116 @option{--create} option, it creates an incremental archive without
6117 creating snapshot file.  Thus, it is impossible to create several
6118 levels of incremental backups with @option{--incremental} option.
6119
6120 @node Backup Levels
6121 @section Levels of Backups
6122
6123 An archive containing all the files in the file system is called a
6124 @dfn{full backup} or @dfn{full dump}.  You could insure your data by
6125 creating a full dump every day.  This strategy, however, would waste a
6126 substantial amount of archive media and user time, as unchanged files
6127 are daily re-archived.
6128
6129 It is more efficient to do a full dump only occasionally.  To back up
6130 files between full dumps, you can use @dfn{incremental dumps}.  A @dfn{level
6131 one} dump archives all the files that have changed since the last full
6132 dump.
6133
6134 A typical dump strategy would be to perform a full dump once a week,
6135 and a level one dump once a day.  This means some versions of files
6136 will in fact be archived more than once, but this dump strategy makes
6137 it possible to restore a file system to within one day of accuracy by
6138 only extracting two archives---the last weekly (full) dump and the
6139 last daily (level one) dump.  The only information lost would be in
6140 files changed or created since the last daily backup.  (Doing dumps
6141 more than once a day is usually not worth the trouble.)
6142
6143 @GNUTAR{} comes with scripts you can use to do full
6144 and level-one (actually, even level-two and so on) dumps.  Using
6145 scripts (shell programs) to perform backups and restoration is a
6146 convenient and reliable alternative to typing out file name lists
6147 and @command{tar} commands by hand.
6148
6149 Before you use these scripts, you need to edit the file
6150 @file{backup-specs}, which specifies parameters used by the backup
6151 scripts and by the restore script.  This file is usually located
6152 in @file{/etc/backup} directory.  @xref{Backup Parameters}, for its
6153 detailed description.  Once the backup parameters are set, you can
6154 perform backups or restoration by running the appropriate script.
6155
6156 The name of the backup script is @code{backup}.  The name of the
6157 restore script is @code{restore}.  The following sections describe
6158 their use in detail.
6159
6160 @emph{Please Note:} The backup and restoration scripts are
6161 designed to be used together.  While it is possible to restore files by
6162 hand from an archive which was created using a backup script, and to create
6163 an archive by hand which could then be extracted using the restore script,
6164 it is easier to use the scripts.  @xref{Incremental Dumps}, before
6165 making such an attempt.
6166
6167 @node Backup Parameters
6168 @section Setting Parameters for Backups and Restoration
6169
6170 The file @file{backup-specs} specifies backup parameters for the
6171 backup and restoration scripts provided with @command{tar}.  You must
6172 edit @file{backup-specs} to fit your system configuration and schedule
6173 before using these scripts.
6174
6175 Syntactically, @file{backup-specs} is a shell script, containing
6176 mainly variable assignments.  However, any valid shell construct
6177 is allowed in this file.  Particularly, you may wish to define
6178 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6179 For more information about shell script syntax, please refer to
6180 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6181 g_02, the definition of the Shell Command Language}.  See also
6182 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6183
6184 The shell variables controlling behavior of @code{backup} and
6185 @code{restore} are described in the following subsections.
6186
6187 @menu
6188 * General-Purpose Variables::
6189 * Magnetic Tape Control::
6190 * User Hooks::
6191 * backup-specs example::        An Example Text of @file{Backup-specs}
6192 @end menu
6193
6194 @node General-Purpose Variables
6195 @subsection General-Purpose Variables
6196
6197 @defvr {Backup variable} ADMINISTRATOR
6198 The user name of the backup administrator.  @code{Backup} scripts
6199 sends a backup report to this address.
6200 @end defvr
6201
6202 @defvr {Backup variable} BACKUP_HOUR
6203 The hour at which the backups are done.  This can be a number from 0
6204 to 23, or the time specification in form @var{hours}:@var{minutes},
6205 or the string @samp{now}.
6206
6207 This variable is used by @code{backup}.  Its value may be overridden
6208 using @option{--time} option (@pxref{Scripted Backups}).
6209 @end defvr
6210
6211 @defvr {Backup variable} TAPE_FILE
6212
6213 The device @command{tar} writes the archive to.  If @var{TAPE_FILE}
6214 is a remote archive (@pxref{remote-dev}), backup script will suppose
6215 that your @command{mt} is able to access remote devices.  If @var{RSH}
6216 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
6217 invocations of @command{mt}.
6218 @end defvr
6219
6220 @defvr {Backup variable} BLOCKING
6221
6222 The blocking factor @command{tar} will use when writing the dump archive.
6223 @xref{Blocking Factor}.
6224 @end defvr
6225
6226 @defvr {Backup variable} BACKUP_DIRS
6227
6228 A list of file systems to be dumped (for @code{backup}), or restored
6229 (for @code{restore}).  You can include any directory
6230 name in the list --- subdirectories on that file system will be
6231 included, regardless of how they may look to other networked machines.
6232 Subdirectories on other file systems will be ignored.
6233
6234 The host name specifies which host to run @command{tar} on, and should
6235 normally be the host that actually contains the file system.  However,
6236 the host machine must have @GNUTAR{} installed, and
6237 must be able to access the directory containing the backup scripts and
6238 their support files using the same file name that is used on the
6239 machine where the scripts are run (i.e., what @command{pwd} will print
6240 when in that directory on that machine).  If the host that contains
6241 the file system does not have this capability, you can specify another
6242 host as long as it can access the file system through @acronym{NFS}.
6243
6244 If the list of file systems is very long you may wish to put it
6245 in a separate file.  This file is usually named
6246 @file{/etc/backup/dirs}, but this name may be overridden in
6247 @file{backup-specs} using @code{DIRLIST} variable.
6248 @end defvr
6249
6250 @defvr {Backup variable} DIRLIST
6251
6252 The name of the file that contains a list of file systems to backup
6253 or restore.  By default it is @file{/etc/backup/dirs}.
6254 @end defvr
6255
6256 @defvr {Backup variable} BACKUP_FILES
6257
6258 A list of individual files to be dumped (for @code{backup}), or restored
6259 (for @code{restore}).  These should be accessible from the machine on
6260 which the backup script is run.
6261
6262 If the list of individual files is very long you may wish to store it
6263 in a separate file.  This file is usually named
6264 @file{/etc/backup/files}, but this name may be overridden in
6265 @file{backup-specs} using @code{FILELIST} variable.
6266 @end defvr
6267
6268 @defvr {Backup variable} FILELIST
6269
6270 The name of the file that contains a list of individual files to backup
6271 or restore.  By default it is @file{/etc/backup/files}.
6272 @end defvr
6273
6274 @defvr {Backup variable} MT
6275
6276 Full file name of @command{mt} binary.
6277 @end defvr
6278
6279 @defvr {Backup variable} RSH
6280 @anchor{RSH}
6281 Full file name of @command{rsh} binary or its equivalent.  You may wish to
6282 set it to @code{ssh}, to improve security.  In this case you will have
6283 to use public key authentication.
6284 @end defvr
6285
6286 @defvr {Backup variable} RSH_COMMAND
6287
6288 Full file name of @command{rsh} binary on remote machines.  This will
6289 be passed via @option{--rsh-command} option to the remote invocation
6290 of @GNUTAR{}.
6291 @end defvr
6292
6293 @defvr {Backup variable} VOLNO_FILE
6294
6295 Name of temporary file to hold volume numbers.  This needs to be accessible
6296 by all the machines which have file systems to be dumped.
6297 @end defvr
6298
6299 @defvr {Backup variable} XLIST
6300
6301 Name of @dfn{exclude file list}.  An @dfn{exclude file list} is a file
6302 located on the remote machine and containing the list of files to
6303 be excluded from the backup.  Exclude file lists are searched in
6304 /etc/tar-backup directory.  A common use for exclude file lists
6305 is to exclude files containing security-sensitive information
6306 (e.g., @file{/etc/shadow} from backups).
6307
6308 This variable affects only @code{backup}.
6309 @end defvr
6310
6311 @defvr {Backup variable} SLEEP_TIME
6312
6313 Time to sleep between dumps of any two successive file systems
6314
6315 This variable affects only @code{backup}.
6316 @end defvr
6317
6318 @defvr {Backup variable} DUMP_REMIND_SCRIPT
6319
6320 Script to be run when it's time to insert a new tape in for the next
6321 volume.  Administrators may want to tailor this script for their site.
6322 If this variable isn't set, @GNUTAR{} will display its built-in
6323 prompt, and will expect confirmation from the console.  For the
6324 description of the default prompt, see @ref{change volume prompt}.
6325
6326 @end defvr
6327
6328 @defvr {Backup variable} SLEEP_MESSAGE
6329
6330 Message to display on the terminal while waiting for dump time.  Usually
6331 this will just be some literal text.
6332 @end defvr
6333
6334 @defvr {Backup variable} TAR
6335
6336 Full file name of the @GNUTAR{} executable.  If this is not set, backup
6337 scripts will search @command{tar} in the current shell path.
6338 @end defvr
6339
6340 @node Magnetic Tape Control
6341 @subsection Magnetic Tape Control
6342
6343 Backup scripts access tape device using special @dfn{hook functions}.
6344 These functions take a single argument --- the name of the tape
6345 device.  Their names are kept in the following variables:
6346
6347 @defvr {Backup variable} MT_BEGIN
6348 The name of @dfn{begin} function.  This function is called before
6349 accessing the drive.  By default it retensions the tape:
6350
6351 @smallexample
6352 MT_BEGIN=mt_begin
6353
6354 mt_begin() @{
6355     mt -f "$1" retension
6356 @}
6357 @end smallexample
6358 @end defvr
6359
6360 @defvr {Backup variable} MT_REWIND
6361 The name of @dfn{rewind} function.  The default definition is as
6362 follows:
6363
6364 @smallexample
6365 MT_REWIND=mt_rewind
6366
6367 mt_rewind() @{
6368     mt -f "$1" rewind
6369 @}
6370 @end smallexample
6371
6372 @end defvr
6373
6374 @defvr {Backup variable} MT_OFFLINE
6375 The name of the function switching the tape off line.  By default
6376 it is defined as follows:
6377
6378 @smallexample
6379 MT_OFFLINE=mt_offline
6380
6381 mt_offline() @{
6382     mt -f "$1" offl
6383 @}
6384 @end smallexample
6385 @end defvr
6386
6387 @defvr {Backup variable} MT_STATUS
6388 The name of the function used to obtain the status of the archive device,
6389 including error count.  Default definition:
6390
6391 @smallexample
6392 MT_STATUS=mt_status
6393
6394 mt_status() @{
6395     mt -f "$1" status
6396 @}
6397 @end smallexample
6398 @end defvr
6399
6400 @node User Hooks
6401 @subsection User Hooks
6402
6403 @dfn{User hooks} are shell functions executed before and after
6404 each @command{tar} invocation.  Thus, there are @dfn{backup
6405 hooks}, which are executed before and after dumping each file
6406 system, and @dfn{restore hooks}, executed before and
6407 after restoring a file system.  Each user hook is a shell function
6408 taking four arguments:
6409
6410 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6411 Its arguments are:
6412
6413 @table @var
6414 @item level
6415 Current backup or restore level.
6416
6417 @item host
6418 Name or IP address of the host machine being dumped or restored.
6419
6420 @item fs
6421 Full file name of the file system being dumped or restored.
6422
6423 @item fsname
6424 File system name with directory separators replaced with colons.  This
6425 is useful, e.g., for creating unique files.
6426 @end table
6427 @end deffn
6428
6429 Following variables keep the names of user hook functions:
6430
6431 @defvr {Backup variable} DUMP_BEGIN
6432 Dump begin function.  It is executed before dumping the file system.
6433 @end defvr
6434
6435 @defvr {Backup variable} DUMP_END
6436 Executed after dumping the file system.
6437 @end defvr
6438
6439 @defvr {Backup variable} RESTORE_BEGIN
6440 Executed before restoring the file system.
6441 @end defvr
6442
6443 @defvr {Backup variable} RESTORE_END
6444 Executed after restoring the file system.
6445 @end defvr
6446
6447 @node backup-specs example
6448 @subsection An Example Text of @file{Backup-specs}
6449
6450 The following is an example of @file{backup-specs}:
6451
6452 @smallexample
6453 # site-specific parameters for file system backup.
6454
6455 ADMINISTRATOR=friedman
6456 BACKUP_HOUR=1
6457 TAPE_FILE=/dev/nrsmt0
6458
6459 # Use @code{ssh} instead of the less secure @code{rsh}
6460 RSH=/usr/bin/ssh
6461 RSH_COMMAND=/usr/bin/ssh
6462
6463 # Override MT_STATUS function:
6464 my_status() @{
6465       mts -t $TAPE_FILE
6466 @}
6467 MT_STATUS=my_status
6468
6469 # Disable MT_OFFLINE function
6470 MT_OFFLINE=:
6471
6472 BLOCKING=124
6473 BACKUP_DIRS="
6474         albert:/fs/fsf
6475         apple-gunkies:/gd
6476         albert:/fs/gd2
6477         albert:/fs/gp
6478         geech:/usr/jla
6479         churchy:/usr/roland
6480         albert:/
6481         albert:/usr
6482         apple-gunkies:/
6483         apple-gunkies:/usr
6484         gnu:/hack
6485         gnu:/u
6486         apple-gunkies:/com/mailer/gnu
6487         apple-gunkies:/com/archive/gnu"
6488
6489 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6490
6491 @end smallexample
6492
6493 @node Scripted Backups
6494 @section Using the Backup Scripts
6495
6496 The syntax for running a backup script is:
6497
6498 @smallexample
6499 backup --level=@var{level} --time=@var{time}
6500 @end smallexample
6501
6502 The @option{--level} option requests the dump level.  Thus, to produce
6503 a full dump, specify @code{--level=0} (this is the default, so
6504 @option{--level} may be omitted if its value is
6505 @code{0})@footnote{For backward compatibility, the @code{backup} will also
6506 try to deduce the requested dump level from the name of the
6507 script itself.  If the name consists of a string @samp{level-}
6508 followed by a single decimal digit, that digit is taken as
6509 the dump level number.  Thus, you may create a link from @code{backup}
6510 to @code{level-1} and then run @code{level-1} whenever you need to
6511 create a level one dump.}.
6512
6513 The @option{--time} option determines when should the backup be
6514 run.  @var{Time} may take three forms:
6515
6516 @table @asis
6517 @item @var{hh}:@var{mm}
6518
6519 The dump must be run at @var{hh} hours @var{mm} minutes.
6520
6521 @item @var{hh}
6522
6523 The dump must be run at @var{hh} hours.
6524
6525 @item now
6526
6527 The dump must be run immediately.
6528 @end table
6529
6530 You should start a script with a tape or disk mounted.  Once you
6531 start a script, it prompts you for new tapes or disks as it
6532 needs them.  Media volumes don't have to correspond to archive
6533 files --- a multi-volume archive can be started in the middle of a
6534 tape that already contains the end of another multi-volume archive.
6535 The @code{restore} script prompts for media by its archive volume,
6536 so to avoid an error message you should keep track of which tape
6537 (or disk) contains which volume of the archive (@pxref{Scripted
6538 Restoration}).
6539
6540 The backup scripts write two files on the file system.  The first is a
6541 record file in @file{/etc/tar-backup/}, which is used by the scripts
6542 to store and retrieve information about which files were dumped.  This
6543 file is not meant to be read by humans, and should not be deleted by
6544 them.  @xref{Snapshot Files}, for a more detailed explanation of this
6545 file.
6546
6547 The second file is a log file containing the names of the file systems
6548 and files dumped, what time the backup was made, and any error
6549 messages that were generated, as well as how much space was left in
6550 the media volume after the last volume of the archive was written.
6551 You should check this log file after every backup.  The file name is
6552 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6553 represents current date, and @var{n} represents current dump level number.
6554
6555 The script also prints the name of each system being dumped to the
6556 standard output.
6557
6558 Following is the full list of options accepted by @code{backup}
6559 script:
6560
6561 @table @option
6562 @item -l @var{level}
6563 @itemx --level=@var{level}
6564 Do backup level @var{level} (default 0).
6565
6566 @item -f
6567 @itemx --force
6568 Force backup even if today's log file already exists.
6569
6570 @item -v[@var{level}]
6571 @itemx --verbose[=@var{level}]
6572 Set verbosity level.  The higher the level is, the more debugging
6573 information will be output during execution.  Default @var{level}
6574 is 100, which means the highest debugging level.
6575
6576 @item -t @var{start-time}
6577 @itemx --time=@var{start-time}
6578 Wait till @var{time}, then do backup.
6579
6580 @item -h
6581 @itemx --help
6582 Display short help message and exit.
6583
6584 @item -V
6585 @itemx --version
6586 Display information about the program's name, version, origin and legal
6587 status, all on standard output, and then exit successfully.
6588 @end table
6589
6590
6591 @node Scripted Restoration
6592 @section Using the Restore Script
6593
6594 To restore files that were archived using a scripted backup, use the
6595 @code{restore} script.  Its usage is quite straightforward.  In the
6596 simplest form, invoke @code{restore --all}, it will
6597 then restore all the file systems and files specified in
6598 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6599
6600 You may select the file systems (and/or files) to restore by
6601 giving @code{restore} a list of @dfn{patterns} in its command
6602 line.  For example, running
6603
6604 @smallexample
6605 restore 'albert:*'
6606 @end smallexample
6607
6608 @noindent
6609 will restore all file systems on the machine @samp{albert}.  A more
6610 complicated example:
6611
6612 @smallexample
6613 restore 'albert:*' '*:/var'
6614 @end smallexample
6615
6616 @noindent
6617 This command will restore all file systems on the machine @samp{albert}
6618 as well as @file{/var} file system on all machines.
6619
6620 By default @code{restore} will start restoring files from the lowest
6621 available dump level (usually zero) and will continue through
6622 all available dump levels.  There may be situations where such a
6623 thorough restore is not necessary.  For example, you may wish to
6624 restore only files from the recent level one backup.  To do so,
6625 use @option{--level} option, as shown in the example below:
6626
6627 @smallexample
6628 restore --level=1
6629 @end smallexample
6630
6631 The full list of options accepted by @code{restore} follows:
6632
6633 @table @option
6634 @item -a
6635 @itemx --all
6636 Restore all file systems and files specified in @file{backup-specs}.
6637
6638 @item -l @var{level}
6639 @itemx --level=@var{level}
6640 Start restoring from the given backup level, instead of the default 0.
6641
6642 @item -v[@var{level}]
6643 @itemx --verbose[=@var{level}]
6644 Set verbosity level.  The higher the level is, the more debugging
6645 information will be output during execution.  Default @var{level}
6646 is 100, which means the highest debugging level.
6647
6648 @item -h
6649 @itemx --help
6650 Display short help message and exit.
6651
6652 @item -V
6653 @itemx --version
6654 Display information about the program's name, version, origin and legal
6655 status, all on standard output, and then exit successfully.
6656 @end table
6657
6658 You should start the restore script with the media containing the
6659 first volume of the archive mounted.  The script will prompt for other
6660 volumes as they are needed.  If the archive is on tape, you don't need
6661 to rewind the tape to to its beginning---if the tape head is
6662 positioned past the beginning of the archive, the script will rewind
6663 the tape as needed.  @xref{Tape Positioning}, for a discussion of tape
6664 positioning.
6665
6666 @quotation
6667 @strong{Warning:} The script will delete files from the active file
6668 system if they were not in the file system when the archive was made.
6669 @end quotation
6670
6671 @xref{Incremental Dumps}, for an explanation of how the script makes
6672 that determination.
6673
6674 @node Choosing
6675 @chapter Choosing Files and Names for @command{tar}
6676
6677 Certain options to @command{tar} enable you to specify a name for your
6678 archive.  Other options let you decide which files to include or exclude
6679 from the archive, based on when or whether files were modified, whether
6680 the file names do or don't match specified patterns, or whether files
6681 are in specified directories.
6682
6683 This chapter discusses these options in detail.
6684
6685 @menu
6686 * file::                        Choosing the Archive's Name
6687 * Selecting Archive Members::
6688 * files::                       Reading Names from a File
6689 * exclude::                     Excluding Some Files
6690 * wildcards::                   Wildcards Patterns and Matching
6691 * quoting styles::              Ways of Quoting Special Characters in Names
6692 * transform::                   Modifying File and Member Names
6693 * after::                       Operating Only on New Files
6694 * recurse::                     Descending into Directories
6695 * one::                         Crossing File System Boundaries
6696 @end menu
6697
6698 @node file
6699 @section Choosing and Naming Archive Files
6700
6701 @cindex Naming an archive
6702 @cindex Archive Name
6703 @cindex Choosing an archive file
6704 @cindex Where is the archive?
6705 @opindex file
6706 By default, @command{tar} uses an archive file name that was compiled when
6707 it was built on the system; usually this name refers to some physical
6708 tape drive on the machine.  However, the person who installed @command{tar}
6709 on the system may not have set the default to a meaningful value as far as
6710 most users are concerned.  As a result, you will usually want to tell
6711 @command{tar} where to find (or create) the archive.  The
6712 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6713 option allows you to either specify or name a file to use as the archive
6714 instead of the default archive file location.
6715
6716 @table @option
6717 @xopindex{file, short description}
6718 @item --file=@var{archive-name}
6719 @itemx -f @var{archive-name}
6720 Name the archive to create or operate on.  Use in conjunction with
6721 any operation.
6722 @end table
6723
6724 For example, in this @command{tar} command,
6725
6726 @smallexample
6727 $ @kbd{tar -cvf collection.tar blues folk jazz}
6728 @end smallexample
6729
6730 @noindent
6731 @file{collection.tar} is the name of the archive.  It must directly
6732 follow the @option{-f} option, since whatever directly follows @option{-f}
6733 @emph{will} end up naming the archive.  If you neglect to specify an
6734 archive name, you may end up overwriting a file in the working directory
6735 with the archive you create since @command{tar} will use this file's name
6736 for the archive name.
6737
6738 An archive can be saved as a file in the file system, sent through a
6739 pipe or over a network, or written to an I/O device such as a tape,
6740 floppy disk, or CD write drive.
6741
6742 @cindex Writing new archives
6743 @cindex Archive creation
6744 If you do not name the archive, @command{tar} uses the value of the
6745 environment variable @env{TAPE} as the file name for the archive.  If
6746 that is not available, @command{tar} uses a default, compiled-in archive
6747 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6748
6749 @cindex Standard input and output
6750 @cindex tar to standard input and output
6751 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6752 archive from standard input (when listing or extracting files), or
6753 writes it to standard output (when creating an archive).  If you use
6754 @file{-} as an @var{archive-name} when modifying an archive,
6755 @command{tar} reads the original archive from its standard input and
6756 writes the entire new archive to its standard output.
6757
6758 The following example is a convenient way of copying directory
6759 hierarchy from @file{sourcedir} to @file{targetdir}.
6760
6761 @smallexample
6762 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6763 @end smallexample
6764
6765 The @option{-C} option allows to avoid using subshells:
6766
6767 @smallexample
6768 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6769 @end smallexample
6770
6771 In both examples above, the leftmost @command{tar} invocation archives
6772 the contents of @file{sourcedir} to the standard output, while the
6773 rightmost one reads this archive from its standard input and
6774 extracts it.  The @option{-p} option tells it to restore permissions
6775 of the extracted files.
6776
6777 @cindex Remote devices
6778 @cindex tar to a remote device
6779 @anchor{remote-dev}
6780 To specify an archive file on a device attached to a remote machine,
6781 use the following:
6782
6783 @smallexample
6784 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6785 @end smallexample
6786
6787 @noindent
6788 @command{tar} will set up the remote connection, if possible, and
6789 prompt you for a username and password.  If you use
6790 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6791 will attempt to set up the remote connection using your username
6792 as the username on the remote machine.
6793
6794 @cindex Local and remote archives
6795 @anchor{local and remote archives}
6796 If the archive file name includes a colon (@samp{:}), then it is assumed
6797 to be a file on another machine.  If the archive file is
6798 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6799 host @var{host}.  The remote host is accessed using the @command{rsh}
6800 program, with a username of @var{user}.  If the username is omitted
6801 (along with the @samp{@@} sign), then your user name will be used.
6802 (This is the normal @command{rsh} behavior.)  It is necessary for the
6803 remote machine, in addition to permitting your @command{rsh} access, to
6804 have the @file{rmt} program installed (this command is included in
6805 the @GNUTAR{} distribution and by default is installed under
6806 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
6807 installation prefix).  If you need to use a file whose name includes a
6808 colon, then the remote tape drive behavior
6809 can be inhibited by using the @option{--force-local} option.
6810
6811 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6812 tries to minimize input and output operations.  The Amanda backup
6813 system, when used with @GNUTAR{}, has an initial sizing pass which
6814 uses this feature.
6815
6816 @node Selecting Archive Members
6817 @section Selecting Archive Members
6818 @cindex Specifying files to act on
6819 @cindex Specifying archive members
6820
6821 @dfn{File Name arguments} specify which files in the file system
6822 @command{tar} operates on, when creating or adding to an archive, or which
6823 archive members @command{tar} operates on, when reading or deleting from
6824 an archive.  @xref{Operations}.
6825
6826 To specify file names, you can include them as the last arguments on
6827 the command line, as follows:
6828 @smallexample
6829 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6830 @end smallexample
6831
6832 If a file name begins with dash (@samp{-}), precede it with
6833 @option{--add-file} option to prevent it from being treated as an
6834 option.
6835
6836 @anchor{input name quoting}
6837 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6838 name, replacing @dfn{escape sequences} according to the following
6839 table:
6840
6841 @multitable @columnfractions 0.20 0.60
6842 @headitem Escape @tab Replaced with
6843 @item \a         @tab Audible bell (@acronym{ASCII} 7)
6844 @item \b         @tab Backspace (@acronym{ASCII} 8)
6845 @item \f         @tab Form feed (@acronym{ASCII} 12)
6846 @item \n         @tab New line (@acronym{ASCII} 10)
6847 @item \r         @tab Carriage return (@acronym{ASCII} 13)
6848 @item \t         @tab Horizontal tabulation (@acronym{ASCII} 9)
6849 @item \v         @tab Vertical tabulation (@acronym{ASCII} 11)
6850 @item \?         @tab @acronym{ASCII} 127
6851 @item \@var{n}   @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6852                  of up to 3 digits)
6853 @end multitable
6854
6855 A backslash followed by any other symbol is retained.
6856
6857 This default behavior is controlled by the following command line
6858 option:
6859
6860 @table @option
6861 @opindex unquote
6862 @item --unquote
6863 Enable unquoting input file or member names (default).
6864
6865 @opindex no-unquote
6866 @item --no-unquote
6867 Disable unquoting input file or member names.
6868 @end table
6869
6870 If you specify a directory name as a file name argument, all the files
6871 in that directory are operated on by @command{tar}.
6872
6873 If you do not specify files, @command{tar} behavior differs depending
6874 on the operation mode as described below:
6875
6876 When @command{tar} is invoked with @option{--create} (@option{-c}),
6877 @command{tar} will stop immediately, reporting the following:
6878
6879 @smallexample
6880 @group
6881 $ @kbd{tar cf a.tar}
6882 tar: Cowardly refusing to create an empty archive
6883 Try `tar --help' or `tar --usage' for more information.
6884 @end group
6885 @end smallexample
6886
6887 If you specify either @option{--list} (@option{-t}) or
6888 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6889 operates on all the archive members in the archive.
6890
6891 If run with @option{--diff} option, tar will compare the archive with
6892 the contents of the current working directory.
6893
6894 If you specify any other operation, @command{tar} does nothing.
6895
6896 By default, @command{tar} takes file names from the command line.  However,
6897 there are other ways to specify file or member names, or to modify the
6898 manner in which @command{tar} selects the files or members upon which to
6899 operate.  In general, these methods work both for specifying the names
6900 of files and archive members.
6901
6902 @node files
6903 @section Reading Names from a File
6904
6905 @cindex Reading file names from a file
6906 @cindex Lists of file names
6907 @cindex File Name arguments, alternatives
6908 @cindex @command{find}, using with @command{tar}
6909 Instead of giving the names of files or archive members on the command
6910 line, you can put the names into a file, and then use the
6911 @option{--files-from=@var{file-of-names}} (@option{-T
6912 @var{file-of-names}}) option to @command{tar}.  Give the name of the
6913 file which contains the list of files to include as the argument to
6914 @option{--files-from}.  In the list, the file names should be separated by
6915 newlines.  You will frequently use this option when you have generated
6916 the list of files to archive with the @command{find} utility.
6917
6918 @table @option
6919 @opindex files-from
6920 @item --files-from=@var{file-name}
6921 @itemx -T @var{file-name}
6922 Get names to extract or create from file @var{file-name}.
6923 @end table
6924
6925 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6926 you specify either @code{--files-from=-} or @code{-T -}), then the file
6927 names are read from standard input.
6928
6929 Unless you are running @command{tar} with @option{--create}, you can not use
6930 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6931 command.
6932
6933 Any number of @option{-T} options can be given in the command line.
6934
6935 The following example shows how to use @command{find} to generate a list of
6936 files smaller than 400K in length and put that list into a file
6937 called @file{small-files}.  You can then use the @option{-T} option to
6938 @command{tar} to specify the files from that file, @file{small-files}, to
6939 create the archive @file{little.tgz}.  (The @option{-z} option to
6940 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6941 more information.)
6942
6943 @smallexample
6944 $ @kbd{find . -size -400 -print > small-files}
6945 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6946 @end smallexample
6947
6948 @noindent
6949 In the file list given by @option{-T} option, any file name beginning
6950 with @samp{-} character is considered a @command{tar} option and is
6951 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
6952 recognized only @option{-C} option in file lists, and only if the
6953 option and its argument occupied two consecutive lines.}. For example,
6954 the common use of this feature is to change to another directory by
6955 specifying @option{-C} option:
6956
6957 @smallexample
6958 @group
6959 $ @kbd{cat list}
6960 -C/etc
6961 passwd
6962 hosts
6963 -C/lib
6964 libc.a
6965 $ @kbd{tar -c -f foo.tar --files-from list}
6966 @end group
6967 @end smallexample
6968
6969 @noindent
6970 In this example, @command{tar} will first switch to @file{/etc}
6971 directory and add files @file{passwd} and @file{hosts} to the
6972 archive.  Then it will change to @file{/lib} directory and will archive
6973 the file @file{libc.a}.  Thus, the resulting archive @file{foo.tar} will
6974 contain:
6975
6976 @smallexample
6977 @group
6978 $ @kbd{tar tf foo.tar}
6979 passwd
6980 hosts
6981 libc.a
6982 @end group
6983 @end smallexample
6984
6985 @noindent
6986 @xopindex{directory, using in @option{--files-from} argument}
6987 Notice that the option parsing algorithm used with @option{-T} is
6988 stricter than the one used by shell.  Namely, when specifying option
6989 arguments, you should observe the following rules:
6990
6991 @itemize @bullet
6992 @item
6993 When using short (single-letter) option form, its argument must
6994 immediately follow the option letter, without any intervening
6995 whitespace.  For example: @code{-Cdir}.
6996
6997 @item
6998 When using long option form, the option argument must be separated
6999 from the option by a single equal sign.  No whitespace is allowed on
7000 any side of the equal sign.  For example: @code{--directory=dir}.
7001
7002 @item
7003 For both short and long option forms, the option argument can be given
7004 on the next line after the option name, e.g.:
7005
7006 @smallexample
7007 @group
7008 --directory
7009 dir
7010 @end group
7011 @end smallexample
7012
7013 @noindent
7014 and
7015
7016 @smallexample
7017 @group
7018 -C
7019 dir
7020 @end group
7021 @end smallexample
7022 @end itemize
7023
7024 @opindex add-file
7025 If you happen to have a file whose name starts with @samp{-},
7026 precede it with @option{--add-file} option to prevent it from
7027 being recognized as an option.  For example: @code{--add-file=--my-file}.
7028
7029 @menu
7030 * nul::
7031 @end menu
7032
7033 @node nul
7034 @subsection @code{NUL}-Terminated File Names
7035
7036 @cindex File names, terminated by @code{NUL}
7037 @cindex @code{NUL}-terminated file names
7038 The @option{--null} option causes
7039 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7040 to read file names terminated by a @code{NUL} instead of a newline, so
7041 files whose names contain newlines can be archived using
7042 @option{--files-from}.
7043
7044 @table @option
7045 @xopindex{null, described}
7046 @item --null
7047 Only consider @code{NUL}-terminated file names, instead of files that
7048 terminate in a newline.
7049
7050 @xopindex{no-null, described}
7051 @item --no-null
7052 Undo the effect of any previous @option{--null} option.
7053 @end table
7054
7055 The @option{--null} option is just like the one in @acronym{GNU}
7056 @command{xargs} and @command{cpio}, and is useful with the
7057 @option{-print0} predicate of @acronym{GNU} @command{find}.  In
7058 @command{tar}, @option{--null} also disables special handling for
7059 file names that begin with dash.
7060
7061 This example shows how to use @command{find} to generate a list of files
7062 larger than 800K in length and put that list into a file called
7063 @file{long-files}.  The @option{-print0} option to @command{find} is just
7064 like @option{-print}, except that it separates files with a @code{NUL}
7065 rather than with a newline.  You can then run @command{tar} with both the
7066 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7067 files from that file, @file{long-files}, to create the archive
7068 @file{big.tgz}.  The @option{--null} option to @command{tar} will cause
7069 @command{tar} to recognize the @code{NUL} separator between files.
7070
7071 @smallexample
7072 $ @kbd{find . -size +800 -print0 > long-files}
7073 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7074 @end smallexample
7075
7076 The @option{--no-null} option can be used if you need to read both
7077 @code{NUL}-terminated and newline-terminated files on the same command line.
7078 For example, if @file{flist} is a newline-terminated file, then the
7079 following command can be used to combine it with the above command:
7080
7081 @smallexample
7082 @group
7083 $ @kbd{find . -size +800 -print0 |
7084   tar -c -f big.tar --null -T - --no-null -T flist}
7085 @end group
7086 @end smallexample
7087
7088 This example uses short options for typographic reasons, to avoid
7089 very long lines.
7090
7091 @GNUTAR is able to automatically detect @code{NUL}-terminated file lists, so
7092 it is safe to use them even without the @option{--null} option.  In
7093 this case @command{tar} will print a warning and continue reading such
7094 a file as if @option{--null} were actually given:
7095
7096 @smallexample
7097 @group
7098 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7099 tar: -: file name read contains nul character
7100 @end group
7101 @end smallexample
7102
7103 The null terminator, however, remains in effect only for this
7104 particular file, any following @option{-T} options will assume
7105 newline termination.  Of course, the null autodetection applies
7106 to these eventual surplus @option{-T} options as well.
7107
7108 @node exclude
7109 @section Excluding Some Files
7110
7111 @cindex File names, excluding files by
7112 @cindex Excluding files by name and pattern
7113 @cindex Excluding files by file system
7114 @opindex exclude
7115 @opindex exclude-from
7116 To avoid operating on files whose names match a particular pattern,
7117 use the @option{--exclude} or @option{--exclude-from} options.
7118
7119 @table @option
7120 @opindex exclude
7121 @item --exclude=@var{pattern}
7122 Causes @command{tar} to ignore files that match the @var{pattern}.
7123 @end table
7124
7125 @findex exclude
7126 The @option{--exclude=@var{pattern}} option prevents any file or
7127 member whose name matches the shell wildcard (@var{pattern}) from
7128 being operated on.
7129 For example, to create an archive with all the contents of the directory
7130 @file{src} except for files whose names end in @file{.o}, use the
7131 command @samp{tar -cf src.tar --exclude='*.o' src}.
7132
7133 You may give multiple @option{--exclude} options.
7134
7135 @table @option
7136 @opindex exclude-from
7137 @item --exclude-from=@var{file}
7138 @itemx -X @var{file}
7139 Causes @command{tar} to ignore files that match the patterns listed in
7140 @var{file}.
7141 @end table
7142
7143 @findex exclude-from
7144 Use the @option{--exclude-from} option to read a
7145 list of patterns, one per line, from @var{file}; @command{tar} will
7146 ignore files matching those patterns.  Thus if @command{tar} is
7147 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7148 single line @file{*.o}, no files whose names end in @file{.o} will be
7149 added to the archive.
7150
7151 Notice, that lines from @var{file} are read verbatim. One of the
7152 frequent errors is leaving some extra whitespace after a file name,
7153 which is difficult to catch using text editors.
7154
7155 However, empty lines are OK.
7156
7157 @table @option
7158 @cindex version control system, excluding files
7159 @cindex VCS, excluding files
7160 @cindex SCCS, excluding files
7161 @cindex RCS, excluding files
7162 @cindex CVS, excluding files
7163 @cindex SVN, excluding files
7164 @cindex git, excluding files
7165 @cindex Bazaar, excluding files
7166 @cindex Arch, excluding files
7167 @cindex Mercurial, excluding files
7168 @cindex Darcs, excluding files
7169 @opindex exclude-vcs
7170 @item --exclude-vcs
7171 Exclude files and directories used by following version control
7172 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
7173 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
7174
7175 As of version @value{VERSION}, the following files are excluded:
7176
7177 @itemize @bullet
7178 @item @file{CVS/}, and everything under it
7179 @item @file{RCS/}, and everything under it
7180 @item @file{SCCS/}, and everything under it
7181 @item @file{.git/}, and everything under it
7182 @item @file{.gitignore}
7183 @item @file{.cvsignore}
7184 @item @file{.svn/}, and everything under it
7185 @item @file{.arch-ids/}, and everything under it
7186 @item @file{@{arch@}/}, and everything under it
7187 @item @file{=RELEASE-ID}
7188 @item @file{=meta-update}
7189 @item @file{=update}
7190 @item @file{.bzr}
7191 @item @file{.bzrignore}
7192 @item @file{.bzrtags}
7193 @item @file{.hg}
7194 @item @file{.hgignore}
7195 @item @file{.hgrags}
7196 @item @file{_darcs}
7197 @end itemize
7198
7199 @opindex exclude-backups
7200 @item --exclude-backups
7201 Exclude backup and lock files.  This option causes exclusion of files
7202 that match the following shell globbing patterns:
7203
7204 @table @asis
7205 @item .#*
7206 @item *~
7207 @item #*#
7208 @end table
7209
7210 @end table
7211
7212 @findex exclude-caches
7213 When creating an archive, the @option{--exclude-caches} option family
7214 causes @command{tar} to exclude all directories that contain a @dfn{cache
7215 directory tag}. A cache directory tag is a short file with the
7216 well-known name @file{CACHEDIR.TAG} and having a standard header
7217 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
7218 Various applications write cache directory tags into directories they
7219 use to hold regenerable, non-precious data, so that such data can be
7220 more easily excluded from backups.
7221
7222 There are three @samp{exclude-caches} options, each providing a different
7223 exclusion semantics:
7224
7225 @table @option
7226 @opindex exclude-caches
7227 @item --exclude-caches
7228 Do not archive the contents of the directory, but archive the
7229 directory itself and the @file{CACHEDIR.TAG} file.
7230
7231 @opindex exclude-caches-under
7232 @item --exclude-caches-under
7233 Do not archive the contents of the directory, nor the
7234 @file{CACHEDIR.TAG} file, archive only the directory itself.
7235
7236 @opindex exclude-caches-all
7237 @item --exclude-caches-all
7238 Omit directories containing @file{CACHEDIR.TAG} file entirely.
7239 @end table
7240
7241 @findex exclude-tag
7242 Another option family, @option{--exclude-tag}, provides a generalization of
7243 this concept.  It takes a single argument, a file name to look for.
7244 Any directory that contains this file will be excluded from the dump.
7245 Similarly to @samp{exclude-caches}, there are three options in this
7246 option family:
7247
7248 @table @option
7249 @opindex exclude-tag
7250 @item --exclude-tag=@var{file}
7251 Do not dump the contents of the directory, but dump the
7252 directory itself and the @var{file}.
7253
7254 @opindex exclude-tag-under
7255 @item --exclude-tag-under=@var{file}
7256 Do not dump the contents of the directory, nor the
7257 @var{file}, archive only the directory itself.
7258
7259 @opindex exclude-tag-all
7260 @item --exclude-tag-all=@var{file}
7261 Omit directories containing @var{file} file entirely.
7262 @end table
7263
7264 Multiple @option{--exclude-tag*} options can be given.
7265
7266 For example, given this directory:
7267
7268 @smallexample
7269 @group
7270 $ @kbd{find dir}
7271 dir
7272 dir/blues
7273 dir/jazz
7274 dir/folk
7275 dir/folk/tagfile
7276 dir/folk/sanjuan
7277 dir/folk/trote
7278 @end group
7279 @end smallexample
7280
7281 The @option{--exclude-tag} will produce the following:
7282
7283 @smallexample
7284 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
7285 dir/
7286 dir/blues
7287 dir/jazz
7288 dir/folk/
7289 tar: dir/folk/: contains a cache directory tag tagfile;
7290   contents not dumped
7291 dir/folk/tagfile
7292 @end smallexample
7293
7294 Both the @file{dir/folk} directory and its tagfile are preserved in
7295 the archive, however the rest of files in this directory are not.
7296
7297 Now, using the @option{--exclude-tag-under} option will exclude
7298 @file{tagfile} from the dump, while still preserving the directory
7299 itself, as shown in this example:
7300
7301 @smallexample
7302 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
7303 dir/
7304 dir/blues
7305 dir/jazz
7306 dir/folk/
7307 ./tar: dir/folk/: contains a cache directory tag tagfile;
7308   contents not dumped
7309 @end smallexample
7310
7311 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
7312 directory entirely:
7313
7314 @smallexample
7315 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
7316 dir/
7317 dir/blues
7318 dir/jazz
7319 ./tar: dir/folk/: contains a cache directory tag tagfile;
7320   directory not dumped
7321 @end smallexample
7322
7323 @menu
7324 * problems with exclude::
7325 @end menu
7326
7327 @node problems with exclude
7328 @unnumberedsubsec Problems with Using the @code{exclude} Options
7329
7330 @xopindex{exclude, potential problems with}
7331 Some users find @samp{exclude} options confusing.  Here are some common
7332 pitfalls:
7333
7334 @itemize @bullet
7335 @item
7336 The main operating mode of @command{tar} does not act on a file name
7337 explicitly listed on the command line, if one of its file name
7338 components is excluded.  In the example above, if
7339 you create an archive and exclude files that end with @samp{*.o}, but
7340 explicitly name the file @samp{dir.o/foo} after all the options have been
7341 listed, @samp{dir.o/foo} will be excluded from the archive.
7342
7343 @item
7344 You can sometimes confuse the meanings of @option{--exclude} and
7345 @option{--exclude-from}.  Be careful: use @option{--exclude} when files
7346 to be excluded are given as a pattern on the command line.  Use
7347 @option{--exclude-from} to introduce the name of a file which contains
7348 a list of patterns, one per line; each of these patterns can exclude
7349 zero, one, or many files.
7350
7351 @item
7352 When you use @option{--exclude=@var{pattern}}, be sure to quote the
7353 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
7354 like @samp{*}.  If you do not do this, the shell might expand the
7355 @samp{*} itself using files at hand, so @command{tar} might receive a
7356 list of files instead of one pattern, or none at all, making the
7357 command somewhat illegal.  This might not correspond to what you want.
7358
7359 For example, write:
7360
7361 @smallexample
7362 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
7363 @end smallexample
7364
7365 @noindent
7366 rather than:
7367
7368 @smallexample
7369 # @emph{Wrong!}
7370 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
7371 @end smallexample
7372
7373 @item
7374 You must use use shell syntax, or globbing, rather than @code{regexp}
7375 syntax, when using exclude options in @command{tar}.  If you try to use
7376 @code{regexp} syntax to describe files to be excluded, your command
7377 might fail.
7378
7379 @item
7380 @FIXME{The change in semantics must have occurred before 1.11,
7381 so I doubt if it is worth mentioning at all. Anyway, should at
7382 least specify in which version the semantics changed.}
7383 In earlier versions of @command{tar}, what is now the
7384 @option{--exclude-from} option was called @option{--exclude} instead.
7385 Now, @option{--exclude} applies to patterns listed on the command
7386 line and @option{--exclude-from} applies to patterns listed in a
7387 file.
7388
7389 @end itemize
7390
7391 @node wildcards
7392 @section Wildcards Patterns and Matching
7393
7394 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
7395 @samp{*} or @samp{?} for example, are replaced and expanded into all
7396 existing files matching the given pattern.  @GNUTAR{} can use wildcard
7397 patterns for matching (or globbing) archive members when extracting
7398 from or listing an archive.  Wildcard patterns are also used for
7399 verifying volume labels of @command{tar} archives.  This section has the
7400 purpose of explaining wildcard syntax for @command{tar}.
7401
7402 @FIXME{the next few paragraphs need work.}
7403
7404 A @var{pattern} should be written according to shell syntax, using wildcard
7405 characters to effect globbing.  Most characters in the pattern stand
7406 for themselves in the matched string, and case is significant: @samp{a}
7407 will match only @samp{a}, and not @samp{A}.  The character @samp{?} in the
7408 pattern matches any single character in the matched string.  The character
7409 @samp{*} in the pattern matches zero, one, or more single characters in
7410 the matched string.  The character @samp{\} says to take the following
7411 character of the pattern @emph{literally}; it is useful when one needs to
7412 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
7413
7414 The character @samp{[}, up to the matching @samp{]}, introduces a character
7415 class.  A @dfn{character class} is a list of acceptable characters
7416 for the next single character of the matched string.  For example,
7417 @samp{[abcde]} would match any of the first five letters of the alphabet.
7418 Note that within a character class, all of the ``special characters''
7419 listed above other than @samp{\} lose their special meaning; for example,
7420 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
7421 @samp{[}, @samp{*}, @samp{?}, or @samp{]}.  (Due to parsing constraints,
7422 the characters @samp{-} and @samp{]} must either come @emph{first} or
7423 @emph{last} in a character class.)
7424
7425 @cindex Excluding characters from a character class
7426 @cindex Character class, excluding characters from
7427 If the first character of the class after the opening @samp{[}
7428 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7429 Rather than listing character to match, it lists those characters which
7430 are @emph{forbidden} as the next single character of the matched string.
7431
7432 Other characters of the class stand for themselves.  The special
7433 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7434 letters, is meant to represent all characters between @var{a} and
7435 @var{e}, inclusive.
7436
7437 @FIXME{need to add a sentence or so here to make this clear for those
7438 who don't have dan around.}
7439
7440 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7441 special for wildcard matches.  However, if a pattern completely matches
7442 a directory prefix of a matched string, then it matches the full matched
7443 string: thus, excluding a directory also excludes all the files beneath it.
7444
7445 @menu
7446 * controlling pattern-matching::
7447 @end menu
7448
7449 @node controlling pattern-matching
7450 @unnumberedsubsec Controlling Pattern-Matching
7451
7452 For the purposes of this section, we call @dfn{exclusion members} all
7453 member names obtained while processing @option{--exclude} and
7454 @option{--exclude-from} options, and @dfn{inclusion members} those
7455 member names that were given in the command line or read from the file
7456 specified with @option{--files-from} option.
7457
7458 These two pairs of member lists are used in the following operations:
7459 @option{--diff}, @option{--extract}, @option{--list},
7460 @option{--update}.
7461
7462 There are no inclusion members in create mode (@option{--create} and
7463 @option{--append}), since in this mode the names obtained from the
7464 command line refer to @emph{files}, not archive members.
7465
7466 By default, inclusion members are compared with archive members
7467 literally @footnote{Notice that earlier @GNUTAR{} versions used
7468 globbing for inclusion members, which contradicted to UNIX98
7469 specification and was not documented. @xref{Changes}, for more
7470 information on this and other changes.} and exclusion members are
7471 treated as globbing patterns.  For example:
7472
7473 @smallexample
7474 @group
7475 $ @kbd{tar tf foo.tar}
7476 a.c
7477 b.c
7478 a.txt
7479 [remarks]
7480 # @i{Member names are used verbatim:}
7481 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7482 [remarks]
7483 # @i{Exclude member names are globbed:}
7484 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7485 a.txt
7486 [remarks]
7487 @end group
7488 @end smallexample
7489
7490 This behavior can be altered by using the following options:
7491
7492 @table @option
7493 @opindex wildcards
7494 @item --wildcards
7495 Treat all member names as wildcards.
7496
7497 @opindex no-wildcards
7498 @item --no-wildcards
7499 Treat all member names as literal strings.
7500 @end table
7501
7502 Thus, to extract files whose names end in @samp{.c}, you can use:
7503
7504 @smallexample
7505 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7506 a.c
7507 b.c
7508 @end smallexample
7509
7510 @noindent
7511 Notice quoting of the pattern to prevent the shell from interpreting
7512 it.
7513
7514 The effect of @option{--wildcards} option is canceled by
7515 @option{--no-wildcards}.  This can be used to pass part of
7516 the command line arguments verbatim and other part as globbing
7517 patterns.  For example, the following invocation:
7518
7519 @smallexample
7520 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7521 @end smallexample
7522
7523 @noindent
7524 instructs @command{tar} to extract from @file{foo.tar} all files whose
7525 names end in @samp{.txt} and the file named @file{[remarks]}.
7526
7527 Normally, a pattern matches a name if an initial subsequence of the
7528 name's components matches the pattern, where @samp{*}, @samp{?}, and
7529 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7530 and wildcards can match @samp{/}.
7531
7532 Other than optionally stripping leading @samp{/} from names
7533 (@pxref{absolute}), patterns and names are used as-is.  For
7534 example, trailing @samp{/} is not trimmed from a user-specified name
7535 before deciding whether to exclude it.
7536
7537 However, this matching procedure can be altered by the options listed
7538 below.  These options accumulate.  For example:
7539
7540 @smallexample
7541 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7542 @end smallexample
7543
7544 @noindent
7545 ignores case when excluding @samp{makefile}, but not when excluding
7546 @samp{readme}.
7547
7548 @table @option
7549 @opindex anchored
7550 @opindex no-anchored
7551 @item --anchored
7552 @itemx --no-anchored
7553 If anchored, a pattern must match an initial subsequence
7554 of the name's components.  Otherwise, the pattern can match any
7555 subsequence.  Default is @option{--no-anchored} for exclusion members
7556 and @option{--anchored} inclusion members.
7557
7558 @opindex ignore-case
7559 @opindex no-ignore-case
7560 @item --ignore-case
7561 @itemx --no-ignore-case
7562 When ignoring case, upper-case patterns match lower-case names and vice versa.
7563 When not ignoring case (the default), matching is case-sensitive.
7564
7565 @opindex wildcards-match-slash
7566 @opindex no-wildcards-match-slash
7567 @item --wildcards-match-slash
7568 @itemx --no-wildcards-match-slash
7569 When wildcards match slash (the default for exclusion members), a
7570 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7571 name.  Otherwise, @samp{/} is matched only by @samp{/}.
7572
7573 @end table
7574
7575 The @option{--recursion} and @option{--no-recursion} options
7576 (@pxref{recurse}) also affect how member patterns are interpreted.  If
7577 recursion is in effect, a pattern matches a name if it matches any of
7578 the name's parent directories.
7579
7580 The following table summarizes pattern-matching default values:
7581
7582 @multitable @columnfractions .3 .7
7583 @headitem Members @tab Default settings
7584 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7585 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7586 @end multitable
7587
7588 @node quoting styles
7589 @section Quoting Member Names
7590
7591 When displaying member names, @command{tar} takes care to avoid
7592 ambiguities caused by certain characters.  This is called @dfn{name
7593 quoting}.  The characters in question are:
7594
7595 @itemize @bullet
7596 @item Non-printable control characters:
7597 @anchor{escape sequences}
7598 @multitable @columnfractions 0.20 0.10 0.60
7599 @headitem Character @tab @acronym{ASCII} @tab Character name
7600 @item \a @tab 7  @tab Audible bell
7601 @item \b @tab 8  @tab Backspace
7602 @item \f @tab 12 @tab Form feed
7603 @item \n @tab 10 @tab New line
7604 @item \r @tab 13 @tab Carriage return
7605 @item \t @tab 9  @tab Horizontal tabulation
7606 @item \v @tab 11 @tab Vertical tabulation
7607 @end multitable
7608
7609 @item Space (@acronym{ASCII} 32)
7610
7611 @item Single and double quotes (@samp{'} and @samp{"})
7612
7613 @item Backslash (@samp{\})
7614 @end itemize
7615
7616 The exact way @command{tar} uses to quote these characters depends on
7617 the @dfn{quoting style}.  The default quoting style, called
7618 @dfn{escape} (see below), uses backslash notation to represent control
7619 characters, space and backslash.  Using this quoting style, control
7620 characters are represented as listed in column @samp{Character} in the
7621 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7622
7623 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7624 using @option{--quoting-style} option:
7625
7626 @table @option
7627 @item --quoting-style=@var{style}
7628 @opindex quoting-style
7629
7630 Sets quoting style.  Valid values for @var{style} argument are:
7631 literal, shell, shell-always, c, escape, locale, clocale.
7632 @end table
7633
7634 These styles are described in detail below.  To illustrate their
7635 effect, we will use an imaginary tar archive @file{arch.tar}
7636 containing the following members:
7637
7638 @smallexample
7639 @group
7640 # 1. Contains horizontal tabulation character.
7641 a       tab
7642 # 2. Contains newline character
7643 a
7644 newline
7645 # 3. Contains a space
7646 a space
7647 # 4. Contains double quotes
7648 a"double"quote
7649 # 5. Contains single quotes
7650 a'single'quote
7651 # 6. Contains a backslash character:
7652 a\backslash
7653 @end group
7654 @end smallexample
7655
7656 Here is how usual @command{ls} command would have listed them, if they
7657 had existed in the current working directory:
7658
7659 @smallexample
7660 @group
7661 $ @kbd{ls}
7662 a\ttab
7663 a\nnewline
7664 a\ space
7665 a"double"quote
7666 a'single'quote
7667 a\\backslash
7668 @end group
7669 @end smallexample
7670
7671 Quoting styles:
7672
7673 @table @samp
7674 @item literal
7675 No quoting, display each character as is:
7676
7677 @smallexample
7678 @group
7679 $ @kbd{tar tf arch.tar --quoting-style=literal}
7680 ./
7681 ./a space
7682 ./a'single'quote
7683 ./a"double"quote
7684 ./a\backslash
7685 ./a     tab
7686 ./a
7687 newline
7688 @end group
7689 @end smallexample
7690
7691 @item shell
7692 Display characters the same way Bourne shell does:
7693 control characters, except @samp{\t} and @samp{\n}, are printed using
7694 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7695 single quote is printed as @samp{\'}.  If a name contains any quoted
7696 characters, it is enclosed in single quotes.  In particular, if a name
7697 contains single quotes, it is printed as several single-quoted strings:
7698
7699 @smallexample
7700 @group
7701 $ @kbd{tar tf arch.tar --quoting-style=shell}
7702 ./
7703 './a space'
7704 './a'\''single'\''quote'
7705 './a"double"quote'
7706 './a\backslash'
7707 './a    tab'
7708 './a
7709 newline'
7710 @end group
7711 @end smallexample
7712
7713 @item shell-always
7714 Same as @samp{shell}, but the names are always enclosed in single
7715 quotes:
7716
7717 @smallexample
7718 @group
7719 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7720 './'
7721 './a space'
7722 './a'\''single'\''quote'
7723 './a"double"quote'
7724 './a\backslash'
7725 './a    tab'
7726 './a
7727 newline'
7728 @end group
7729 @end smallexample
7730
7731 @item c
7732 Use the notation of the C programming language.  All names are
7733 enclosed in double quotes.  Control characters are quoted using
7734 backslash notations, double quotes are represented as @samp{\"},
7735 backslash characters are represented as @samp{\\}.  Single quotes and
7736 spaces are not quoted:
7737
7738 @smallexample
7739 @group
7740 $ @kbd{tar tf arch.tar --quoting-style=c}
7741 "./"
7742 "./a space"
7743 "./a'single'quote"
7744 "./a\"double\"quote"
7745 "./a\\backslash"
7746 "./a\ttab"
7747 "./a\nnewline"
7748 @end group
7749 @end smallexample
7750
7751 @item escape
7752 Control characters are printed using backslash notation, a space is
7753 printed as @samp{\ } and a backslash as @samp{\\}.  This is the
7754 default quoting style, unless it was changed when configured the
7755 package.
7756
7757 @smallexample
7758 @group
7759 $ @kbd{tar tf arch.tar --quoting-style=escape}
7760 ./
7761 ./a space
7762 ./a'single'quote
7763 ./a"double"quote
7764 ./a\\backslash
7765 ./a\ttab
7766 ./a\nnewline
7767 @end group
7768 @end smallexample
7769
7770 @item locale
7771 Control characters, single quote and backslash are printed using
7772 backslash notation.  All names are quoted using left and right
7773 quotation marks, appropriate to the current locale.  If it does not
7774 define quotation marks, use @samp{`} as left and @samp{'} as right
7775 quotation marks.  Any occurrences of the right quotation mark in a
7776 name are escaped with @samp{\}, for example:
7777
7778 For example:
7779
7780 @smallexample
7781 @group
7782 $ @kbd{tar tf arch.tar --quoting-style=locale}
7783 `./'
7784 `./a space'
7785 `./a\'single\'quote'
7786 `./a"double"quote'
7787 `./a\\backslash'
7788 `./a\ttab'
7789 `./a\nnewline'
7790 @end group
7791 @end smallexample
7792
7793 @item clocale
7794 Same as @samp{locale}, but @samp{"} is used for both left and right
7795 quotation marks, if not provided by the currently selected locale:
7796
7797 @smallexample
7798 @group
7799 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7800 "./"
7801 "./a space"
7802 "./a'single'quote"
7803 "./a\"double\"quote"
7804 "./a\\backslash"
7805 "./a\ttab"
7806 "./a\nnewline"
7807 @end group
7808 @end smallexample
7809 @end table
7810
7811 You can specify which characters should be quoted in addition to those
7812 implied by the current quoting style:
7813
7814 @table @option
7815 @item --quote-chars=@var{string}
7816 Always quote characters from @var{string}, even if the selected
7817 quoting style would not quote them.
7818 @end table
7819
7820 For example, using @samp{escape} quoting (compare with the usual
7821 escape listing above):
7822
7823 @smallexample
7824 @group
7825 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7826 ./
7827 ./a\ space
7828 ./a'single'quote
7829 ./a\"double\"quote
7830 ./a\\backslash
7831 ./a\ttab
7832 ./a\nnewline
7833 @end group
7834 @end smallexample
7835
7836 To disable quoting of such additional characters, use the following
7837 option:
7838
7839 @table @option
7840 @item --no-quote-chars=@var{string}
7841 Remove characters listed in @var{string} from the list of quoted
7842 characters set by the previous @option{--quote-chars} option.
7843 @end table
7844
7845 This option is particularly useful if you have added
7846 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7847 and wish to disable it for the current invocation.
7848
7849 Note, that @option{--no-quote-chars} does @emph{not} disable those
7850 characters that are quoted by default in the selected quoting style.
7851
7852 @node transform
7853 @section Modifying File and Member Names
7854
7855 @command{Tar} archives contain detailed information about files stored
7856 in them and full file names are part of that information.  When
7857 storing a file to an archive, its file name is recorded in it,
7858 along with the actual file contents.  When restoring from an archive,
7859 a file is created on disk with exactly the same name as that stored
7860 in the archive.  In the majority of cases this is the desired behavior
7861 of a file archiver.  However, there are some cases when it is not.
7862
7863 First of all, it is often unsafe to extract archive members with
7864 absolute file names or those that begin with a @file{../}.  @GNUTAR{}
7865 takes special precautions when extracting such names and provides a
7866 special option for handling them, which is described in
7867 @ref{absolute}.
7868
7869 Secondly, you may wish to extract file names without some leading
7870 directory components, or with otherwise modified names.  In other
7871 cases it is desirable to store files under differing names in the
7872 archive.
7873
7874 @GNUTAR{} provides several options for these needs.
7875
7876 @table @option
7877 @opindex strip-components
7878 @item --strip-components=@var{number}
7879 Strip given @var{number} of leading components from file names before
7880 extraction.
7881 @end table
7882
7883 For example, suppose you have archived whole @file{/usr} hierarchy to
7884 a tar archive named @file{usr.tar}.  Among other files, this archive
7885 contains @file{usr/include/stdlib.h}, which you wish to extract to
7886 the current working directory.  To do so, you type:
7887
7888 @smallexample
7889 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7890 @end smallexample
7891
7892 The option @option{--strip=2} instructs @command{tar} to strip the
7893 two leading components (@file{usr/} and @file{include/}) off the file
7894 name.
7895
7896 If you add the @option{--verbose} (@option{-v}) option to the invocation
7897 above, you will note that the verbose listing still contains the
7898 full file name, with the two removed components still in place.  This
7899 can be inconvenient, so @command{tar} provides a special option for
7900 altering this behavior:
7901
7902 @anchor{show-transformed-names}
7903 @table @option
7904 @opindex show-transformed-names
7905 @item --show-transformed-names
7906 Display file or member names with all requested transformations
7907 applied.
7908 @end table
7909
7910 @noindent
7911 For example:
7912
7913 @smallexample
7914 @group
7915 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7916 usr/include/stdlib.h
7917 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7918 stdlib.h
7919 @end group
7920 @end smallexample
7921
7922 Notice that in both cases the file @file{stdlib.h} is extracted to the
7923 current working directory, @option{--show-transformed-names} affects
7924 only the way its name is displayed.
7925
7926 This option is especially useful for verifying whether the invocation
7927 will have the desired effect.  Thus, before running
7928
7929 @smallexample
7930 $ @kbd{tar -x --strip=@var{n}}
7931 @end smallexample
7932
7933 @noindent
7934 it is often advisable to run
7935
7936 @smallexample
7937 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7938 @end smallexample
7939
7940 @noindent
7941 to make sure the command will produce the intended results.
7942
7943 In case you need to apply more complex modifications to the file name,
7944 @GNUTAR{} provides a general-purpose transformation option:
7945
7946 @table @option
7947 @opindex transform
7948 @opindex xform
7949 @item --transform=@var{expression}
7950 @itemx --xform=@var{expression}
7951 Modify file names using supplied @var{expression}.
7952 @end table
7953
7954 @noindent
7955 The @var{expression} is a @command{sed}-like replace expression of the
7956 form:
7957
7958 @smallexample
7959 s/@var{regexp}/@var{replace}/[@var{flags}]
7960 @end smallexample
7961
7962 @noindent
7963 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7964 replacement for each file name part that matches @var{regexp}.  Both
7965 @var{regexp} and @var{replace} are described in detail in
7966 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7967
7968 Any delimiter can be used in lieu of @samp{/}, the only requirement being
7969 that it be used consistently throughout the expression. For example,
7970 the following two expressions are equivalent:
7971
7972 @smallexample
7973 @group
7974 s/one/two/
7975 s,one,two,
7976 @end group
7977 @end smallexample
7978
7979 Changing delimiters is often useful when the @var{regex} contains
7980 slashes.  For example, it is more convenient to write @code{s,/,-,} than
7981 @code{s/\//-/}.
7982
7983 As in @command{sed}, you can give several replace expressions,
7984 separated by a semicolon.
7985
7986 Supported @var{flags} are:
7987
7988 @table @samp
7989 @item g
7990 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7991 just the first.
7992
7993 @item i
7994 Use case-insensitive matching.
7995
7996 @item x
7997 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7998 regexps, Extended regular expressions, Extended regular expressions,
7999 sed, GNU sed}).
8000
8001 @item @var{number}
8002 Only replace the @var{number}th match of the @var{regexp}.
8003
8004 Note: the @acronym{POSIX} standard does not specify what should happen
8005 when you mix the @samp{g} and @var{number} modifiers.  @GNUTAR{}
8006 follows the GNU @command{sed} implementation in this regard, so
8007 the interaction is defined to be: ignore matches before the
8008 @var{number}th, and then match and replace all matches from the
8009 @var{number}th on.
8010
8011 @end table
8012
8013 In addition, several @dfn{transformation scope} flags are supported,
8014 that control to what files transformations apply.  These are:
8015
8016 @table @samp
8017 @item r
8018 Apply transformation to regular archive members.
8019
8020 @item R
8021 Do not apply transformation to regular archive members.
8022
8023 @item s
8024 Apply transformation to symbolic link targets.
8025
8026 @item S
8027 Do not apply transformation to symbolic link targets.
8028
8029 @item h
8030 Apply transformation to hard link targets.
8031
8032 @item H
8033 Do not apply transformation to hard link targets.
8034 @end table
8035
8036 Default is @samp{rsh}, which means to apply tranformations to both archive
8037 members and targets of symbolic and hard links.
8038
8039 Default scope flags can also be changed using @samp{flags=} statement
8040 in the transform expression.  The flags set this way remain in force
8041 until next @samp{flags=} statement or end of expression, whichever
8042 occurs first.  For example:
8043
8044 @smallexample
8045   --transform 'flags=S;s|^|/usr/local/|'
8046 @end smallexample
8047
8048 Here are several examples of @option{--transform} usage:
8049
8050 @enumerate
8051 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8052
8053 @smallexample
8054 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8055 @end smallexample
8056
8057 @item Strip two leading directory components (equivalent to
8058 @option{--strip-components=2}):
8059
8060 @smallexample
8061 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8062 @end smallexample
8063
8064 @item Convert each file name to lower case:
8065
8066 @smallexample
8067 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8068 @end smallexample
8069
8070 @item Prepend @file{/prefix/}  to each file name:
8071
8072 @smallexample
8073 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8074 @end smallexample
8075
8076 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8077 to each archive member:
8078
8079 @smallexample
8080 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8081 @end smallexample
8082 @end enumerate
8083
8084 Notice the use of flags in the last example.  The @file{/lib}
8085 directory often contains many symbolic links to files within it.
8086 It may look, for example, like this:
8087
8088 @smallexample
8089 $ @kbd{ls -l}
8090 drwxr-xr-x root/root       0 2008-07-08 16:20 /lib/
8091 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8092 lrwxrwxrwx root/root       0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8093 ...
8094 @end smallexample
8095
8096 Using the expression @samp{s,^,/usr/local/,} would mean adding
8097 @samp{/usr/local} to both regular archive members and to link
8098 targets. In this case, @file{/lib/libc.so.6} would become:
8099
8100 @smallexample
8101   /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8102 @end smallexample
8103
8104 This is definitely not desired.  To avoid this, the @samp{S} flag
8105 is used, which excludes symbolic link targets from filename
8106 transformations.  The result is:
8107
8108 @smallexample
8109 $ @kbd{tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
8110        --show-transformed /lib}
8111 drwxr-xr-x root/root       0 2008-07-08 16:20 /usr/local/lib/
8112 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8113 lrwxrwxrwx root/root       0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8114  -> libc-2.3.2.so
8115 @end smallexample
8116
8117 Unlike @option{--strip-components}, @option{--transform} can be used
8118 in any @GNUTAR{} operation mode.  For example, the following command
8119 adds files to the archive while replacing the leading @file{usr/}
8120 component with @file{var/}:
8121
8122 @smallexample
8123 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8124 @end smallexample
8125
8126 To test @option{--transform} effect we suggest using
8127 @option{--show-transformed-names} option:
8128
8129 @smallexample
8130 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8131        --verbose --show-transformed-names /}
8132 @end smallexample
8133
8134 If both @option{--strip-components} and @option{--transform} are used
8135 together, then @option{--transform} is applied first, and the required
8136 number of components is then stripped from its result.
8137
8138 You can use as many @option{--transform} options in a single command
8139 line as you want.  The specified expressions will then be applied in
8140 order of their appearance.  For example, the following two invocations
8141 are equivalent:
8142
8143 @smallexample
8144 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
8145                         --transform='s,/usr/local,/usr/,'}
8146 $ @kbd{tar -cf arch.tar \
8147                --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
8148 @end smallexample
8149
8150 @node after
8151 @section Operating Only on New Files
8152
8153 @cindex Excluding file by age
8154 @cindex Data Modification time, excluding files by
8155 @cindex Modification time, excluding files by
8156 @cindex Age, excluding files by
8157 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
8158 @option{-N @var{date}}) option causes @command{tar} to only work on
8159 files whose data modification or status change times are newer than
8160 the @var{date} given.  If @var{date} starts with @samp{/} or @samp{.},
8161 it is taken to be a file name; the data modification time of that file
8162 is used as the date. If you use this option when creating or appending
8163 to an archive, the archive will only include new files.  If you use
8164 @option{--after-date} when extracting an archive, @command{tar} will
8165 only extract files newer than the @var{date} you specify.
8166
8167 If you only want @command{tar} to make the date comparison based on
8168 modification of the file's data (rather than status
8169 changes), then use the @option{--newer-mtime=@var{date}} option.
8170
8171 @cindex --after-date and --update compared
8172 @cindex --newer-mtime and --update compared
8173 You may use these options with any operation.  Note that these options
8174 differ from the @option{--update} (@option{-u}) operation in that they
8175 allow you to specify a particular date against which @command{tar} can
8176 compare when deciding whether or not to archive the files.
8177
8178 @table @option
8179 @opindex after-date
8180 @opindex newer
8181 @item --after-date=@var{date}
8182 @itemx --newer=@var{date}
8183 @itemx -N @var{date}
8184 Only store files newer than @var{date}.
8185
8186 Acts on files only if their data modification or status change times are
8187 later than @var{date}.  Use in conjunction with any operation.
8188
8189 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
8190 name; the data modification time of that file is used as the date.
8191
8192 @opindex newer-mtime
8193 @item --newer-mtime=@var{date}
8194 Acts like @option{--after-date}, but only looks at data modification times.
8195 @end table
8196
8197 These options limit @command{tar} to operate only on files which have
8198 been modified after the date specified.  A file's status is considered to have
8199 changed if its contents have been modified, or if its owner,
8200 permissions, and so forth, have been changed.  (For more information on
8201 how to specify a date, see @ref{Date input formats}; remember that the
8202 entire date argument must be quoted if it contains any spaces.)
8203
8204 Gurus would say that @option{--after-date} tests both the data
8205 modification time (@code{mtime}, the time the contents of the file
8206 were last modified) and the status change time (@code{ctime}, the time
8207 the file's status was last changed: owner, permissions, etc.@:)
8208 fields, while @option{--newer-mtime} tests only the @code{mtime}
8209 field.
8210
8211 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
8212 @code{ctime} and processes the file if either one is more recent than
8213 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
8214 disregards @code{ctime}.  Neither does it use @code{atime} (the last time the
8215 contents of the file were looked at).
8216
8217 Date specifiers can have embedded spaces.  Because of this, you may need
8218 to quote date arguments to keep the shell from parsing them as separate
8219 arguments.  For example, the following command will add to the archive
8220 all the files modified less than two days ago:
8221
8222 @smallexample
8223 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
8224 @end smallexample
8225
8226 When any of these options is used with the option @option{--verbose}
8227 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
8228 date back to its textual representation and compare that with the
8229 one given with the option.  If the two dates differ, @command{tar} will
8230 print a warning saying what date it will use.  This is to help user
8231 ensure he is using the right date.  For example:
8232
8233 @smallexample
8234 @group
8235 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
8236 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
8237 13:19:37.232434
8238 @end group
8239 @end smallexample
8240
8241 @quotation
8242 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
8243 should not be used for incremental backups.  @xref{Incremental Dumps},
8244 for proper way of creating incremental backups.
8245 @end quotation
8246
8247 @node recurse
8248 @section Descending into Directories
8249 @cindex Avoiding recursion in directories
8250 @cindex Descending directories, avoiding
8251 @cindex Directories, avoiding recursion
8252 @cindex Recursion in directories, avoiding
8253
8254 Usually, @command{tar} will recursively explore all directories (either
8255 those given on the command line or through the @option{--files-from}
8256 option) for the various files they contain.  However, you may not always
8257 want @command{tar} to act this way.
8258
8259 @opindex no-recursion
8260 @cindex @command{find}, using with @command{tar}
8261 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
8262 into specified directories.  If you specify @option{--no-recursion}, you can
8263 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
8264 utility for hunting through levels of directories to
8265 construct a list of file names which you could then pass to @command{tar}.
8266 @command{find} allows you to be more selective when choosing which files to
8267 archive; see @ref{files}, for more information on using @command{find} with
8268 @command{tar}.
8269
8270 @table @option
8271 @item --no-recursion
8272 Prevents @command{tar} from recursively descending directories.
8273
8274 @opindex recursion
8275 @item --recursion
8276 Requires @command{tar} to recursively descend directories.
8277 This is the default.
8278 @end table
8279
8280 When you use @option{--no-recursion}, @GNUTAR{} grabs
8281 directory entries themselves, but does not descend on them
8282 recursively.  Many people use @command{find} for locating files they
8283 want to back up, and since @command{tar} @emph{usually} recursively
8284 descends on directories, they have to use the @samp{@w{-not -type d}}
8285 test in their @command{find} invocation (@pxref{Type, Type, Type test,
8286 find, Finding Files}), as they usually do not want all the files in a
8287 directory. They then use the @option{--files-from} option to archive
8288 the files located via @command{find}.
8289
8290 The problem when restoring files archived in this manner is that the
8291 directories themselves are not in the archive; so the
8292 @option{--same-permissions} (@option{--preserve-permissions},
8293 @option{-p}) option does not affect them---while users might really
8294 like it to.  Specifying @option{--no-recursion} is a way to tell
8295 @command{tar} to grab only the directory entries given to it, adding
8296 no new files on its own.  To summarize, if you use @command{find} to
8297 create a list of files to be stored in an archive, use it as follows:
8298
8299 @smallexample
8300 @group
8301 $ @kbd{find @var{dir} @var{tests} | \
8302   tar -cf @var{archive} -T - --no-recursion}
8303 @end group
8304 @end smallexample
8305
8306 The @option{--no-recursion} option also applies when extracting: it
8307 causes @command{tar} to extract only the matched directory entries, not
8308 the files under those directories.
8309
8310 The @option{--no-recursion} option also affects how globbing patterns
8311 are interpreted (@pxref{controlling pattern-matching}).
8312
8313 The @option{--no-recursion} and @option{--recursion} options apply to
8314 later options and operands, and can be overridden by later occurrences
8315 of @option{--no-recursion} and @option{--recursion}.  For example:
8316
8317 @smallexample
8318 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
8319 @end smallexample
8320
8321 @noindent
8322 creates an archive with one entry for @file{grape}, and the recursive
8323 contents of @file{grape/concord}, but no entries under @file{grape}
8324 other than @file{grape/concord}.
8325
8326 @node one
8327 @section Crossing File System Boundaries
8328 @cindex File system boundaries, not crossing
8329
8330 @command{tar} will normally automatically cross file system boundaries in
8331 order to archive files which are part of a directory tree.  You can
8332 change this behavior by running @command{tar} and specifying
8333 @option{--one-file-system}.  This option only affects files that are
8334 archived because they are in a directory that is being archived;
8335 @command{tar} will still archive files explicitly named on the command line
8336 or through @option{--files-from}, regardless of where they reside.
8337
8338 @table @option
8339 @opindex one-file-system
8340 @item --one-file-system
8341 Prevents @command{tar} from crossing file system boundaries when
8342 archiving.  Use in conjunction with any write operation.
8343 @end table
8344
8345 The @option{--one-file-system} option causes @command{tar} to modify its
8346 normal behavior in archiving the contents of directories.  If a file in
8347 a directory is not on the same file system as the directory itself, then
8348 @command{tar} will not archive that file.  If the file is a directory
8349 itself, @command{tar} will not archive anything beneath it; in other words,
8350 @command{tar} will not cross mount points.
8351
8352 This option is useful for making full or incremental archival backups of
8353 a file system.  If this option is used in conjunction with
8354 @option{--verbose} (@option{-v}), files that are excluded are
8355 mentioned by name on the standard error.
8356
8357 @menu
8358 * directory::                   Changing Directory
8359 * absolute::                    Absolute File Names
8360 @end menu
8361
8362 @node directory
8363 @subsection Changing the Working Directory
8364
8365 @FIXME{need to read over this node now for continuity; i've switched
8366 things around some.}
8367
8368 @cindex Changing directory mid-stream
8369 @cindex Directory, changing mid-stream
8370 @cindex Working directory, specifying
8371 To change the working directory in the middle of a list of file names,
8372 either on the command line or in a file specified using
8373 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
8374 This will change the working directory to the specified directory
8375 after that point in the list.
8376
8377 @table @option
8378 @opindex directory
8379 @item --directory=@var{directory}
8380 @itemx -C @var{directory}
8381 Changes the working directory in the middle of a command line.
8382 @end table
8383
8384 For example,
8385
8386 @smallexample
8387 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
8388 @end smallexample
8389
8390 @noindent
8391 will place the files @file{grape} and @file{prune} from the current
8392 directory into the archive @file{jams.tar}, followed by the file
8393 @file{cherry} from the directory @file{food}.  This option is especially
8394 useful when you have several widely separated files that you want to
8395 store in the same archive.
8396
8397 Note that the file @file{cherry} is recorded in the archive under the
8398 precise name @file{cherry}, @emph{not} @file{food/cherry}.  Thus, the
8399 archive will contain three files that all appear to have come from the
8400 same directory; if the archive is extracted with plain @samp{tar
8401 --extract}, all three files will be written in the current directory.
8402
8403 Contrast this with the command,
8404
8405 @smallexample
8406 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
8407 @end smallexample
8408
8409 @noindent
8410 which records the third file in the archive under the name
8411 @file{red/cherry} so that, if the archive is extracted using
8412 @samp{tar --extract}, the third file will be written in a subdirectory
8413 named @file{red}.
8414
8415 You can use the @option{--directory} option to make the archive
8416 independent of the original name of the directory holding the files.
8417 The following command places the files @file{/etc/passwd},
8418 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
8419 @file{foo.tar}:
8420
8421 @smallexample
8422 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
8423 @end smallexample
8424
8425 @noindent
8426 However, the names of the archive members will be exactly what they were
8427 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
8428 They will not appear to be related by file name to the original
8429 directories where those files were located.
8430
8431 Note that @option{--directory} options are interpreted consecutively.  If
8432 @option{--directory} specifies a relative file name, it is interpreted
8433 relative to the then current directory, which might not be the same as
8434 the original current working directory of @command{tar}, due to a previous
8435 @option{--directory} option.
8436
8437 When using @option{--files-from} (@pxref{files}), you can put various
8438 @command{tar} options (including @option{-C}) in the file list.  Notice,
8439 however, that in this case the option and its argument may not be
8440 separated by whitespace.  If you use short option, its argument must
8441 either follow the option letter immediately, without any intervening
8442 whitespace, or occupy the next line.  Otherwise, if you use long
8443 option, separate its argument by an equal sign.
8444
8445 For instance, the file list for the above example will be:
8446
8447 @smallexample
8448 @group
8449 -C/etc
8450 passwd
8451 hosts
8452 --directory=/lib
8453 libc.a
8454 @end group
8455 @end smallexample
8456
8457 @noindent
8458 To use it, you would invoke @command{tar} as follows:
8459
8460 @smallexample
8461 $ @kbd{tar -c -f foo.tar --files-from list}
8462 @end smallexample
8463
8464 The interpretation of @option{--directory} is disabled by
8465 @option{--null} option.
8466
8467 @node absolute
8468 @subsection Absolute File Names
8469 @cindex absolute file names
8470 @cindex file names, absolute
8471
8472 By default, @GNUTAR{} drops a leading @samp{/} on
8473 input or output, and complains about file names containing a @file{..}
8474 component.  There is an option that turns off this behavior:
8475
8476 @table @option
8477 @opindex absolute-names
8478 @item --absolute-names
8479 @itemx -P
8480 Do not strip leading slashes from file names, and permit file names
8481 containing a @file{..} file name component.
8482 @end table
8483
8484 When @command{tar} extracts archive members from an archive, it strips any
8485 leading slashes (@samp{/}) from the member name.  This causes absolute
8486 member names in the archive to be treated as relative file names.  This
8487 allows you to have such members extracted wherever you want, instead of
8488 being restricted to extracting the member in the exact directory named
8489 in the archive.  For example, if the archive member has the name
8490 @file{/etc/passwd}, @command{tar} will extract it as if the name were
8491 really @file{etc/passwd}.
8492
8493 File names containing @file{..} can cause problems when extracting, so
8494 @command{tar} normally warns you about such files when creating an
8495 archive, and rejects attempts to extracts such files.
8496
8497 Other @command{tar} programs do not do this.  As a result, if you
8498 create an archive whose member names start with a slash, they will be
8499 difficult for other people with a non-@GNUTAR{}
8500 program to use.  Therefore, @GNUTAR{} also strips
8501 leading slashes from member names when putting members into the
8502 archive.  For example, if you ask @command{tar} to add the file
8503 @file{/bin/ls} to an archive, it will do so, but the member name will
8504 be @file{bin/ls}@footnote{A side effect of this is that when
8505 @option{--create} is used with @option{--verbose} the resulting output
8506 is not, generally speaking, the same as the one you'd get running
8507 @kbd{tar --list} command.  This may be important if you use some
8508 scripts for comparing both outputs.  @xref{listing member and file names},
8509 for the information on how to handle this case.}.
8510
8511 If you use the @option{--absolute-names} (@option{-P}) option,
8512 @command{tar} will do none of these transformations.
8513
8514 To archive or extract files relative to the root directory, specify
8515 the @option{--absolute-names} (@option{-P}) option.
8516
8517 Normally, @command{tar} acts on files relative to the working
8518 directory---ignoring superior directory names when archiving, and
8519 ignoring leading slashes when extracting.
8520
8521 When you specify @option{--absolute-names} (@option{-P}),
8522 @command{tar} stores file names including all superior directory
8523 names, and preserves leading slashes.  If you only invoked
8524 @command{tar} from the root directory you would never need the
8525 @option{--absolute-names} option, but using this option
8526 may be more convenient than switching to root.
8527
8528 @FIXME{Should be an example in the tutorial/wizardry section using this
8529 to transfer files between systems.}
8530
8531 @table @option
8532 @item --absolute-names
8533 Preserves full file names (including superior directory names) when
8534 archiving files.  Preserves leading slash when extracting files.
8535
8536 @end table
8537
8538 @command{tar} prints out a message about removing the @samp{/} from
8539 file names.  This message appears once per @GNUTAR{}
8540 invocation.  It represents something which ought to be told; ignoring
8541 what it means can cause very serious surprises, later.
8542
8543 Some people, nevertheless, do not want to see this message.  Wanting to
8544 play really dangerously, one may of course redirect @command{tar} standard
8545 error to the sink.  For example, under @command{sh}:
8546
8547 @smallexample
8548 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8549 @end smallexample
8550
8551 @noindent
8552 Another solution, both nicer and simpler, would be to change to
8553 the @file{/} directory first, and then avoid absolute notation.
8554 For example:
8555
8556 @smallexample
8557 $ @kbd{tar -c -f archive.tar -C / home}
8558 @end smallexample
8559
8560 @xref{Integrity}, for some of the security-related implications
8561 of using this option.
8562
8563 @include parse-datetime.texi
8564
8565 @node Formats
8566 @chapter Controlling the Archive Format
8567
8568 @cindex Tar archive formats
8569 Due to historical reasons, there are several formats of tar archives.
8570 All of them are based on the same principles, but have some subtle
8571 differences that often make them incompatible with each other.
8572
8573 GNU tar is able to create and handle archives in a variety of formats.
8574 The most frequently used formats are (in alphabetical order):
8575
8576 @table @asis
8577 @item gnu
8578 Format used by @GNUTAR{} versions up to 1.13.25.  This format derived
8579 from an early @acronym{POSIX} standard, adding some improvements such as
8580 sparse file handling and incremental archives.  Unfortunately these
8581 features were implemented in a way incompatible with other archive
8582 formats.
8583
8584 Archives in @samp{gnu} format are able to hold file names of unlimited
8585 length.
8586
8587 @item oldgnu
8588 Format used by @GNUTAR{} of versions prior to 1.12.
8589
8590 @item v7
8591 Archive format, compatible with the V7 implementation of tar.  This
8592 format imposes a number of limitations.  The most important of them
8593 are:
8594
8595 @enumerate
8596 @item The maximum length of a file name is limited to 99 characters.
8597 @item The maximum length of a symbolic link is limited to 99 characters.
8598 @item It is impossible to store special files (block and character
8599 devices, fifos etc.)
8600 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8601 octal)
8602 @item V7 archives do not contain symbolic ownership information (user
8603 and group name of the file owner).
8604 @end enumerate
8605
8606 This format has traditionally been used by Automake when producing
8607 Makefiles.  This practice will change in the future, in the meantime,
8608 however this means that projects containing file names more than 99
8609 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8610 Automake prior to 1.9.
8611
8612 @item ustar
8613 Archive format defined by @acronym{POSIX.1-1988} specification.  It stores
8614 symbolic ownership information.  It is also able to store
8615 special files.  However, it imposes several restrictions as well:
8616
8617 @enumerate
8618 @item The maximum length of a file name is limited to 256 characters,
8619 provided that the file name can be split at a directory separator in
8620 two parts, first of them being at most 155 bytes long.  So, in most
8621 cases the maximum file name length will be shorter than 256
8622 characters.
8623 @item The maximum length of a symbolic link name is limited to
8624 100 characters.
8625 @item Maximum size of a file the archive is able to accommodate
8626 is 8GB
8627 @item Maximum value of UID/GID is 2097151.
8628 @item Maximum number of bits in device major and minor numbers is 21.
8629 @end enumerate
8630
8631 @item star
8632 Format used by J@"org Schilling @command{star}
8633 implementation.  @GNUTAR{} is able to read @samp{star} archives but
8634 currently does not produce them.
8635
8636 @item posix
8637 Archive format defined by @acronym{POSIX.1-2001} specification.  This is the
8638 most flexible and feature-rich format.  It does not impose any
8639 restrictions on file sizes or file name lengths.  This format is quite
8640 recent, so not all tar implementations are able to handle it properly.
8641 However, this format is designed in such a way that any tar
8642 implementation able to read @samp{ustar} archives will be able to read
8643 most @samp{posix} archives as well, with the only exception that any
8644 additional information (such as long file names etc.) will in such
8645 case be extracted as plain text files along with the files it refers to.
8646
8647 This archive format will be the default format for future versions
8648 of @GNUTAR{}.
8649
8650 @end table
8651
8652 The following table summarizes the limitations of each of these
8653 formats:
8654
8655 @multitable @columnfractions .10 .20 .20 .20 .20
8656 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8657 @item gnu    @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8658 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8659 @item v7     @tab 2097151 @tab 8GB @tab 99 @tab n/a
8660 @item ustar  @tab 2097151 @tab 8GB @tab 256 @tab 21
8661 @item posix  @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8662 @end multitable
8663
8664 The default format for @GNUTAR{} is defined at compilation
8665 time.  You may check it by running @command{tar --help}, and examining
8666 the last lines of its output.  Usually, @GNUTAR{} is configured
8667 to create archives in @samp{gnu} format, however, future version will
8668 switch to @samp{posix}.
8669
8670 @menu
8671 * Compression::                 Using Less Space through Compression
8672 * Attributes::                  Handling File Attributes
8673 * Portability::                 Making @command{tar} Archives More Portable
8674 * cpio::                        Comparison of @command{tar} and @command{cpio}
8675 @end menu
8676
8677 @node Compression
8678 @section Using Less Space through Compression
8679
8680 @menu
8681 * gzip::                        Creating and Reading Compressed Archives
8682 * sparse::                      Archiving Sparse Files
8683 @end menu
8684
8685 @node gzip
8686 @subsection Creating and Reading Compressed Archives
8687 @cindex Compressed archives
8688 @cindex Storing archives in compressed format
8689
8690 @cindex gzip
8691 @cindex bzip2
8692 @cindex lzip
8693 @cindex lzma
8694 @cindex lzop
8695 @cindex compress
8696 @GNUTAR{} is able to create and read compressed archives.  It supports
8697 a wide variety of compression programs, namely: @command{gzip},
8698 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
8699 @command{xz} and traditional @command{compress}. The latter is
8700 supported mostly for backward compatibility, and we recommend
8701 against using it, because it is by far less effective than the other
8702 compression programs@footnote{It also had patent problems in the past.}.
8703
8704 Creating a compressed archive is simple: you just specify a
8705 @dfn{compression option} along with the usual archive creation
8706 commands.  The compression option is @option{-z} (@option{--gzip}) to
8707 create a @command{gzip} compressed archive, @option{-j}
8708 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8709 @option{--lzip} to create an @asis{lzip} compressed archive,
8710 @option{-J} (@option{--xz}) to create an @asis{XZ} archive,
8711 @option{--lzma} to create an @asis{LZMA} compressed
8712 archive, @option{--lzop} to create an @asis{LSOP} archive, and
8713 @option{-Z} (@option{--compress}) to use @command{compress} program.
8714 For example:
8715
8716 @smallexample
8717 $ @kbd{tar cfz archive.tar.gz .}
8718 @end smallexample
8719
8720 You can also let @GNUTAR{} select the compression program based on
8721 the suffix of the archive file name. This is done using
8722 @option{--auto-compress} (@option{-a}) command line option. For
8723 example, the following invocation will use @command{bzip2} for
8724 compression:
8725
8726 @smallexample
8727 $ @kbd{tar cfa archive.tar.bz2 .}
8728 @end smallexample
8729
8730 @noindent
8731 whereas the following one will use @command{lzma}:
8732
8733 @smallexample
8734 $ @kbd{tar cfa archive.tar.lzma .}
8735 @end smallexample
8736
8737 For a complete list of file name suffixes recognized by @GNUTAR{},
8738 see @ref{auto-compress}.
8739
8740 Reading compressed archive is even simpler: you don't need to specify
8741 any additional options as @GNUTAR{} recognizes its format
8742 automatically.  Thus, the following commands will list and extract the
8743 archive created in previous example:
8744
8745 @smallexample
8746 # List the compressed archive
8747 $ @kbd{tar tf archive.tar.gz}
8748 # Extract the compressed archive
8749 $ @kbd{tar xf archive.tar.gz}
8750 @end smallexample
8751
8752 The format recognition algorithm is based on @dfn{signatures}, a
8753 special byte sequences in the beginning of file, that are specific for
8754 certain compression formats.  If this approach fails, @command{tar}
8755 falls back to using archive name suffix to determine its format
8756 (@pxref{auto-compress}, for a list of recognized suffixes).
8757
8758 The only case when you have to specify a decompression option while
8759 reading the archive is when reading from a pipe or from a tape drive
8760 that does not support random access.  However, in this case @GNUTAR{}
8761 will indicate which option you should use.  For example:
8762
8763 @smallexample
8764 $ @kbd{cat archive.tar.gz | tar tf -}
8765 tar: Archive is compressed.  Use -z option
8766 tar: Error is not recoverable: exiting now
8767 @end smallexample
8768
8769 If you see such diagnostics, just add the suggested option to the
8770 invocation of @GNUTAR{}:
8771
8772 @smallexample
8773 $ @kbd{cat archive.tar.gz | tar tfz -}
8774 @end smallexample
8775
8776 Notice also, that there are several restrictions on operations on
8777 compressed archives.  First of all, compressed archives cannot be
8778 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
8779 them or delete (@option{--delete}) members from them or
8780 add (@option{--append}, alias @option{-r}) members to them.  Likewise, you
8781 cannot append another @command{tar} archive to a compressed archive using
8782 @option{--concatenate} (@option{-A}).  Secondly, multi-volume
8783 archives cannot be compressed.
8784
8785 The following options allow to select a particular compressor program:
8786
8787 @table @option
8788 @opindex gzip
8789 @opindex ungzip
8790 @item -z
8791 @itemx --gzip
8792 @itemx --ungzip
8793 Filter the archive through @command{gzip}.
8794
8795 @opindex xz
8796 @item -J
8797 @itemx --xz
8798 Filter the archive through @code{xz}.
8799
8800 @item -j
8801 @itemx --bzip2
8802 Filter the archive through @code{bzip2}.
8803
8804 @opindex lzip
8805 @item --lzip
8806 Filter the archive through @command{lzip}.
8807
8808 @opindex lzma
8809 @item --lzma
8810 Filter the archive through @command{lzma}.
8811
8812 @opindex lzop
8813 @item --lzop
8814 Filter the archive through @command{lzop}.
8815
8816 @opindex compress
8817 @opindex uncompress
8818 @item -Z
8819 @itemx --compress
8820 @itemx --uncompress
8821 Filter the archive through @command{compress}.
8822 @end table
8823
8824 When any of these options is given, @GNUTAR{} searches the compressor
8825 binary in the current path and invokes it.  The name of the compressor
8826 program is specified at compilation time using a corresponding
8827 @option{--with-@var{compname}} option to @command{configure}, e.g.
8828 @option{--with-bzip2} to select a specific @command{bzip2} binary.
8829 @xref{lbzip2}, for a detailed discussion.
8830
8831 The output produced by @command{tar --help} shows the actual
8832 compressor names along with each of these options.
8833
8834 You can use any of these options on physical devices (tape drives,
8835 etc.) and remote files as well as on normal files; data to or from
8836 such devices or remote files is reblocked by another copy of the
8837 @command{tar} program to enforce the specified (or default) record
8838 size.  The default compression parameters are used.  Most compression
8839 programs allow to override these by setting a program-specific
8840 environment variable.  For example, when using @command{gzip} you can
8841 use @env{GZIP} as in the example below:
8842
8843 @smallexample
8844 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8845 @end smallexample
8846
8847 @noindent
8848 Another way would be to use the @option{-I} option instead (see
8849 below), e.g.:
8850
8851 @smallexample
8852 $ @kbd{tar -cf archive.tar.gz -I 'gzip --best' subdir}
8853 @end smallexample
8854
8855 @noindent
8856 Finally, the third, traditional, way to achieve the same result is to
8857 use pipe:
8858
8859 @smallexample
8860 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8861 @end smallexample
8862
8863 @cindex corrupted archives
8864 About corrupted compressed archives: compressed files have no
8865 redundancy, for maximum compression.  The adaptive nature of the
8866 compression scheme means that the compression tables are implicitly
8867 spread all over the archive.  If you lose a few blocks, the dynamic
8868 construction of the compression tables becomes unsynchronized, and there
8869 is little chance that you could recover later in the archive.
8870
8871 Another compression options provide a better control over creating
8872 compressed archives.  These are:
8873
8874 @table @option
8875 @anchor{auto-compress}
8876 @opindex auto-compress
8877 @item --auto-compress
8878 @itemx -a
8879 Select a compression program to use by the archive file name
8880 suffix.  The following suffixes are recognized:
8881
8882 @multitable @columnfractions 0.3 0.6
8883 @headitem Suffix @tab Compression program
8884 @item @samp{.gz} @tab @command{gzip}
8885 @item @samp{.tgz} @tab @command{gzip}
8886 @item @samp{.taz} @tab @command{gzip}
8887 @item @samp{.Z} @tab @command{compress}
8888 @item @samp{.taZ} @tab @command{compress}
8889 @item @samp{.bz2} @tab @command{bzip2}
8890 @item @samp{.tz2} @tab @command{bzip2}
8891 @item @samp{.tbz2} @tab @command{bzip2}
8892 @item @samp{.tbz} @tab @command{bzip2}
8893 @item @samp{.lz} @tab @command{lzip}
8894 @item @samp{.lzma} @tab @command{lzma}
8895 @item @samp{.tlz} @tab @command{lzma}
8896 @item @samp{.lzo} @tab @command{lzop}
8897 @item @samp{.xz} @tab @command{xz}
8898 @end multitable
8899
8900 @opindex use-compress-program
8901 @item --use-compress-program=@var{prog}
8902 @itemx -I=@var{prog}
8903 Use external compression program @var{prog}.  Use this option if you
8904 are not happy with the compression program associated with the suffix
8905 at compile time or if you have a compression program that @GNUTAR{}
8906 does not support.  There are two requirements to which @var{prog}
8907 should comply:
8908
8909 First, when called without options, it should read data from standard
8910 input, compress it and output it on standard output.
8911
8912 Secondly, if called with @option{-d} argument, it should do exactly
8913 the opposite, i.e., read the compressed data from the standard input
8914 and produce uncompressed data on the standard output.
8915 @end table
8916
8917 @cindex gpg, using with tar
8918 @cindex gnupg, using with tar
8919 @cindex Using encrypted archives
8920 The @option{--use-compress-program} option, in particular, lets you
8921 implement your own filters, not necessarily dealing with
8922 compression/decompression.  For example, suppose you wish to implement
8923 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8924 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8925 Manual}).  The following script does that:
8926
8927 @smallexample
8928 @group
8929 #! /bin/sh
8930 case $1 in
8931 -d) gpg --decrypt - | gzip -d -c;;
8932 '') gzip -c | gpg -s;;
8933 *)  echo "Unknown option $1">&2; exit 1;;
8934 esac
8935 @end group
8936 @end smallexample
8937
8938 Suppose you name it @file{gpgz} and save it somewhere in your
8939 @env{PATH}.  Then the following command will create a compressed
8940 archive signed with your private key:
8941
8942 @smallexample
8943 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
8944 @end smallexample
8945
8946 @noindent
8947 Likewise, the command below will list its contents:
8948
8949 @smallexample
8950 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
8951 @end smallexample
8952
8953 @ignore
8954 The above is based on the following discussion:
8955
8956      I have one question, or maybe it's a suggestion if there isn't a way
8957      to do it now.  I would like to use @option{--gzip}, but I'd also like
8958      the output to be fed through a program like @acronym{GNU}
8959      @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8960      to use :-)), basically adding ECC protection on top of compression.
8961      It seems as if this should be quite easy to do, but I can't work out
8962      exactly how to go about it.  Of course, I can pipe the standard output
8963      of @command{tar} through @command{ecc}, but then I lose (though I
8964      haven't started using it yet, I confess) the ability to have
8965      @command{tar} use @command{rmt} for it's I/O (I think).
8966
8967      I think the most straightforward thing would be to let me specify a
8968      general set of filters outboard of compression (preferably ordered,
8969      so the order can be automatically reversed on input operations, and
8970      with the options they require specifiable), but beggars shouldn't be
8971      choosers and anything you decide on would be fine with me.
8972
8973      By the way, I like @command{ecc} but if (as the comments say) it can't
8974      deal with loss of block sync, I'm tempted to throw some time at adding
8975      that capability.  Supposing I were to actually do such a thing and
8976      get it (apparently) working, do you accept contributed changes to
8977      utilities like that?  (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8978
8979   Isn't that exactly the role of the
8980   @option{--use-compress-prog=@var{program}} option?
8981   I never tried it myself, but I suspect you may want to write a
8982   @var{prog} script or program able to filter stdin to stdout to
8983   way you want.  It should recognize the @option{-d} option, for when
8984   extraction is needed rather than creation.
8985
8986   It has been reported that if one writes compressed data (through the
8987   @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8988   the DLT compression mode, the data will actually get bigger and one will
8989   end up with less space on the tape.
8990 @end ignore
8991
8992 @menu
8993 * lbzip2::  Using lbzip2 with @GNUTAR{}.
8994 @end menu
8995
8996 @node lbzip2
8997 @subsubsection Using lbzip2 with @GNUTAR{}.
8998 @cindex lbzip2
8999 @cindex Laszlo Ersek
9000   @command{Lbzip2} is a multithreaded utility for handling
9001 @samp{bzip2} compression, written by Laszlo Ersek.  It makes use of
9002 multiple processors to speed up its operation and in general works
9003 considerably faster than @command{bzip2}.  For a detailed description
9004 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9005 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9006 lbzip2: parallel bzip2 utility}.
9007
9008   Recent versions of @command{lbzip2} are mostly command line compatible
9009 with @command{bzip2}, which makes it possible to automatically invoke
9010 it via the @option{--bzip2} @GNUTAR{} command line option.  To do so,
9011 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9012 line option, like this:
9013
9014 @smallexample
9015 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9016 @end smallexample
9017
9018   Once configured and compiled this way, @command{tar --help} will show the
9019 following:
9020
9021 @smallexample
9022 @group
9023 $ @kbd{tar --help | grep -- --bzip2}
9024   -j, --bzip2                filter the archive through lbzip2
9025 @end group
9026 @end smallexample
9027
9028 @noindent
9029 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9030
9031 @node sparse
9032 @subsection Archiving Sparse Files
9033 @cindex Sparse Files
9034
9035 Files in the file system occasionally have @dfn{holes}.  A @dfn{hole}
9036 in a file is a section of the file's contents which was never written.
9037 The contents of a hole reads as all zeros.  On many operating systems,
9038 actual disk storage is not allocated for holes, but they are counted
9039 in the length of the file.  If you archive such a file, @command{tar}
9040 could create an archive longer than the original.  To have @command{tar}
9041 attempt to recognize the holes in a file, use @option{--sparse}
9042 (@option{-S}).  When you use this option, then, for any file using
9043 less disk space than would be expected from its length, @command{tar}
9044 searches the file for consecutive stretches of zeros.  It then records
9045 in the archive for the file where the consecutive stretches of zeros
9046 are, and only archives the ``real contents'' of the file.  On
9047 extraction (using @option{--sparse} is not needed on extraction) any
9048 such files have holes created wherever the continuous stretches of zeros
9049 were found.  Thus, if you use @option{--sparse}, @command{tar} archives
9050 won't take more space than the original.
9051
9052 @table @option
9053 @opindex sparse
9054 @item -S
9055 @itemx --sparse
9056 This option instructs @command{tar} to test each file for sparseness
9057 before attempting to archive it.  If the file is found to be sparse it
9058 is treated specially, thus allowing to decrease the amount of space
9059 used by its image in the archive.
9060
9061 This option is meaningful only when creating or updating archives.  It
9062 has no effect on extraction.
9063 @end table
9064
9065 Consider using @option{--sparse} when performing file system backups,
9066 to avoid archiving the expanded forms of files stored sparsely in the
9067 system.
9068
9069 Even if your system has no sparse files currently, some may be
9070 created in the future.  If you use @option{--sparse} while making file
9071 system backups as a matter of course, you can be assured the archive
9072 will never take more space on the media than the files take on disk
9073 (otherwise, archiving a disk filled with sparse files might take
9074 hundreds of tapes).  @xref{Incremental Dumps}.
9075
9076 However, be aware that @option{--sparse} option presents a serious
9077 drawback.  Namely, in order to determine if the file is sparse
9078 @command{tar} has to read it before trying to archive it, so in total
9079 the file is read @strong{twice}.  So, always bear in mind that the
9080 time needed to process all files with this option is roughly twice
9081 the time needed to archive them without it.
9082 @FIXME{A technical note:
9083
9084 Programs like @command{dump} do not have to read the entire file; by
9085 examining the file system directly, they can determine in advance
9086 exactly where the holes are and thus avoid reading through them.  The
9087 only data it need read are the actual allocated data blocks.
9088 @GNUTAR{} uses a more portable and straightforward
9089 archiving approach, it would be fairly difficult that it does
9090 otherwise.  Elizabeth Zwicky writes to @file{comp.unix.internals}, on
9091 1990-12-10:
9092
9093 @quotation
9094 What I did say is that you cannot tell the difference between a hole and an
9095 equivalent number of nulls without reading raw blocks.  @code{st_blocks} at
9096 best tells you how many holes there are; it doesn't tell you @emph{where}.
9097 Just as programs may, conceivably, care what @code{st_blocks} is (care
9098 to name one that does?), they may also care where the holes are (I have
9099 no examples of this one either, but it's equally imaginable).
9100
9101 I conclude from this that good archivers are not portable.  One can
9102 arguably conclude that if you want a portable program, you can in good
9103 conscience restore files with as many holes as possible, since you can't
9104 get it right.
9105 @end quotation
9106 }
9107
9108 @cindex sparse formats, defined
9109 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9110 sparse files using in three distinct ways, called @dfn{sparse
9111 formats}.  A sparse format is identified by its @dfn{number},
9112 consisting, as usual of two decimal numbers, delimited by a dot.  By
9113 default, format @samp{1.0} is used.  If, for some reason, you wish to
9114 use an earlier format, you can select it using
9115 @option{--sparse-version} option.
9116
9117 @table @option
9118 @opindex sparse-version
9119 @item --sparse-version=@var{version}
9120
9121 Select the format to store sparse files in.  Valid @var{version} values
9122 are: @samp{0.0}, @samp{0.1} and @samp{1.0}.  @xref{Sparse Formats},
9123 for a detailed description of each format.
9124 @end table
9125
9126 Using @option{--sparse-format} option implies @option{--sparse}.
9127
9128 @node Attributes
9129 @section Handling File Attributes
9130 @cindex atrributes, files
9131 @cindex file attributes
9132
9133 When @command{tar} reads files, it updates their access times.  To
9134 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
9135 reset the access time retroactively or avoid changing it in the first
9136 place.
9137
9138 @table @option
9139 @opindex atime-preserve
9140 @item --atime-preserve
9141 @itemx --atime-preserve=replace
9142 @itemx --atime-preserve=system
9143 Preserve the access times of files that are read.  This works only for
9144 files that you own, unless you have superuser privileges.
9145
9146 @option{--atime-preserve=replace} works on most systems, but it also
9147 restores the data modification time and updates the status change
9148 time.  Hence it doesn't interact with incremental dumps nicely
9149 (@pxref{Incremental Dumps}), and it can set access or data modification times
9150 incorrectly if other programs access the file while @command{tar} is
9151 running.
9152
9153 @option{--atime-preserve=system} avoids changing the access time in
9154 the first place, if the operating system supports this.
9155 Unfortunately, this may or may not work on any given operating system
9156 or file system.  If @command{tar} knows for sure it won't work, it
9157 complains right away.
9158
9159 Currently @option{--atime-preserve} with no operand defaults to
9160 @option{--atime-preserve=replace}, but this is intended to change to
9161 @option{--atime-preserve=system} when the latter is better-supported.
9162
9163 @opindex touch
9164 @item -m
9165 @itemx --touch
9166 Do not extract data modification time.
9167
9168 When this option is used, @command{tar} leaves the data modification times
9169 of the files it extracts as the times when the files were extracted,
9170 instead of setting it to the times recorded in the archive.
9171
9172 This option is meaningless with @option{--list} (@option{-t}).
9173
9174 @opindex same-owner
9175 @item --same-owner
9176 Create extracted files with the same ownership they have in the
9177 archive.
9178
9179 This is the default behavior for the superuser,
9180 so this option is meaningful only for non-root users, when @command{tar}
9181 is executed on those systems able to give files away.  This is
9182 considered as a security flaw by many people, at least because it
9183 makes quite difficult to correctly account users for the disk space
9184 they occupy.  Also, the @code{suid} or @code{sgid} attributes of
9185 files are easily and silently lost when files are given away.
9186
9187 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
9188 separately.  If it can't find a user name (because the user @acronym{ID} is not
9189 in @file{/etc/passwd}), then it does not write one.  When restoring,
9190 it tries to look the name (if one was written) up in
9191 @file{/etc/passwd}.  If it fails, then it uses the user @acronym{ID} stored in
9192 the archive instead.
9193
9194 @opindex no-same-owner
9195 @item --no-same-owner
9196 @itemx -o
9197 Do not attempt to restore ownership when extracting.  This is the
9198 default behavior for ordinary users, so this option has an effect
9199 only for the superuser.
9200
9201 @opindex numeric-owner
9202 @item --numeric-owner
9203 The @option{--numeric-owner} option allows (ANSI) archives to be written
9204 without user/group name information or such information to be ignored
9205 when extracting.  It effectively disables the generation and/or use
9206 of user/group name information.  This option forces extraction using
9207 the numeric ids from the archive, ignoring the names.
9208
9209 This is useful in certain circumstances, when restoring a backup from
9210 an emergency floppy with different passwd/group files for example.
9211 It is otherwise impossible to extract files with the right ownerships
9212 if the password file in use during the extraction does not match the
9213 one belonging to the file system(s) being extracted.  This occurs,
9214 for example, if you are restoring your files after a major crash and
9215 had booted from an emergency floppy with no password file or put your
9216 disk into another machine to do the restore.
9217
9218 The numeric ids are @emph{always} saved into @command{tar} archives.
9219 The identifying names are added at create time when provided by the
9220 system, unless @option{--format=oldgnu} is used.  Numeric ids could be
9221 used when moving archives between a collection of machines using
9222 a centralized management for attribution of numeric ids to users
9223 and groups.  This is often made through using the NIS capabilities.
9224
9225 When making a @command{tar} file for distribution to other sites, it
9226 is sometimes cleaner to use a single owner for all files in the
9227 distribution, and nicer to specify the write permission bits of the
9228 files as stored in the archive independently of their actual value on
9229 the file system.  The way to prepare a clean distribution is usually
9230 to have some Makefile rule creating a directory, copying all needed
9231 files in that directory, then setting ownership and permissions as
9232 wanted (there are a lot of possible schemes), and only then making a
9233 @command{tar} archive out of this directory, before cleaning
9234 everything out.  Of course, we could add a lot of options to
9235 @GNUTAR{} for fine tuning permissions and ownership.
9236 This is not the good way, I think.  @GNUTAR{} is
9237 already crowded with options and moreover, the approach just explained
9238 gives you a great deal of control already.
9239
9240 @xopindex{same-permissions, short description}
9241 @xopindex{preserve-permissions, short description}
9242 @item -p
9243 @itemx --same-permissions
9244 @itemx --preserve-permissions
9245 Extract all protection information.
9246
9247 This option causes @command{tar} to set the modes (access permissions) of
9248 extracted files exactly as recorded in the archive.  If this option
9249 is not used, the current @code{umask} setting limits the permissions
9250 on extracted files.  This option is by default enabled when
9251 @command{tar} is executed by a superuser.
9252
9253
9254 This option is meaningless with @option{--list} (@option{-t}).
9255
9256 @opindex preserve
9257 @item --preserve
9258 Same as both @option{--same-permissions} and @option{--same-order}.
9259
9260 This option is deprecated, and will be removed in @GNUTAR{} version 1.23.
9261
9262 @end table
9263
9264 @node Portability
9265 @section Making @command{tar} Archives More Portable
9266
9267 Creating a @command{tar} archive on a particular system that is meant to be
9268 useful later on many other machines and with other versions of @command{tar}
9269 is more challenging than you might think.  @command{tar} archive formats
9270 have been evolving since the first versions of Unix.  Many such formats
9271 are around, and are not always compatible with each other.  This section
9272 discusses a few problems, and gives some advice about making @command{tar}
9273 archives more portable.
9274
9275 One golden rule is simplicity.  For example, limit your @command{tar}
9276 archives to contain only regular files and directories, avoiding
9277 other kind of special files.  Do not attempt to save sparse files or
9278 contiguous files as such.  Let's discuss a few more problems, in turn.
9279
9280 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
9281 archives and archive labels) in GNU and PAX formats.}
9282
9283 @menu
9284 * Portable Names::              Portable Names
9285 * dereference::                 Symbolic Links
9286 * hard links::                  Hard Links
9287 * old::                         Old V7 Archives
9288 * ustar::                       Ustar Archives
9289 * gnu::                         GNU and old GNU format archives.
9290 * posix::                       @acronym{POSIX} archives
9291 * Checksumming::                Checksumming Problems
9292 * Large or Negative Values::    Large files, negative time stamps, etc.
9293 * Other Tars::                  How to Extract GNU-Specific Data Using
9294                                 Other @command{tar} Implementations
9295 @end menu
9296
9297 @node Portable Names
9298 @subsection Portable Names
9299
9300 Use portable file and member names.  A name is portable if it contains
9301 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
9302 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
9303 contain @samp{/-}.  Avoid deep directory nesting.  For portability to
9304 old Unix hosts, limit your file name components to 14 characters or
9305 less.
9306
9307 If you intend to have your @command{tar} archives to be read under
9308 MSDOS, you should not rely on case distinction for file names, and you
9309 might use the @acronym{GNU} @command{doschk} program for helping you
9310 further diagnosing illegal MSDOS names, which are even more limited
9311 than System V's.
9312
9313 @node dereference
9314 @subsection Symbolic Links
9315 @cindex File names, using symbolic links
9316 @cindex Symbolic link as file name
9317
9318 @opindex dereference
9319 Normally, when @command{tar} archives a symbolic link, it writes a
9320 block to the archive naming the target of the link.  In that way, the
9321 @command{tar} archive is a faithful record of the file system contents.
9322 When @option{--dereference} (@option{-h}) is used with
9323 @option{--create} (@option{-c}), @command{tar} archives the files
9324 symbolic links point to, instead of
9325 the links themselves.
9326
9327 When creating portable archives, use @option{--dereference}
9328 (@option{-h}): some systems do not support
9329 symbolic links, and moreover, your distribution might be unusable if
9330 it contains unresolved symbolic links.
9331
9332 When reading from an archive, the @option{--dereference} (@option{-h})
9333 option causes @command{tar} to follow an already-existing symbolic
9334 link when @command{tar} writes or reads a file named in the archive.
9335 Ordinarily, @command{tar} does not follow such a link, though it may
9336 remove the link before writing a new file.  @xref{Dealing with Old
9337 Files}.
9338
9339 The @option{--dereference} option is unsafe if an untrusted user can
9340 modify directories while @command{tar} is running.  @xref{Security}.
9341
9342 @node hard links
9343 @subsection Hard Links
9344 @cindex File names, using hard links
9345 @cindex hard links, dereferencing
9346 @cindex dereferencing hard links
9347
9348 Normally, when @command{tar} archives a hard link, it writes a
9349 block to the archive naming the target of the link (a @samp{1} type
9350 block).  In that way, the actual file contents is stored in file only
9351 once.  For example, consider the following two files:
9352
9353 @smallexample
9354 @group
9355 $ ls
9356 -rw-r--r--   2 gray staff       4 2007-10-30 15:11 one
9357 -rw-r--r--   2 gray staff       4 2007-10-30 15:11 jeden
9358 @end group
9359 @end smallexample
9360
9361 Here, @file{jeden} is a link to @file{one}.  When archiving this
9362 directory with a verbose level 2, you will get an output similar to
9363 the following:
9364
9365 @smallexample
9366 $ tar cfvv ../archive.tar .
9367 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
9368 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
9369 hrw-r--r-- gray/staff        0 2007-10-30 15:11 ./one link to ./jeden
9370 @end smallexample
9371
9372 The last line shows that, instead of storing two copies of the file,
9373 @command{tar} stored it only once, under the name @file{jeden}, and
9374 stored file @file{one} as a hard link to this file.
9375
9376 It may be important to know that all hard links to the given file are
9377 stored in the archive.  For example, this may be necessary for exact
9378 reproduction of the file system.  The following option does that:
9379
9380 @table @option
9381 @xopindex{check-links, described}
9382 @item --check-links
9383 @itemx -l
9384 Check the number of links dumped for each processed file.  If this
9385 number does not match the total number of hard links for the file, print
9386 a warning message.
9387 @end table
9388
9389 For example, trying to archive only file @file{jeden} with this option
9390 produces the following diagnostics:
9391
9392 @smallexample
9393 $ tar -c -f ../archive.tar -l jeden
9394 tar: Missing links to `jeden'.
9395 @end smallexample
9396
9397 Although creating special records for hard links helps keep a faithful
9398 record of the file system contents and makes archives more compact, it
9399 may present some difficulties when extracting individual members from
9400 the archive.  For example, trying to extract file @file{one} from the
9401 archive created in previous examples produces, in the absense of file
9402 @file{jeden}:
9403
9404 @smallexample
9405 $ tar xf archive.tar ./one
9406 tar: ./one: Cannot hard link to `./jeden': No such file or directory
9407 tar: Error exit delayed from previous errors
9408 @end smallexample
9409
9410 The reason for this behavior is that @command{tar} cannot seek back in
9411 the archive to the previous member (in this case, @file{one}), to
9412 extract it@footnote{There are plans to fix this in future releases.}.
9413 If you wish to avoid such problems at the cost of a bigger archive,
9414 use the following option:
9415
9416 @table @option
9417 @xopindex{hard-dereference, described}
9418 @item --hard-dereference
9419 Dereference hard links and store the files they refer to.
9420 @end table
9421
9422 For example, trying this option on our two sample files, we get two
9423 copies in the archive, each of which can then be extracted
9424 independently of the other:
9425
9426 @smallexample
9427 @group
9428 $ tar -c -vv -f ../archive.tar --hard-dereference .
9429 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
9430 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
9431 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./one
9432 @end group
9433 @end smallexample
9434
9435 @node old
9436 @subsection Old V7 Archives
9437 @cindex Format, old style
9438 @cindex Old style format
9439 @cindex Old style archives
9440 @cindex v7 archive format
9441
9442 Certain old versions of @command{tar} cannot handle additional
9443 information recorded by newer @command{tar} programs.  To create an
9444 archive in V7 format (not ANSI), which can be read by these old
9445 versions, specify the @option{--format=v7} option in
9446 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
9447 accepts @option{--portability} or @option{--old-archive} for this
9448 option).  When you specify it,
9449 @command{tar} leaves out information about directories, pipes, fifos,
9450 contiguous files, and device files, and specifies file ownership by
9451 group and user IDs instead of group and user names.
9452
9453 When updating an archive, do not use @option{--format=v7}
9454 unless the archive was created using this option.
9455
9456 In most cases, a @emph{new} format archive can be read by an @emph{old}
9457 @command{tar} program without serious trouble, so this option should
9458 seldom be needed.  On the other hand, most modern @command{tar}s are
9459 able to read old format archives, so it might be safer for you to
9460 always use @option{--format=v7} for your distributions.  Notice,
9461 however, that @samp{ustar} format is a better alternative, as it is
9462 free from many of @samp{v7}'s drawbacks.
9463
9464 @node ustar
9465 @subsection Ustar Archive Format
9466
9467 @cindex ustar archive format
9468 Archive format defined by @acronym{POSIX}.1-1988 specification is called
9469 @code{ustar}.  Although it is more flexible than the V7 format, it
9470 still has many restrictions (@pxref{Formats,ustar}, for the detailed
9471 description of @code{ustar} format).  Along with V7 format,
9472 @code{ustar} format is a good choice for archives intended to be read
9473 with other implementations of @command{tar}.
9474
9475 To create archive in @code{ustar} format, use @option{--format=ustar}
9476 option in conjunction with the @option{--create} (@option{-c}).
9477
9478 @node gnu
9479 @subsection @acronym{GNU} and old @GNUTAR{} format
9480
9481 @cindex GNU archive format
9482 @cindex Old GNU archive format
9483 @GNUTAR{} was based on an early draft of the
9484 @acronym{POSIX} 1003.1 @code{ustar} standard.  @acronym{GNU} extensions to
9485 @command{tar}, such as the support for file names longer than 100
9486 characters, use portions of the @command{tar} header record which were
9487 specified in that @acronym{POSIX} draft as unused.  Subsequent changes in
9488 @acronym{POSIX} have allocated the same parts of the header record for
9489 other purposes.  As a result, @GNUTAR{} format is
9490 incompatible with the current @acronym{POSIX} specification, and with
9491 @command{tar} programs that follow it.
9492
9493 In the majority of cases, @command{tar} will be configured to create
9494 this format by default.  This will change in future releases, since
9495 we plan to make @samp{POSIX} format the default.
9496
9497 To force creation a @GNUTAR{} archive, use option
9498 @option{--format=gnu}.
9499
9500 @node posix
9501 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
9502
9503 @cindex POSIX archive format
9504 @cindex PAX archive format
9505 Starting from version 1.14 @GNUTAR{} features full support for
9506 @acronym{POSIX.1-2001} archives.
9507
9508 A @acronym{POSIX} conformant archive will be created if @command{tar}
9509 was given @option{--format=posix} (@option{--format=pax}) option.  No
9510 special option is required to read and extract from a @acronym{POSIX}
9511 archive.
9512
9513 @menu
9514 * PAX keywords:: Controlling Extended Header Keywords.
9515 @end menu
9516
9517 @node PAX keywords
9518 @subsubsection Controlling Extended Header Keywords
9519
9520 @table @option
9521 @opindex pax-option
9522 @item --pax-option=@var{keyword-list}
9523 Handle keywords in @acronym{PAX} extended headers.  This option is
9524 equivalent to @option{-o} option of the @command{pax} utility.
9525 @end table
9526
9527 @var{Keyword-list} is a comma-separated
9528 list of keyword options, each keyword option taking one of
9529 the following forms:
9530
9531 @table @code
9532 @item delete=@var{pattern}
9533 When used with one of archive-creation commands,
9534 this option instructs @command{tar} to omit from extended header records
9535 that it produces any keywords matching the string @var{pattern}.
9536
9537 When used in extract or list mode, this option instructs tar
9538 to ignore any keywords matching the given @var{pattern} in the extended
9539 header records.  In both cases, matching is performed using the pattern
9540 matching notation described in @acronym{POSIX 1003.2}, 3.13
9541 (@pxref{wildcards}).  For example:
9542
9543 @smallexample
9544 --pax-option delete=security.*
9545 @end smallexample
9546
9547 would suppress security-related information.
9548
9549 @item exthdr.name=@var{string}
9550
9551 This keyword allows user control over the name that is written into the
9552 ustar header blocks for the extended headers.  The name is obtained
9553 from @var{string} after making the following substitutions:
9554
9555 @multitable @columnfractions .25 .55
9556 @headitem Meta-character @tab Replaced By
9557 @item %d @tab  The directory name of the file, equivalent to the
9558 result of the @command{dirname} utility on the translated file name.
9559 @item %f @tab  The name of the file with the directory information
9560 stripped, equivalent to the result of the @command{basename} utility
9561 on the translated file name.
9562 @item %p @tab  The process @acronym{ID} of the @command{tar} process.
9563 @item %% @tab  A @samp{%} character.
9564 @end multitable
9565
9566 Any other @samp{%} characters in @var{string} produce undefined
9567 results.
9568
9569 If no option @samp{exthdr.name=string} is specified, @command{tar}
9570 will use the following default value:
9571
9572 @smallexample
9573 %d/PaxHeaders.%p/%f
9574 @end smallexample
9575
9576 @item exthdr.mtime=@var{value}
9577
9578 This keyword defines the value of the @samp{mtime} field that
9579 is written into the ustar header blocks for the extended headers.
9580 By default, the @samp{mtime} field is set to the modification time
9581 of the archive member described by that extended headers.
9582
9583 @item globexthdr.name=@var{string}
9584 This keyword allows user control over the name that is written into
9585 the ustar header blocks for global extended header records.  The name
9586 is obtained from the contents of @var{string}, after making
9587 the following substitutions:
9588
9589 @multitable @columnfractions .25 .55
9590 @headitem Meta-character @tab Replaced By
9591 @item %n @tab An integer that represents the
9592 sequence number of the global extended header record in the archive,
9593 starting at 1.
9594 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9595 @item %% @tab A @samp{%} character.
9596 @end multitable
9597
9598 Any other @samp{%} characters in @var{string} produce undefined results.
9599
9600 If no option @samp{globexthdr.name=string} is specified, @command{tar}
9601 will use the following default value:
9602
9603 @smallexample
9604 $TMPDIR/GlobalHead.%p.%n
9605 @end smallexample
9606
9607 @noindent
9608 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9609 environment variable.  If @var{TMPDIR} is not set, @command{tar}
9610 uses @samp{/tmp}.
9611
9612 @item globexthdr.mtime=@var{value}
9613
9614 This keyword defines the value of the @samp{mtime} field that
9615 is written into the ustar header blocks for the global extended headers.
9616 By default, the @samp{mtime} field is set to the time when
9617 @command{tar} was invoked.
9618
9619 @item @var{keyword}=@var{value}
9620 When used with one of archive-creation commands, these keyword/value pairs
9621 will be included at the beginning of the archive in a global extended
9622 header record.  When used with one of archive-reading commands,
9623 @command{tar} will behave as if it has encountered these keyword/value
9624 pairs at the beginning of the archive in a global extended header
9625 record.
9626
9627 @item @var{keyword}:=@var{value}
9628 When used with one of archive-creation commands, these keyword/value pairs
9629 will be included as records at the beginning of an extended header for
9630 each file.  This is effectively equivalent to @var{keyword}=@var{value}
9631 form except that it creates no global extended header records.
9632
9633 When used with one of archive-reading commands, @command{tar} will
9634 behave as if these keyword/value pairs were included as records at the
9635 end of each extended header; thus, they will override any global or
9636 file-specific extended header record keywords of the same names.
9637 For example, in the command:
9638
9639 @smallexample
9640 tar --format=posix --create \
9641     --file archive --pax-option gname:=user .
9642 @end smallexample
9643
9644 the group name will be forced to a new value for all files
9645 stored in the archive.
9646 @end table
9647
9648 In any of the forms described above, the @var{value} may be
9649 a string enclosed in curly braces.  In that case, the string
9650 between the braces is understood either as a textual time
9651 representation, as described in @ref{Date input formats}, or a name of
9652 the existing file, starting with @samp{/} or @samp{.}.  In the latter
9653 case, the modification time of that file is used.
9654
9655 For example, to set all modification times to the current date, you
9656 use the following option:
9657
9658 @smallexample
9659 --pax-option='mtime:=@{now@}'
9660 @end smallexample
9661
9662 Note quoting of the option's argument.
9663
9664 @cindex archives, binary equivalent
9665 @cindex binary equivalent archives, creating
9666 As another example, here is the option that ensures that any two
9667 archives created using it, will be binary equivalent if they have the
9668 same contents:
9669
9670 @smallexample
9671 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0
9672 @end smallexample
9673
9674 @node Checksumming
9675 @subsection Checksumming Problems
9676
9677 SunOS and HP-UX @command{tar} fail to accept archives created using
9678 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9679 is, file names having characters with the eight bit set, because they
9680 use signed checksums, while @GNUTAR{} uses unsigned
9681 checksums while creating archives, as per @acronym{POSIX} standards.  On
9682 reading, @GNUTAR{} computes both checksums and
9683 accepts any.  It is somewhat worrying that a lot of people may go
9684 around doing backup of their files using faulty (or at least
9685 non-standard) software, not learning about it until it's time to
9686 restore their missing files with an incompatible file extractor, or
9687 vice versa.
9688
9689 @GNUTAR{} computes checksums both ways, and accept
9690 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9691 wrong checksums.  @GNUTAR{} produces the standard
9692 checksum, however, raising incompatibilities with Sun.  That is to
9693 say, @GNUTAR{} has not been modified to
9694 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9695 I've been told that more recent Sun @command{tar} now read standard
9696 archives, so maybe Sun did a similar patch, after all?
9697
9698 The story seems to be that when Sun first imported @command{tar}
9699 sources on their system, they recompiled it without realizing that
9700 the checksums were computed differently, because of a change in
9701 the default signing of @code{char}'s in their compiler.  So they
9702 started computing checksums wrongly.  When they later realized their
9703 mistake, they merely decided to stay compatible with it, and with
9704 themselves afterwards.  Presumably, but I do not really know, HP-UX
9705 has chosen that their @command{tar} archives to be compatible with Sun's.
9706 The current standards do not favor Sun @command{tar} format.  In any
9707 case, it now falls on the shoulders of SunOS and HP-UX users to get
9708 a @command{tar} able to read the good archives they receive.
9709
9710 @node Large or Negative Values
9711 @subsection Large or Negative Values
9712 @cindex large values
9713 @cindex future time stamps
9714 @cindex negative time stamps
9715 @UNREVISED
9716
9717 The above sections suggest to use @samp{oldest possible} archive
9718 format if in doubt.  However, sometimes it is not possible.  If you
9719 attempt to archive a file whose metadata cannot be represented using
9720 required format, @GNUTAR{} will print error message and ignore such a
9721 file.  You will than have to switch to a format that is able to
9722 handle such values.  The format summary table (@pxref{Formats}) will
9723 help you to do so.
9724
9725 In particular, when trying to archive files larger than 8GB or with
9726 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9727 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9728 @acronym{POSIX} archive formats.  When considering which format to
9729 choose, bear in mind that the @acronym{GNU} format uses
9730 two's-complement base-256 notation to store values that do not fit
9731 into standard @acronym{ustar} range.  Such archives can generally be
9732 read only by a @GNUTAR{} implementation.  Moreover, they sometimes
9733 cannot be correctly restored on another hosts even by @GNUTAR{}.  For
9734 example, using two's complement representation for negative time
9735 stamps that assumes a signed 32-bit @code{time_t} generates archives
9736 that are not portable to hosts with differing @code{time_t}
9737 representations.
9738
9739 On the other hand, @acronym{POSIX} archives, generally speaking, can
9740 be extracted by any tar implementation that understands older
9741 @acronym{ustar} format.  The only exception are files larger than 8GB.
9742
9743 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9744 POSIX-aware tars.}
9745
9746 @node Other Tars
9747 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9748
9749 In previous sections you became acquainted with various quirks
9750 necessary to make your archives portable.  Sometimes you may need to
9751 extract archives containing GNU-specific members using some
9752 third-party @command{tar} implementation or an older version of
9753 @GNUTAR{}.  Of course your best bet is to have @GNUTAR{} installed,
9754 but if it is for some reason impossible, this section will explain
9755 how to cope without it.
9756
9757 When we speak about @dfn{GNU-specific} members we mean two classes of
9758 them: members split between the volumes of a multi-volume archive and
9759 sparse members.  You will be able to always recover such members if
9760 the archive is in PAX format.  In addition split members can be
9761 recovered from archives in old GNU format.  The following subsections
9762 describe the required procedures in detail.
9763
9764 @menu
9765 * Split Recovery::       Members Split Between Volumes
9766 * Sparse Recovery::      Sparse Members
9767 @end menu
9768
9769 @node Split Recovery
9770 @subsubsection Extracting Members Split Between Volumes
9771
9772 @cindex Mutli-volume archives, extracting using non-GNU tars
9773 If a member is split between several volumes of an old GNU format archive
9774 most third party @command{tar} implementation will fail to extract
9775 it.  To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9776 This program is available from
9777 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9778 home page}.  It concatenates several archive volumes into a single
9779 valid archive.  For example, if you have three volumes named from
9780 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9781 extract them using a third-party @command{tar}:
9782
9783 @smallexample
9784 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9785 @end smallexample
9786
9787 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9788 You could use this approach for most (although not all) PAX
9789 format archives as well.  However, extracting split members from a PAX
9790 archive is a much easier task, because PAX volumes are constructed in
9791 such a way that each part of a split member is extracted to a
9792 different file by @command{tar} implementations that are not aware of
9793 GNU extensions.  More specifically, the very first part retains its
9794 original name, and all subsequent parts are named using the pattern:
9795
9796 @smallexample
9797 %d/GNUFileParts.%p/%f.%n
9798 @end smallexample
9799
9800 @noindent
9801 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9802 have the following meaning:
9803
9804 @multitable @columnfractions .25 .55
9805 @headitem Meta-character @tab Replaced By
9806 @item %d @tab  The directory name of the file, equivalent to the
9807 result of the @command{dirname} utility on its full name.
9808 @item %f @tab  The file name of the file, equivalent to the result
9809 of the @command{basename} utility on its full name.
9810 @item %p @tab  The process @acronym{ID} of the @command{tar} process that
9811 created the archive.
9812 @item %n @tab  Ordinal number of this particular part.
9813 @end multitable
9814
9815 For example, if the file @file{var/longfile} was split during archive
9816 creation between three volumes, and the creator @command{tar} process
9817 had process @acronym{ID} @samp{27962}, then the member names will be:
9818
9819 @smallexample
9820 var/longfile
9821 var/GNUFileParts.27962/longfile.1
9822 var/GNUFileParts.27962/longfile.2
9823 @end smallexample
9824
9825 When you extract your archive using a third-party @command{tar}, these
9826 files will be created on your disk, and the only thing you will need
9827 to do to restore your file in its original form is concatenate them in
9828 the proper order, for example:
9829
9830 @smallexample
9831 @group
9832 $ @kbd{cd var}
9833 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9834   GNUFileParts.27962/longfile.2 >> longfile}
9835 $ rm -f GNUFileParts.27962
9836 @end group
9837 @end smallexample
9838
9839 Notice, that if the @command{tar} implementation you use supports PAX
9840 format archives, it will probably emit warnings about unknown keywords
9841 during extraction.  They will look like this:
9842
9843 @smallexample
9844 @group
9845 Tar file too small
9846 Unknown extended header keyword 'GNU.volume.filename' ignored.
9847 Unknown extended header keyword 'GNU.volume.size' ignored.
9848 Unknown extended header keyword 'GNU.volume.offset' ignored.
9849 @end group
9850 @end smallexample
9851
9852 @noindent
9853 You can safely ignore these warnings.
9854
9855 If your @command{tar} implementation is not PAX-aware, you will get
9856 more warnings and more files generated on your disk, e.g.:
9857
9858 @smallexample
9859 @group
9860 $ @kbd{tar xf vol-1.tar}
9861 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
9862 normal file
9863 Unexpected EOF in archive
9864 $ @kbd{tar xf vol-2.tar}
9865 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
9866 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
9867 'x', extracted as normal file
9868 @end group
9869 @end smallexample
9870
9871 Ignore these warnings.  The @file{PaxHeaders.*} directories created
9872 will contain files with @dfn{extended header keywords} describing the
9873 extracted files.  You can delete them, unless they describe sparse
9874 members.  Read further to learn more about them.
9875
9876 @node Sparse Recovery
9877 @subsubsection Extracting Sparse Members
9878
9879 @cindex sparse files, extracting with non-GNU tars
9880 Any @command{tar} implementation will be able to extract sparse members from a
9881 PAX archive.  However, the extracted files will be @dfn{condensed},
9882 i.e., any zero blocks will be removed from them.  When we restore such
9883 a condensed file to its original form, by adding zero blocks (or
9884 @dfn{holes}) back to their original locations, we call this process
9885 @dfn{expanding} a compressed sparse file.
9886
9887 @pindex xsparse
9888 To expand a file, you will need a simple auxiliary program called
9889 @command{xsparse}.  It is available in source form from
9890 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
9891 home page}.
9892
9893 @cindex sparse files v.1.0, extracting with non-GNU tars
9894 Let's begin with archive members in @dfn{sparse format
9895 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
9896 The condensed file will contain both file map and file data, so no
9897 additional data will be needed to restore it.  If the original file
9898 name was @file{@var{dir}/@var{name}}, then the condensed file will be
9899 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
9900 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
9901 @dfn{process @acronym{ID}} of the @command{tar} process which created the
9902 archive (@pxref{PAX keywords}).}.
9903
9904 To expand a version 1.0 file, run @command{xsparse} as follows:
9905
9906 @smallexample
9907 $ @kbd{xsparse @file{cond-file}}
9908 @end smallexample
9909
9910 @noindent
9911 where @file{cond-file} is the name of the condensed file.  The utility
9912 will deduce the name for the resulting expanded file using the
9913 following algorithm:
9914
9915 @enumerate 1
9916 @item If @file{cond-file} does not contain any directories,
9917 @file{../cond-file} will be used;
9918
9919 @item If @file{cond-file} has the form
9920 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
9921 are simple names, with no @samp{/} characters in them, the output file
9922 name will be @file{@var{dir}/@var{name}}.
9923
9924 @item Otherwise, if @file{cond-file} has the form
9925 @file{@var{dir}/@var{name}}, the output file name will be
9926 @file{@var{name}}.
9927 @end enumerate
9928
9929 In the unlikely case when this algorithm does not suit your needs,
9930 you can explicitly specify output file name as a second argument to
9931 the command:
9932
9933 @smallexample
9934 $ @kbd{xsparse @file{cond-file} @file{out-file}}
9935 @end smallexample
9936
9937 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
9938 first.  In this mode, the command does not actually expand the file,
9939 but verbosely lists all actions it would be taking to do so.  The dry
9940 run mode is enabled by @option{-n} command line argument:
9941
9942 @smallexample
9943 @group
9944 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
9945 Reading v.1.0 sparse map
9946 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9947 `/home/gray/sparsefile'
9948 Finished dry run
9949 @end group
9950 @end smallexample
9951
9952 To actually expand the file, you would run:
9953
9954 @smallexample
9955 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
9956 @end smallexample
9957
9958 @noindent
9959 The program behaves the same way all UNIX utilities do: it will keep
9960 quiet unless it has simething important to tell you (e.g. an error
9961 condition or something).  If you wish it to produce verbose output,
9962 similar to that from the dry run mode, use @option{-v} option:
9963
9964 @smallexample
9965 @group
9966 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
9967 Reading v.1.0 sparse map
9968 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9969 `/home/gray/sparsefile'
9970 Done
9971 @end group
9972 @end smallexample
9973
9974 Additionally, if your @command{tar} implementation has extracted the
9975 @dfn{extended headers} for this file, you can instruct @command{xstar}
9976 to use them in order to verify the integrity of the expanded file.
9977 The option @option{-x} sets the name of the extended header file to
9978 use.  Continuing our example:
9979
9980 @smallexample
9981 @group
9982 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
9983   /home/gray/GNUSparseFile.6058/sparsefile}
9984 Reading extended header file
9985 Found variable GNU.sparse.major = 1
9986 Found variable GNU.sparse.minor = 0
9987 Found variable GNU.sparse.name = sparsefile
9988 Found variable GNU.sparse.realsize = 217481216
9989 Reading v.1.0 sparse map
9990 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9991 `/home/gray/sparsefile'
9992 Done
9993 @end group
9994 @end smallexample
9995
9996 @anchor{extracting sparse v.0.x}
9997 @cindex sparse files v.0.1, extracting with non-GNU tars
9998 @cindex sparse files v.0.0, extracting with non-GNU tars
9999 An @dfn{extended header} is a special @command{tar} archive header
10000 that precedes an archive member and contains a set of
10001 @dfn{variables}, describing the member properties that cannot be
10002 stored in the standard @code{ustar} header.  While optional for
10003 expanding sparse version 1.0 members, the use of extended headers is
10004 mandatory when expanding sparse members in older sparse formats: v.0.0
10005 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10006 Formats}.)  So, for these formats, the question is: how to obtain
10007 extended headers from the archive?
10008
10009 If you use a @command{tar} implementation that does not support PAX
10010 format, extended headers for each member will be extracted as a
10011 separate file.  If we represent the member name as
10012 @file{@var{dir}/@var{name}}, then the extended header file will be
10013 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
10014 @var{n} is an integer number.
10015
10016 Things become more difficult if your @command{tar} implementation
10017 does support PAX headers, because in this case you will have to
10018 manually extract the headers.  We recommend the following algorithm:
10019
10020 @enumerate 1
10021 @item
10022 Consult the documentation of your @command{tar} implementation for an
10023 option that prints @dfn{block numbers} along with the archive
10024 listing (analogous to @GNUTAR{}'s @option{-R} option).  For example,
10025 @command{star} has @option{-block-number}.
10026
10027 @item
10028 Obtain verbose listing using the @samp{block number} option, and
10029 find block numbers of the sparse member in question and the member
10030 immediately following it.  For example, running @command{star} on our
10031 archive we obtain:
10032
10033 @smallexample
10034 @group
10035 $ @kbd{star -t -v -block-number -f arc.tar}
10036 @dots{}
10037 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10038 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10039 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10040 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10041 block        56:  425984 -rw-r--r--  gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10042 block       897:   65391 -rw-r--r--  gray/users Jun 24 20:06 2006 README
10043 @dots{}
10044 @end group
10045 @end smallexample
10046
10047 @noindent
10048 (as usual, ignore the warnings about unknown keywords.)
10049
10050 @item
10051 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10052 and @var{Bn} be the block number of the next member.
10053 Compute:
10054
10055 @smallexample
10056 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10057 @end smallexample
10058
10059 @noindent
10060 This number gives the size of the extended header part in tar @dfn{blocks}.
10061 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10062 = 7}.
10063
10064 @item
10065 Use @command{dd} to extract the headers:
10066
10067 @smallexample
10068 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10069 @end smallexample
10070
10071 @noindent
10072 where @var{archive} is the archive name, @var{hname} is a name of the
10073 file to store the extended header in, @var{Bs} and @var{N} are
10074 computed in previous steps.
10075
10076 In our example, this command will be
10077
10078 @smallexample
10079 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
10080 @end smallexample
10081 @end enumerate
10082
10083 Finally, you can expand the condensed file, using the obtained header:
10084
10085 @smallexample
10086 @group
10087 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
10088 Reading extended header file
10089 Found variable GNU.sparse.size = 217481216
10090 Found variable GNU.sparse.numblocks = 208
10091 Found variable GNU.sparse.name = sparsefile
10092 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
10093 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
10094 Done
10095 @end group
10096 @end smallexample
10097
10098 @node cpio
10099 @section Comparison of @command{tar} and @command{cpio}
10100 @UNREVISED
10101
10102 @FIXME{Reorganize the following material}
10103
10104 The @command{cpio} archive formats, like @command{tar}, do have maximum
10105 file name lengths.  The binary and old @acronym{ASCII} formats have a maximum file
10106 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
10107 file length of 1024.  @acronym{GNU} @command{cpio} can read and write archives
10108 with arbitrary file name lengths, but other @command{cpio} implementations
10109 may crash unexplainedly trying to read them.
10110
10111 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
10112 @command{cpio} doesn't handle symbolic links in the form in which it comes
10113 in System V prior to SVR4, and some vendors may have added symlinks
10114 to their system without enhancing @command{cpio} to know about them.
10115 Others may have enhanced it in a way other than the way I did it
10116 at Sun, and which was adopted by AT&T (and which is, I think, also
10117 present in the @command{cpio} that Berkeley picked up from AT&T and put
10118 into a later @acronym{BSD} release---I think I gave them my changes).
10119
10120 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
10121 can handle @command{tar} format input, and write it on output, and it
10122 probably handles symbolic links.  They may not have bothered doing
10123 anything to enhance @command{tar} as a result.)
10124
10125 @command{cpio} handles special files; traditional @command{tar} doesn't.
10126
10127 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
10128 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
10129 (4.3-tahoe and later).
10130
10131 @command{tar}'s way of handling multiple hard links to a file can handle
10132 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
10133 @command{cpio}s way requires you to play some games (in its ``binary''
10134 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
10135 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
10136 field of the header to make sure that the file system @acronym{ID}/i-number pairs
10137 of different files were always different), and I don't know which
10138 @command{cpio}s, if any, play those games.  Those that don't might get
10139 confused and think two files are the same file when they're not, and
10140 make hard links between them.
10141
10142 @command{tar}s way of handling multiple hard links to a file places only
10143 one copy of the link on the tape, but the name attached to that copy
10144 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
10145 way puts one copy for every link, but you can retrieve it using any
10146 of the names.
10147
10148 @quotation
10149 What type of check sum (if any) is used, and how is this calculated.
10150 @end quotation
10151
10152 See the attached manual pages for @command{tar} and @command{cpio} format.
10153 @command{tar} uses a checksum which is the sum of all the bytes in the
10154 @command{tar} header for a file; @command{cpio} uses no checksum.
10155
10156 @quotation
10157 If anyone knows why @command{cpio} was made when @command{tar} was present
10158 at the unix scene,
10159 @end quotation
10160
10161 It wasn't.  @command{cpio} first showed up in PWB/UNIX 1.0; no
10162 generally-available version of UNIX had @command{tar} at the time.  I don't
10163 know whether any version that was generally available @emph{within AT&T}
10164 had @command{tar}, or, if so, whether the people within AT&T who did
10165 @command{cpio} knew about it.
10166
10167 On restore, if there is a corruption on a tape @command{tar} will stop at
10168 that point, while @command{cpio} will skip over it and try to restore the
10169 rest of the files.
10170
10171 The main difference is just in the command syntax and header format.
10172
10173 @command{tar} is a little more tape-oriented in that everything is blocked
10174 to start on a record boundary.
10175
10176 @quotation
10177 Is there any differences between the ability to recover crashed
10178 archives between the two of them.  (Is there any chance of recovering
10179 crashed archives at all.)
10180 @end quotation
10181
10182 Theoretically it should be easier under @command{tar} since the blocking
10183 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
10184 However, modern @command{cpio}'s and variations have an option to just
10185 search for the next file header after an error with a reasonable chance
10186 of resyncing.  However, lots of tape driver software won't allow you to
10187 continue past a media error which should be the only reason for getting
10188 out of sync unless a file changed sizes while you were writing the
10189 archive.
10190
10191 @quotation
10192 If anyone knows why @command{cpio} was made when @command{tar} was present
10193 at the unix scene, please tell me about this too.
10194 @end quotation
10195
10196 Probably because it is more media efficient (by not blocking everything
10197 and using only the space needed for the headers where @command{tar}
10198 always uses 512 bytes per file header) and it knows how to archive
10199 special files.
10200
10201 You might want to look at the freely available alternatives.  The
10202 major ones are @command{afio}, @GNUTAR{}, and
10203 @command{pax}, each of which have their own extensions with some
10204 backwards compatibility.
10205
10206 Sparse files were @command{tar}red as sparse files (which you can
10207 easily test, because the resulting archive gets smaller, and
10208 @acronym{GNU} @command{cpio} can no longer read it).
10209
10210 @node Media
10211 @chapter Tapes and Other Archive Media
10212 @UNREVISED
10213
10214 A few special cases about tape handling warrant more detailed
10215 description.  These special cases are discussed below.
10216
10217 Many complexities surround the use of @command{tar} on tape drives.  Since
10218 the creation and manipulation of archives located on magnetic tape was
10219 the original purpose of @command{tar}, it contains many features making
10220 such manipulation easier.
10221
10222 Archives are usually written on dismountable media---tape cartridges,
10223 mag tapes, or floppy disks.
10224
10225 The amount of data a tape or disk holds depends not only on its size,
10226 but also on how it is formatted.  A 2400 foot long reel of mag tape
10227 holds 40 megabytes of data when formatted at 1600 bits per inch.  The
10228 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
10229
10230 Magnetic media are re-usable---once the archive on a tape is no longer
10231 needed, the archive can be erased and the tape or disk used over.
10232 Media quality does deteriorate with use, however.  Most tapes or disks
10233 should be discarded when they begin to produce data errors.  EXABYTE
10234 tape cartridges should be discarded when they generate an @dfn{error
10235 count} (number of non-usable bits) of more than 10k.
10236
10237 Magnetic media are written and erased using magnetic fields, and
10238 should be protected from such fields to avoid damage to stored data.
10239 Sticking a floppy disk to a filing cabinet using a magnet is probably
10240 not a good idea.
10241
10242 @menu
10243 * Device::                      Device selection and switching
10244 * Remote Tape Server::
10245 * Common Problems and Solutions::
10246 * Blocking::                    Blocking
10247 * Many::                        Many archives on one tape
10248 * Using Multiple Tapes::        Using Multiple Tapes
10249 * label::                       Including a Label in the Archive
10250 * verify::
10251 * Write Protection::
10252 @end menu
10253
10254 @node Device
10255 @section Device Selection and Switching
10256 @UNREVISED
10257
10258 @table @option
10259 @item -f [@var{hostname}:]@var{file}
10260 @itemx --file=[@var{hostname}:]@var{file}
10261 Use archive file or device @var{file} on @var{hostname}.
10262 @end table
10263
10264 This option is used to specify the file name of the archive @command{tar}
10265 works on.
10266
10267 If the file name is @samp{-}, @command{tar} reads the archive from standard
10268 input (when listing or extracting), or writes it to standard output
10269 (when creating).  If the @samp{-} file name is given when updating an
10270 archive, @command{tar} will read the original archive from its standard
10271 input, and will write the entire new archive to its standard output.
10272
10273 If the file name contains a @samp{:}, it is interpreted as
10274 @samp{hostname:file name}.  If the @var{hostname} contains an @dfn{at}
10275 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}.  In
10276 either case, @command{tar} will invoke the command @command{rsh} (or
10277 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
10278 machine.  If you give an alternate login name, it will be given to the
10279 @command{rsh}.
10280 Naturally, the remote machine must have an executable
10281 @command{/usr/libexec/rmt}.  This program is free software from the
10282 University of California, and a copy of the source code can be found
10283 with the sources for @command{tar}; it's compiled and installed by default.
10284 The exact path to this utility is determined when configuring the package.
10285 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
10286 your installation prefix.  This location may also be overridden at
10287 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
10288 ---rmt-command}, for detailed description of this option.  @xref{Remote
10289 Tape Server}, for the description of @command{rmt} command).
10290
10291 If this option is not given, but the environment variable @env{TAPE}
10292 is set, its value is used; otherwise, old versions of @command{tar}
10293 used a default archive name (which was picked when @command{tar} was
10294 compiled).  The default is normally set up to be the @dfn{first} tape
10295 drive or other transportable I/O medium on the system.
10296
10297 Starting with version 1.11.5, @GNUTAR{} uses
10298 standard input and standard output as the default device, and I will
10299 not try anymore supporting automatic device detection at installation
10300 time.  This was failing really in too many cases, it was hopeless.
10301 This is now completely left to the installer to override standard
10302 input and standard output for default device, if this seems
10303 preferable.  Further, I think @emph{most} actual usages of
10304 @command{tar} are done with pipes or disks, not really tapes,
10305 cartridges or diskettes.
10306
10307 Some users think that using standard input and output is running
10308 after trouble.  This could lead to a nasty surprise on your screen if
10309 you forget to specify an output file name---especially if you are going
10310 through a network or terminal server capable of buffering large amounts
10311 of output.  We had so many bug reports in that area of configuring
10312 default tapes automatically, and so many contradicting requests, that
10313 we finally consider the problem to be portably intractable.  We could
10314 of course use something like @samp{/dev/tape} as a default, but this
10315 is @emph{also} running after various kind of trouble, going from hung
10316 processes to accidental destruction of real tapes.  After having seen
10317 all this mess, using standard input and output as a default really
10318 sounds like the only clean choice left, and a very useful one too.
10319
10320 @GNUTAR{} reads and writes archive in records, I
10321 suspect this is the main reason why block devices are preferred over
10322 character devices.  Most probably, block devices are more efficient
10323 too.  The installer could also check for @samp{DEFTAPE} in
10324 @file{<sys/mtio.h>}.
10325
10326 @table @option
10327 @xopindex{force-local, short description}
10328 @item --force-local
10329 Archive file is local even if it contains a colon.
10330
10331 @opindex rsh-command
10332 @item --rsh-command=@var{command}
10333 Use remote @var{command} instead of @command{rsh}.  This option exists
10334 so that people who use something other than the standard @command{rsh}
10335 (e.g., a Kerberized @command{rsh}) can access a remote device.
10336
10337 When this command is not used, the shell command found when
10338 the @command{tar} program was installed is used instead.  This is
10339 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
10340 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
10341 The installer may have overridden this by defining the environment
10342 variable @env{RSH} @emph{at installation time}.
10343
10344 @item -[0-7][lmh]
10345 Specify drive and density.
10346
10347 @xopindex{multi-volume, short description}
10348 @item -M
10349 @itemx --multi-volume
10350 Create/list/extract multi-volume archive.
10351
10352 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
10353 that may be larger than will fit on the medium used to hold it.
10354 @xref{Multi-Volume Archives}.
10355
10356 @xopindex{tape-length, short description}
10357 @item -L @var{num}
10358 @itemx --tape-length=@var{size}[@var{suf}]
10359 Change tape after writing @var{size} units of data.  Unless @var{suf} is
10360 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
10361 1024} bytes.  The following suffixes alter this behavior:
10362
10363 @float Table, size-suffixes
10364 @caption{Size Suffixes}
10365 @multitable @columnfractions 0.2 0.3 0.3
10366 @headitem Suffix @tab Units            @tab Byte Equivalent
10367 @item b          @tab Blocks           @tab @var{size} x 512
10368 @item B          @tab Kilobytes        @tab @var{size} x 1024
10369 @item c          @tab Bytes            @tab @var{size}
10370 @item G          @tab Gigabytes        @tab @var{size} x 1024^3
10371 @item K          @tab Kilobytes        @tab @var{size} x 1024
10372 @item k          @tab Kilobytes        @tab @var{size} x 1024
10373 @item M          @tab Megabytes        @tab @var{size} x 1024^2
10374 @item P          @tab Petabytes        @tab @var{size} x 1024^5
10375 @item T          @tab Terabytes        @tab @var{size} x 1024^4
10376 @item w          @tab Words            @tab @var{size} x 2
10377 @end multitable
10378 @end float
10379
10380 This option might be useful when your tape drivers do not properly
10381 detect end of physical tapes.  By being slightly conservative on the
10382 maximum tape length, you might avoid the problem entirely.
10383
10384 @xopindex{info-script, short description}
10385 @xopindex{new-volume-script, short description}
10386 @item -F @var{file}
10387 @itemx --info-script=@var{file}
10388 @itemx --new-volume-script=@var{file}
10389 Execute @file{file} at end of each tape.  This implies
10390 @option{--multi-volume} (@option{-M}).  @xref{info-script}, for a detailed
10391 description of this option.
10392 @end table
10393
10394 @node Remote Tape Server
10395 @section Remote Tape Server
10396
10397 @cindex remote tape drive
10398 @pindex rmt
10399 In order to access the tape drive on a remote machine, @command{tar}
10400 uses the remote tape server written at the University of California at
10401 Berkeley.  The remote tape server must be installed as
10402 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
10403 want to use.  @command{tar} calls @command{rmt} by running an
10404 @command{rsh} or @command{remsh} to the remote machine, optionally
10405 using a different login name if one is supplied.
10406
10407 A copy of the source for the remote tape server is provided.  It is
10408 Copyright @copyright{} 1983 by the Regents of the University of
10409 California, but can be freely distributed.  It is compiled and
10410 installed by default.
10411
10412 @cindex absolute file names
10413 Unless you use the @option{--absolute-names} (@option{-P}) option,
10414 @GNUTAR{} will not allow you to create an archive that contains
10415 absolute file names (a file name beginning with @samp{/}.) If you try,
10416 @command{tar} will automatically remove the leading @samp{/} from the
10417 file names it stores in the archive.  It will also type a warning
10418 message telling you what it is doing.
10419
10420 When reading an archive that was created with a different
10421 @command{tar} program, @GNUTAR{} automatically
10422 extracts entries in the archive which have absolute file names as if
10423 the file names were not absolute.  This is an important feature.  A
10424 visitor here once gave a @command{tar} tape to an operator to restore;
10425 the operator used Sun @command{tar} instead of @GNUTAR{},
10426 and the result was that it replaced large portions of
10427 our @file{/bin} and friends with versions from the tape; needless to
10428 say, we were unhappy about having to recover the file system from
10429 backup tapes.
10430
10431 For example, if the archive contained a file @file{/usr/bin/computoy},
10432 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
10433 relative to the current directory.  If you want to extract the files in
10434 an archive to the same absolute names that they had when the archive
10435 was created, you should do a @samp{cd /} before extracting the files
10436 from the archive, or you should either use the @option{--absolute-names}
10437 option, or use the command @samp{tar -C / @dots{}}.
10438
10439 @cindex Ultrix 3.1 and write failure
10440 Some versions of Unix (Ultrix 3.1 is known to have this problem),
10441 can claim that a short write near the end of a tape succeeded,
10442 when it actually failed.  This will result in the -M option not
10443 working correctly.  The best workaround at the moment is to use a
10444 significantly larger blocking factor than the default 20.
10445
10446 In order to update an archive, @command{tar} must be able to backspace the
10447 archive in order to reread or rewrite a record that was just read (or
10448 written).  This is currently possible only on two kinds of files: normal
10449 disk files (or any other file that can be backspaced with @samp{lseek}),
10450 and industry-standard 9-track magnetic tape (or any other kind of tape
10451 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
10452
10453 This means that the @option{--append}, @option{--concatenate}, and
10454 @option{--delete} commands will not work on any other kind of file.
10455 Some media simply cannot be backspaced, which means these commands and
10456 options will never be able to work on them.  These non-backspacing
10457 media include pipes and cartridge tape drives.
10458
10459 Some other media can be backspaced, and @command{tar} will work on them
10460 once @command{tar} is modified to do so.
10461
10462 Archives created with the @option{--multi-volume}, @option{--label}, and
10463 @option{--incremental} (@option{-G}) options may not be readable by other version
10464 of @command{tar}.  In particular, restoring a file that was split over
10465 a volume boundary will require some careful work with @command{dd}, if
10466 it can be done at all.  Other versions of @command{tar} may also create
10467 an empty file whose name is that of the volume header.  Some versions
10468 of @command{tar} may create normal files instead of directories archived
10469 with the @option{--incremental} (@option{-G}) option.
10470
10471 @node Common Problems and Solutions
10472 @section Some Common Problems and their Solutions
10473
10474 @ifclear PUBLISH
10475
10476 @format
10477 errors from system:
10478 permission denied
10479 no such file or directory
10480 not owner
10481
10482 errors from @command{tar}:
10483 directory checksum error
10484 header format error
10485
10486 errors from media/system:
10487 i/o error
10488 device busy
10489 @end format
10490
10491 @end ifclear
10492
10493 @node Blocking
10494 @section Blocking
10495 @cindex block
10496 @cindex record
10497
10498 @dfn{Block} and @dfn{record} terminology is rather confused, and it
10499 is also confusing to the expert reader.  On the other hand, readers
10500 who are new to the field have a fresh mind, and they may safely skip
10501 the next two paragraphs, as the remainder of this manual uses those
10502 two terms in a quite consistent way.
10503
10504 John Gilmore, the writer of the public domain @command{tar} from which
10505 @GNUTAR{} was originally derived, wrote (June 1995):
10506
10507 @quotation
10508 The nomenclature of tape drives comes from IBM, where I believe
10509 they were invented for the IBM 650 or so.  On IBM mainframes, what
10510 is recorded on tape are tape blocks.  The logical organization of
10511 data is into records.  There are various ways of putting records into
10512 blocks, including @code{F} (fixed sized records), @code{V} (variable
10513 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
10514 to a block), @code{VB} (variable size records, @var{n} to a block),
10515 @code{VSB} (variable spanned blocked: variable sized records that can
10516 occupy more than one block), etc.  The @code{JCL} @samp{DD RECFORM=}
10517 parameter specified this to the operating system.
10518
10519 The Unix man page on @command{tar} was totally confused about this.
10520 When I wrote @code{PD TAR}, I used the historically correct terminology
10521 (@command{tar} writes data records, which are grouped into blocks).
10522 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
10523 here), and now Fran@,{c}ois has migrated that terminology back
10524 into the source code too.
10525 @end quotation
10526
10527 The term @dfn{physical block} means the basic transfer chunk from or
10528 to a device, after which reading or writing may stop without anything
10529 being lost.  In this manual, the term @dfn{block} usually refers to
10530 a disk physical block, @emph{assuming} that each disk block is 512
10531 bytes in length.  It is true that some disk devices have different
10532 physical blocks, but @command{tar} ignore these differences in its own
10533 format, which is meant to be portable, so a @command{tar} block is always
10534 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
10535 The term @dfn{logical block} often represents the basic chunk of
10536 allocation of many disk blocks as a single entity, which the operating
10537 system treats somewhat atomically; this concept is only barely used
10538 in @GNUTAR{}.
10539
10540 The term @dfn{physical record} is another way to speak of a physical
10541 block, those two terms are somewhat interchangeable.  In this manual,
10542 the term @dfn{record} usually refers to a tape physical block,
10543 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
10544 It is true that archives may be put on disk or used with pipes,
10545 but nevertheless, @command{tar} tries to read and write the archive one
10546 @dfn{record} at a time, whatever the medium in use.  One record is made
10547 up of an integral number of blocks, and this operation of putting many
10548 disk blocks into a single tape block is called @dfn{reblocking}, or
10549 more simply, @dfn{blocking}.  The term @dfn{logical record} refers to
10550 the logical organization of many characters into something meaningful
10551 to the application.  The term @dfn{unit record} describes a small set
10552 of characters which are transmitted whole to or by the application,
10553 and often refers to a line of text.  Those two last terms are unrelated
10554 to what we call a @dfn{record} in @GNUTAR{}.
10555
10556 When writing to tapes, @command{tar} writes the contents of the archive
10557 in chunks known as @dfn{records}.  To change the default blocking
10558 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
10559 @var{512-size}}) option.  Each record will then be composed of
10560 @var{512-size} blocks.  (Each @command{tar} block is 512 bytes.
10561 @xref{Standard}.)  Each file written to the archive uses at least one
10562 full record.  As a result, using a larger record size can result in
10563 more wasted space for small files.  On the other hand, a larger record
10564 size can often be read and written much more efficiently.
10565
10566 Further complicating the problem is that some tape drives ignore the
10567 blocking entirely.  For these, a larger record size can still improve
10568 performance (because the software layers above the tape drive still
10569 honor the blocking), but not as dramatically as on tape drives that
10570 honor blocking.
10571
10572 When reading an archive, @command{tar} can usually figure out the
10573 record size on itself.  When this is the case, and a non-standard
10574 record size was used when the archive was created, @command{tar} will
10575 print a message about a non-standard blocking factor, and then operate
10576 normally.  On some tape devices, however, @command{tar} cannot figure
10577 out the record size itself.  On most of those, you can specify a
10578 blocking factor (with @option{--blocking-factor}) larger than the
10579 actual blocking factor, and then use the @option{--read-full-records}
10580 (@option{-B}) option.  (If you specify a blocking factor with
10581 @option{--blocking-factor} and don't use the
10582 @option{--read-full-records} option, then @command{tar} will not
10583 attempt to figure out the recording size itself.)  On some devices,
10584 you must always specify the record size exactly with
10585 @option{--blocking-factor} when reading, because @command{tar} cannot
10586 figure it out.  In any case, use @option{--list} (@option{-t}) before
10587 doing any extractions to see whether @command{tar} is reading the archive
10588 correctly.
10589
10590 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
10591 putting them into records is to put a whole number of them (one or
10592 more) into each record.  @command{tar} records are all the same size;
10593 at the end of the file there's a block containing all zeros, which
10594 is how you tell that the remainder of the last record(s) are garbage.
10595
10596 In a standard @command{tar} file (no options), the block size is 512
10597 and the record size is 10240, for a blocking factor of 20.  What the
10598 @option{--blocking-factor} option does is sets the blocking factor,
10599 changing the record size while leaving the block size at 512 bytes.
10600 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
10601 most tape drives these days prefer much bigger records in order to
10602 stream and not waste tape.  When writing tapes for myself, some tend
10603 to use a factor of the order of 2048, say, giving a record size of
10604 around one megabyte.
10605
10606 If you use a blocking factor larger than 20, older @command{tar}
10607 programs might not be able to read the archive, so we recommend this
10608 as a limit to use in practice.  @GNUTAR{}, however,
10609 will support arbitrarily large record sizes, limited only by the
10610 amount of virtual memory or the physical characteristics of the tape
10611 device.
10612
10613 @menu
10614 * Format Variations::           Format Variations
10615 * Blocking Factor::             The Blocking Factor of an Archive
10616 @end menu
10617
10618 @node Format Variations
10619 @subsection Format Variations
10620 @cindex Format Parameters
10621 @cindex Format Options
10622 @cindex Options, archive format specifying
10623 @cindex Options, format specifying
10624 @UNREVISED
10625
10626 Format parameters specify how an archive is written on the archive
10627 media.  The best choice of format parameters will vary depending on
10628 the type and number of files being archived, and on the media used to
10629 store the archive.
10630
10631 To specify format parameters when accessing or creating an archive,
10632 you can use the options described in the following sections.
10633 If you do not specify any format parameters, @command{tar} uses
10634 default parameters.  You cannot modify a compressed archive.
10635 If you create an archive with the @option{--blocking-factor} option
10636 specified (@pxref{Blocking Factor}), you must specify that
10637 blocking-factor when operating on the archive.  @xref{Formats}, for other
10638 examples of format parameter considerations.
10639
10640 @node Blocking Factor
10641 @subsection The Blocking Factor of an Archive
10642 @cindex Blocking Factor
10643 @cindex Record Size
10644 @cindex Number of blocks per record
10645 @cindex Number of bytes per record
10646 @cindex Bytes per record
10647 @cindex Blocks per record
10648 @UNREVISED
10649
10650 @opindex blocking-factor
10651 The data in an archive is grouped into blocks, which are 512 bytes.
10652 Blocks are read and written in whole number multiples called
10653 @dfn{records}.  The number of blocks in a record (i.e., the size of a
10654 record in units of 512 bytes) is called the @dfn{blocking factor}.
10655 The @option{--blocking-factor=@var{512-size}} (@option{-b
10656 @var{512-size}}) option specifies the blocking factor of an archive.
10657 The default blocking factor is typically 20 (i.e., 10240 bytes), but
10658 can be specified at installation.  To find out the blocking factor of
10659 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10660 This may not work on some devices.
10661
10662 Records are separated by gaps, which waste space on the archive media.
10663 If you are archiving on magnetic tape, using a larger blocking factor
10664 (and therefore larger records) provides faster throughput and allows you
10665 to fit more data on a tape (because there are fewer gaps).  If you are
10666 archiving on cartridge, a very large blocking factor (say 126 or more)
10667 greatly increases performance.  A smaller blocking factor, on the other
10668 hand, may be useful when archiving small files, to avoid archiving lots
10669 of nulls as @command{tar} fills out the archive to the end of the record.
10670 In general, the ideal record size depends on the size of the
10671 inter-record gaps on the tape you are using, and the average size of the
10672 files you are archiving.  @xref{create}, for information on
10673 writing archives.
10674
10675 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10676
10677 Archives with blocking factors larger than 20 cannot be read
10678 by very old versions of @command{tar}, or by some newer versions
10679 of @command{tar} running on old machines with small address spaces.
10680 With @GNUTAR{}, the blocking factor of an archive is limited
10681 only by the maximum record size of the device containing the archive,
10682 or by the amount of available virtual memory.
10683
10684 Also, on some systems, not using adequate blocking factors, as sometimes
10685 imposed by the device drivers, may yield unexpected diagnostics.  For
10686 example, this has been reported:
10687
10688 @smallexample
10689 Cannot write to /dev/dlt: Invalid argument
10690 @end smallexample
10691
10692 @noindent
10693 In such cases, it sometimes happen that the @command{tar} bundled by
10694 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10695 requires an explicit specification for the block size,
10696 which it cannot guess.  This yields some people to consider
10697 @GNUTAR{} is misbehaving, because by comparison,
10698 @cite{the bundle @command{tar} works OK}.  Adding @w{@kbd{-b 256}},
10699 for example, might resolve the problem.
10700
10701 If you use a non-default blocking factor when you create an archive, you
10702 must specify the same blocking factor when you modify that archive.  Some
10703 archive devices will also require you to specify the blocking factor when
10704 reading that archive, however this is not typically the case.  Usually, you
10705 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10706 reports a non-default record size and then lists the archive members as
10707 it would normally.  To extract files from an archive with a non-standard
10708 blocking factor (particularly if you're not sure what the blocking factor
10709 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10710 specifying a blocking factor larger then the blocking factor of the archive
10711 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
10712 @xref{list}, for more information on the @option{--list} (@option{-t})
10713 operation.  @xref{Reading}, for a more detailed explanation of that option.
10714
10715 @table @option
10716 @item --blocking-factor=@var{number}
10717 @itemx -b @var{number}
10718 Specifies the blocking factor of an archive.  Can be used with any
10719 operation, but is usually not necessary with @option{--list} (@option{-t}).
10720 @end table
10721
10722 Device blocking
10723
10724 @table @option
10725 @item -b @var{blocks}
10726 @itemx --blocking-factor=@var{blocks}
10727 Set record size to @math{@var{blocks}*512} bytes.
10728
10729 This option is used to specify a @dfn{blocking factor} for the archive.
10730 When reading or writing the archive, @command{tar}, will do reads and writes
10731 of the archive in records of @math{@var{block}*512} bytes.  This is true
10732 even when the archive is compressed.  Some devices requires that all
10733 write operations be a multiple of a certain size, and so, @command{tar}
10734 pads the archive out to the next record boundary.
10735
10736 The default blocking factor is set when @command{tar} is compiled, and is
10737 typically 20.  Blocking factors larger than 20 cannot be read by very
10738 old versions of @command{tar}, or by some newer versions of @command{tar}
10739 running on old machines with small address spaces.
10740
10741 With a magnetic tape, larger records give faster throughput and fit
10742 more data on a tape (because there are fewer inter-record gaps).
10743 If the archive is in a disk file or a pipe, you may want to specify
10744 a smaller blocking factor, since a large one will result in a large
10745 number of null bytes at the end of the archive.
10746
10747 When writing cartridge or other streaming tapes, a much larger
10748 blocking factor (say 126 or more) will greatly increase performance.
10749 However, you must specify the same blocking factor when reading or
10750 updating the archive.
10751
10752 Apparently, Exabyte drives have a physical block size of 8K bytes.
10753 If we choose our blocksize as a multiple of 8k bytes, then the problem
10754 seems to disappear.  Id est, we are using block size of 112 right
10755 now, and we haven't had the problem since we switched@dots{}
10756
10757 With @GNUTAR{} the blocking factor is limited only
10758 by the maximum record size of the device containing the archive, or by
10759 the amount of available virtual memory.
10760
10761 However, deblocking or reblocking is virtually avoided in a special
10762 case which often occurs in practice, but which requires all the
10763 following conditions to be simultaneously true:
10764 @itemize @bullet
10765 @item
10766 the archive is subject to a compression option,
10767 @item
10768 the archive is not handled through standard input or output, nor
10769 redirected nor piped,
10770 @item
10771 the archive is directly handled to a local disk, instead of any special
10772 device,
10773 @item
10774 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10775 invocation.
10776 @end itemize
10777
10778 If the output goes directly to a local disk, and not through
10779 stdout, then the last write is not extended to a full record size.
10780 Otherwise, reblocking occurs.  Here are a few other remarks on this
10781 topic:
10782
10783 @itemize @bullet
10784
10785 @item
10786 @command{gzip} will complain about trailing garbage if asked to
10787 uncompress a compressed archive on tape, there is an option to turn
10788 the message off, but it breaks the regularity of simply having to use
10789 @samp{@var{prog} -d} for decompression.  It would be nice if gzip was
10790 silently ignoring any number of trailing zeros.  I'll ask Jean-loup
10791 Gailly, by sending a copy of this message to him.
10792
10793 @item
10794 @command{compress} does not show this problem, but as Jean-loup pointed
10795 out to Michael, @samp{compress -d} silently adds garbage after
10796 the result of decompression, which tar ignores because it already
10797 recognized its end-of-file indicator.  So this bug may be safely
10798 ignored.
10799
10800 @item
10801 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10802 but will still return an exit status of 2 which tar reports in turn.
10803 @command{tar} might ignore the exit status returned, but I hate doing
10804 that, as it weakens the protection @command{tar} offers users against
10805 other possible problems at decompression time.  If @command{gzip} was
10806 silently skipping trailing zeros @emph{and} also avoiding setting the
10807 exit status in this innocuous case, that would solve this situation.
10808
10809 @item
10810 @command{tar} should become more solid at not stopping to read a pipe at
10811 the first null block encountered.  This inelegantly breaks the pipe.
10812 @command{tar} should rather drain the pipe out before exiting itself.
10813 @end itemize
10814
10815 @xopindex{ignore-zeros, short description}
10816 @item -i
10817 @itemx --ignore-zeros
10818 Ignore blocks of zeros in archive (means EOF).
10819
10820 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10821 of zeros in the archive.  Normally a block of zeros indicates the
10822 end of the archive, but when reading a damaged archive, or one which
10823 was created by concatenating several archives together, this option
10824 allows @command{tar} to read the entire archive.  This option is not on
10825 by default because many versions of @command{tar} write garbage after
10826 the zeroed blocks.
10827
10828 Note that this option causes @command{tar} to read to the end of the
10829 archive file, which may sometimes avoid problems when multiple files
10830 are stored on a single physical tape.
10831
10832 @xopindex{read-full-records, short description}
10833 @item -B
10834 @itemx --read-full-records
10835 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10836
10837 If @option{--read-full-records} is used, @command{tar}
10838 will not panic if an attempt to read a record from the archive does
10839 not return a full record.  Instead, @command{tar} will keep reading
10840 until it has obtained a full
10841 record.
10842
10843 This option is turned on by default when @command{tar} is reading
10844 an archive from standard input, or from a remote machine.  This is
10845 because on @acronym{BSD} Unix systems, a read of a pipe will return however
10846 much happens to be in the pipe, even if it is less than @command{tar}
10847 requested.  If this option was not used, @command{tar} would fail as
10848 soon as it read an incomplete record from the pipe.
10849
10850 This option is also useful with the commands for updating an archive.
10851
10852 @end table
10853
10854 Tape blocking
10855
10856 @FIXME{Appropriate options should be moved here from elsewhere.}
10857
10858 @cindex blocking factor
10859 @cindex tape blocking
10860
10861 When handling various tapes or cartridges, you have to take care of
10862 selecting a proper blocking, that is, the number of disk blocks you
10863 put together as a single tape block on the tape, without intervening
10864 tape gaps.  A @dfn{tape gap} is a small landing area on the tape
10865 with no information on it, used for decelerating the tape to a
10866 full stop, and for later regaining the reading or writing speed.
10867 When the tape driver starts reading a record, the record has to
10868 be read whole without stopping, as a tape gap is needed to stop the
10869 tape motion without losing information.
10870
10871 @cindex Exabyte blocking
10872 @cindex DAT blocking
10873 Using higher blocking (putting more disk blocks per tape block) will use
10874 the tape more efficiently as there will be less tape gaps.  But reading
10875 such tapes may be more difficult for the system, as more memory will be
10876 required to receive at once the whole record.  Further, if there is a
10877 reading error on a huge record, this is less likely that the system will
10878 succeed in recovering the information.  So, blocking should not be too
10879 low, nor it should be too high.  @command{tar} uses by default a blocking of
10880 20 for historical reasons, and it does not really matter when reading or
10881 writing to disk.  Current tape technology would easily accommodate higher
10882 blockings.  Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
10883 We were told that for some DLT drives, the blocking should be a multiple
10884 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
10885 Other manufacturers may use different recommendations for the same tapes.
10886 This might also depends of the buffering techniques used inside modern
10887 tape controllers.  Some imposes a minimum blocking, or a maximum blocking.
10888 Others request blocking to be some exponent of two.
10889
10890 So, there is no fixed rule for blocking.  But blocking at read time
10891 should ideally be the same as blocking used at write time.  At one place
10892 I know, with a wide variety of equipment, they found it best to use a
10893 blocking of 32 to guarantee that their tapes are fully interchangeable.
10894
10895 I was also told that, for recycled tapes, prior erasure (by the same
10896 drive unit that will be used to create the archives) sometimes lowers
10897 the error rates observed at rewriting time.
10898
10899 I might also use @option{--number-blocks} instead of
10900 @option{--block-number}, so @option{--block} will then expand to
10901 @option{--blocking-factor} unambiguously.
10902
10903 @node Many
10904 @section Many Archives on One Tape
10905
10906 @FIXME{Appropriate options should be moved here from elsewhere.}
10907
10908 @findex ntape @r{device}
10909 Most tape devices have two entries in the @file{/dev} directory, or
10910 entries that come in pairs, which differ only in the minor number for
10911 this device.  Let's take for example @file{/dev/tape}, which often
10912 points to the only or usual tape device of a given system.  There might
10913 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}.  The simpler
10914 name is the @emph{rewinding} version of the device, while the name
10915 having @samp{nr} in it is the @emph{no rewinding} version of the same
10916 device.
10917
10918 A rewinding tape device will bring back the tape to its beginning point
10919 automatically when this device is opened or closed.  Since @command{tar}
10920 opens the archive file before using it and closes it afterwards, this
10921 means that a simple:
10922
10923 @smallexample
10924 $ @kbd{tar cf /dev/tape @var{directory}}
10925 @end smallexample
10926
10927 @noindent
10928 will reposition the tape to its beginning both prior and after saving
10929 @var{directory} contents to it, thus erasing prior tape contents and
10930 making it so that any subsequent write operation will destroy what has
10931 just been saved.
10932
10933 @cindex tape positioning
10934 So, a rewinding device is normally meant to hold one and only one file.
10935 If you want to put more than one @command{tar} archive on a given tape, you
10936 will need to avoid using the rewinding version of the tape device.  You
10937 will also have to pay special attention to tape positioning.  Errors in
10938 positioning may overwrite the valuable data already on your tape.  Many
10939 people, burnt by past experiences, will only use rewinding devices and
10940 limit themselves to one file per tape, precisely to avoid the risk of
10941 such errors.  Be fully aware that writing at the wrong position on a
10942 tape loses all information past this point and most probably until the
10943 end of the tape, and this destroyed information @emph{cannot} be
10944 recovered.
10945
10946 To save @var{directory-1} as a first archive at the beginning of a
10947 tape, and leave that tape ready for a second archive, you should use:
10948
10949 @smallexample
10950 $ @kbd{mt -f /dev/nrtape rewind}
10951 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
10952 @end smallexample
10953
10954 @cindex tape marks
10955 @dfn{Tape marks} are special magnetic patterns written on the tape
10956 media, which are later recognizable by the reading hardware.  These
10957 marks are used after each file, when there are many on a single tape.
10958 An empty file (that is to say, two tape marks in a row) signal the
10959 logical end of the tape, after which no file exist.  Usually,
10960 non-rewinding tape device drivers will react to the close request issued
10961 by @command{tar} by first writing two tape marks after your archive, and by
10962 backspacing over one of these.  So, if you remove the tape at that time
10963 from the tape drive, it is properly terminated.  But if you write
10964 another file at the current position, the second tape mark will be
10965 erased by the new information, leaving only one tape mark between files.
10966
10967 So, you may now save @var{directory-2} as a second archive after the
10968 first on the same tape by issuing the command:
10969
10970 @smallexample
10971 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
10972 @end smallexample
10973
10974 @noindent
10975 and so on for all the archives you want to put on the same tape.
10976
10977 Another usual case is that you do not write all the archives the same
10978 day, and you need to remove and store the tape between two archive
10979 sessions.  In general, you must remember how many files are already
10980 saved on your tape.  Suppose your tape already has 16 files on it, and
10981 that you are ready to write the 17th.  You have to take care of skipping
10982 the first 16 tape marks before saving @var{directory-17}, say, by using
10983 these commands:
10984
10985 @smallexample
10986 $ @kbd{mt -f /dev/nrtape rewind}
10987 $ @kbd{mt -f /dev/nrtape fsf 16}
10988 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
10989 @end smallexample
10990
10991 In all the previous examples, we put aside blocking considerations, but
10992 you should do the proper things for that as well.  @xref{Blocking}.
10993
10994 @menu
10995 * Tape Positioning::            Tape Positions and Tape Marks
10996 * mt::                          The @command{mt} Utility
10997 @end menu
10998
10999 @node Tape Positioning
11000 @subsection Tape Positions and Tape Marks
11001 @UNREVISED
11002
11003 Just as archives can store more than one file from the file system,
11004 tapes can store more than one archive file.  To keep track of where
11005 archive files (or any other type of file stored on tape) begin and
11006 end, tape archive devices write magnetic @dfn{tape marks} on the
11007 archive media.  Tape drives write one tape mark between files,
11008 two at the end of all the file entries.
11009
11010 If you think of data as a series of records "rrrr"'s, and tape marks as
11011 "*"'s, a tape might look like the following:
11012
11013 @smallexample
11014 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11015 @end smallexample
11016
11017 Tape devices read and write tapes using a read/write @dfn{tape
11018 head}---a physical part of the device which can only access one
11019 point on the tape at a time.  When you use @command{tar} to read or
11020 write archive data from a tape device, the device will begin reading
11021 or writing from wherever on the tape the tape head happens to be,
11022 regardless of which archive or what part of the archive the tape
11023 head is on.  Before writing an archive, you should make sure that no
11024 data on the tape will be overwritten (unless it is no longer needed).
11025 Before reading an archive, you should make sure the tape head is at
11026 the beginning of the archive you want to read.  You can do it manually
11027 via @code{mt} utility (@pxref{mt}).  The @code{restore} script does
11028 that automatically (@pxref{Scripted Restoration}).
11029
11030 If you want to add new archive file entries to a tape, you should
11031 advance the tape to the end of the existing file entries, backspace
11032 over the last tape mark, and write the new archive file.  If you were
11033 to add two archives to the example above, the tape might look like the
11034 following:
11035
11036 @smallexample
11037 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11038 @end smallexample
11039
11040 @node mt
11041 @subsection The @command{mt} Utility
11042 @UNREVISED
11043
11044 @FIXME{Is it true that this only works on non-block devices?
11045 should explain the difference, (fixed or variable).}
11046 @xref{Blocking Factor}.
11047
11048 You can use the @command{mt} utility to advance or rewind a tape past a
11049 specified number of archive files on the tape.  This will allow you
11050 to move to the beginning of an archive before extracting or reading
11051 it, or to the end of all the archives before writing a new one.
11052 @FIXME{Why isn't there an "advance 'til you find two tape marks
11053 together"?}
11054
11055 The syntax of the @command{mt} command is:
11056
11057 @smallexample
11058 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11059 @end smallexample
11060
11061 where @var{tapename} is the name of the tape device, @var{number} is
11062 the number of times an operation is performed (with a default of one),
11063 and @var{operation} is one of the following:
11064
11065 @FIXME{is there any use for record operations?}
11066
11067 @table @option
11068 @item eof
11069 @itemx weof
11070 Writes @var{number} tape marks at the current position on the tape.
11071
11072 @item fsf
11073 Moves tape position forward @var{number} files.
11074
11075 @item bsf
11076 Moves tape position back @var{number} files.
11077
11078 @item rewind
11079 Rewinds the tape.  (Ignores @var{number}.)
11080
11081 @item offline
11082 @itemx rewoff1
11083 Rewinds the tape and takes the tape device off-line.  (Ignores @var{number}.)
11084
11085 @item status
11086 Prints status information about the tape unit.
11087
11088 @end table
11089
11090 If you don't specify a @var{tapename}, @command{mt} uses the environment
11091 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
11092 the default device specified in your @file{sys/mtio.h} file
11093 (@code{DEFTAPE} variable).  If this is not defined, the program will
11094 display a descriptive error message and exit with code 1.
11095
11096 @command{mt} returns a 0 exit status when the operation(s) were
11097 successful, 1 if the command was unrecognized, and 2 if an operation
11098 failed.
11099
11100 @node Using Multiple Tapes
11101 @section Using Multiple Tapes
11102
11103 Often you might want to write a large archive, one larger than will fit
11104 on the actual tape you are using.  In such a case, you can run multiple
11105 @command{tar} commands, but this can be inconvenient, particularly if you
11106 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
11107 Therefore, @command{tar} provides a special mode for creating
11108 multi-volume archives.
11109
11110 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
11111 on several media volumes of fixed size.  Although in this section we will
11112 often call @samp{volume} a @dfn{tape}, there is absolutely no
11113 requirement for multi-volume archives to be stored on tapes.  Instead,
11114 they can use whatever media type the user finds convenient, they can
11115 even be located on files.
11116
11117 When creating a multi-volume archive, @GNUTAR{} continues to fill
11118 current volume until it runs out of space, then it switches to
11119 next volume (usually the operator is queried to replace the tape on
11120 this point), and continues working on the new volume.  This operation
11121 continues until all requested files are dumped.  If @GNUTAR{} detects
11122 end of media while dumping a file, such a file is archived in split
11123 form.  Some very big files can even be split across several volumes.
11124
11125 Each volume is itself a valid @GNUTAR{} archive, so it can be read
11126 without any special options.  Consequently any file member residing
11127 entirely on one volume can be extracted or otherwise operated upon
11128 without needing the other volume.  Sure enough, to extract a split
11129 member you would need all volumes its parts reside on.
11130
11131 Multi-volume archives suffer from several limitations.  In particular,
11132 they cannot be compressed.
11133
11134 @GNUTAR{} is able to create multi-volume archives of two formats
11135 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
11136
11137 @menu
11138 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
11139 * Tape Files::                  Tape Files
11140 * Tarcat::                      Concatenate Volumes into a Single Archive
11141
11142 @end menu
11143
11144 @node Multi-Volume Archives
11145 @subsection Archives Longer than One Tape or Disk
11146 @cindex Multi-volume archives
11147
11148 @opindex multi-volume
11149 To create an archive that is larger than will fit on a single unit of
11150 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
11151 the @option{--create} option (@pxref{create}).  A @dfn{multi-volume}
11152 archive can be manipulated like any other archive (provided the
11153 @option{--multi-volume} option is specified), but is stored on more
11154 than one tape or file.
11155
11156 When you specify @option{--multi-volume}, @command{tar} does not report an
11157 error when it comes to the end of an archive volume (when reading), or
11158 the end of the media (when writing).  Instead, it prompts you to load
11159 a new storage volume.  If the archive is on a magnetic tape, you
11160 should change tapes when you see the prompt; if the archive is on a
11161 floppy disk, you should change disks; etc.
11162
11163 @table @option
11164 @item --multi-volume
11165 @itemx -M
11166 Creates a multi-volume archive, when used in conjunction with
11167 @option{--create} (@option{-c}).  To perform any other operation on a multi-volume
11168 archive, specify @option{--multi-volume} in conjunction with that
11169 operation.
11170 For example:
11171
11172 @smallexample
11173 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
11174 @end smallexample
11175 @end table
11176
11177 The method @command{tar} uses to detect end of tape is not perfect, and
11178 fails on some operating systems or on some devices.  If @command{tar}
11179 cannot detect the end of the tape itself, you can use
11180 @option{--tape-length} option to inform it about the capacity of the
11181 tape:
11182
11183 @anchor{tape-length}
11184 @table @option
11185 @opindex tape-length
11186 @item --tape-length=@var{size}[@var{suf}]
11187 @itemx -L @var{size}[@var{suf}]
11188 Set maximum length of a volume.  The @var{suf}, if given, specifies
11189 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
11190 megabytes (@pxref{size-suffixes}, for a list of allowed size
11191 suffixes).  Without @var{suf}, units of 1024 bytes (kilobyte) are
11192 assumed.
11193
11194 This option selects @option{--multi-volume} automatically.  For example:
11195
11196 @smallexample
11197 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
11198 @end smallexample
11199
11200 @noindent
11201 or, which is equivalent:
11202
11203 @smallexample
11204 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
11205 @end smallexample
11206 @end table
11207
11208 @anchor{change volume prompt}
11209 When @GNUTAR{} comes to the end of a storage media, it asks you to
11210 change the volume.  The built-in prompt for POSIX locale
11211 is@footnote{If you run @GNUTAR{} under a different locale, the
11212 translation to the locale's language will be used.}:
11213
11214 @smallexample
11215 Prepare volume #@var{n} for `@var{archive}' and hit return:
11216 @end smallexample
11217
11218 @noindent
11219 where @var{n} is the ordinal number of the volume to be created and
11220 @var{archive} is archive file or device name.
11221
11222 When prompting for a new tape, @command{tar} accepts any of the following
11223 responses:
11224
11225 @table @kbd
11226 @item ?
11227 Request @command{tar} to explain possible responses.
11228 @item q
11229 Request @command{tar} to exit immediately.
11230 @item n @var{file-name}
11231 Request @command{tar} to write the next volume on the file @var{file-name}.
11232 @item !
11233 Request @command{tar} to run a subshell.  This option can be disabled
11234 by giving @option{--restrict} command line option to
11235 @command{tar}@footnote{@xref{--restrict}, for more information about
11236 this option.}.
11237 @item y
11238 Request @command{tar} to begin writing the next volume.
11239 @end table
11240
11241 (You should only type @samp{y} after you have changed the tape;
11242 otherwise @command{tar} will write over the volume it just finished.)
11243
11244 @cindex Volume number file
11245 @cindex volno file
11246 @anchor{volno-file}
11247 @opindex volno-file
11248 The volume number used by @command{tar} in its tape-changing prompt
11249 can be changed; if you give the
11250 @option{--volno-file=@var{file-of-number}} option, then
11251 @var{file-of-number} should be an non-existing file to be created, or
11252 else, a file already containing a decimal number.  That number will be
11253 used as the volume number of the first volume written.  When
11254 @command{tar} is finished, it will rewrite the file with the
11255 now-current volume number. (This does not change the volume number
11256 written on a tape label, as per @ref{label}, it @emph{only} affects
11257 the number used in the prompt.)
11258
11259 @cindex End-of-archive info script
11260 @cindex Info script
11261 @anchor{info-script}
11262 @opindex info-script
11263 @opindex new-volume-script
11264 If you want more elaborate behavior than this, you can write a special
11265 @dfn{new volume script}, that will be responsible for changing the
11266 volume, and instruct @command{tar} to use it instead of its normal
11267 prompting procedure:
11268
11269 @table @option
11270 @item --info-script=@var{script-name}
11271 @itemx --new-volume-script=@var{script-name}
11272 @itemx -F @var{script-name}
11273 Specify the full name of the volume script to use.  The script can be
11274 used to eject cassettes, or to broadcast messages such as
11275 @samp{Someone please come change my tape} when performing unattended
11276 backups.
11277 @end table
11278
11279 The @var{script-name} is executed without any command line
11280 arguments.  It inherits @command{tar}'s shell environment.
11281 Additional data is passed to it via the following
11282 environment variables:
11283
11284 @table @env
11285 @vrindex TAR_VERSION, info script environment variable
11286 @item TAR_VERSION
11287 @GNUTAR{} version number.
11288
11289 @vrindex TAR_ARCHIVE, info script environment variable
11290 @item TAR_ARCHIVE
11291 The name of the archive @command{tar} is processing.
11292
11293 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
11294 @item TAR_BLOCKING_FACTOR
11295 Current blocking factor (@pxref{Blocking}).
11296
11297 @vrindex TAR_VOLUME, info script environment variable
11298 @item TAR_VOLUME
11299 Ordinal number of the volume @command{tar} is about to start.
11300
11301 @vrindex TAR_SUBCOMMAND, info script environment variable
11302 @item TAR_SUBCOMMAND
11303 A short option describing the operation @command{tar} is executing.
11304 @xref{Operations}, for a complete list of subcommand options.
11305
11306 @vrindex TAR_FORMAT, info script environment variable
11307 @item TAR_FORMAT
11308 Format of the archive being processed. @xref{Formats}, for a complete
11309 list of archive format names.
11310
11311 @vrindex TAR_FD, info script environment variable
11312 @item TAR_FD
11313 File descriptor which can be used to communicate the new volume
11314 name to @command{tar}.
11315 @end table
11316
11317 The volume script can instruct @command{tar} to use new archive name,
11318 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
11319
11320 If the info script fails, @command{tar} exits; otherwise, it begins
11321 writing the next volume.
11322
11323 If you want @command{tar} to cycle through a series of files or tape
11324 drives, there are three approaches to choose from.  First of all, you
11325 can give @command{tar} multiple @option{--file} options.  In this case
11326 the specified files will be used, in sequence, as the successive
11327 volumes of the archive.  Only when the first one in the sequence needs
11328 to be used again will @command{tar} prompt for a tape change (or run
11329 the info script).  For example, suppose someone has two tape drives on
11330 a system named @file{/dev/tape0} and @file{/dev/tape1}.  For having
11331 @GNUTAR{} to switch to the second drive when it needs to write the
11332 second tape, and then back to the first tape, etc., just do either of:
11333
11334 @smallexample
11335 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
11336 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
11337 @end smallexample
11338
11339 The second method is to use the @samp{n} response to the tape-change
11340 prompt.
11341
11342 Finally, the most flexible approach is to use a volume script, that
11343 writes new archive name to the file descriptor @env{$TAR_FD}.  For example, the
11344 following volume script will create a series of archive files, named
11345 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
11346 archive being created (as given by @option{--file} option) and
11347 @var{vol} is the ordinal number of the archive being created:
11348
11349 @smallexample
11350 @group
11351 #! /bin/sh
11352 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
11353
11354 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
11355 case $TAR_SUBCOMMAND in
11356 -c)       ;;
11357 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
11358           ;;
11359 *)        exit 1
11360 esac
11361
11362 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
11363 @end group
11364 @end smallexample
11365
11366 The same script can be used while listing, comparing or extracting
11367 from the created archive.  For example:
11368
11369 @smallexample
11370 @group
11371 # @r{Create a multi-volume archive:}
11372 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
11373 # @r{Extract from the created archive:}
11374 $ @kbd{tar -x -f archive.tar -F new-volume .}
11375 @end group
11376 @end smallexample
11377
11378 @noindent
11379 Notice, that the first command had to use @option{-L} option, since
11380 otherwise @GNUTAR{} will end up writing everything to file
11381 @file{archive.tar}.
11382
11383 You can read each individual volume of a multi-volume archive as if it
11384 were an archive by itself.  For example, to list the contents of one
11385 volume, use @option{--list}, without @option{--multi-volume} specified.
11386 To extract an archive member from one volume (assuming it is described
11387 that volume), use @option{--extract}, again without
11388 @option{--multi-volume}.
11389
11390 If an archive member is split across volumes (i.e., its entry begins on
11391 one volume of the media and ends on another), you need to specify
11392 @option{--multi-volume} to extract it successfully.  In this case, you
11393 should load the volume where the archive member starts, and use
11394 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
11395 volumes as it needs them.  @xref{extracting archives}, for more
11396 information about extracting archives.
11397
11398 Multi-volume archives can be modified like any other archive.  To add
11399 files to a multi-volume archive, you need to only mount the last
11400 volume of the archive media (and new volumes, if needed).  For all
11401 other operations, you need to use the entire archive.
11402
11403 If a multi-volume archive was labeled using
11404 @option{--label=@var{archive-label}} (@pxref{label}) when it was
11405 created, @command{tar} will not automatically label volumes which are
11406 added later.  To label subsequent volumes, specify
11407 @option{--label=@var{archive-label}} again in conjunction with the
11408 @option{--append}, @option{--update} or @option{--concatenate} operation.
11409
11410 Notice that multi-volume support is a GNU extension and the archives
11411 created in this mode should be read only using @GNUTAR{}.  If you
11412 absolutely have to process such archives using a third-party @command{tar}
11413 implementation, read @ref{Split Recovery}.
11414
11415 @node Tape Files
11416 @subsection Tape Files
11417 @cindex labeling archives
11418 @opindex label
11419 @UNREVISED
11420
11421 To give the archive a name which will be recorded in it, use the
11422 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
11423 option.  This will write a special block identifying
11424 @var{volume-label} as the name of the archive to the front of the
11425 archive which will be displayed when the archive is listed with
11426 @option{--list}.  If you are creating a multi-volume archive with
11427 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
11428 volume label will have @samp{Volume @var{nnn}} appended to the name
11429 you give, where @var{nnn} is the number of the volume of the archive.
11430 If you use the @option{--label=@var{volume-label}} option when
11431 reading an archive, it checks to make sure the label on the tape
11432 matches the one you gave.  @xref{label}.
11433
11434 When @command{tar} writes an archive to tape, it creates a single
11435 tape file.  If multiple archives are written to the same tape, one
11436 after the other, they each get written as separate tape files.  When
11437 extracting, it is necessary to position the tape at the right place
11438 before running @command{tar}.  To do this, use the @command{mt} command.
11439 For more information on the @command{mt} command and on the organization
11440 of tapes into a sequence of tape files, see @ref{mt}.
11441
11442 People seem to often do:
11443
11444 @smallexample
11445 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
11446 @end smallexample
11447
11448 or such, for pushing a common date in all volumes or an archive set.
11449
11450 @node Tarcat
11451 @subsection Concatenate Volumes into a Single Archive
11452
11453 @pindex tarcat
11454   Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
11455 archive to a single @command{tar} archive.  Simply concatenating all
11456 volumes into one will not work, since each volume carries an additional
11457 information at the beginning.  @GNUTAR{} is shipped with the shell
11458 script @command{tarcat} designed for this purpose.
11459
11460   The script takes a list of files comprising a multi-volume archive
11461 and creates the resulting archive at the standard output.  For example:
11462
11463 @smallexample
11464 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
11465 @end smallexample
11466
11467   The script implements a simple heuristics to determine the format of
11468 the first volume file and to decide how to process the rest of the
11469 files.  However, it makes no attempt to verify whether the files are
11470 given in order or even if they are valid @command{tar} archives.
11471 It uses @command{dd} and does not filter its standard error, so you
11472 will usually see lots of spurious messages.
11473
11474 @FIXME{The script is not installed.  Should we install it?}
11475
11476 @node label
11477 @section Including a Label in the Archive
11478 @cindex Labeling an archive
11479 @cindex Labels on the archive media
11480 @cindex Labeling multi-volume archives
11481
11482 @opindex label
11483   To avoid problems caused by misplaced paper labels on the archive
11484 media, you can include a @dfn{label} entry --- an archive member which
11485 contains the name of the archive --- in the archive itself.  Use the
11486 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11487 option@footnote{Until version 1.10, that option was called
11488 @option{--volume}, but is not available under that name anymore.} in
11489 conjunction with the @option{--create} operation to include a label
11490 entry in the archive as it is being created.
11491
11492 @table @option
11493 @item --label=@var{archive-label}
11494 @itemx -V @var{archive-label}
11495 Includes an @dfn{archive-label} at the beginning of the archive when
11496 the archive is being created, when used in conjunction with the
11497 @option{--create} operation.  Checks to make sure the archive label
11498 matches the one specified (when used in conjunction with any other
11499 operation).
11500 @end table
11501
11502   If you create an archive using both
11503 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11504 and @option{--multi-volume} (@option{-M}), each volume of the archive
11505 will have an archive label of the form @samp{@var{archive-label}
11506 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
11507 next, and so on. @xref{Using Multiple Tapes}, for information on
11508 creating multiple volume archives.
11509
11510 @cindex Volume label, listing
11511 @cindex Listing volume label
11512   The volume label will be displayed by @option{--list} along with
11513 the file contents.  If verbose display is requested, it will also be
11514 explicitly marked as in the example below:
11515
11516 @smallexample
11517 @group
11518 $ @kbd{tar --verbose --list --file=iamanarchive}
11519 V--------- 0 0        0 1992-03-07 12:01 iamalabel--Volume Header--
11520 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
11521 @end group
11522 @end smallexample
11523
11524 @opindex test-label
11525 @anchor{--test-label option}
11526   However, @option{--list} option will cause listing entire
11527 contents of the archive, which may be undesirable (for example, if the
11528 archive is stored on a tape).  You can request checking only the volume
11529 label by specifying @option{--test-label} option.  This option reads only the
11530 first block of an archive, so it can be used with slow storage
11531 devices.  For example:
11532
11533 @smallexample
11534 @group
11535 $ @kbd{tar --test-label --file=iamanarchive}
11536 iamalabel
11537 @end group
11538 @end smallexample
11539
11540   If @option{--test-label} is used with one or more command line
11541 arguments, @command{tar} compares the volume label with each
11542 argument.  It exits with code 0 if a match is found, and with code 1
11543 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
11544 mismatch with an exit code 2 and printed a spurious diagnostics on
11545 stderr.}.  No output is displayed, unless you also used the
11546 @option{--verbose} option.  For example:
11547
11548 @smallexample
11549 @group
11550 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
11551 @result{} 0
11552 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
11553 @result{} 1
11554 @end group
11555 @end smallexample
11556
11557   When used with the @option{--verbose} option, @command{tar}
11558 prints the actual volume label (if any), and a verbose diagnostics in
11559 case of a mismatch:
11560
11561 @smallexample
11562 @group
11563 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
11564 iamalabel
11565 @result{} 0
11566 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
11567 iamalabel
11568 tar: Archive label mismatch
11569 @result{} 1
11570 @end group
11571 @end smallexample
11572
11573   If you request any operation, other than @option{--create}, along
11574 with using @option{--label} option, @command{tar} will first check if
11575 the archive label matches the one specified and will refuse to proceed
11576 if it does not.  Use this as a safety precaution to avoid accidentally
11577 overwriting existing archives.  For example, if you wish to add files
11578 to @file{archive}, presumably labeled with string @samp{My volume},
11579 you will get:
11580
11581 @smallexample
11582 @group
11583 $ @kbd{tar -rf archive --label 'My volume' .}
11584 tar: Archive not labeled to match `My volume'
11585 @end group
11586 @end smallexample
11587
11588 @noindent
11589 in case its label does not match.  This will work even if
11590 @file{archive} is not labeled at all.
11591
11592   Similarly, @command{tar} will refuse to list or extract the
11593 archive if its label doesn't match the @var{archive-label}
11594 specified.  In those cases, @var{archive-label} argument is interpreted
11595 as a globbing-style pattern which must match the actual magnetic
11596 volume label.  @xref{exclude}, for a precise description of how match
11597 is attempted@footnote{Previous versions of @command{tar} used full
11598 regular expression matching, or before that, only exact string
11599 matching, instead of wildcard matchers.  We decided for the sake of
11600 simplicity to use a uniform matching device through
11601 @command{tar}.}.  If the switch @option{--multi-volume} (@option{-M}) is being used,
11602 the volume label matcher will also suffix @var{archive-label} by
11603 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
11604 up.  Since the volume numbering is automatically added in labels at
11605 creation time, it sounded logical to equally help the user taking care
11606 of it when the archive is being read.
11607
11608   You can also use @option{--label} to get a common information on
11609 all tapes of a series.  For having this information different in each
11610 series created through a single script used on a regular basis, just
11611 manage to get some date string as part of the label.  For example:
11612
11613 @smallexample
11614 @group
11615 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
11616 $ @kbd{tar --create --file=/dev/tape --multi-volume \
11617      --label="Daily backup for `date +%Y-%m-%d`"}
11618 @end group
11619 @end smallexample
11620
11621   Some more notes about volume labels:
11622
11623 @itemize @bullet
11624 @item Each label has its own date and time, which corresponds
11625 to the time when @GNUTAR{} initially attempted to write it,
11626 often soon after the operator launches @command{tar} or types the
11627 carriage return telling that the next tape is ready.
11628
11629 @item Comparing date labels to get an idea of tape throughput is
11630 unreliable.  It gives correct results only if the delays for rewinding
11631 tapes and the operator switching them were negligible, which is
11632 usually not the case.
11633 @end itemize
11634
11635 @node verify
11636 @section Verifying Data as It is Stored
11637 @cindex Verifying a write operation
11638 @cindex Double-checking a write operation
11639
11640 @table @option
11641 @item -W
11642 @itemx --verify
11643 @opindex verify, short description
11644 Attempt to verify the archive after writing.
11645 @end table
11646
11647 This option causes @command{tar} to verify the archive after writing it.
11648 Each volume is checked after it is written, and any discrepancies
11649 are recorded on the standard error output.
11650
11651 Verification requires that the archive be on a back-space-able medium.
11652 This means pipes, some cartridge tape drives, and some other devices
11653 cannot be verified.
11654
11655 You can insure the accuracy of an archive by comparing files in the
11656 system with archive members.  @command{tar} can compare an archive to the
11657 file system as the archive is being written, to verify a write
11658 operation, or can compare a previously written archive, to insure that
11659 it is up to date.
11660
11661 @xopindex{verify, using with @option{--create}}
11662 @xopindex{create, using with @option{--verify}}
11663 To check for discrepancies in an archive immediately after it is
11664 written, use the @option{--verify} (@option{-W}) option in conjunction with
11665 the @option{--create} operation.  When this option is
11666 specified, @command{tar} checks archive members against their counterparts
11667 in the file system, and reports discrepancies on the standard error.
11668
11669 To verify an archive, you must be able to read it from before the end
11670 of the last written entry.  This option is useful for detecting data
11671 errors on some tapes.  Archives written to pipes, some cartridge tape
11672 drives, and some other devices cannot be verified.
11673
11674 One can explicitly compare an already made archive with the file
11675 system by using the @option{--compare} (@option{--diff}, @option{-d})
11676 option, instead of using the more automatic @option{--verify} option.
11677 @xref{compare}.
11678
11679 Note that these two options have a slightly different intent.  The
11680 @option{--compare} option checks how identical are the logical contents of some
11681 archive with what is on your disks, while the @option{--verify} option is
11682 really for checking if the physical contents agree and if the recording
11683 media itself is of dependable quality.  So, for the @option{--verify}
11684 operation, @command{tar} tries to defeat all in-memory cache pertaining to
11685 the archive, while it lets the speed optimization undisturbed for the
11686 @option{--compare} option.  If you nevertheless use @option{--compare} for
11687 media verification, you may have to defeat the in-memory cache yourself,
11688 maybe by opening and reclosing the door latch of your recording unit,
11689 forcing some doubt in your operating system about the fact this is really
11690 the same volume as the one just written or read.
11691
11692 The @option{--verify} option would not be necessary if drivers were indeed
11693 able to detect dependably all write failures.  This sometimes require many
11694 magnetic heads, some able to read after the writes occurred.  One would
11695 not say that drivers unable to detect all cases are necessarily flawed,
11696 as long as programming is concerned.
11697
11698 The @option{--verify} (@option{-W}) option will not work in
11699 conjunction with the @option{--multi-volume} (@option{-M}) option or
11700 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11701 and @option{--delete} operations.  @xref{Operations}, for more
11702 information on these operations.
11703
11704 Also, since @command{tar} normally strips leading @samp{/} from file
11705 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11706 /tmp/foo.tar /etc} will work as desired only if the working directory is
11707 @file{/}, as @command{tar} uses the archive's relative member names
11708 (e.g., @file{etc/motd}) when verifying the archive.
11709
11710 @node Write Protection
11711 @section Write Protection
11712
11713 Almost all tapes and diskettes, and in a few rare cases, even disks can
11714 be @dfn{write protected}, to protect data on them from being changed.
11715 Once an archive is written, you should write protect the media to prevent
11716 the archive from being accidentally overwritten or deleted.  (This will
11717 protect the archive from being changed with a tape or floppy drive---it
11718 will not protect it from magnet fields or other physical hazards.)
11719
11720 The write protection device itself is usually an integral part of the
11721 physical media, and can be a two position (write enabled/write
11722 disabled) switch, a notch which can be popped out or covered, a ring
11723 which can be removed from the center of a tape reel, or some other
11724 changeable feature.
11725
11726 @node Reliability and security
11727 @chapter Reliability and Security
11728
11729 The @command{tar} command reads and writes files as any other
11730 application does, and is subject to the usual caveats about
11731 reliability and security.  This section contains some commonsense
11732 advice on the topic.
11733
11734 @menu
11735 * Reliability::
11736 * Security::
11737 @end menu
11738
11739 @node Reliability
11740 @section Reliability
11741
11742 Ideally, when @command{tar} is creating an archive, it reads from a
11743 file system that is not being modified, and encounters no errors or
11744 inconsistencies while reading and writing.  If this is the case, the
11745 archive should faithfully reflect what was read.  Similarly, when
11746 extracting from an archive, ideally @command{tar} ideally encounters
11747 no errors and the extracted files faithfully reflect what was in the
11748 archive.
11749
11750 However, when reading or writing real-world file systems, several
11751 things can go wrong; these include permissions problems, corruption of
11752 data, and race conditions.
11753
11754 @menu
11755 * Permissions problems::
11756 * Data corruption and repair::
11757 * Race conditions::
11758 @end menu
11759
11760 @node Permissions problems
11761 @subsection Permissions Problems
11762
11763 If @command{tar} encounters errors while reading or writing files, it
11764 normally reports an error and exits with nonzero status.  The work it
11765 does may therefore be incomplete.  For example, when creating an
11766 archive, if @command{tar} cannot read a file then it cannot copy the
11767 file into the archive.
11768
11769 @node Data corruption and repair
11770 @subsection Data Corruption and Repair
11771
11772 If an archive becomes corrupted by an I/O error, this may corrupt the
11773 data in an extracted file.  Worse, it may corrupt the file's metadata,
11774 which may cause later parts of the archive to become misinterpreted.
11775 An tar-format archive contains a checksum that most likely will detect
11776 errors in the metadata, but it will not detect errors in the data.
11777
11778 If data corruption is a concern, you can compute and check your own
11779 checksums of an archive by using other programs, such as
11780 @command{cksum}.
11781
11782 When attempting to recover from a read error or data corruption in an
11783 archive, you may need to skip past the questionable data and read the
11784 rest of the archive.  This requires some expertise in the archive
11785 format and in other software tools.
11786
11787 @node Race conditions
11788 @subsection Race conditions
11789
11790 If some other process is modifying the file system while @command{tar}
11791 is reading or writing files, the result may well be inconsistent due
11792 to race conditions.  For example, if another process creates some
11793 files in a directory while @command{tar} is creating an archive
11794 containing the directory's files, @command{tar} may see some of the
11795 files but not others, or it may see a file that is in the process of
11796 being created.  The resulting archive may not be a snapshot of the
11797 file system at any point in time.  If an application such as a
11798 database system depends on an accurate snapshot, restoring from the
11799 @command{tar} archive of a live file system may therefore break that
11800 consistency and may break the application.  The simplest way to avoid
11801 the consistency issues is to avoid making other changes to the file
11802 system while tar is reading it or writing it.
11803
11804 When creating an archive, several options are available to avoid race
11805 conditions.  Some hosts have a way of snapshotting a file system, or
11806 of temporarily suspending all changes to a file system, by (say)
11807 suspending the only virtual machine that can modify a file system; if
11808 you use these facilities and have @command{tar -c} read from a
11809 snapshot when creating an archive, you can avoid inconsistency
11810 problems.  More drastically, before starting @command{tar} you could
11811 suspend or shut down all processes other than @command{tar} that have
11812 access to the file system, or you could unmount the file system and
11813 then mount it read-only.
11814
11815 When extracting from an archive, one approach to avoid race conditions
11816 is to create a directory that no other process can write to, and
11817 extract into that.
11818
11819 @node Security
11820 @section Security
11821
11822 In some cases @command{tar} may be used in an adversarial situation,
11823 where an untrusted user is attempting to gain information about or
11824 modify otherwise-inaccessible files.  Dealing with untrusted data
11825 (that is, data generated by an untrusted user) typically requires
11826 extra care, because even the smallest mistake in the use of
11827 @command{tar} is more likely to be exploited by an adversary than by a
11828 race condition.
11829
11830 @menu
11831 * Privacy::
11832 * Integrity::
11833 * Live untrusted data::
11834 * Security rules of thumb::
11835 @end menu
11836
11837 @node Privacy
11838 @subsection Privacy
11839
11840 Standard privacy concerns apply when using @command{tar}.  For
11841 example, suppose you are archiving your home directory into a file
11842 @file{/archive/myhome.tar}.  Any secret information in your home
11843 directory, such as your SSH secret keys, are copied faithfully into
11844 the archive.  Therefore, if your home directory contains any file that
11845 should not be read by some other user, the archive itself should be
11846 not be readable by that user.  And even if the archive's data are
11847 inaccessible to untrusted users, its metadata (such as size or
11848 last-modified date) may reveal some information about your home
11849 directory; if the metadata are intended to be private, the archive's
11850 parent directory should also be inaccessible to untrusted users.
11851
11852 One precaution is to create @file{/archive} so that it is not
11853 accessible to any user, unless that user also has permission to access
11854 all the files in your home directory.
11855
11856 Similarly, when extracting from an archive, take care that the
11857 permissions of the extracted files are not more generous than what you
11858 want.  Even if the archive itself is readable only to you, files
11859 extracted from it have their own permissions that may differ.
11860
11861 @node Integrity
11862 @subsection Integrity
11863
11864 When creating archives, take care that they are not writable by a
11865 untrusted user; otherwise, that user could modify the archive, and
11866 when you later extract from the archive you will get incorrect data.
11867
11868 When @command{tar} extracts from an archive, by default it writes into
11869 files relative to the working directory.  If the archive was generated
11870 by an untrusted user, that user therefore can write into any file
11871 under the working directory.  If the working directory contains a
11872 symbolic link to another directory, the untrusted user can also write
11873 into any file under the referenced directory.  When extracting from an
11874 untrusted archive, it is therefore good practice to create an empty
11875 directory and run @command{tar} in that directory.
11876
11877 When extracting from two or more untrusted archives, each one should
11878 be extracted independently, into different empty directories.
11879 Otherwise, the first archive could create a symbolic link into an area
11880 outside the working directory, and the second one could follow the
11881 link and overwrite data that is not under the working directory.  For
11882 example, when restoring from a series of incremental dumps, the
11883 archives should have been created by a trusted process, as otherwise
11884 the incremental restores might alter data outside the working
11885 directory.
11886
11887 If you use the @option{--absolute-names} (@option{-P}) option when
11888 extracting, @command{tar} respects any file names in the archive, even
11889 file names that begin with @file{/} or contain @file{..}.  As this
11890 lets the archive overwrite any file in your system that you can write,
11891 the @option{--absolute-names} (@option{-P}) option should be used only
11892 for trusted archives.
11893
11894 Conversely, with the @option{--keep-old-files} (@option{-k}) option,
11895 @command{tar} refuses to replace existing files when extracting; and
11896 with the @option{--no-overwrite-dir} option, @command{tar} refuses to
11897 replace the permissions or ownership of already-existing directories.
11898 These options may help when extracting from untrusted archives.
11899
11900 @node Live untrusted data
11901 @subsection Dealing with Live Untrusted Data
11902
11903 Extra care is required when creating from or extracting into a file
11904 system that is accessible to untrusted users.  For example, superusers
11905 who invoke @command{tar} must be wary about its actions being hijacked
11906 by an adversary who is reading or writing the file system at the same
11907 time that @command{tar} is operating.
11908
11909 When creating an archive from a live file system, @command{tar} is
11910 vulnerable to denial-of-service attacks.  For example, an adversarial
11911 user could create the illusion of an indefinitely-deep directory
11912 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
11913 @command{tar}, or the illusion of an indefinitely-long file by
11914 creating a sparse file but arranging for blocks to be allocated just
11915 before @command{tar} reads them.  There is no easy way for
11916 @command{tar} to distinguish these scenarios from legitimate uses, so
11917 you may need to monitor @command{tar}, just as you'd need to monitor
11918 any other system service, to detect such attacks.
11919
11920 While a superuser is extracting from an archive into a live file
11921 system, an untrusted user might replace a directory with a symbolic
11922 link, in hopes that @command{tar} will follow the symbolic link and
11923 extract data into files that the untrusted user does not have access
11924 to.  Even if the archive was generated by the superuser, it may
11925 contain a file such as @file{d/etc/passwd} that the untrusted user
11926 earlier created in order to break in; if the untrusted user replaces
11927 the directory @file{d/etc} with a symbolic link to @file{/etc} while
11928 @command{tar} is running, @command{tar} will overwrite
11929 @file{/etc/passwd}.  This attack can be prevented by extracting into a
11930 directory that is inaccessible to untrusted users.
11931
11932 Similar attacks via symbolic links are also possible when creating an
11933 archive, if the untrusted user can modify an ancestor of a top-level
11934 argument of @command{tar}.  For example, an untrusted user that can
11935 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
11936 - /home/eve/Documents/yesterday} by replacing
11937 @file{/home/eve/Documents} with a symbolic link to some other
11938 location.  Attacks like these can be prevented by making sure that
11939 untrusted users cannot modify any files that are top-level arguments
11940 to @command{tar}, or any ancestor directories of these files.
11941
11942 @node Security rules of thumb
11943 @subsection Security Rules of Thumb
11944
11945 This section briefly summarizes rules of thumb for avoiding security
11946 pitfalls.
11947
11948 @itemize @bullet
11949
11950 @item
11951 Protect archives at least as much as you protect any of the files
11952 being archived.
11953
11954 @item
11955 Extract from an untrusted archive only into an otherwise-empty
11956 directory.  This directory and its parent should be accessible only to
11957 trusted users.  For example:
11958
11959 @example
11960 @group
11961 $ @kbd{chmod go-rwx .}
11962 $ @kbd{mkdir -m go-rwx dir}
11963 $ @kbd{cd dir}
11964 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
11965 @end group
11966 @end example
11967
11968 As a corollary, do not do an incremental restore from an untrusted archive.
11969
11970 @item
11971 Do not let untrusted users access files extracted from untrusted
11972 archives without checking first for problems such as setuid programs.
11973
11974 @item
11975 Do not let untrusted users modify directories that are ancestors of
11976 top-level arguments of @command{tar}.  For example, while you are
11977 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
11978 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
11979
11980 @item
11981 Pay attention to the diagnostics and exit status of @command{tar}.
11982
11983 @item
11984 When archiving live file systems, monitor running instances of
11985 @command{tar} to detect denial-of-service attacks.
11986
11987 @item
11988 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
11989 @option{--dereference} (@option{-h}), @option{--overwrite},
11990 @option{--recursive-unlink}, and @option{--remove-files} unless you
11991 understand their security implications.
11992
11993 @end itemize
11994
11995 @node Changes
11996 @appendix Changes
11997
11998 This appendix lists some important user-visible changes between
11999 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
12000 version of this document is available at
12001 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12002 @GNUTAR{} documentation page}.
12003
12004 @table @asis
12005 @item Use of globbing patterns when listing and extracting.
12006
12007 Previous versions of GNU tar assumed shell-style globbing when
12008 extracting from or listing an archive.  For example:
12009
12010 @smallexample
12011 $ @kbd{tar xf foo.tar '*.c'}
12012 @end smallexample
12013
12014 would extract all files whose names end in @samp{.c}.  This behavior
12015 was not documented and was incompatible with traditional tar
12016 implementations.  Therefore, starting from version 1.15.91, GNU tar
12017 no longer uses globbing by default.  For example, the above invocation
12018 is now interpreted as a request to extract from the archive the file
12019 named @file{*.c}.
12020
12021 To facilitate transition to the new behavior for those users who got
12022 used to the previous incorrect one, @command{tar} will print a warning
12023 if it finds out that a requested member was not found in the archive
12024 and its name looks like a globbing pattern.  For example:
12025
12026 @smallexample
12027 $ @kbd{tar xf foo.tar  '*.c'}
12028 tar: Pattern matching characters used in file names. Please,
12029 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12030 tar: suppress this warning.
12031 tar: *.c: Not found in archive
12032 tar: Error exit delayed from previous errors
12033 @end smallexample
12034
12035 To treat member names as globbing patterns, use the @option{--wildcards} option.
12036 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12037 add this option to your @env{TAR_OPTIONS} variable.
12038
12039 @xref{wildcards}, for the detailed discussion of the use of globbing
12040 patterns by @GNUTAR{}.
12041
12042 @item Use of short option @option{-o}.
12043
12044 Earlier versions of @GNUTAR{} understood @option{-o} command line
12045 option as a synonym for @option{--old-archive}.
12046
12047 @GNUTAR{} starting from version 1.13.90 understands this option as
12048 a synonym for @option{--no-same-owner}.  This is compatible with
12049 UNIX98 @command{tar} implementations.
12050
12051 However, to facilitate transition, @option{-o} option retains its
12052 old semantics when it is used with one of archive-creation commands.
12053 Users are encouraged to use @option{--format=oldgnu} instead.
12054
12055 It is especially important, since versions of @acronym{GNU} Automake
12056 up to and including 1.8.4 invoke tar with this option to produce
12057 distribution tarballs.  @xref{Formats,v7}, for the detailed discussion
12058 of this issue and its implications.
12059
12060 @xref{Options, tar-formats, Changing Automake's Behavior,
12061 automake, GNU Automake}, for a description on how to use various
12062 archive formats with @command{automake}.
12063
12064 Future versions of @GNUTAR{} will understand @option{-o} only as a
12065 synonym for @option{--no-same-owner}.
12066
12067 @item Use of short option @option{-l}
12068
12069 Earlier versions of @GNUTAR{} understood @option{-l} option as a
12070 synonym for @option{--one-file-system}.  Since such usage contradicted
12071 to UNIX98 specification and harmed compatibility with other
12072 implementations, it was declared deprecated in version 1.14.  However,
12073 to facilitate transition to its new semantics, it was supported by
12074 versions 1.15 and 1.15.90.  The present use of @option{-l} as a short
12075 variant of @option{--check-links} was introduced in version 1.15.91.
12076
12077 @item Use of options @option{--portability} and @option{--old-archive}
12078
12079 These options are deprecated.  Please use @option{--format=v7} instead.
12080
12081 @item Use of option @option{--posix}
12082
12083 This option is deprecated.  Please use @option{--format=posix} instead.
12084 @end table
12085
12086 @node Configuring Help Summary
12087 @appendix Configuring Help Summary
12088
12089 Running @kbd{tar --help} displays the short @command{tar} option
12090 summary (@pxref{help}). This summary is organized by @dfn{groups} of
12091 semantically close options. The options within each group are printed
12092 in the following order: a short option, eventually followed by a list
12093 of corresponding long option names, followed by a short description of
12094 the option. For example, here is an excerpt from the actual @kbd{tar
12095 --help} output:
12096
12097 @verbatim
12098  Main operation mode:
12099
12100   -A, --catenate, --concatenate   append tar files to an archive
12101   -c, --create               create a new archive
12102   -d, --diff, --compare      find differences between archive and
12103                              file system
12104       --delete               delete from the archive
12105 @end verbatim
12106
12107 @vrindex ARGP_HELP_FMT, environment variable
12108 The exact visual representation of the help output is configurable via
12109 @env{ARGP_HELP_FMT} environment variable. The value of this variable
12110 is a comma-separated list of @dfn{format variable} assignments. There
12111 are two kinds of format variables. An @dfn{offset variable} keeps the
12112 offset of some part of help output text from the leftmost column on
12113 the screen. A @dfn{boolean} variable is a flag that toggles some
12114 output feature on or off. Depending on the type of the corresponding
12115 variable, there are two kinds of assignments:
12116
12117 @table @asis
12118 @item Offset assignment
12119
12120 The assignment to an offset variable has the following syntax:
12121
12122 @smallexample
12123 @var{variable}=@var{value}
12124 @end smallexample
12125
12126 @noindent
12127 where @var{variable} is the variable name, and @var{value} is a
12128 numeric value to be assigned to the variable.
12129
12130 @item Boolean assignment
12131
12132 To assign @code{true} value to a variable, simply put this variable name. To
12133 assign @code{false} value, prefix the variable name with @samp{no-}. For
12134 example:
12135
12136 @smallexample
12137 @group
12138 # Assign @code{true} value:
12139 dup-args
12140 # Assign @code{false} value:
12141 no-dup-args
12142 @end group
12143 @end smallexample
12144 @end table
12145
12146 Following variables are declared:
12147
12148 @deftypevr {Help Output} boolean dup-args
12149 If true, arguments for an option are shown with both short and long
12150 options, even when a given option has both forms, for example:
12151
12152 @smallexample
12153   -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
12154 @end smallexample
12155
12156 If false, then if an option has both short and long forms, the
12157 argument is only shown with the long one, for example:
12158
12159 @smallexample
12160   -f, --file=ARCHIVE         use archive file or device ARCHIVE
12161 @end smallexample
12162
12163 @noindent
12164 and a message indicating that the argument is applicable to both
12165 forms is printed below the options. This message can be disabled
12166 using @code{dup-args-note} (see below).
12167
12168 The default is false.
12169 @end deftypevr
12170
12171 @deftypevr {Help Output} boolean dup-args-note
12172 If this variable is true, which is the default, the following notice
12173 is displayed at the end of the help output:
12174
12175 @quotation
12176 Mandatory or optional arguments to long options are also mandatory or
12177 optional for any corresponding short options.
12178 @end quotation
12179
12180 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
12181 variables @code{dup-args} or @code{dup-args-note} should be set.
12182 @end deftypevr
12183
12184 @deftypevr {Help Output} offset short-opt-col
12185 Column in which short options start. Default is 2.
12186
12187 @smallexample
12188 @group
12189 $ @kbd{tar --help|grep ARCHIVE}
12190   -f, --file=ARCHIVE   use archive file or device ARCHIVE
12191 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
12192       -f, --file=ARCHIVE   use archive file or device ARCHIVE
12193 @end group
12194 @end smallexample
12195 @end deftypevr
12196
12197 @deftypevr {Help Output} offset long-opt-col
12198 Column in which long options start. Default is 6. For example:
12199
12200 @smallexample
12201 @group
12202 $ @kbd{tar --help|grep ARCHIVE}
12203   -f, --file=ARCHIVE   use archive file or device ARCHIVE
12204 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
12205   -f,           --file=ARCHIVE   use archive file or device ARCHIVE
12206 @end group
12207 @end smallexample
12208 @end deftypevr
12209
12210 @deftypevr {Help Output} offset doc-opt-col
12211 Column in which @dfn{doc options} start.  A doc option isn't actually
12212 an option, but rather an arbitrary piece of documentation that is
12213 displayed in much the same manner as the options.  For example, in
12214 the description of @option{--format} option:
12215
12216 @smallexample
12217 @group
12218   -H, --format=FORMAT        create archive of the given format.
12219
12220  FORMAT is one of the following:
12221
12222     gnu                      GNU tar 1.13.x format
12223     oldgnu                   GNU format as per tar <= 1.12
12224     pax                      POSIX 1003.1-2001 (pax) format
12225     posix                    same as pax
12226     ustar                    POSIX 1003.1-1988 (ustar) format
12227     v7                       old V7 tar format
12228 @end group
12229 @end smallexample
12230
12231 @noindent
12232 the format names are doc options. Thus, if you set
12233 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
12234 will look as follows:
12235
12236 @smallexample
12237 @group
12238   -H, --format=FORMAT        create archive of the given format.
12239
12240  FORMAT is one of the following:
12241
12242         gnu                      GNU tar 1.13.x format
12243         oldgnu                   GNU format as per tar <= 1.12
12244         pax                      POSIX 1003.1-2001 (pax) format
12245         posix                    same as pax
12246         ustar                    POSIX 1003.1-1988 (ustar) format
12247         v7                       old V7 tar format
12248 @end group
12249 @end smallexample
12250 @end deftypevr
12251
12252 @deftypevr {Help Output} offset opt-doc-col
12253 Column in which option description starts. Default is 29.
12254
12255 @smallexample
12256 @group
12257 $ @kbd{tar --help|grep ARCHIVE}
12258   -f, --file=ARCHIVE         use archive file or device ARCHIVE
12259 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
12260   -f, --file=ARCHIVE   use archive file or device ARCHIVE
12261 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
12262   -f, --file=ARCHIVE
12263            use archive file or device ARCHIVE
12264 @end group
12265 @end smallexample
12266
12267 @noindent
12268 Notice, that the description starts on a separate line if
12269 @code{opt-doc-col} value is too small.
12270 @end deftypevr
12271
12272 @deftypevr {Help Output} offset header-col
12273 Column in which @dfn{group headers} are printed.  A group header is a
12274 descriptive text preceding an option group.  For example, in the
12275 following text:
12276
12277 @verbatim
12278  Main operation mode:
12279
12280   -A, --catenate, --concatenate   append tar files to
12281                              an archive
12282   -c, --create               create a new archive
12283 @end verbatim
12284 @noindent
12285 @samp{Main operation mode:} is the group header.
12286
12287 The default value is 1.
12288 @end deftypevr
12289
12290 @deftypevr {Help Output} offset usage-indent
12291 Indentation of wrapped usage lines. Affects @option{--usage}
12292 output. Default is 12.
12293 @end deftypevr
12294
12295 @deftypevr {Help Output} offset rmargin
12296 Right margin of the text output. Used for wrapping.
12297 @end deftypevr
12298
12299 @node Fixing Snapshot Files
12300 @appendix Fixing Snapshot Files
12301 @include tar-snapshot-edit.texi
12302
12303 @node Tar Internals
12304 @appendix Tar Internals
12305 @include intern.texi
12306
12307 @node Genfile
12308 @appendix Genfile
12309 @include genfile.texi
12310
12311 @node Free Software Needs Free Documentation
12312 @appendix Free Software Needs Free Documentation
12313 @include freemanuals.texi
12314
12315 @node GNU Free Documentation License
12316 @appendix GNU Free Documentation License
12317
12318 @include fdl.texi
12319
12320 @node Index of Command Line Options
12321 @appendix Index of Command Line Options
12322
12323 This appendix contains an index of all @GNUTAR{} long command line
12324 options. The options are listed without the preceding double-dash.
12325 For a cross-reference of short command line options, see
12326 @ref{Short Option Summary}.
12327
12328 @printindex op
12329
12330 @node Index
12331 @appendix Index
12332
12333 @printindex cp
12334
12335 @summarycontents
12336 @contents
12337 @bye
12338
12339 @c Local variables:
12340 @c texinfo-column-for-description: 32
12341 @c End: