Import upstream version 1.29
[debian/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--1997, 1999--2001, 2003--2016 Free
40 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 the
46 Invariant Sections being ``GNU General Public License'', with the
47 Front-Cover Texts being ``A GNU Manual'', and with the Back-Cover Texts
48 as in (a) below.  A copy of the license is included in the section
49 entitled ``GNU Free Documentation License''.
50
51 (a) The FSF's Back-Cover Text is: ``You have the freedom to
52 copy and modify this GNU manual.''
53 @end quotation
54 @end copying
55
56 @dircategory Archiving
57 @direntry
58 * Tar: (tar).                   Making tape (or disk) archives.
59 @end direntry
60
61 @dircategory Individual utilities
62 @direntry
63 * tar: (tar)tar invocation.                     Invoking @GNUTAR{}.
64 @end direntry
65
66 @shorttitlepage @acronym{GNU} @command{tar}
67
68 @titlepage
69 @title @acronym{GNU} tar: an archiver tool
70 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
71 @author John Gilmore, Jay Fenlason et al.
72
73 @page
74 @vskip 0pt plus 1filll
75 @insertcopying
76 @end titlepage
77
78 @ifnottex
79 @node Top
80 @top @acronym{GNU} tar: an archiver tool
81
82 @insertcopying
83
84 @cindex file archival
85 @cindex archiving files
86
87 The first part of this master menu lists the major nodes in this Info
88 document.  The rest of the menu lists all the lower level nodes.
89 @end ifnottex
90
91 @c The master menu goes here.
92 @c
93 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
94 @c loaded and run texinfo-master-menu.
95 @c To update it from the command line, run
96 @c
97 @c    make master-menu
98
99 @menu
100 * Introduction::
101 * Tutorial::
102 * tar invocation::
103 * operations::
104 * Backups::
105 * Choosing::
106 * Date input formats::
107 * Formats::
108 * Media::
109 * Reliability and security::
110
111 Appendices
112
113 * Changes::
114 * Configuring Help Summary::
115 * Fixing Snapshot Files::
116 * Tar Internals::
117 * Genfile::
118 * Free Software Needs Free Documentation::
119 * GNU Free Documentation License::
120 * Index of Command Line Options::
121 * Index::
122
123 @detailmenu
124  --- The Detailed Node Listing ---
125
126 Introduction
127
128 * Book Contents::               What this Book Contains
129 * Definitions::                 Some Definitions
130 * What tar Does::               What @command{tar} Does
131 * Naming tar Archives::         How @command{tar} Archives are Named
132 * Authors::                     @GNUTAR{} Authors
133 * Reports::                     Reporting bugs or suggestions
134
135 Tutorial Introduction to @command{tar}
136
137 * assumptions::
138 * stylistic conventions::
139 * basic tar options::           Basic @command{tar} Operations and Options
140 * frequent operations::
141 * Two Frequent Options::
142 * create::                      How to Create Archives
143 * list::                        How to List Archives
144 * extract::                     How to Extract Members from an Archive
145 * going further::
146
147 Two Frequently Used Options
148
149 * file tutorial::
150 * verbose tutorial::
151 * help tutorial::
152
153 How to Create Archives
154
155 * prepare for examples::
156 * Creating the archive::
157 * create verbose::
158 * short create::
159 * create dir::
160
161 How to List Archives
162
163 * list dir::
164
165 How to Extract Members from an Archive
166
167 * extracting archives::
168 * extracting files::
169 * extract dir::
170 * extracting untrusted archives::
171 * failing commands::
172
173 Invoking @GNUTAR{}
174
175 * Synopsis::
176 * using tar options::
177 * Styles::
178 * All Options::
179 * help::
180 * defaults::
181 * verbose::
182 * checkpoints::
183 * warnings::
184 * interactive::
185
186 The Three Option Styles
187
188 * Long Options::                Long Option Style
189 * Short Options::               Short Option Style
190 * Old Options::                 Old Option Style
191 * Mixing::                      Mixing Option Styles
192
193 All @command{tar} Options
194
195 * Operation Summary::
196 * Option Summary::
197 * Short Option Summary::
198 * Position-Sensitive Options::
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 * Extended File Attributes::
232 * Ignore Failed Read::
233
234 Options Used by @option{--extract}
235
236 * Reading::                     Options to Help Read Archives
237 * Writing::                     Changing How @command{tar} Writes Files
238 * Scarce::                      Coping with Scarce Resources
239
240 Options to Help Read Archives
241
242 * read full records::
243 * Ignore Zeros::
244
245 Changing How @command{tar} Writes Files
246
247 * Dealing with Old Files::
248 * Overwrite Old Files::
249 * Keep Old Files::
250 * Keep Newer Files::
251 * Unlink First::
252 * Recursive Unlink::
253 * Data Modification Times::
254 * Setting Access Permissions::
255 * Directory Modification Times and Permissions::
256 * Writing to Standard Output::
257 * Writing to an External Program::
258 * remove files::
259
260 Coping with Scarce Resources
261
262 * Starting File::
263 * Same Order::
264
265 Performing Backups and Restoring Files
266
267 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
268 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
269 * Backup Levels::               Levels of Backups
270 * Backup Parameters::           Setting Parameters for Backups and Restoration
271 * Scripted Backups::            Using the Backup Scripts
272 * Scripted Restoration::        Using the Restore Script
273
274 Setting Parameters for Backups and Restoration
275
276 * General-Purpose Variables::
277 * Magnetic Tape Control::
278 * User Hooks::
279 * backup-specs example::        An Example Text of @file{Backup-specs}
280
281 Choosing Files and Names for @command{tar}
282
283 * file::                        Choosing the Archive's Name
284 * Selecting Archive Members::
285 * files::                       Reading Names from a File
286 * exclude::                     Excluding Some Files
287 * wildcards::                   Wildcards Patterns and Matching
288 * quoting styles::              Ways of Quoting Special Characters in Names
289 * transform::                   Modifying File and Member Names
290 * after::                       Operating Only on New Files
291 * recurse::                     Descending into Directories
292 * one::                         Crossing File System Boundaries
293
294 Reading Names from a File
295
296 * nul::
297
298 Excluding Some Files
299
300 * problems with exclude::
301
302 Wildcards Patterns and Matching
303
304 * controlling pattern-matching::
305
306 Crossing File System Boundaries
307
308 * directory::                   Changing Directory
309 * absolute::                    Absolute File Names
310
311 Date input formats
312
313 * General date syntax::            Common rules.
314 * Calendar date items::            19 Dec 1994.
315 * Time of day items::              9:20pm.
316 * Time zone items::                @sc{est}, @sc{pdt}, @sc{gmt}.
317 * Day of week items::              Monday and others.
318 * Relative items in date strings:: next tuesday, 2 years ago.
319 * Pure numbers in date strings::   19931219, 1440.
320 * Seconds since the Epoch::        @@1078100502.
321 * Specifying time zone rules::     TZ="America/New_York", TZ="UTC0".
322 * Authors of parse_datetime::      Bellovin, Eggert, Salz, Berets, et al.
323
324 Controlling the Archive Format
325
326 * Compression::                 Using Less Space through Compression
327 * Attributes::                  Handling File Attributes
328 * Portability::                 Making @command{tar} Archives More Portable
329 * cpio::                        Comparison of @command{tar} and @command{cpio}
330
331 Using Less Space through Compression
332
333 * gzip::                        Creating and Reading Compressed Archives
334 * sparse::                      Archiving Sparse Files
335
336 Creating and Reading Compressed Archives
337
338 * lbzip2::  Using lbzip2 with @GNUTAR{}.
339
340 Making @command{tar} Archives More Portable
341
342 * Portable Names::              Portable Names
343 * dereference::                 Symbolic Links
344 * hard links::                  Hard Links
345 * old::                         Old V7 Archives
346 * ustar::                       Ustar Archives
347 * gnu::                         GNU and old GNU format archives.
348 * posix::                       @acronym{POSIX} archives
349 * Checksumming::                Checksumming Problems
350 * Large or Negative Values::    Large files, negative time stamps, etc.
351 * Other Tars::                  How to Extract GNU-Specific Data Using
352                                 Other @command{tar} Implementations
353
354 @GNUTAR{} and @acronym{POSIX} @command{tar}
355
356 * PAX keywords:: Controlling Extended Header Keywords.
357
358 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
359
360 * Split Recovery::       Members Split Between Volumes
361 * Sparse Recovery::      Sparse Members
362
363 Tapes and Other Archive Media
364
365 * Device::                      Device selection and switching
366 * Remote Tape Server::
367 * Common Problems and Solutions::
368 * Blocking::                    Blocking
369 * Many::                        Many archives on one tape
370 * Using Multiple Tapes::        Using Multiple Tapes
371 * label::                       Including a Label in the Archive
372 * verify::
373 * Write Protection::
374
375 Blocking
376
377 * Format Variations::           Format Variations
378 * Blocking Factor::             The Blocking Factor of an Archive
379
380 Many Archives on One Tape
381
382 * Tape Positioning::            Tape Positions and Tape Marks
383 * mt::                          The @command{mt} Utility
384
385 Using Multiple Tapes
386
387 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
388 * Tape Files::                  Tape Files
389 * Tarcat::                      Concatenate Volumes into a Single Archive
390
391
392 Tar Internals
393
394 * Standard::           Basic Tar Format
395 * Extensions::         @acronym{GNU} Extensions to the Archive Format
396 * Sparse Formats::     Storing Sparse Files
397 * Snapshot Files::
398 * Dumpdir::
399
400 Storing Sparse Files
401
402 * Old GNU Format::
403 * PAX 0::                PAX Format, Versions 0.0 and 0.1
404 * PAX 1::                PAX Format, Version 1.0
405
406 Genfile
407
408 * Generate Mode::     File Generation Mode.
409 * Status Mode::       File Status Mode.
410 * Exec Mode::         Synchronous Execution mode.
411
412 Copying This Manual
413
414 * GNU Free Documentation License::  License for copying this manual
415
416 @end detailmenu
417 @end menu
418
419 @node Introduction
420 @chapter Introduction
421
422 @GNUTAR{} creates
423 and manipulates @dfn{archives} which are actually collections of
424 many other files; the program provides users with an organized and
425 systematic method for controlling a large amount of data.
426 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
427 archives need not (and these days, typically do not) reside on tapes.
428
429 @menu
430 * Book Contents::               What this Book Contains
431 * Definitions::                 Some Definitions
432 * What tar Does::               What @command{tar} Does
433 * Naming tar Archives::         How @command{tar} Archives are Named
434 * Authors::                     @GNUTAR{} Authors
435 * Reports::                     Reporting bugs or suggestions
436 @end menu
437
438 @node Book Contents
439 @section What this Book Contains
440
441 The first part of this chapter introduces you to various terms that will
442 recur throughout the book.  It also tells you who has worked on @GNUTAR{}
443 and its documentation, and where you should send bug reports
444 or comments.
445
446 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
447 gentle introduction for people who are new to using @command{tar}.  It is
448 meant to be self-contained, not requiring any reading from subsequent
449 chapters to make sense.  It moves from topic to topic in a logical,
450 progressive order, building on information already explained.
451
452 Although the tutorial is paced and structured to allow beginners to
453 learn how to use @command{tar}, it is not intended solely for beginners.
454 The tutorial explains how to use the three most frequently used
455 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
456 two frequently used options (@samp{file} and @samp{verbose}).  The other
457 chapters do not refer to the tutorial frequently; however, if a section
458 discusses something which is a complex variant of a basic concept, there
459 may be a cross-reference to that basic concept.  (The entire book,
460 including the tutorial, assumes that the reader understands some basic
461 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
462
463 The third chapter presents the remaining five operations, and
464 information about using @command{tar} options and option syntax.
465
466 The other chapters are meant to be used as a reference.  Each chapter
467 presents everything that needs to be said about a specific topic.
468
469 One of the chapters (@pxref{Date input formats}) exists in its
470 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
471 In addition, one section of this manual (@pxref{Standard}) contains a
472 big quote which is taken directly from @command{tar} sources.
473
474 In general, we give both long and short (abbreviated) option names
475 at least once in each section where the relevant option is covered, so
476 that novice readers will become familiar with both styles.  (A few
477 options have no short versions, and the relevant sections will
478 indicate this.)
479
480 @node Definitions
481 @section Some Definitions
482
483 @cindex archive
484 @cindex tar archive
485 The @command{tar} program is used to create and manipulate @command{tar}
486 archives.  An @dfn{archive} is a single file which contains the contents
487 of many files, while still identifying the names of the files, their
488 owner(s), and so forth.  (In addition, archives record access
489 permissions, user and group, size in bytes, and data modification time.
490 Some archives also record the file names in each archived directory, as
491 well as other file and directory information.)  You can use @command{tar}
492 to @dfn{create} a new archive in a specified directory.
493
494 @cindex member
495 @cindex archive member
496 @cindex file name
497 @cindex member name
498 The files inside an archive are called @dfn{members}.  Within this
499 manual, we use the term @dfn{file} to refer only to files accessible in
500 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
501 @dfn{member} to refer only to the members of an archive.  Similarly, a
502 @dfn{file name} is the name of a file, as it resides in the file system,
503 and a @dfn{member name} is the name of an archive member within the
504 archive.
505
506 @cindex extraction
507 @cindex unpacking
508 The term @dfn{extraction} refers to the process of copying an archive
509 member (or multiple members) into a file in the file system.  Extracting
510 all the members of an archive is often called @dfn{extracting the
511 archive}.  The term @dfn{unpack} can also be used to refer to the
512 extraction of many or all the members of an archive.  Extracting an
513 archive does not destroy the archive's structure, just as creating an
514 archive does not destroy the copies of the files that exist outside of
515 the archive.  You may also @dfn{list} the members in a given archive
516 (this is often thought of as ``printing'' them to the standard output,
517 or the command line), or @dfn{append} members to a pre-existing archive.
518 All of these operations can be performed using @command{tar}.
519
520 @node What tar Does
521 @section What @command{tar} Does
522
523 @cindex tar
524 The @command{tar} program provides the ability to create @command{tar}
525 archives, as well as various other kinds of manipulation.  For example,
526 you can use @command{tar} on previously created archives to extract files,
527 to store additional files, or to update or list files which were already
528 stored.
529
530 Initially, @command{tar} archives were used to store files conveniently on
531 magnetic tape.  The name @command{tar} comes from this use; it stands for
532 @code{t}ape @code{ar}chiver.  Despite the utility's name, @command{tar} can
533 direct its output to available devices, files, or other programs (using
534 pipes).  @command{tar} may even access remote devices or files (as archives).
535
536 You can use @command{tar} archives in many ways.  We want to stress a few
537 of them: storage, backup, and transportation.
538
539 @FIXME{the following table entries need a bit of work.}
540 @table @asis
541 @item Storage
542 Often, @command{tar} archives are used to store related files for
543 convenient file transfer over a network.  For example, the
544 @acronym{GNU} Project distributes its software bundled into
545 @command{tar} archives, so that all the files relating to a particular
546 program (or set of related programs) can be transferred as a single
547 unit.
548
549 A magnetic tape can store several files in sequence.  However, the tape
550 has no names for these files; it only knows their relative position on
551 the tape.  One way to store several files on one tape and retain their
552 names is by creating a @command{tar} archive.  Even when the basic transfer
553 mechanism can keep track of names, as FTP can, the nuisance of handling
554 multiple files, directories, and multiple links makes @command{tar}
555 archives useful.
556
557 Archive files are also used for long-term storage.  You can think of
558 this as transportation from the present into the future.  (It is a
559 science-fiction idiom that you can move through time as well as in
560 space; the idea here is that @command{tar} can be used to move archives in
561 all dimensions, even time!)
562
563 @item Backup
564 Because the archive created by @command{tar} is capable of preserving
565 file information and directory structure, @command{tar} is commonly
566 used for performing full and incremental backups of disks.  A backup
567 puts a collection of files (possibly pertaining to many users and
568 projects) together on a disk or a tape.  This guards against
569 accidental destruction of the information in those files.
570 @GNUTAR{} has special features that allow it to be
571 used to make incremental and full dumps of all the files in a
572 file system.
573
574 @item Transportation
575 You can create an archive on one system, transfer it to another system,
576 and extract the contents there.  This allows you to transport a group of
577 files from one system to another.
578 @end table
579
580 @node Naming tar Archives
581 @section How @command{tar} Archives are Named
582
583 Conventionally, @command{tar} archives are given names ending with
584 @samp{.tar}.  This is not necessary for @command{tar} to operate properly,
585 but this manual follows that convention in order to accustom readers to
586 it and to make examples more clear.
587
588 @cindex tar file
589 @cindex entry
590 @cindex tar entry
591 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
592 archive members as ``files'' or ``entries''.  For people familiar with
593 the operation of @command{tar}, this causes no difficulty.  However, in
594 this manual, we consistently refer to ``archives'' and ``archive
595 members'' to make learning to use @command{tar} easier for novice users.
596
597 @node Authors
598 @section @GNUTAR{} Authors
599
600 @GNUTAR{} was originally written by John Gilmore,
601 and modified by many people.  The @acronym{GNU} enhancements were
602 written by Jay Fenlason, then Joy Kendall, and the whole package has
603 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
604 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
605 numerous and kind users.
606
607 We wish to stress that @command{tar} is a collective work, and owes much to
608 all those people who reported problems, offered solutions and other
609 insights, or shared their thoughts and suggestions.  An impressive, yet
610 partial list of those contributors can be found in the @file{THANKS}
611 file from the @GNUTAR{} distribution.
612
613 @FIXME{i want all of these names mentioned, Absolutely.  BUT, i'm not
614 sure i want to spell out the history in this detail, at least not for
615 the printed book.  i'm just not sure it needs to be said this way.
616 i'll think about it.}
617
618 @FIXME{History is more important, and surely more interesting, than
619 actual names.  Quoting names without history would be meaningless.  FP}
620
621 Jay Fenlason put together a draft of a @GNUTAR{}
622 manual, borrowing notes from the original man page from John Gilmore.
623 This was withdrawn in version 1.11.  Thomas Bushnell, n/BSG and Amy
624 Gorin worked on a tutorial and manual for @GNUTAR{}.
625 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
626 taking information from all these sources and merging them.  Melissa
627 Weisshaus finally edited and redesigned the book to create version
628 1.12.  The book for versions from 1.14 up to @value{VERSION} were edited
629 by the current maintainer, Sergey Poznyakoff.
630
631 For version 1.12, Daniel Hagerty contributed a great deal of technical
632 consulting.  In particular, he is the primary author of @ref{Backups}.
633
634 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
635 (see @url{http://savannah.gnu.org/projects/tar}), and
636 active development and maintenance work has started
637 again.  Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
638 Poznyakoff and Jeff Bailey.
639
640 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
641
642 @node Reports
643 @section Reporting bugs or suggestions
644
645 @cindex bug reports
646 @cindex reporting bugs
647 If you find problems or have suggestions about this program or manual,
648 please report them to @file{bug-tar@@gnu.org}.
649
650 When reporting a bug, please be sure to include as much detail as
651 possible, in order to reproduce it.
652 @FIXME{Be more specific, I'd like to make this node as detailed as
653 'Bug reporting' node in Emacs manual.}
654
655 @node Tutorial
656 @chapter Tutorial Introduction to @command{tar}
657
658 This chapter guides you through some basic examples of three @command{tar}
659 operations: @option{--create}, @option{--list}, and @option{--extract}.  If
660 you already know how to use some other version of @command{tar}, then you
661 may not need to read this chapter.  This chapter omits most complicated
662 details about how @command{tar} works.
663
664 @menu
665 * assumptions::
666 * stylistic conventions::
667 * basic tar options::           Basic @command{tar} Operations and Options
668 * frequent operations::
669 * Two Frequent Options::
670 * create::                      How to Create Archives
671 * list::                        How to List Archives
672 * extract::                     How to Extract Members from an Archive
673 * going further::
674 @end menu
675
676 @node assumptions
677 @section Assumptions this Tutorial Makes
678
679 This chapter is paced to allow beginners to learn about @command{tar}
680 slowly.  At the same time, we will try to cover all the basic aspects of
681 these three operations.  In order to accomplish both of these tasks, we
682 have made certain assumptions about your knowledge before reading this
683 manual, and the hardware you will be using:
684
685 @itemize @bullet
686 @item
687 Before you start to work through this tutorial, you should understand
688 what the terms ``archive'' and ``archive member'' mean
689 (@pxref{Definitions}).  In addition, you should understand something
690 about how Unix-type operating systems work, and you should know how to
691 use some basic utilities.  For example, you should know how to create,
692 list, copy, rename, edit, and delete files and directories; how to
693 change between directories; and how to figure out where you are in the
694 file system.  You should have some basic understanding of directory
695 structure and how files are named according to which directory they are
696 in.  You should understand concepts such as standard output and standard
697 input, what various definitions of the term @samp{argument} mean, and the
698 differences between relative and absolute file names.
699 @FIXME{and what else?}
700
701 @item
702 This manual assumes that you are working from your own home directory
703 (unless we state otherwise).  In this tutorial, you will create a
704 directory to practice @command{tar} commands in.  When we show file names,
705 we will assume that those names are relative to your home directory.
706 For example, my home directory is @file{/home/fsf/melissa}.  All of
707 my examples are in a subdirectory of the directory named by that file
708 name; the subdirectory is called @file{practice}.
709
710 @item
711 In general, we show examples of archives which exist on (or can be
712 written to, or worked with from) a directory on a hard disk.  In most
713 cases, you could write those archives to, or work with them on any other
714 device, such as a tape drive.  However, some of the later examples in
715 the tutorial and next chapter will not work on tape drives.
716 Additionally, working with tapes is much more complicated than working
717 with hard disks.  For these reasons, the tutorial does not cover working
718 with tape drives.  @xref{Media}, for complete information on using
719 @command{tar} archives with tape drives.
720
721 @FIXME{this is a cop out.  need to add some simple tape drive info.}
722 @end itemize
723
724 @node stylistic conventions
725 @section Stylistic Conventions
726
727 In the examples, @samp{$} represents a typical shell prompt.  It
728 precedes lines you should type; to make this more clear, those lines are
729 shown in @kbd{this font}, as opposed to lines which represent the
730 computer's response; those lines are shown in @code{this font}, or
731 sometimes @samp{like this}.
732
733 @c When we have lines which are too long to be
734 @c displayed in any other way, we will show them like this:
735
736 @node basic tar options
737 @section Basic @command{tar} Operations and Options
738
739 @command{tar} can take a wide variety of arguments which specify and define
740 the actions it will have on the particular set of files or the archive.
741 The main types of arguments to @command{tar} fall into one of two classes:
742 operations, and options.
743
744 Some arguments fall into a class called @dfn{operations}; exactly one of
745 these is both allowed and required for any instance of using @command{tar};
746 you may @emph{not} specify more than one.  People sometimes speak of
747 @dfn{operating modes}.  You are in a particular operating mode when you
748 have specified the operation which specifies it; there are eight
749 operations in total, and thus there are eight operating modes.
750
751 The other arguments fall into the class known as @dfn{options}.  You are
752 not required to specify any options, and you are allowed to specify more
753 than one at a time (depending on the way you are using @command{tar} at
754 that time).  Some options are used so frequently, and are so useful for
755 helping you type commands more carefully that they are effectively
756 ``required''.  We will discuss them in this chapter.
757
758 You can write most of the @command{tar} operations and options in any
759 of three forms: long (mnemonic) form, short form, and old style.  Some
760 of the operations and options have no short or ``old'' forms; however,
761 the operations and options which we will cover in this tutorial have
762 corresponding abbreviations.  We will indicate those abbreviations
763 appropriately to get you used to seeing them.  Note, that the ``old
764 style'' option forms exist in @GNUTAR{} for compatibility with Unix
765 @command{tar}.  In this book we present a full discussion of this way
766 of writing options and operations (@pxref{Old Options}), and we discuss
767 the other two styles of writing options (@xref{Long Options}, and
768 @pxref{Short Options}).
769
770 In the examples and in the text of this tutorial, we usually use the
771 long forms of operations and options; but the ``short'' forms produce
772 the same result and can make typing long @command{tar} commands easier.
773 For example, instead of typing
774
775 @smallexample
776 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
777 @end smallexample
778
779 @noindent
780 you can type
781 @smallexample
782 @kbd{tar -c -v -f afiles.tar apple angst aspic}
783 @end smallexample
784
785 @noindent
786 or even
787 @smallexample
788 @kbd{tar -cvf afiles.tar apple angst aspic}
789 @end smallexample
790
791 @noindent
792 For more information on option syntax, see @ref{Advanced tar}.  In
793 discussions in the text, when we name an option by its long form, we
794 also give the corresponding short option in parentheses.
795
796 The term, ``option'', can be confusing at times, since ``operations''
797 are often lumped in with the actual, @emph{optional} ``options'' in certain
798 general class statements.  For example, we just talked about ``short and
799 long forms of options and operations''.  However, experienced @command{tar}
800 users often refer to these by shorthand terms such as, ``short and long
801 options''.  This term assumes that the ``operations'' are included, also.
802 Context will help you determine which definition of ``options'' to use.
803
804 Similarly, the term ``command'' can be confusing, as it is often used in
805 two different ways.  People sometimes refer to @command{tar} ``commands''.
806 A @command{tar} @dfn{command} is the entire command line of user input
807 which tells @command{tar} what to do --- including the operation, options,
808 and any arguments (file names, pipes, other commands, etc.).  However,
809 you will also sometimes hear the term ``the @command{tar} command''.  When
810 the word ``command'' is used specifically like this, a person is usually
811 referring to the @command{tar} @emph{operation}, not the whole line.
812 Again, use context to figure out which of the meanings the speaker
813 intends.
814
815 @node frequent operations
816 @section The Three Most Frequently Used Operations
817
818 Here are the three most frequently used operations (both short and long
819 forms), as well as a brief description of their meanings.  The rest of
820 this chapter will cover how to use these operations in detail.  We will
821 present the rest of the operations in the next chapter.
822
823 @table @option
824 @item --create
825 @itemx -c
826 Create a new @command{tar} archive.
827 @item --list
828 @itemx -t
829 List the contents of an archive.
830 @item --extract
831 @itemx -x
832 Extract one or more members from an archive.
833 @end table
834
835 @node Two Frequent Options
836 @section Two Frequently Used Options
837
838 To understand how to run @command{tar} in the three operating modes listed
839 previously, you also need to understand how to use two of the options to
840 @command{tar}: @option{--file} (which takes an archive file as an argument)
841 and @option{--verbose}.  (You are usually not @emph{required} to specify
842 either of these options when you run @command{tar}, but they can be very
843 useful in making things more clear and helping you avoid errors.)
844
845 @menu
846 * file tutorial::
847 * verbose tutorial::
848 * help tutorial::
849 @end menu
850
851 @node file tutorial
852 @unnumberedsubsec The @option{--file} Option
853
854 @table @option
855 @xopindex{file, tutorial}
856 @item --file=@var{archive-name}
857 @itemx -f @var{archive-name}
858 Specify the name of an archive file.
859 @end table
860
861 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
862 use @command{tar}; this option determines the name of the archive file
863 that @command{tar} will work on.
864
865 @vrindex TAPE
866 If you don't specify this argument, then @command{tar} will examine
867 the environment variable @env{TAPE}.  If it is set, its value will be
868 used as the archive name.  Otherwise, @command{tar} will use the
869 default archive, determined at compile time. Usually it is
870 standard output or some physical tape drive attached to your machine
871 (you can verify what the default is by running @kbd{tar
872 --show-defaults}, @pxref{defaults}).  If there is no tape drive
873 attached, or the default is not meaningful, then @command{tar} will
874 print an error message.  The error message might look roughly like one
875 of the following:
876
877 @smallexample
878 tar: can't open /dev/rmt8 : No such device or address
879 tar: can't open /dev/rsmt0 : I/O error
880 @end smallexample
881
882 @noindent
883 To avoid confusion, we recommend that you always specify an archive file
884 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
885 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
886 @ref{file}.
887
888 @node verbose tutorial
889 @unnumberedsubsec The @option{--verbose} Option
890
891 @table @option
892 @xopindex{verbose, introduced}
893 @item --verbose
894 @itemx -v
895 Show the files being worked on as @command{tar} is running.
896 @end table
897
898 @option{--verbose} (@option{-v}) shows details about the results of running
899 @command{tar}.  This can be especially useful when the results might not be
900 obvious.  For example, if you want to see the progress of @command{tar} as
901 it writes files into the archive, you can use the @option{--verbose}
902 option.  In the beginning, you may find it useful to use
903 @option{--verbose} at all times; when you are more accustomed to
904 @command{tar}, you will likely want to use it at certain times but not at
905 others.  We will use @option{--verbose} at times to help make something
906 clear, and we will give many examples both using and not using
907 @option{--verbose} to show the differences.
908
909 Each instance of @option{--verbose} on the command line increases the
910 verbosity level by one, so if you need more details on the output,
911 specify it twice.
912
913 When reading archives (@option{--list}, @option{--extract},
914 @option{--diff}), @command{tar} by default prints only the names of
915 the members being extracted.  Using @option{--verbose} will show a full,
916 @command{ls} style member listing.
917
918 In contrast, when writing archives (@option{--create}, @option{--append},
919 @option{--update}), @command{tar} does not print file names by
920 default.  So, a single @option{--verbose} option shows the file names
921 being added to the archive, while two @option{--verbose} options
922 enable the full listing.
923
924 For example, to create an archive in verbose mode:
925
926 @smallexample
927 $ @kbd{tar -cvf afiles.tar apple angst aspic}
928 apple
929 angst
930 aspic
931 @end smallexample
932
933 @noindent
934 Creating the same archive with the verbosity level 2 could give:
935
936 @smallexample
937 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
938 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
939 -rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
940 -rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic
941 @end smallexample
942
943 @noindent
944 This works equally well using short or long forms of options.  Using
945 long forms, you would simply write out the mnemonic form of the option
946 twice, like this:
947
948 @smallexample
949 $ @kbd{tar --create --verbose --verbose @dots{}}
950 @end smallexample
951
952 @noindent
953 Note that you must double the hyphens properly each time.
954
955 Later in the tutorial, we will give examples using @w{@option{--verbose
956 --verbose}}.
957
958 @anchor{verbose member listing}
959 The full output consists of six fields:
960
961 @itemize @bullet
962 @item File type and permissions in symbolic form.
963 These are displayed in the same format as the first column of
964 @command{ls -l} output (@pxref{What information is listed,
965 format=verbose, Verbose listing, fileutils, GNU file utilities}).
966
967 @item Owner name and group separated by a slash character.
968 If these data are not available (for example, when listing a @samp{v7} format
969 archive), numeric @acronym{ID} values are printed instead.
970
971 @item Size of the file, in bytes.
972
973 @item File modification date in ISO 8601 format.
974
975 @item File modification time.
976
977 @item File name.
978 If the name contains any special characters (white space, newlines,
979 etc.)@: these are displayed in an unambiguous form using so called
980 @dfn{quoting style}.  For the detailed discussion of available styles
981 and on how to use them, see @ref{quoting styles}.
982
983 Depending on the file type, the name can be followed by some
984 additional information, described in the following table:
985
986 @table @samp
987 @item -> @var{link-name}
988 The file or archive member is a @dfn{symbolic link} and
989 @var{link-name} is the name of file it links to.
990
991 @item link to @var{link-name}
992 The file or archive member is a @dfn{hard link} and @var{link-name} is
993 the name of file it links to.
994
995 @item --Long Link--
996 The archive member is an old GNU format long link.  You will normally
997 not encounter this.
998
999 @item --Long Name--
1000 The archive member is an old GNU format long name.  You will normally
1001 not encounter this.
1002
1003 @item --Volume Header--
1004 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1005
1006 @item --Continued at byte @var{n}--
1007 Encountered only at the beginning of a multi-volume archive
1008 (@pxref{Using Multiple Tapes}).  This archive member is a continuation
1009 from the previous volume. The number @var{n} gives the offset where
1010 the original file was split.
1011
1012 @item  unknown file type @var{c}
1013 An archive member of unknown type. @var{c} is the type character from
1014 the archive header.  If you encounter such a message, it means that
1015 either your archive contains proprietary member types @GNUTAR{} is not
1016 able to handle, or the archive is corrupted.
1017 @end table
1018
1019 @end itemize
1020
1021 For example, here is an archive listing containing most of the special
1022 suffixes explained above:
1023
1024 @smallexample
1025 @group
1026 V--------- 0/0            1536 2006-06-09 13:07 MyVolume--Volume Header--
1027 -rw-r--r-- gray/staff   456783 2006-06-09 12:06 aspic--Continued at 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
1053 @cindex Creation of the archive
1054 @cindex Archive, creation of
1055 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1056 you use to create a @command{tar} archive.  We will explain
1057 @option{--create} first because, in order to learn about the other
1058 operations, you will find it useful to have an archive available to
1059 practice on.
1060
1061 To make this easier, in this section you will first create a directory
1062 containing three files.  Then, we will show you how to create an
1063 @emph{archive} (inside the new directory).  Both the directory, and
1064 the archive are specifically for you to practice on.  The rest of this
1065 chapter and the next chapter will show many examples using this
1066 directory and the files you will create: some of those files may be
1067 other directories and other archives.
1068
1069 The three files you will archive in this example are called
1070 @file{blues}, @file{folk}, and @file{jazz}.  The archive is called
1071 @file{collection.tar}.
1072
1073 This section will proceed slowly, detailing how to use @option{--create}
1074 in @code{verbose} mode, and showing examples using both short and long
1075 forms.  In the rest of the tutorial, and in the examples in the next
1076 chapter, we will proceed at a slightly quicker pace.  This section
1077 moves more slowly to allow beginning users to understand how
1078 @command{tar} works.
1079
1080 @menu
1081 * prepare for examples::
1082 * Creating the archive::
1083 * create verbose::
1084 * short create::
1085 * create dir::
1086 @end menu
1087
1088 @node prepare for examples
1089 @subsection Preparing a Practice Directory for Examples
1090
1091 To follow along with this and future examples, create a new directory
1092 called @file{practice} containing files called @file{blues}, @file{folk}
1093 and @file{jazz}.  The files can contain any information you like:
1094 ideally, they should contain information which relates to their names,
1095 and be of different lengths.  Our examples assume that @file{practice}
1096 is a subdirectory of your home directory.
1097
1098 Now @command{cd} to the directory named @file{practice}; @file{practice}
1099 is now your @dfn{working directory}.  (@emph{Please note}: Although
1100 the full file name of this directory is
1101 @file{/@var{homedir}/practice}, in our examples we will refer to
1102 this directory as @file{practice}; the @var{homedir} is presumed.)
1103
1104 In general, you should check that the files to be archived exist where
1105 you think they do (in the working directory) by running @command{ls}.
1106 Because you just created the directory and the files and have changed to
1107 that directory, you probably don't need to do that this time.
1108
1109 It is very important to make sure there isn't already a file in the
1110 working directory with the archive name you intend to use (in this case,
1111 @samp{collection.tar}), or that you don't care about its contents.
1112 Whenever you use @samp{create}, @command{tar} will erase the current
1113 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists.  @command{tar}
1114 will not tell you if you are about to overwrite an archive unless you
1115 specify an option which does this (@pxref{backup}, for the
1116 information on how to do so).  To add files to an existing archive,
1117 you need to use a different option, such as @option{--append} (@option{-r}); see
1118 @ref{append} for information on how to do this.
1119
1120 @node Creating the archive
1121 @subsection Creating the Archive
1122
1123 @xopindex{create, introduced}
1124 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1125 archive named @file{collection.tar}, use the following command:
1126
1127 @smallexample
1128 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1129 @end smallexample
1130
1131 The order of the arguments is not very important, @emph{when using long
1132 option forms}, however you should always remember to use option as the
1133 first argument to tar.   For example, the following is wrong:
1134
1135 @smallexample
1136 $ @kbd{tar blues -c folk -f collection.tar jazz}
1137 tar: -c: Invalid blocking factor
1138 Try 'tar --help' or 'tar --usage' for more information.
1139 @end smallexample
1140
1141 The error message is produced because @command{tar} always treats its
1142 first argument as an option (or cluster of options), even if it does
1143 not start with dash.  This is @dfn{traditional} or @dfn{old option}
1144 style, called so because all implementations of @command{tar} have
1145 used it since the very inception of the tar archiver in 1970s.  This
1146 option style will be explained later (@pxref{Old Options}), for now
1147 just remember to always place option as the first argument.
1148
1149 That being said, you could issue the following command:
1150
1151 @smallexample
1152 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1153 @end smallexample
1154
1155 @noindent
1156 However, you can see that this order is harder to understand; this is
1157 why we will list the arguments in the order that makes the commands
1158 easiest to understand (and we encourage you to do the same when you use
1159 @command{tar}, to avoid errors).
1160
1161 Note that the sequence
1162 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1163 If you substituted any other string of characters for
1164 @kbd{collection.tar},  then that string would become the name of the
1165 archive file you create.
1166
1167 The order of the options becomes more important when you begin to use
1168 short forms.  With short forms, if you type commands in the wrong order
1169 (even if you type them correctly in all other ways), you may end up with
1170 results you don't expect.  For this reason, it is a good idea to get
1171 into the habit of typing options in the order that makes inherent sense.
1172 @xref{short create}, for more information on this.
1173
1174 In this example, you type the command as shown above: @option{--create}
1175 is the operation which creates the new archive
1176 (@file{collection.tar}), and @option{--file} is the option which lets
1177 you give it the name you chose.  The files, @file{blues}, @file{folk},
1178 and @file{jazz}, are now members of the archive, @file{collection.tar}
1179 (they are @dfn{file name arguments} to the @option{--create} operation.
1180 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1181 in the archive, they are called @emph{archive members}, not files.
1182 (@pxref{Definitions,members}).
1183
1184 When you create an archive, you @emph{must} specify which files you
1185 want placed in the archive.  If you do not specify any archive
1186 members, @GNUTAR{} will complain.
1187
1188 If you now list the contents of the working directory (@command{ls}), you will
1189 find the archive file listed as well as the files you saw previously:
1190
1191 @smallexample
1192 blues   folk   jazz   collection.tar
1193 @end smallexample
1194
1195 @noindent
1196 Creating the archive @samp{collection.tar} did not destroy the copies of
1197 the files in the directory.
1198
1199 Keep in mind that if you don't indicate an operation, @command{tar} will not
1200 run and will prompt you for one.  If you don't name any files, @command{tar}
1201 will complain.  You must have write access to the working directory,
1202 or else you will not be able to create an archive in that directory.
1203
1204 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1205 an existing archive; it will delete the archive and write a new one.
1206 Use @option{--append} (@option{-r}) instead.  @xref{append}.
1207
1208 @node create verbose
1209 @subsection Running @option{--create} with @option{--verbose}
1210
1211 @xopindex{create, using with @option{--verbose}}
1212 @xopindex{verbose, using with @option{--create}}
1213 If you include the @option{--verbose} (@option{-v}) option on the command line,
1214 @command{tar} will list the files it is acting on as it is working.  In
1215 verbose mode, the @code{create} example above would appear as:
1216
1217 @smallexample
1218 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1219 blues
1220 folk
1221 jazz
1222 @end smallexample
1223
1224 This example is just like the example we showed which did not use
1225 @option{--verbose}, except that @command{tar} generated the remaining
1226 @iftex
1227 lines (note the different font styles).
1228 @end iftex
1229 @ifinfo
1230 lines.
1231 @end ifinfo
1232
1233 In the rest of the examples in this chapter, we will frequently use
1234 @code{verbose} mode so we can show actions or @command{tar} responses that
1235 you would otherwise not see, and which are important for you to
1236 understand.
1237
1238 @node short create
1239 @subsection Short Forms with @samp{create}
1240
1241 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1242 basic uses of @command{tar}, and you will use it countless times.
1243 Eventually, you will probably want to use abbreviated (or ``short'')
1244 forms of options.  A full discussion of the three different forms that
1245 options can take appears in @ref{Styles}; for now, here is what the
1246 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1247 using short option forms:
1248
1249 @smallexample
1250 $ @kbd{tar -cvf collection.tar blues folk jazz}
1251 blues
1252 folk
1253 jazz
1254 @end smallexample
1255
1256 @noindent
1257 As you can see, the system responds the same no matter whether you use
1258 long or short option forms.
1259
1260 @FIXME{i don't like how this is worded:} One difference between using
1261 short and long option forms is that, although the exact placement of
1262 arguments following options is no more specific when using short forms,
1263 it is easier to become confused and make a mistake when using short
1264 forms.  For example, suppose you attempted the above example in the
1265 following way:
1266
1267 @smallexample
1268 $ @kbd{tar -cfv collection.tar blues folk jazz}
1269 @end smallexample
1270
1271 @noindent
1272 In this case, @command{tar} will make an archive file called @file{v},
1273 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1274 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1275 is thus taken to be the chosen archive file name.  @command{tar} will try
1276 to add a file called @file{collection.tar} to the @file{v} archive file;
1277 if the file @file{collection.tar} did not already exist, @command{tar} will
1278 report an error indicating that this file does not exist.  If the file
1279 @file{collection.tar} does already exist (e.g., from a previous command
1280 you may have run), then @command{tar} will add this file to the archive.
1281 Because the @option{-v} option did not get registered, @command{tar} will not
1282 run under @samp{verbose} mode, and will not report its progress.
1283
1284 The end result is that you may be quite confused about what happened,
1285 and possibly overwrite a file.  To illustrate this further, we will show
1286 you how an example we showed previously would look using short forms.
1287
1288 This example,
1289
1290 @smallexample
1291 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1292 @end smallexample
1293
1294 @noindent
1295 is confusing as it is.  It becomes even more so when using short forms:
1296
1297 @smallexample
1298 $ @kbd{tar -c folk blues -f collection.tar jazz}
1299 @end smallexample
1300
1301 @noindent
1302 It would be very easy to put the wrong string of characters
1303 immediately following the @option{-f}, but doing that could sacrifice
1304 valuable data.
1305
1306 For this reason, we recommend that you pay very careful attention to
1307 the order of options and placement of file and archive names,
1308 especially when using short option forms.  Not having the option name
1309 written out mnemonically can affect how well you remember which option
1310 does what, and therefore where different names have to be placed.
1311
1312 @node create dir
1313 @subsection Archiving Directories
1314
1315 @cindex Archiving Directories
1316 @cindex Directories, Archiving
1317 You can archive a directory by specifying its directory name as a
1318 file name argument to @command{tar}.  The files in the directory will be
1319 archived relative to the working directory, and the directory will be
1320 re-created along with its contents when the archive is extracted.
1321
1322 To archive a directory, first move to its superior directory.  If you
1323 have followed the previous instructions in this tutorial, you should
1324 type:
1325
1326 @smallexample
1327 $ @kbd{cd ..}
1328 $
1329 @end smallexample
1330
1331 @noindent
1332 This will put you into the directory which contains @file{practice},
1333 i.e., your home directory.  Once in the superior directory, you can
1334 specify the subdirectory, @file{practice}, as a file name argument.  To
1335 store @file{practice} in the new archive file @file{music.tar}, type:
1336
1337 @smallexample
1338 $ @kbd{tar --create --verbose --file=music.tar practice}
1339 @end smallexample
1340
1341 @noindent
1342 @command{tar} should output:
1343
1344 @smallexample
1345 practice/
1346 practice/blues
1347 practice/folk
1348 practice/jazz
1349 practice/collection.tar
1350 @end smallexample
1351
1352 Note that the archive thus created is not in the subdirectory
1353 @file{practice}, but rather in the current working directory---the
1354 directory from which @command{tar} was invoked.  Before trying to archive a
1355 directory from its superior directory, you should make sure you have
1356 write access to the superior directory itself, not only the directory
1357 you are trying archive with @command{tar}.  For example, you will probably
1358 not be able to store your home directory in an archive by invoking
1359 @command{tar} from the root directory; @xref{absolute}.  (Note
1360 also that @file{collection.tar}, the original archive file, has itself
1361 been archived.  @command{tar} will accept any file as a file to be
1362 archived, regardless of its content.  When @file{music.tar} is
1363 extracted, the archive file @file{collection.tar} will be re-written
1364 into the file system).
1365
1366 If you give @command{tar} a command such as
1367
1368 @smallexample
1369 $ @kbd{tar --create --file=foo.tar .}
1370 @end smallexample
1371
1372 @noindent
1373 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1374 dumped}.  This happens because @command{tar} creates the archive
1375 @file{foo.tar} in the current directory before putting any files into
1376 it.  Then, when @command{tar} attempts to add all the files in the
1377 directory @file{.} to the archive, it notices that the file
1378 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1379 it.  (It makes no sense to put an archive into itself.)  @GNUTAR{}
1380 will continue in this case, and create the archive
1381 normally, except for the exclusion of that one file.  (@emph{Please
1382 note:} Other implementations of @command{tar} may not be so clever;
1383 they will enter an infinite loop when this happens, so you should not
1384 depend on this behavior unless you are certain you are running
1385 @GNUTAR{}.  In general, it is wise to always place the archive outside
1386 of the directory being dumped.)
1387
1388 @node list
1389 @section How to List Archives
1390
1391 @opindex list
1392 Frequently, you will find yourself wanting to determine exactly what a
1393 particular archive contains.  You can use the @option{--list}
1394 (@option{-t}) operation to get the member names as they currently
1395 appear in the archive, as well as various attributes of the files at
1396 the time they were archived.  For example, assuming @file{practice} is
1397 your working directory, you can examine the archive
1398 @file{collection.tar} that you created in the last section with the
1399 command,
1400
1401 @smallexample
1402 $ @kbd{tar --list --file=collection.tar}
1403 @end smallexample
1404
1405 @noindent
1406 The output of @command{tar} would then be:
1407
1408 @smallexample
1409 blues
1410 folk
1411 jazz
1412 @end smallexample
1413
1414 @noindent
1415 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1416 @var{archive-name}}) option just as with @option{--create}
1417 (@option{-c}) to specify the name of the archive.
1418
1419 @cindex File name arguments, using @option{--list} with
1420 @xopindex{list, using with file name arguments}
1421 You can specify one or more individual member names as arguments when
1422 using @samp{list}.  In this case, @command{tar} will only list the
1423 names of members you identify.  For example, @w{@kbd{tar --list
1424 --file=collection.tar folk}} would only print @file{folk}:
1425
1426 @smallexample
1427 $ @kbd{tar --list --file=collection.tar folk}
1428 folk
1429 @end smallexample
1430
1431 @xopindex{list, using with @option{--verbose}}
1432 @xopindex{verbose, using with @option{--list}}
1433 If you use the @option{--verbose} (@option{-v}) option with
1434 @option{--list}, then @command{tar} will print out a listing
1435 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1436 forth.  This output is described in detail in @ref{verbose member listing}.
1437
1438 If you had used @option{--verbose} (@option{-v}) mode, the example
1439 above would look like:
1440
1441 @smallexample
1442 $ @kbd{tar --list --verbose --file=collection.tar folk}
1443 -rw-r--r-- myself/user      62 1990-05-23 10:55 folk
1444 @end smallexample
1445
1446 @cindex listing member and file names
1447 @anchor{listing member and file names}
1448 It is important to notice that the output of @kbd{tar --list
1449 --verbose} does not necessarily match that produced by @kbd{tar
1450 --create --verbose} while creating the archive.  It is because
1451 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1452 prefixes from file names before storing them in the archive
1453 (@xref{absolute}, for more information).  In other
1454 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1455 an archive and @dfn{member names} when listing it.  Consider this
1456 example, run from your home directory:
1457
1458 @smallexample
1459 @group
1460 $ @kbd{tar --create --verbose --file practice.tar ~/practice}
1461 tar: Removing leading '/' from member names
1462 /home/myself/practice/
1463 /home/myself/practice/blues
1464 /home/myself/practice/folk
1465 /home/myself/practice/jazz
1466 /home/myself/practice/collection.tar
1467 $ @kbd{tar --test --file practice.tar}
1468 home/myself/practice/
1469 home/myself/practice/blues
1470 home/myself/practice/folk
1471 home/myself/practice/jazz
1472 home/myself/practice/collection.tar
1473 @end group
1474 @end smallexample
1475
1476 @opindex show-stored-names
1477   This default behavior can sometimes be inconvenient.  You can force
1478 @GNUTAR{} show member names when creating archive by supplying
1479 @option{--show-stored-names} option.
1480
1481 @table @option
1482 @item --show-stored-names
1483 Print member (as opposed to @emph{file}) names when creating the archive.
1484 @end table
1485
1486 With this option, both commands produce the same output:
1487
1488 @smallexample
1489 @group
1490 $ @kbd{tar --create --verbose --show-stored-names \
1491            --file practice.tar ~/practice}
1492 tar: Removing leading '/' from member names
1493 home/myself/practice/
1494 home/myself/practice/blues
1495 home/myself/practice/folk
1496 home/myself/practice/jazz
1497 home/myself/practice/collection.tar
1498 $ @kbd{tar --test --file practice.tar}
1499 home/myself/practice/
1500 home/myself/practice/blues
1501 home/myself/practice/folk
1502 home/myself/practice/jazz
1503 home/myself/practice/collection.tar
1504 @end group
1505 @end smallexample
1506
1507 Since @command{tar} preserves file names, those you wish to list must be
1508 specified as they appear in the archive (i.e., relative to the
1509 directory from which the archive was created).  Continuing the example
1510 above:
1511
1512 @smallexample
1513 @group
1514 $ @kbd{tar --list --file=practice.tar folk}
1515 tar: folk: Not found in archive
1516 tar: Exiting with failure status due to previous errors
1517 @end group
1518 @end smallexample
1519
1520 the error message is produced because there is no member named
1521 @file{folk}, only one named @file{home/myself/folk}.
1522
1523 If you are not sure of the exact file name, use @dfn{globbing
1524 patterns}, for example: 
1525
1526 @smallexample
1527 $ @kbd{tar --list --file=practice.tar --wildcards '*/folk'}
1528 home/myself/practice/folk
1529 @end smallexample
1530
1531 @noindent
1532 @xref{wildcards}, for a detailed discussion of globbing patterns and related
1533 @command{tar} command line options.
1534
1535 @menu
1536 * list dir::
1537 @end menu
1538
1539 @node list dir
1540 @unnumberedsubsec Listing the Contents of a Stored Directory
1541
1542 To get information about the contents of an archived directory,
1543 use the directory name as a file name argument in conjunction with
1544 @option{--list} (@option{-t}).  To find out file attributes, include the
1545 @option{--verbose} (@option{-v}) option.
1546
1547 For example, to find out about files in the directory @file{practice}, in
1548 the archive file @file{music.tar}, type:
1549
1550 @smallexample
1551 $ @kbd{tar --list --verbose --file=music.tar practice}
1552 @end smallexample
1553
1554 @command{tar} responds:
1555
1556 @smallexample
1557 drwxrwxrwx myself/user       0 1990-05-31 21:49 practice/
1558 -rw-r--r-- myself/user      42 1990-05-21 13:29 practice/blues
1559 -rw-r--r-- myself/user      62 1990-05-23 10:55 practice/folk
1560 -rw-r--r-- myself/user      40 1990-05-21 13:30 practice/jazz
1561 -rw-r--r-- myself/user   10240 1990-05-31 21:49 practice/collection.tar
1562 @end smallexample
1563
1564 When you use a directory name as a file name argument, @command{tar} acts on
1565 all the files (including sub-directories) in that directory.
1566
1567 @node extract
1568 @section How to Extract Members from an Archive
1569 @cindex Extraction
1570 @cindex Retrieving files from an archive
1571 @cindex Resurrecting files from an archive
1572
1573 @opindex extract
1574 Creating an archive is only half the job---there is no point in storing
1575 files in an archive if you can't retrieve them.  The act of retrieving
1576 members from an archive so they can be used and manipulated as
1577 unarchived files again is called @dfn{extraction}.  To extract files
1578 from an archive, use the @option{--extract} (@option{--get} or
1579 @option{-x}) operation.  As with @option{--create}, specify the name
1580 of the archive with @option{--file} (@option{-f}) option. Extracting
1581 an archive does not modify the archive in any way; you can extract it
1582 multiple times if you want or need to.
1583
1584 Using @option{--extract}, you can extract an entire archive, or specific
1585 files.  The files can be directories containing other files, or not.  As
1586 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1587 long form of the operation without affecting the performance.
1588
1589 @menu
1590 * extracting archives::
1591 * extracting files::
1592 * extract dir::
1593 * extracting untrusted archives::
1594 * failing commands::
1595 @end menu
1596
1597 @node extracting archives
1598 @subsection Extracting an Entire Archive
1599
1600 To extract an entire archive, specify the archive file name only, with
1601 no individual file names as arguments.  For example,
1602
1603 @smallexample
1604 $ @kbd{tar -xvf collection.tar}
1605 @end smallexample
1606
1607 @noindent
1608 produces this:
1609
1610 @smallexample
1611 -rw-r--r-- myself/user      28 1996-10-18 16:31 jazz
1612 -rw-r--r-- myself/user      21 1996-09-23 16:44 blues
1613 -rw-r--r-- myself/user      20 1996-09-23 16:44 folk
1614 @end smallexample
1615
1616 @node extracting files
1617 @subsection Extracting Specific Files
1618
1619 To extract specific archive members, give their exact member names as
1620 arguments, as printed by @option{--list} (@option{-t}).  If you had
1621 mistakenly deleted one of the files you had placed in the archive
1622 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1623 from the archive without changing the archive's structure.  Its
1624 contents will be identical to the original file @file{blues} that you
1625 deleted.
1626
1627 First, make sure you are in the @file{practice} directory, and list the
1628 files in the directory.  Now, delete the file, @samp{blues}, and list
1629 the files in the directory again.
1630
1631 You can now extract the member @file{blues} from the archive file
1632 @file{collection.tar} like this:
1633
1634 @smallexample
1635 $ @kbd{tar --extract --file=collection.tar blues}
1636 @end smallexample
1637
1638 @noindent
1639 If you list the files in the directory again, you will see that the file
1640 @file{blues} has been restored, with its original permissions, data
1641 modification times, and owner.@footnote{This is only accidentally
1642 true, but not in general.  Whereas modification times are always
1643 restored, in most cases, one has to be root for restoring the owner,
1644 and use a special option for restoring permissions.  Here, it just
1645 happens that the restoring user is also the owner of the archived
1646 members, and that the current @code{umask} is compatible with original
1647 permissions.}  (These parameters will be identical to those which
1648 the file had when you originally placed it in the archive; any changes
1649 you may have made before deleting the file from the file system,
1650 however, will @emph{not} have been made to the archive member.)  The
1651 archive file, @samp{collection.tar}, is the same as it was before you
1652 extracted @samp{blues}.  You can confirm this by running @command{tar} with
1653 @option{--list} (@option{-t}).
1654
1655 Remember that as with other operations, specifying the exact member
1656 name is important (@xref{failing commands}, for more examples).
1657
1658 You can extract a file to standard output by combining the above options
1659 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1660 Output}).
1661
1662 If you give the @option{--verbose} option, then @option{--extract}
1663 will print the names of the archive members as it extracts them.
1664
1665 @node extract dir
1666 @subsection Extracting Files that are Directories
1667
1668 Extracting directories which are members of an archive is similar to
1669 extracting other files.  The main difference to be aware of is that if
1670 the extracted directory has the same name as any directory already in
1671 the working directory, then files in the extracted directory will be
1672 placed into the directory of the same name.  Likewise, if there are
1673 files in the pre-existing directory with the same names as the members
1674 which you extract, the files from the extracted archive will replace
1675 the files already in the working directory (and possible
1676 subdirectories).  This will happen regardless of whether or not the
1677 files in the working directory were more recent than those extracted
1678 (there exist, however, special options that alter this behavior
1679 @pxref{Writing}).
1680
1681 However, if a file was stored with a directory name as part of its file
1682 name, and that directory does not exist under the working directory when
1683 the file is extracted, @command{tar} will create the directory.
1684
1685 We can demonstrate how to use @option{--extract} to extract a directory
1686 file with an example.  Change to the @file{practice} directory if you
1687 weren't there, and remove the files @file{folk} and @file{jazz}.  Then,
1688 go back to the parent directory and extract the archive
1689 @file{music.tar}.  You may either extract the entire archive, or you may
1690 extract only the files you just deleted.  To extract the entire archive,
1691 don't give any file names as arguments after the archive name
1692 @file{music.tar}.  To extract only the files you deleted, use the
1693 following command:
1694
1695 @smallexample
1696 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1697 practice/folk
1698 practice/jazz
1699 @end smallexample
1700
1701 @noindent
1702 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1703 would have displayed more detail about the extracted files, as shown
1704 in the example below:
1705
1706 @smallexample
1707 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1708 -rw-r--r-- me/user          28 1996-10-18 16:31 practice/jazz
1709 -rw-r--r-- me/user          20 1996-09-23 16:44 practice/folk
1710 @end smallexample
1711
1712 @noindent
1713 Because you created the directory with @file{practice} as part of the
1714 file names of each of the files by archiving the @file{practice}
1715 directory as @file{practice}, you must give @file{practice} as part
1716 of the file names when you extract those files from the archive.
1717
1718 @node extracting untrusted archives
1719 @subsection Extracting Archives from Untrusted Sources
1720
1721 Extracting files from archives can overwrite files that already exist.
1722 If you receive an archive from an untrusted source, you should make a
1723 new directory and extract into that directory, so that you don't have
1724 to worry about the extraction overwriting one of your existing files.
1725 For example, if @file{untrusted.tar} came from somewhere else on the
1726 Internet, and you don't necessarily trust its contents, you can
1727 extract it as follows:
1728
1729 @smallexample
1730 $ @kbd{mkdir newdir}
1731 $ @kbd{cd newdir}
1732 $ @kbd{tar -xvf ../untrusted.tar}
1733 @end smallexample
1734
1735 It is also a good practice to examine contents of the archive
1736 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1737 with @option{--verbose} (@option{-v}).
1738
1739 @node failing commands
1740 @subsection Commands That Will Fail
1741
1742 Here are some sample commands you might try which will not work, and why
1743 they won't work.
1744
1745 If you try to use this command,
1746
1747 @smallexample
1748 $ @kbd{tar -xvf music.tar folk jazz}
1749 @end smallexample
1750
1751 @noindent
1752 you will get the following response:
1753
1754 @smallexample
1755 tar: folk: Not found in archive
1756 tar: jazz: Not found in archive
1757 @end smallexample
1758
1759 @noindent
1760 This is because these files were not originally @emph{in} the parent
1761 directory @file{..}, where the archive is located; they were in the
1762 @file{practice} directory, and their file names reflect this:
1763
1764 @smallexample
1765 $ @kbd{tar -tvf music.tar}
1766 practice/blues
1767 practice/folk
1768 practice/jazz
1769 @end smallexample
1770
1771 @noindent
1772 Likewise, if you try to use this command,
1773
1774 @smallexample
1775 $ @kbd{tar -tvf music.tar folk jazz}
1776 @end smallexample
1777
1778 @noindent
1779 you would get a similar response.  Members with those names are not in the
1780 archive.  You must use the correct member names, or wildcards, in order
1781 to extract the files from the archive.
1782
1783 If you have forgotten the correct names of the files in the archive,
1784 use @w{@kbd{tar --list --verbose}} to list them correctly.
1785
1786 To extract the member named @file{practice/folk}, you must specify
1787
1788 @smallexample
1789 $ @kbd{tar --extract --file=music.tar practice/folk}
1790 @end smallexample
1791
1792 @noindent
1793 Notice also, that as explained above, the @file{practice} directory
1794 will be created, if it didn't already exist.  There are options that
1795 allow you to strip away a certain number of leading directory
1796 components (@pxref{transform}).  For example,
1797
1798 @smallexample
1799 $ @kbd{tar --extract --file=music.tar --strip-components=1 folk}
1800 @end smallexample
1801
1802 @noindent
1803 will extract the file @file{folk} into the current working directory.
1804
1805 @node going further
1806 @section Going Further Ahead in this Manual
1807 @UNREVISED
1808
1809 @FIXME{need to write up a node here about the things that are going to
1810 be in the rest of the manual.}
1811
1812 @node tar invocation
1813 @chapter Invoking @GNUTAR{}
1814
1815 This chapter is about how one invokes the @GNUTAR{}
1816 command, from the command synopsis (@pxref{Synopsis}).  There are
1817 numerous options, and many styles for writing them.  One mandatory
1818 option specifies the operation @command{tar} should perform
1819 (@pxref{Operation Summary}), other options are meant to detail how
1820 this operation should be performed (@pxref{Option Summary}).
1821 Non-option arguments are not always interpreted the same way,
1822 depending on what the operation is.
1823
1824 You will find in this chapter everything about option styles and rules for
1825 writing them (@pxref{Styles}).  On the other hand, operations and options
1826 are fully described elsewhere, in other chapters.  Here, you will find
1827 only synthetic descriptions for operations and options, together with
1828 pointers to other parts of the @command{tar} manual.
1829
1830 Some options are so special they are fully described right in this
1831 chapter.  They have the effect of inhibiting the normal operation of
1832 @command{tar} or else, they globally alter the amount of feedback the user
1833 receives about what is going on.  These are the @option{--help} and
1834 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1835 and @option{--interactive} options (@pxref{interactive}).
1836
1837 @menu
1838 * Synopsis::
1839 * using tar options::
1840 * Styles::
1841 * All Options::           All @command{tar} Options.
1842 * help::                  Where to Get Help.
1843 * defaults::              What are the Default Values.
1844 * verbose::               Checking @command{tar} progress.
1845 * checkpoints::           Checkpoints.
1846 * warnings::              Controlling Warning Messages.
1847 * interactive::           Asking for Confirmation During Operations.
1848 * external::              Running External Commands.
1849 @end menu
1850
1851 @node Synopsis
1852 @section General Synopsis of @command{tar}
1853
1854 The @GNUTAR{} program is invoked as either one of:
1855
1856 @smallexample
1857 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1858 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1859 @end smallexample
1860
1861 The second form is for when old options are being used.
1862
1863 You can use @command{tar} to store files in an archive, to extract them from
1864 an archive, and to do other types of archive manipulation.  The primary
1865 argument to @command{tar}, which is called the @dfn{operation}, specifies
1866 which action to take.  The other arguments to @command{tar} are either
1867 @dfn{options}, which change the way @command{tar} performs an operation,
1868 or file names or archive members, which specify the files or members
1869 @command{tar} is to act on.
1870
1871 You can actually type in arguments in any order, even if in this manual
1872 the options always precede the other arguments, to make examples easier
1873 to understand.  Further, the option stating the main operation mode
1874 (the @command{tar} main command) is usually given first.
1875
1876 Each @var{name} in the synopsis above is interpreted as an archive member
1877 name when the main command is one of @option{--compare}
1878 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1879 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1880 @option{--update} (@option{-u}).  When naming archive members, you
1881 must give the exact name of the member in the archive, as it is
1882 printed by @option{--list}.  For @option{--append} (@option{-r}) and
1883 @option{--create} (@option{-c}), these @var{name} arguments specify
1884 the names of either files or directory hierarchies to place in the archive.
1885 These files or hierarchies should already exist in the file system,
1886 prior to the execution of the @command{tar} command.
1887
1888 @command{tar} interprets relative file names as being relative to the
1889 working directory.  @command{tar} will make all file names relative
1890 (by removing leading slashes when archiving or restoring files),
1891 unless you specify otherwise (using the @option{--absolute-names}
1892 option).  @xref{absolute}, for more information about
1893 @option{--absolute-names}.
1894
1895 If you give the name of a directory as either a file name or a member
1896 name, then @command{tar} acts recursively on all the files and directories
1897 beneath that directory.  For example, the name @file{/} identifies all
1898 the files in the file system to @command{tar}.
1899
1900 The distinction between file names and archive member names is especially
1901 important when shell globbing is used, and sometimes a source of confusion
1902 for newcomers.  @xref{wildcards}, for more information about globbing.
1903 The problem is that shells may only glob using existing files in the
1904 file system.  Only @command{tar} itself may glob on archive members, so when
1905 needed, you must ensure that wildcard characters reach @command{tar} without
1906 being interpreted by the shell first.  Using a backslash before @samp{*}
1907 or @samp{?}, or putting the whole argument between quotes, is usually
1908 sufficient for this.
1909
1910 Even if @var{name}s are often specified on the command line, they
1911 can also be read from a text file in the file system, using the
1912 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1913
1914 If you don't use any file name arguments, @option{--append} (@option{-r}),
1915 @option{--delete} and @option{--concatenate} (@option{--catenate},
1916 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1917 will usually yield a diagnostic and inhibit @command{tar} execution.
1918 The other operations of @command{tar} (@option{--list},
1919 @option{--extract}, @option{--compare}, and @option{--update})
1920 will act on the entire contents of the archive.
1921
1922 @anchor{exit status}
1923 @cindex exit status
1924 @cindex return status
1925 Besides successful exits, @GNUTAR{} may fail for
1926 many reasons.  Some reasons correspond to bad usage, that is, when the
1927 @command{tar} command line is improperly written.  Errors may be
1928 encountered later, while processing the archive or the files.  Some
1929 errors are recoverable, in which case the failure is delayed until
1930 @command{tar} has completed all its work.  Some errors are such that
1931 it would be not meaningful, or at least risky, to continue processing:
1932 @command{tar} then aborts processing immediately.  All abnormal exits,
1933 whether immediate or delayed, should always be clearly diagnosed on
1934 @code{stderr}, after a line stating the nature of the error.
1935
1936 Possible exit codes of @GNUTAR{} are summarized in the following
1937 table:
1938
1939 @table @asis
1940 @item 0
1941 @samp{Successful termination}.
1942
1943 @item 1
1944 @samp{Some files differ}.  If tar was invoked with @option{--compare}
1945 (@option{--diff}, @option{-d}) command line option, this means that
1946 some files in the archive differ from their disk counterparts
1947 (@pxref{compare}).  If tar was given @option{--create},
1948 @option{--append} or @option{--update} option, this exit code means
1949 that some files were changed while being archived and so the resulting
1950 archive does not contain the exact copy of the file set.
1951
1952 @item 2
1953 @samp{Fatal error}.  This means that some fatal, unrecoverable error
1954 occurred.
1955 @end table
1956
1957 If @command{tar} has invoked a subprocess and that subprocess exited with a
1958 nonzero exit code, @command{tar} exits with that code as well.
1959 This can happen, for example, if @command{tar} was given some
1960 compression option (@pxref{gzip}) and the external compressor program
1961 failed.  Another example is @command{rmt} failure during backup to the
1962 remote device (@pxref{Remote Tape Server}).
1963
1964 @node using tar options
1965 @section Using @command{tar} Options
1966
1967 @GNUTAR{} has a total of eight operating modes which
1968 allow you to perform a variety of tasks.  You are required to choose
1969 one operating mode each time you employ the @command{tar} program by
1970 specifying one, and only one operation as an argument to the
1971 @command{tar} command (the corresponding options may be found
1972 at @ref{frequent operations} and @ref{Operations}).  Depending on
1973 circumstances, you may also wish to customize how the chosen operating
1974 mode behaves.  For example, you may wish to change the way the output
1975 looks, or the format of the files that you wish to archive may require
1976 you to do something special in order to make the archive look right.
1977
1978 You can customize and control @command{tar}'s performance by running
1979 @command{tar} with one or more options (such as @option{--verbose}
1980 (@option{-v}), which we used in the tutorial).  As we said in the
1981 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1982 their name suggests) optional. Depending on the operating mode, you
1983 may specify one or more options. Different options will have different
1984 effects, but in general they all change details of the operation, such
1985 as archive format, archive name, or level of user interaction.  Some
1986 options make sense with all operating modes, while others are
1987 meaningful only with particular modes. You will likely use some
1988 options frequently, while you will only use others infrequently, or
1989 not at all.  (A full list of options is available in @pxref{All Options}.)
1990
1991 @vrindex TAR_OPTIONS, environment variable
1992 @anchor{TAR_OPTIONS}
1993 The @env{TAR_OPTIONS} environment variable specifies default options to
1994 be placed in front of any explicit options.  For example, if
1995 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1996 if the two options @option{-v} and @option{--unlink-first} had been
1997 specified before any explicit options.  Option specifications are
1998 separated by whitespace.  A backslash escapes the next character, so it
1999 can be used to specify an option containing whitespace or a backslash.
2000
2001 Note that @command{tar} options are case sensitive.  For example, the
2002 options @option{-T} and @option{-t} are different; the first requires an
2003 argument for stating the name of a file providing a list of @var{name}s,
2004 while the second does not require an argument and is another way to
2005 write @option{--list} (@option{-t}).
2006
2007 In addition to the eight operations, there are many options to
2008 @command{tar}, and three different styles for writing both: long (mnemonic)
2009 form, short form, and old style.  These styles are discussed below.
2010 Both the options and the operations can be written in any of these three
2011 styles.
2012
2013 @FIXME{menu at end of this node.  need to think of an actual outline
2014 for this chapter; probably do that after stuff from chapter 4 is
2015 incorporated.}
2016
2017 @node Styles
2018 @section The Three Option Styles
2019
2020 There are three styles for writing operations and options to the command
2021 line invoking @command{tar}.  The different styles were developed at
2022 different times during the history of @command{tar}.  These styles will be
2023 presented below, from the most recent to the oldest.
2024
2025 Some options must take an argument@footnote{For example, @option{--file}
2026 (@option{-f}) takes the name of an archive file as an argument.  If
2027 you do not supply an archive file name, @command{tar} will use a
2028 default, but this can be confusing; thus, we recommend that you always
2029 supply a specific archive file name.}.  Where you @emph{place} the
2030 arguments generally depends on which style of options you choose.  We
2031 will detail specific information relevant to each option style in the
2032 sections on the different option styles, below.  The differences are
2033 subtle, yet can often be very important; incorrect option placement
2034 can cause you to overwrite a number of important files.  We urge you
2035 to note these differences, and only use the option style(s) which
2036 makes the most sense to you until you feel comfortable with the others.
2037
2038 Some options @emph{may} take an argument.  Such options may have at
2039 most long and short forms, they do not have old style equivalent.  The
2040 rules for specifying an argument for such options are stricter than
2041 those for specifying mandatory arguments.  Please, pay special
2042 attention to them.
2043
2044 @menu
2045 * Long Options::                Long Option Style
2046 * Short Options::               Short Option Style
2047 * Old Options::                 Old Option Style
2048 * Mixing::                      Mixing Option Styles
2049 @end menu
2050
2051 @node Long Options
2052 @subsection Long Option Style
2053
2054 @cindex long options
2055 @cindex options, long style
2056 @cindex options, GNU style
2057 @cindex options, mnemonic names
2058 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2059 dashes in a row, e.g., @option{--list}.  The long names are more clear than
2060 their corresponding short or old names.  It sometimes happens that a
2061 single long option has many different names which are
2062 synonymous, such as @option{--compare} and @option{--diff}.  In addition,
2063 long option names can be given unique abbreviations.  For example,
2064 @option{--cre} can be used in place of @option{--create} because there is no
2065 other long option which begins with @samp{cre}.  (One way to find
2066 this out is by trying it and seeing what happens; if a particular
2067 abbreviation could represent more than one option, @command{tar} will tell
2068 you that that abbreviation is ambiguous and you'll know that that
2069 abbreviation won't work.  You may also choose to run @samp{tar --help}
2070 to see a list of options.  Be aware that if you run @command{tar} with a
2071 unique abbreviation for the long name of an option you didn't want to
2072 use, you are stuck; @command{tar} will perform the command as ordered.)
2073
2074 Long options are meant to be obvious and easy to remember, and their
2075 meanings are generally easier to discern than those of their
2076 corresponding short options (see below).  For example:
2077
2078 @smallexample
2079 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2080 @end smallexample
2081
2082 @noindent
2083 gives a fairly good set of hints about what the command does, even
2084 for those not fully acquainted with @command{tar}.
2085
2086 @cindex arguments to long options
2087 @cindex long options with mandatory arguments
2088 Long options which require arguments take those arguments
2089 immediately following the option name.  There are two ways of
2090 specifying a mandatory argument.  It can be separated from the
2091 option name either by an equal sign, or by any amount of
2092 white space characters.  For example, the @option{--file} option (which
2093 tells the name of the @command{tar} archive) is given a file such as
2094 @file{archive.tar} as argument by using any of the following notations:
2095 @option{--file=archive.tar} or @option{--file archive.tar}.
2096
2097 @cindex optional arguments to long options
2098 @cindex long options with optional arguments
2099 In contrast, optional arguments must always be introduced using
2100 an equal sign.  For example, the @option{--backup} option takes
2101 an optional argument specifying backup type.  It must be used
2102 as @option{--backup=@var{backup-type}}.
2103
2104 @node Short Options
2105 @subsection Short Option Style
2106
2107 @cindex short options
2108 @cindex options, short style
2109 @cindex options, traditional
2110 Most options also have a @dfn{short option} name.  Short options start with
2111 a single dash, and are followed by a single character, e.g., @option{-t}
2112 (which is equivalent to @option{--list}).  The forms are absolutely
2113 identical in function; they are interchangeable.
2114
2115 The short option names are faster to type than long option names.
2116
2117 @cindex arguments to short options
2118 @cindex short options with mandatory arguments
2119 Short options which require arguments take their arguments immediately
2120 following the option, usually separated by white space.  It is also
2121 possible to stick the argument right after the short option name, using
2122 no intervening space.  For example, you might write @w{@option{-f
2123 archive.tar}} or @option{-farchive.tar} instead of using
2124 @option{--file=archive.tar}.  Both @option{--file=@var{archive-name}} and
2125 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2126 specific archive, here named @file{archive.tar}.
2127
2128 @cindex optional arguments to short options
2129 @cindex short options with optional arguments
2130 Short options which take optional arguments take their arguments
2131 immediately following the option letter, @emph{without any intervening
2132 white space characters}.
2133
2134 Short options' letters may be clumped together, but you are not
2135 required to do this (as compared to old options; see below).  When
2136 short options are clumped as a set, use one (single) dash for them
2137 all, e.g., @w{@samp{@command{tar} -cvf}}.  Only the last option in
2138 such a set is allowed to have an argument@footnote{Clustering many
2139 options, the last of which has an argument, is a rather opaque way to
2140 write options.  Some wonder if @acronym{GNU} @code{getopt} should not
2141 even be made helpful enough for considering such usages as invalid.}.
2142
2143 When the options are separated, the argument for each option which requires
2144 an argument directly follows that option, as is usual for Unix programs.
2145 For example:
2146
2147 @smallexample
2148 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2149 @end smallexample
2150
2151 If you reorder short options' locations, be sure to move any arguments
2152 that belong to them.  If you do not move the arguments properly, you may
2153 end up overwriting files.
2154
2155 @node Old Options
2156 @subsection Old Option Style
2157 @cindex options, old style
2158 @cindex old option style
2159 @cindex option syntax, traditional
2160
2161 As far as we know, all @command{tar} programs, @acronym{GNU} and
2162 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2163 argument does not start with @samp{-}, it is assumed to specify option
2164 letters.  @GNUTAR{} supports old options not only for historical
2165 reasons, but also because many people are used to them.  If the first
2166 argument does not start with a dash, you are announcing the old option
2167 style instead of the short option style; old options are decoded
2168 differently.
2169
2170 Like short options, old options are single letters.  However, old options
2171 must be written together as a single clumped set, without spaces separating
2172 them or dashes preceding them.  This set
2173 of letters must be the first to appear on the command line, after the
2174 @command{tar} program name and some white space; old options cannot appear
2175 anywhere else.  The letter of an old option is exactly the same letter as
2176 the corresponding short option.  For example, the old option @samp{t} is
2177 the same as the short option @option{-t}, and consequently, the same as the
2178 long option @option{--list}.  So for example, the command @w{@samp{tar
2179 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2180
2181 @cindex arguments to old options
2182 @cindex old options with mandatory arguments
2183 When options that need arguments are given together with the command,
2184 all the associated arguments follow, in the same order as the options.
2185 Thus, the example given previously could also be written in the old
2186 style as follows:
2187
2188 @smallexample
2189 $ @kbd{tar cvbf 20 /dev/rmt0}
2190 @end smallexample
2191
2192 @noindent
2193 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2194 the argument of @option{-f}.
2195
2196 The old style syntax can make it difficult to match
2197 option letters with their corresponding arguments, and is often
2198 confusing.  In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2199 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2200 argument for @option{-f}, and @option{-v} does not have a corresponding
2201 argument.  Even using short options like in @w{@samp{tar -c -v -b 20 -f
2202 /dev/rmt0}} is clearer, putting all arguments next to the option they
2203 pertain to.
2204
2205 If you want to reorder the letters in the old option argument, be
2206 sure to reorder any corresponding argument appropriately.
2207
2208 This old way of writing @command{tar} options can surprise even experienced
2209 users.  For example, the two commands:
2210
2211 @smallexample
2212 @kbd{tar cfz archive.tar.gz file}
2213 @kbd{tar -cfz archive.tar.gz file}
2214 @end smallexample
2215
2216 @noindent
2217 are quite different.  The first example uses @file{archive.tar.gz} as
2218 the value for option @samp{f} and recognizes the option @samp{z}.  The
2219 second example, however, uses @file{z} as the value for option
2220 @samp{f} --- probably not what was intended.
2221
2222 This second example could be corrected in many ways, among which the
2223 following are equivalent:
2224
2225 @smallexample
2226 @kbd{tar -czf archive.tar.gz file}
2227 @kbd{tar -cf archive.tar.gz -z file}
2228 @kbd{tar cf archive.tar.gz -z file}
2229 @end smallexample
2230
2231 @node Mixing
2232 @subsection Mixing Option Styles
2233
2234 @cindex options, mixing different styles
2235 All three styles may be intermixed in a single @command{tar} command,
2236 so long as the rules for each style are fully
2237 respected@footnote{Before @GNUTAR{} version 1.11.6,
2238 a bug prevented intermixing old style options with long options in
2239 some cases.}.  Old style options and either of the modern styles of
2240 options may be mixed within a single @command{tar} command.  However,
2241 old style options must be introduced as the first arguments only,
2242 following the rule for old options (old options must appear directly
2243 after the @command{tar} command and some white space).  Modern options
2244 may be given only after all arguments to the old options have been
2245 collected.  If this rule is not respected, a modern option might be
2246 falsely interpreted as the value of the argument to one of the old
2247 style options.
2248
2249 For example, all the following commands are wholly equivalent, and
2250 illustrate the many combinations and orderings of option styles.
2251
2252 @smallexample
2253 @kbd{tar --create --file=archive.tar}
2254 @kbd{tar --create -f archive.tar}
2255 @kbd{tar --create -farchive.tar}
2256 @kbd{tar --file=archive.tar --create}
2257 @kbd{tar --file=archive.tar -c}
2258 @kbd{tar -c --file=archive.tar}
2259 @kbd{tar -c -f archive.tar}
2260 @kbd{tar -c -farchive.tar}
2261 @kbd{tar -cf archive.tar}
2262 @kbd{tar -cfarchive.tar}
2263 @kbd{tar -f archive.tar --create}
2264 @kbd{tar -f archive.tar -c}
2265 @kbd{tar -farchive.tar --create}
2266 @kbd{tar -farchive.tar -c}
2267 @kbd{tar c --file=archive.tar}
2268 @kbd{tar c -f archive.tar}
2269 @kbd{tar c -farchive.tar}
2270 @kbd{tar cf archive.tar}
2271 @kbd{tar f archive.tar --create}
2272 @kbd{tar f archive.tar -c}
2273 @kbd{tar fc archive.tar}
2274 @end smallexample
2275
2276 On the other hand, the following commands are @emph{not} equivalent to
2277 the previous set:
2278
2279 @smallexample
2280 @kbd{tar -f -c archive.tar}
2281 @kbd{tar -fc archive.tar}
2282 @kbd{tar -fcarchive.tar}
2283 @kbd{tar -farchive.tarc}
2284 @kbd{tar cfarchive.tar}
2285 @end smallexample
2286
2287 @noindent
2288 These last examples mean something completely different from what the
2289 user intended (judging based on the example in the previous set which
2290 uses long options, whose intent is therefore very clear).  The first
2291 four specify that the @command{tar} archive would be a file named
2292 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2293 respectively.  The first two examples also specify a single non-option,
2294 @var{name} argument having the value @samp{archive.tar}.  The last
2295 example contains only old style option letters (repeating option
2296 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2297 @samp{h}, or @samp{i}), with no argument value.
2298 @FIXME{not sure i liked
2299 the first sentence of this paragraph..}
2300
2301 @node All Options
2302 @section All @command{tar} Options
2303
2304 The coming manual sections contain an alphabetical listing of all
2305 @command{tar} operations and options, with brief descriptions and
2306 cross-references to more in-depth explanations in the body of the manual.
2307 They also contain an alphabetically arranged table of the short option
2308 forms with their corresponding long option.  You can use this table as
2309 a reference for deciphering @command{tar} commands in scripts.
2310
2311 @menu
2312 * Operation Summary::
2313 * Option Summary::
2314 * Short Option Summary::
2315 * Position-Sensitive Options::
2316 @end menu
2317
2318 @node Operation Summary
2319 @subsection Operations
2320
2321 @table @option
2322
2323 @opsummary{append}
2324 @item --append
2325 @itemx -r
2326
2327 Appends files to the end of the archive.  @xref{append}.
2328
2329 @opsummary{catenate}
2330 @item --catenate
2331 @itemx -A
2332
2333 Same as @option{--concatenate}.  @xref{concatenate}.
2334
2335 @opsummary{compare}
2336 @item --compare
2337 @itemx -d
2338
2339 Compares archive members with their counterparts in the file
2340 system, and reports differences in file size, mode, owner,
2341 modification date and contents.  @xref{compare}.
2342
2343 @opsummary{concatenate}
2344 @item --concatenate
2345 @itemx -A
2346
2347 Appends other @command{tar} archives to the end of the archive.
2348 @xref{concatenate}.
2349
2350 @opsummary{create}
2351 @item --create
2352 @itemx -c
2353
2354 Creates a new @command{tar} archive.  @xref{create}.
2355
2356 @opsummary{delete}
2357 @item --delete
2358
2359 Deletes members from the archive.  Don't try this on an archive on a
2360 tape!  @xref{delete}.
2361
2362 @opsummary{diff}
2363 @item --diff
2364 @itemx -d
2365
2366 Same @option{--compare}.  @xref{compare}.
2367
2368 @opsummary{extract}
2369 @item --extract
2370 @itemx -x
2371
2372 Extracts members from the archive into the file system.  @xref{extract}.
2373
2374 @opsummary{get}
2375 @item --get
2376 @itemx -x
2377
2378 Same as @option{--extract}.  @xref{extract}.
2379
2380 @opsummary{list}
2381 @item --list
2382 @itemx -t
2383
2384 Lists the members in an archive.  @xref{list}.
2385
2386 @opsummary{update}
2387 @item --update
2388 @itemx -u
2389
2390 Adds files to the end of the archive, but only if they are newer than
2391 their counterparts already in the archive, or if they do not already
2392 exist in the archive. @xref{update}.
2393
2394 @end table
2395
2396 @node Option Summary
2397 @subsection @command{tar} Options
2398
2399 @table @option
2400
2401 @opsummary{absolute-names}
2402 @item --absolute-names
2403 @itemx -P
2404
2405 Normally when creating an archive, @command{tar} strips an initial
2406 @samp{/} from member names, and when extracting from an archive @command{tar}
2407 treats names specially if they have initial @samp{/} or internal
2408 @samp{..}.  This option disables that behavior.  @xref{absolute}.
2409
2410 @opsummary{acls}
2411 @item --acls
2412 Enable POSIX ACLs support.  @xref{Extended File Attributes, acls}.
2413
2414 @opsummary{after-date}
2415 @item --after-date
2416
2417 (See @option{--newer}, @pxref{after})
2418
2419 @opsummary{anchored}
2420 @item --anchored
2421 A pattern must match an initial subsequence of the name's components.
2422 @xref{controlling pattern-matching}.
2423
2424 @opsummary{atime-preserve}
2425 @item --atime-preserve
2426 @itemx --atime-preserve=replace
2427 @itemx --atime-preserve=system
2428
2429 Attempt to preserve the access time of files when reading them.  This
2430 option currently is effective only on files that you own, unless you
2431 have superuser privileges.
2432
2433 @option{--atime-preserve=replace} remembers the access time of a file
2434 before reading it, and then restores the access time afterwards.  This
2435 may cause problems if other programs are reading the file at the same
2436 time, as the times of their accesses will be lost.  On most platforms
2437 restoring the access time also requires @command{tar} to restore the
2438 data modification time too, so this option may also cause problems if
2439 other programs are writing the file at the same time (@command{tar} attempts
2440 to detect this situation, but cannot do so reliably due to race
2441 conditions).  Worse, on most platforms restoring the access time also
2442 updates the status change time, which means that this option is
2443 incompatible with incremental backups.
2444
2445 @option{--atime-preserve=system} avoids changing time stamps on files,
2446 without interfering with time stamp updates
2447 caused by other programs, so it works better with incremental backups.
2448 However, it requires a special @code{O_NOATIME} option from the
2449 underlying operating and file system implementation, and it also requires
2450 that searching directories does not update their access times.  As of
2451 this writing (November 2005) this works only with Linux, and only with
2452 Linux kernels 2.6.8 and later.  Worse, there is currently no reliable
2453 way to know whether this feature actually works.  Sometimes
2454 @command{tar} knows that it does not work, and if you use
2455 @option{--atime-preserve=system} then @command{tar} complains and
2456 exits right away.  But other times @command{tar} might think that the
2457 option works when it actually does not.
2458
2459 Currently @option{--atime-preserve} with no operand defaults to
2460 @option{--atime-preserve=replace}, but this may change in the future
2461 as support for @option{--atime-preserve=system} improves.
2462
2463 If your operating or file system does not support
2464 @option{--atime-preserve=@-system}, you might be able to preserve access
2465 times reliably by using the @command{mount} command.  For example,
2466 you can mount the file system read-only, or access the file system via
2467 a read-only loopback mount, or use the @samp{noatime} mount option
2468 available on some systems.  However, mounting typically requires
2469 superuser privileges and can be a pain to manage.
2470
2471 @opsummary{auto-compress}
2472 @item --auto-compress
2473 @itemx -a
2474
2475 During a @option{--create} operation, enables automatic compressed
2476 format recognition based on the archive suffix.  The effect of this
2477 option is cancelled by @option{--no-auto-compress}.  @xref{gzip}.
2478
2479 @opsummary{backup}
2480 @item --backup=@var{backup-type}
2481
2482 Rather than deleting files from the file system, @command{tar} will
2483 back them up using simple or numbered backups, depending upon
2484 @var{backup-type}.  @xref{backup}.
2485
2486 @opsummary{block-number}
2487 @item --block-number
2488 @itemx -R
2489
2490 With this option present, @command{tar} prints error messages for read errors
2491 with the block number in the archive file.  @xref{block-number}.
2492
2493 @opsummary{blocking-factor}
2494 @item --blocking-factor=@var{blocking}
2495 @itemx -b @var{blocking}
2496
2497 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2498 record.  @xref{Blocking Factor}.
2499
2500 @opsummary{bzip2}
2501 @item --bzip2
2502 @itemx -j
2503
2504 This option tells @command{tar} to read or write archives through
2505 @code{bzip2}.  @xref{gzip}.
2506
2507 @opsummary{check-device}
2508 @item --check-device
2509 Check device numbers when creating a list of modified files for
2510 incremental archiving.  This is the default.  @xref{device numbers},
2511 for a detailed description.
2512
2513 @opsummary{checkpoint}
2514 @item --checkpoint[=@var{number}]
2515
2516 This option directs @command{tar} to print periodic checkpoint
2517 messages as it reads through the archive.  It is intended for when you
2518 want a visual indication that @command{tar} is still running, but
2519 don't want to see @option{--verbose} output.  You can also instruct
2520 @command{tar} to execute a list of actions on each checkpoint, see
2521 @option{--checkpoint-action} below.  For a detailed description, see
2522 @ref{checkpoints}.
2523
2524 @opsummary{checkpoint-action}
2525 @item --checkpoint-action=@var{action}
2526 Instruct @command{tar} to execute an action upon hitting a
2527 breakpoint.  Here we give only a brief outline.  @xref{checkpoints},
2528 for a complete description.
2529
2530 The @var{action} argument can be one of the following:
2531
2532 @table @asis
2533 @item bell
2534 Produce an audible bell on the console.
2535
2536 @item dot
2537 @itemx .
2538 Print a single dot on the standard listing stream.
2539
2540 @item echo
2541 Display a textual message on the standard error, with the status and
2542 number of the checkpoint.  This is the default.
2543
2544 @item echo=@var{string}
2545 Display @var{string} on the standard error.  Before output, the string
2546 is subject to meta-character expansion.
2547
2548 @item exec=@var{command}
2549 Execute the given @var{command}.
2550
2551 @item sleep=@var{time}
2552 Wait for @var{time} seconds.
2553
2554 @item ttyout=@var{string}
2555 Output @var{string} on the current console (@file{/dev/tty}).
2556 @end table
2557
2558 Several @option{--checkpoint-action} options can be specified.  The
2559 supplied actions will be executed in order of their appearance in the
2560 command line.
2561
2562 Using @option{--checkpoint-action} without @option{--checkpoint}
2563 assumes default checkpoint frequency of one checkpoint per 10 records.
2564
2565 @opsummary{check-links}
2566 @item --check-links
2567 @itemx -l
2568 If this option was given, @command{tar} will check the number of links
2569 dumped for each processed file.  If this number does not match the
2570 total number of hard links for the file, a warning message will be
2571 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2572 synonym for @option{--one-file-system}.  The current semantics, which
2573 complies to UNIX98, was introduced with version
2574 1.15.91. @xref{Changes}, for more information.}.
2575
2576 @xref{hard links}.
2577
2578 @opsummary{compress}
2579 @opsummary{uncompress}
2580 @item --compress
2581 @itemx --uncompress
2582 @itemx -Z
2583
2584 @command{tar} will use the @command{compress} program when reading or
2585 writing the archive.  This allows you to directly act on archives
2586 while saving space.  @xref{gzip}.
2587
2588 @opsummary{clamp-mtime}
2589 @item --clamp-mtime
2590
2591 (See @option{--mtime}.)
2592
2593 @opsummary{confirmation}
2594 @item --confirmation
2595
2596 (See @option{--interactive}.)  @xref{interactive}.
2597
2598 @opsummary{delay-directory-restore}
2599 @item --delay-directory-restore
2600
2601 Delay setting modification times and permissions of extracted
2602 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2603
2604 @opsummary{dereference}
2605 @item --dereference
2606 @itemx -h
2607
2608 When reading or writing a file to be archived, @command{tar} accesses
2609 the file that a symbolic link points to, rather than the symlink
2610 itself.  @xref{dereference}.
2611
2612 @opsummary{directory}
2613 @item --directory=@var{dir}
2614 @itemx -C @var{dir}
2615
2616 When this option is specified, @command{tar} will change its current directory
2617 to @var{dir} before performing any operations.  When this option is used
2618 during archive creation, it is order sensitive.  @xref{directory}.
2619
2620 @opsummary{exclude}
2621 @item --exclude=@var{pattern}
2622
2623 When performing operations, @command{tar} will skip files that match
2624 @var{pattern}.  @xref{exclude}.
2625
2626 @opsummary{exclude-backups}
2627 @item --exclude-backups
2628 Exclude backup and lock files.  @xref{exclude,, exclude-backups}.
2629
2630 @opsummary{exclude-from}
2631 @item --exclude-from=@var{file}
2632 @itemx -X @var{file}
2633
2634 Similar to @option{--exclude}, except @command{tar} will use the list of
2635 patterns in the file @var{file}.  @xref{exclude}.
2636
2637 @opsummary{exclude-caches}
2638 @item --exclude-caches
2639
2640 Exclude from dump any directory containing a valid cache directory
2641 tag file, but still dump the directory node and the tag file itself.
2642
2643 @xref{exclude,, exclude-caches}.
2644
2645 @opsummary{exclude-caches-under}
2646 @item --exclude-caches-under
2647
2648 Exclude from dump any directory containing a valid cache directory
2649 tag file, but still dump the directory node itself.
2650
2651 @xref{exclude}.
2652
2653 @opsummary{exclude-caches-all}
2654 @item --exclude-caches-all
2655
2656 Exclude from dump any directory containing a valid cache directory
2657 tag file.  @xref{exclude}.
2658
2659 @opsummary{exclude-ignore}
2660 @item --exclude-ignore=@var{file}
2661 Before dumping a directory, @command{tar} checks if it contains
2662 @var{file}.  If so, exclusion patterns are read from this file.
2663 The patterns affect only the directory itself.  @xref{exclude}.
2664
2665 @opsummary{exclude-ignore-recursive}
2666 @item --exclude-ignore-recursive=@var{file}
2667 Before dumping a directory, @command{tar} checks if it contains
2668 @var{file}.  If so, exclusion patterns are read from this file.
2669 The patterns affect the directory and all itssubdirectories.
2670 @xref{exclude}.
2671
2672 @opsummary{exclude-tag}
2673 @item --exclude-tag=@var{file}
2674
2675 Exclude from dump any directory containing file named @var{file}, but
2676 dump the directory node and @var{file} itself.  @xref{exclude,, exclude-tag}.
2677
2678 @opsummary{exclude-tag-under}
2679 @item --exclude-tag-under=@var{file}
2680
2681 Exclude from dump the contents of any directory containing file
2682 named @var{file}, but dump the directory node itself.  @xref{exclude,,
2683 exclude-tag-under}.
2684
2685 @opsummary{exclude-tag-all}
2686 @item --exclude-tag-all=@var{file}
2687
2688 Exclude from dump any directory containing file named @var{file}.
2689 @xref{exclude,,exclude-tag-all}.
2690
2691 @opsummary{exclude-vcs}
2692 @item --exclude-vcs
2693
2694 Exclude from dump directories and files, that are internal for some
2695 widely used version control systems.
2696
2697 @xref{exclude-vcs}.
2698
2699 @opsummary{exclude-vcs-ignores}
2700 @item --exclude-vcs-ignores
2701 Exclude files that match patterns read from VCS-specific ignore
2702 files.  Supported files are: @file{.cvsignore}, @file{.gitignore},
2703 @file{.bzrignore}, and @file{.hgignore}.  The semantics of each file
2704 is the same as for the corresponding VCS, e.g. patterns read from
2705 @file{.gitignore} affect the directory and all its subdirectories.
2706 @xref{exclude-vcs-ignores}.
2707
2708 @opsummary{file}
2709 @item --file=@var{archive}
2710 @itemx -f @var{archive}
2711
2712 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2713 performs operations on, rather than @command{tar}'s compilation dependent
2714 default.  @xref{file tutorial}.
2715
2716 @opsummary{files-from}
2717 @item --files-from=@var{file}
2718 @itemx -T @var{file}
2719
2720 @command{tar} will use the contents of @var{file} as a list of archive members
2721 or files to operate on, in addition to those specified on the
2722 command-line.  @xref{files}.
2723
2724 @opsummary{force-local}
2725 @item --force-local
2726
2727 Forces @command{tar} to interpret the file name given to @option{--file}
2728 as a local file, even if it looks like a remote tape drive name.
2729 @xref{local and remote archives}.
2730
2731 @opsummary{format}
2732 @item --format=@var{format}
2733 @itemx -H @var{format}
2734
2735 Selects output archive format.  @var{Format} may be one of the
2736 following:
2737
2738 @table @samp
2739 @item v7
2740 Creates an archive that is compatible with Unix V7 @command{tar}.
2741
2742 @item oldgnu
2743 Creates an archive that is compatible with GNU @command{tar} version
2744 1.12 or earlier.
2745
2746 @item gnu
2747 Creates archive in GNU tar 1.13 format.  Basically it is the same as
2748 @samp{oldgnu} with the only difference in the way it handles long
2749 numeric fields.
2750
2751 @item ustar
2752 Creates a @acronym{POSIX.1-1988} compatible archive.
2753
2754 @item posix
2755 Creates a @acronym{POSIX.1-2001 archive}.
2756
2757 @end table
2758
2759 @xref{Formats}, for a detailed discussion of these formats.
2760
2761 @opsummary{full-time}
2762 @item --full-time
2763 This option instructs @command{tar} to print file times to their full
2764 resolution.  Usually this means 1-second resolution, but that depends
2765 on the underlying file system.  The @option{--full-time} option takes
2766 effect only when detailed output (verbosity level 2 or higher) has
2767 been requested using the @option{--verbose} option, e.g., when listing
2768 or extracting archives:
2769
2770 @smallexample
2771 $ @kbd{tar -t -v --full-time -f archive.tar}
2772 @end smallexample
2773
2774 @noindent
2775 or, when creating an archive:
2776
2777 @smallexample
2778 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2779 @end smallexample
2780
2781 Notice, thar when creating the archive you need to specify
2782 @option{--verbose} twice to get a detailed output (@pxref{verbose
2783 tutorial}).
2784
2785 @opsummary{group}
2786 @item --group=@var{group}
2787
2788 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2789 rather than the group from the source file.  @var{group} can specify a
2790 symbolic name, or a numeric @acronym{ID}, or both as
2791 @var{name}:@var{id}.  @xref{override}.
2792
2793 Also see the @option{--group-map} option and comments for the
2794 @option{--owner=@var{user}} option.
2795
2796 @opsummary{group-map}
2797 @item --group-map=@var{file}
2798
2799 Read owner group translation map from @var{file}.  This option allows to
2800 translate only certain group names and/or UIDs.  @xref{override}, for a
2801 detailed description.  When used together with @option{--group}
2802 option, the latter affects only those files whose owner group is not listed
2803 in the @var{file}.
2804
2805 This option does not affect extraction from archives.
2806
2807 @opsummary{gzip}
2808 @opsummary{gunzip}
2809 @opsummary{ungzip}
2810 @item --gzip
2811 @itemx --gunzip
2812 @itemx --ungzip
2813 @itemx -z
2814
2815 This option tells @command{tar} to read or write archives through
2816 @command{gzip}, allowing @command{tar} to directly operate on several
2817 kinds of compressed archives transparently.  @xref{gzip}.
2818
2819 @opsummary{hard-dereference}
2820 @item --hard-dereference
2821 When creating an archive, dereference hard links and store the files
2822 they refer to, instead of creating usual hard link members.
2823
2824 @xref{hard links}.
2825
2826 @opsummary{help}
2827 @item --help
2828 @itemx -?
2829
2830 @command{tar} will print out a short message summarizing the operations and
2831 options to @command{tar} and exit. @xref{help}.
2832
2833 @opsummary{hole-detection}
2834 @item --hole-detection=@var{method}
2835 Use @var{method} to detect holes in sparse files.  This option implies
2836 @option{--sparse}.  Valid methods are @samp{seek} and @samp{raw}.
2837 Default is @samp{seek} with fallback to @samp{raw} when not
2838 applicable. @xref{sparse}.
2839
2840 @opsummary{ignore-case}
2841 @item --ignore-case
2842 Ignore case when matching member or file names with
2843 patterns. @xref{controlling pattern-matching}.
2844
2845 @opsummary{ignore-command-error}
2846 @item --ignore-command-error
2847 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2848
2849 @opsummary{ignore-failed-read}
2850 @item --ignore-failed-read
2851
2852 Do not exit unsuccessfully merely because an unreadable file was encountered.
2853 @xref{Ignore Failed Read}.
2854
2855 @opsummary{ignore-zeros}
2856 @item --ignore-zeros
2857 @itemx -i
2858
2859 With this option, @command{tar} will ignore zeroed blocks in the
2860 archive, which normally signals EOF.  @xref{Reading}.
2861
2862 @opsummary{incremental}
2863 @item --incremental
2864 @itemx -G
2865
2866 Informs @command{tar} that it is working with an old
2867 @acronym{GNU}-format incremental backup archive.  It is intended
2868 primarily for backwards compatibility only.  @xref{Incremental Dumps},
2869 for a detailed discussion of incremental archives.
2870
2871 @opsummary{index-file}
2872 @item --index-file=@var{file}
2873
2874 Send verbose output to @var{file} instead of to standard output.
2875
2876 @opsummary{info-script}
2877 @opsummary{new-volume-script}
2878 @item --info-script=@var{command}
2879 @itemx --new-volume-script=@var{command}
2880 @itemx -F @var{command}
2881
2882 When @command{tar} is performing multi-tape backups, @var{command} is run
2883 at the end of each tape.  If it exits with nonzero status,
2884 @command{tar} fails immediately.  @xref{info-script}, for a detailed
2885 discussion of this feature.
2886
2887 @opsummary{interactive}
2888 @item --interactive
2889 @itemx --confirmation
2890 @itemx -w
2891
2892 Specifies that @command{tar} should ask the user for confirmation before
2893 performing potentially destructive options, such as overwriting files.
2894 @xref{interactive}.
2895
2896 @opsummary{keep-directory-symlink}
2897 @item --keep-directory-symlink
2898
2899 This option changes the behavior of tar when it encounters a symlink
2900 with the same name as the directory that it is about to extract.  By
2901 default, in this case tar would first remove the symlink and then
2902 proceed extracting the directory.
2903
2904 The @option{--keep-directory-symlink} option disables this behavior
2905 and instructs tar to follow symlinks to directories when extracting
2906 from the archive.
2907
2908 It is mainly intended to provide compatibility with the Slackware
2909 installation scripts.
2910
2911 @opsummary{keep-newer-files}
2912 @item --keep-newer-files
2913
2914 Do not replace existing files that are newer than their archive copies
2915 when extracting files from an archive.
2916
2917 @opsummary{keep-old-files}
2918 @item --keep-old-files
2919 @itemx -k
2920
2921 Do not overwrite existing files when extracting files from an
2922 archive.  Return error if such files exist.  See also
2923 @ref{--skip-old-files}.
2924
2925 @xref{Keep Old Files}.
2926
2927 @opsummary{label}
2928 @item --label=@var{name}
2929 @itemx -V @var{name}
2930
2931 When creating an archive, instructs @command{tar} to write @var{name}
2932 as a name record in the archive.  When extracting or listing archives,
2933 @command{tar} will only operate on archives that have a label matching
2934 the pattern specified in @var{name}.  @xref{Tape Files}.
2935
2936 @opsummary{level}
2937 @item --level=@var{n}
2938 Force incremental backup of level @var{n}.  As of @GNUTAR version
2939 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2940 file, thereby forcing the level 0 dump.  Other values of @var{n} are
2941 effectively ignored.  @xref{--level=0}, for details and examples.
2942
2943 The use of this option is valid only in conjunction with the
2944 @option{--listed-incremental} option.  @xref{Incremental Dumps},
2945 for a detailed description.
2946
2947 @opsummary{listed-incremental}
2948 @item --listed-incremental=@var{snapshot-file}
2949 @itemx -g @var{snapshot-file}
2950
2951 During a @option{--create} operation, specifies that the archive that
2952 @command{tar} creates is a new @acronym{GNU}-format incremental
2953 backup, using @var{snapshot-file} to determine which files to backup.
2954 With other operations, informs @command{tar} that the archive is in
2955 incremental format.  @xref{Incremental Dumps}.
2956
2957 @opsummary{lzip}
2958 @item --lzip
2959
2960 This option tells @command{tar} to read or write archives through
2961 @command{lzip}.  @xref{gzip}.
2962
2963 @opsummary{lzma}
2964 @item --lzma
2965
2966 This option tells @command{tar} to read or write archives through
2967 @command{lzma}.  @xref{gzip}.
2968
2969 @item --lzop
2970
2971 This option tells @command{tar} to read or write archives through
2972 @command{lzop}.  @xref{gzip}.
2973
2974 @opsummary{mode}
2975 @item --mode=@var{permissions}
2976
2977 When adding files to an archive, @command{tar} will use
2978 @var{permissions} for the archive members, rather than the permissions
2979 from the files.  @var{permissions} can be specified either as an octal
2980 number or as symbolic permissions, like with
2981 @command{chmod}. @xref{override}.
2982
2983 @opsummary{mtime}
2984 @item --mtime=@var{date}
2985
2986 When adding files to an archive, @command{tar} will use @var{date} as
2987 the modification time of members when creating archives, instead of
2988 their actual modification times.  The value of @var{date} can be
2989 either a textual date representation (@pxref{Date input formats}) or a
2990 name of the existing file, starting with @samp{/} or @samp{.}.  In the
2991 latter case, the modification time of that file is used. @xref{override}.
2992
2993 When @command{--clamp-mtime} is also specified, files with
2994 modification times earlier than @var{date} will retain their actual
2995 modification times, and @var{date} will only be used for files whose
2996 modification times are later than @var{date}.
2997
2998 @opsummary{multi-volume}
2999 @item --multi-volume
3000 @itemx -M
3001
3002 Informs @command{tar} that it should create or otherwise operate on a
3003 multi-volume @command{tar} archive.  @xref{Using Multiple Tapes}.
3004
3005 @opsummary{new-volume-script}
3006 @item --new-volume-script
3007
3008 (see @option{--info-script})
3009
3010 @opsummary{newer}
3011 @item --newer=@var{date}
3012 @itemx --after-date=@var{date}
3013 @itemx -N
3014
3015 When creating an archive, @command{tar} will only add files that have changed
3016 since @var{date}.  If @var{date} begins with @samp{/} or @samp{.}, it
3017 is taken to be the name of a file whose data modification time specifies
3018 the date.  @xref{after}.
3019
3020 @opsummary{newer-mtime}
3021 @item --newer-mtime=@var{date}
3022
3023 Like @option{--newer}, but add only files whose
3024 contents have changed (as opposed to just @option{--newer}, which will
3025 also back up files for which any status information has
3026 changed).  @xref{after}.
3027
3028 @opsummary{no-acls}
3029 @item --no-acls
3030 Disable the POSIX ACLs support.  @xref{Extended File Attributes, acls}.
3031
3032 @opsummary{no-anchored}
3033 @item --no-anchored
3034 An exclude pattern can match any subsequence of the name's components.
3035 @xref{controlling pattern-matching}.
3036
3037 @opsummary{no-auto-compress}
3038 @item --no-auto-compress
3039
3040 Disables automatic compressed format recognition based on the archive
3041 suffix.  @xref{--auto-compress}.  @xref{gzip}.
3042
3043 @opsummary{no-check-device}
3044 @item --no-check-device
3045 Do not check device numbers when creating a list of modified files
3046 for incremental archiving.  @xref{device numbers}, for
3047 a detailed description.
3048
3049 @opsummary{no-delay-directory-restore}
3050 @item --no-delay-directory-restore
3051
3052 Modification times and permissions of extracted
3053 directories are set when all files from this directory have been
3054 extracted.  This is the default.
3055 @xref{Directory Modification Times and Permissions}.
3056
3057 @opsummary{no-ignore-case}
3058 @item --no-ignore-case
3059 Use case-sensitive matching.
3060 @xref{controlling pattern-matching}.
3061
3062 @opsummary{no-ignore-command-error}
3063 @item --no-ignore-command-error
3064 Print warnings about subprocesses that terminated with a nonzero exit
3065 code. @xref{Writing to an External Program}.
3066
3067 @opsummary{no-null}
3068 @item --no-null
3069
3070 If the @option{--null} option was given previously, this option
3071 cancels its effect, so that any following @option{--files-from}
3072 options will expect their file lists to be newline-terminated.
3073
3074 @opsummary{no-overwrite-dir}
3075 @item --no-overwrite-dir
3076
3077 Preserve metadata of existing directories when extracting files
3078 from an archive.  @xref{Overwrite Old Files}.
3079
3080 @opsummary{no-quote-chars}
3081 @item --no-quote-chars=@var{string}
3082 Remove characters listed in @var{string} from the list of quoted
3083 characters set by the previous @option{--quote-chars} option
3084 (@pxref{quoting styles}).
3085
3086 @opsummary{no-recursion}
3087 @item --no-recursion
3088
3089 With this option, @command{tar} will not recurse into directories.
3090 @xref{recurse}.
3091
3092 @opsummary{no-same-owner}
3093 @item --no-same-owner
3094 @itemx -o
3095
3096 When extracting an archive, do not attempt to preserve the owner
3097 specified in the @command{tar} archive.  This the default behavior
3098 for ordinary users.
3099
3100 @opsummary{no-same-permissions}
3101 @item --no-same-permissions
3102
3103 When extracting an archive, subtract the user's umask from files from
3104 the permissions specified in the archive.  This is the default behavior
3105 for ordinary users.
3106
3107 @opsummary{no-seek}
3108 @item --no-seek
3109
3110 The archive media does not support seeks to arbitrary
3111 locations.  Usually @command{tar} determines automatically whether
3112 the archive can be seeked or not.  Use this option to disable this
3113 mechanism.
3114
3115 @opsummary{no-selinux}
3116 @item --no-selinux
3117 Disable SELinux context support.  @xref{Extended File Attributes, SELinux}.
3118
3119 @opsummary{no-unquote}
3120 @item --no-unquote
3121 Treat all input file or member names literally, do not interpret
3122 escape sequences.  @xref{input name quoting}.
3123
3124 @opsummary{no-verbatim-files-from}
3125 @item --no-verbatim-files-from
3126
3127 Instructs @GNUTAR{} to treat each line read from a file list as if it
3128 were supplied in the command line.  I.e., leading and trailing
3129 whitespace is removed and, if the result begins with a dash, it is
3130 treated as a @GNUTAR{} command line option.
3131
3132 This is default behavior.  This option is provided as a way to restore
3133 it after @option{--verbatim-files-from} option.
3134
3135 It is implied by the @option{--no-null} option.
3136
3137 @xref{no-verbatim-files-from}.
3138
3139 @opsummary{no-wildcards}
3140 @item --no-wildcards
3141 Do not use wildcards.
3142 @xref{controlling pattern-matching}.
3143
3144 @opsummary{no-wildcards-match-slash}
3145 @item --no-wildcards-match-slash
3146 Wildcards do not match @samp{/}.
3147 @xref{controlling pattern-matching}.
3148
3149 @opsummary{no-xattrs}
3150 @item --no-xattrs
3151 Disable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3152
3153 @opsummary{null}
3154 @item --null
3155
3156 When @command{tar} is using the @option{--files-from} option, this option
3157 instructs @command{tar} to expect file names terminated with
3158 @acronym{NUL}, and to process file names verbatim.  
3159
3160 This means that @command{tar} correctly works with file names that
3161 contain newlines or begin with a dash.
3162
3163 @xref{nul}.
3164
3165 See also @ref{verbatim-files-from}.
3166
3167 @opsummary{numeric-owner}
3168 @item --numeric-owner
3169
3170 This option will notify @command{tar} that it should use numeric user
3171 and group IDs when creating a @command{tar} file, rather than names.
3172 @xref{Attributes}.
3173
3174 @item -o
3175 The function of this option depends on the action @command{tar} is
3176 performing.  When extracting files, @option{-o} is a synonym for
3177 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3178 restoring ownership of files being extracted.
3179
3180 When creating an archive, it is a synonym for
3181 @option{--old-archive}.  This behavior is for compatibility
3182 with previous versions of @GNUTAR{}, and will be
3183 removed in future releases.
3184
3185 @xref{Changes}, for more information.
3186
3187 @opsummary{occurrence}
3188 @item --occurrence[=@var{number}]
3189
3190 This option can be used in conjunction with one of the subcommands
3191 @option{--delete}, @option{--diff}, @option{--extract} or
3192 @option{--list} when a list of files is given either on the command
3193 line or via @option{-T} option.
3194
3195 This option instructs @command{tar} to process only the @var{number}th
3196 occurrence of each named file.  @var{Number} defaults to 1, so
3197
3198 @smallexample
3199 tar -x -f archive.tar --occurrence filename
3200 @end smallexample
3201
3202 @noindent
3203 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3204 and will terminate without scanning to the end of the archive.
3205
3206 @opsummary{old-archive}
3207 @item --old-archive
3208 Synonym for @option{--format=v7}.
3209
3210 @opsummary{one-file-system}
3211 @item --one-file-system
3212 Used when creating an archive.  Prevents @command{tar} from recursing into
3213 directories that are on different file systems from the current
3214 directory.
3215
3216 @opsummary{one-top-level}
3217 @item --one-top-level[=@var{dir}]
3218 Tells @command{tar} to create a new directory beneath the extraction directory
3219 (or the one passed to @option{-C}) and use it to guard against
3220 tarbombs.  In the absence of @var{dir} argument, the name of the new directory
3221 will be equal to the base name of the archive (file name minus the
3222 archive suffix, if recognized).  Any member names that do not begin
3223 with that directory name (after
3224 transformations from @option{--transform} and
3225 @option{--strip-components}) will be prefixed with it.  Recognized
3226 file name suffixes are @samp{.tar}, and any compression suffixes
3227 recognizable by @xref{--auto-compress}.
3228
3229 @opsummary{overwrite}
3230 @item --overwrite
3231
3232 Overwrite existing files and directory metadata when extracting files
3233 from an archive.  @xref{Overwrite Old Files}.
3234
3235 @opsummary{overwrite-dir}
3236 @item --overwrite-dir
3237
3238 Overwrite the metadata of existing directories when extracting files
3239 from an archive.  @xref{Overwrite Old Files}.
3240
3241 @opsummary{owner}
3242 @item --owner=@var{user}
3243
3244 Specifies that @command{tar} should use @var{user} as the owner of members
3245 when creating archives, instead of the user associated with the source
3246 file.  @var{user} can specify a symbolic name, or a numeric
3247 @acronym{ID}, or both as @var{name}:@var{id}.
3248 @xref{override}.
3249
3250 This option does not affect extraction from archives.  See also
3251 @option{--owner-map}, below.
3252
3253 @opsummary{owner-map}
3254 @item --owner-map=@var{file}
3255
3256 Read owner translation map from @var{file}.  This option allows to
3257 translate only certain owner names or UIDs.  @xref{override}, for a
3258 detailed description.  When used together with @option{--owner}
3259 option, the latter affects only those files whose owner is not listed
3260 in the @var{file}.
3261
3262 This option does not affect extraction from archives.
3263
3264 @opsummary{pax-option}
3265 @item --pax-option=@var{keyword-list}
3266 This option enables creation of the archive in @acronym{POSIX.1-2001}
3267 format (@pxref{posix}) and modifies the way @command{tar} handles the
3268 extended header keywords.  @var{Keyword-list} is a comma-separated
3269 list of keyword options.  @xref{PAX keywords}, for a detailed
3270 discussion.
3271
3272 @opsummary{portability}
3273 @item --portability
3274 @itemx --old-archive
3275 Synonym for @option{--format=v7}.
3276
3277 @opsummary{posix}
3278 @item --posix
3279 Same as @option{--format=posix}.
3280
3281 @opsummary{preserve-order}
3282 @item --preserve-order
3283
3284 (See @option{--same-order}; @pxref{Reading}.)
3285
3286 @opsummary{preserve-permissions}
3287 @opsummary{same-permissions}
3288 @item --preserve-permissions
3289 @itemx --same-permissions
3290 @itemx -p
3291
3292 When @command{tar} is extracting an archive, it normally subtracts the
3293 users' umask from the permissions specified in the archive and uses
3294 that number as the permissions to create the destination file.
3295 Specifying this option instructs @command{tar} that it should use the
3296 permissions directly from the archive.  @xref{Setting Access Permissions}.
3297
3298 @opsummary{quote-chars}
3299 @item --quote-chars=@var{string}
3300 Always quote characters from @var{string}, even if the selected
3301 quoting style would not quote them (@pxref{quoting styles}).
3302
3303 @opsummary{quoting-style}
3304 @item --quoting-style=@var{style}
3305 Set quoting style to use when printing member and file names
3306 (@pxref{quoting styles}). Valid @var{style} values are:
3307 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3308 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3309 style is @code{escape}, unless overridden while configuring the
3310 package.
3311
3312 @opsummary{read-full-records}
3313 @item --read-full-records
3314 @itemx -B
3315
3316 Specifies that @command{tar} should reblock its input, for reading
3317 from pipes on systems with buggy implementations.  @xref{Reading}.
3318
3319 @opsummary{record-size}
3320 @item --record-size=@var{size}[@var{suf}]
3321
3322 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3323 archive.  The argument can be suffixed with a @dfn{size suffix}, e.g.
3324 @option{--record-size=10K} for 10 Kilobytes.  @xref{size-suffixes},
3325 for a list of valid suffixes.   @xref{Blocking Factor}, for a detailed
3326 description of this option.
3327
3328 @opsummary{recursion}
3329 @item --recursion
3330
3331 With this option, @command{tar} recurses into directories (default).
3332 @xref{recurse}.
3333
3334 @opsummary{recursive-unlink}
3335 @item --recursive-unlink
3336
3337 Remove existing
3338 directory hierarchies before extracting directories of the same name
3339 from the archive.  @xref{Recursive Unlink}.
3340
3341 @opsummary{remove-files}
3342 @item --remove-files
3343
3344 Directs @command{tar} to remove the source file from the file system after
3345 appending it to an archive.  @xref{remove files}.
3346
3347 @opsummary{restrict}
3348 @item --restrict
3349
3350 Disable use of some potentially harmful @command{tar} options.
3351 Currently this option disables shell invocation from multi-volume menu
3352 (@pxref{Using Multiple Tapes}).
3353
3354 @opsummary{rmt-command}
3355 @item --rmt-command=@var{cmd}
3356
3357 Notifies @command{tar} that it should use @var{cmd} instead of
3358 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3359
3360 @opsummary{rsh-command}
3361 @item --rsh-command=@var{cmd}
3362
3363 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3364 devices.  @xref{Device}.
3365
3366 @opsummary{same-order}
3367 @item --same-order
3368 @itemx --preserve-order
3369 @itemx -s
3370
3371 This option is an optimization for @command{tar} when running on machines with
3372 small amounts of memory.  It informs @command{tar} that the list of file
3373 arguments has already been sorted to match the order of files in the
3374 archive.  @xref{Reading}.
3375
3376 @opsummary{same-owner}
3377 @item --same-owner
3378
3379 When extracting an archive, @command{tar} will attempt to preserve the owner
3380 specified in the @command{tar} archive with this option present.
3381 This is the default behavior for the superuser; this option has an
3382 effect only for ordinary users.  @xref{Attributes}.
3383
3384 @opsummary{same-permissions}
3385 @item --same-permissions
3386
3387 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3388
3389 @opsummary{seek}
3390 @item --seek
3391 @itemx -n
3392
3393 Assume that the archive media supports seeks to arbitrary
3394 locations.  Usually @command{tar} determines automatically whether
3395 the archive can be seeked or not.  This option is intended for use
3396 in cases when such recognition fails.  It takes effect only if the
3397 archive is open for reading (e.g. with @option{--list} or
3398 @option{--extract} options).
3399
3400 @opsummary{selinux}
3401 @item --selinux
3402 Enable the SELinux context support.
3403 @xref{Extended File Attributes, selinux}.
3404
3405 @opsummary{show-defaults}
3406 @item --show-defaults
3407
3408 Displays the default options used by @command{tar} and exits
3409 successfully.  This option is intended for use in shell scripts.
3410 Here is an example of what you can see using this option:
3411
3412 @smallexample
3413 $ @kbd{tar --show-defaults}
3414 --format=gnu -f- -b20 --quoting-style=escape
3415 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3416 @end smallexample
3417
3418 @noindent
3419 Notice, that this option outputs only one line.  The example output
3420 above has been split to fit page boundaries. @xref{defaults}.
3421
3422 @opsummary{show-omitted-dirs}
3423 @item --show-omitted-dirs
3424
3425 Instructs @command{tar} to mention the directories it is skipping when
3426 operating on a @command{tar} archive.  @xref{show-omitted-dirs}.
3427
3428 @opsummary{show-snapshot-field-ranges}
3429 @item --show-snapshot-field-ranges
3430
3431 Displays the range of values allowed by this version of @command{tar}
3432 for each field in the snapshot file, then exits successfully.
3433 @xref{Snapshot Files}.
3434
3435 @opsummary{show-transformed-names}
3436 @opsummary{show-stored-names}
3437 @item --show-transformed-names
3438 @itemx --show-stored-names
3439
3440 Display file or member names after applying any transformations
3441 (@pxref{transform}).  In particular, when used in conjunction with one of
3442 the archive creation operations it instructs @command{tar} to list the
3443 member names stored in the archive, as opposed to the actual file
3444 names.  @xref{listing member and file names}.
3445
3446 @opsummary{skip-old-files}
3447 @item --skip-old-files
3448
3449 Do not overwrite existing files when extracting files from an
3450 archive.  @xref{Keep Old Files}.
3451
3452 This option differs from @option{--keep-old-files} in that it does not
3453 treat such files as an error, instead it just silently avoids
3454 overwriting them.
3455
3456 The @option{--warning=existing-file} option can be used together with
3457 this option to produce warning messages about existing old files
3458 (@pxref{warnings}).
3459
3460 @opsummary{sort}
3461 @item --sort=@var{order}
3462 Specify the directory sorting order when reading directories.
3463 @var{Order} may be one of the following:
3464
3465 @table @samp
3466 @item none
3467 No directory sorting is performed. This is the default.
3468
3469 @item name
3470 Sort the directory entries on name. The operating system may deliver
3471 directory entries in a more or less random order, and sorting them
3472 makes archive creation reproducible.
3473
3474 @item inode
3475 Sort the directory entries on inode number. Sorting directories on
3476 inode number may reduce the amount of disk seek operations when
3477 creating an archive for some file systems.
3478
3479 @end table
3480
3481 @opsummary{sparse}
3482 @item --sparse
3483 @itemx -S
3484
3485 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3486 sparse files efficiently.  @xref{sparse}.
3487
3488 @opsummary{sparse-version}
3489 @item --sparse-version=@var{version}
3490
3491 Specifies the @dfn{format version} to use when archiving sparse
3492 files.  Implies @option{--sparse}.  @xref{sparse}. For the description
3493 of the supported sparse formats, @xref{Sparse Formats}.
3494
3495 @opsummary{starting-file}
3496 @item --starting-file=@var{name}
3497 @itemx -K @var{name}
3498
3499 This option affects extraction only; @command{tar} will skip extracting
3500 files in the archive until it finds one that matches @var{name}.
3501 @xref{Scarce}.
3502
3503 @opsummary{strip-components}
3504 @item --strip-components=@var{number}
3505 Strip given @var{number} of leading components from file names before
3506 extraction.  For example, if archive @file{archive.tar} contained
3507 @file{/some/file/name}, then running
3508
3509 @smallexample
3510 tar --extract --file archive.tar --strip-components=2
3511 @end smallexample
3512
3513 @noindent
3514 would extract this file to file @file{name}.
3515
3516 @xref{transform}.
3517
3518 @opsummary{suffix}
3519 @item --suffix=@var{suffix}
3520
3521 Alters the suffix @command{tar} uses when backing up files from the default
3522 @samp{~}.  @xref{backup}.
3523
3524 @opsummary{tape-length}
3525 @item --tape-length=@var{num}[@var{suf}]
3526 @itemx -L @var{num}[@var{suf}]
3527
3528 Specifies the length of tapes that @command{tar} is writing as being
3529 @w{@var{num} x 1024} bytes long.  If optional @var{suf} is given, it
3530 specifies a multiplicative factor to be used instead of 1024.  For
3531 example, @samp{-L2M} means 2 megabytes.  @xref{size-suffixes}, for a
3532 list of allowed suffixes.  @xref{Using Multiple Tapes}, for a detailed
3533 discussion of this option.
3534
3535 @opsummary{test-label}
3536 @item --test-label
3537
3538 Reads the volume label.  If an argument is specified, test whether it
3539 matches the volume label.  @xref{--test-label option}.
3540
3541 @opsummary{to-command}
3542 @item --to-command=@var{command}
3543
3544 During extraction @command{tar} will pipe extracted files to the
3545 standard input of @var{command}.  @xref{Writing to an External Program}.
3546
3547 @opsummary{to-stdout}
3548 @item --to-stdout
3549 @itemx -O
3550
3551 During extraction, @command{tar} will extract files to stdout rather
3552 than to the file system.  @xref{Writing to Standard Output}.
3553
3554 @opsummary{totals}
3555 @item --totals[=@var{signo}]
3556
3557 Displays the total number of bytes transferred when processing an
3558 archive.  If an argument is given, these data are displayed on
3559 request, when signal @var{signo} is delivered to @command{tar}.
3560 @xref{totals}.
3561
3562 @opsummary{touch}
3563 @item --touch
3564 @itemx -m
3565
3566 Sets the data modification time of extracted files to the extraction time,
3567 rather than the data modification time stored in the archive.
3568 @xref{Data Modification Times}.
3569
3570 @opsummary{transform}
3571 @opsummary{xform}
3572 @item --transform=@var{sed-expr}
3573 @itemx --xform=@var{sed-expr}
3574 Transform file or member names using @command{sed} replacement expression
3575 @var{sed-expr}.  For example,
3576
3577 @smallexample
3578 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3579 @end smallexample
3580
3581 @noindent
3582 will add to @file{archive} files from the current working directory,
3583 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3584 discussion, @xref{transform}.
3585
3586 To see transformed member names in verbose listings, use
3587 @option{--show-transformed-names} option
3588 (@pxref{show-transformed-names}).
3589
3590 @opsummary{uncompress}
3591 @item --uncompress
3592
3593 (See @option{--compress}, @pxref{gzip})
3594
3595 @opsummary{ungzip}
3596 @item --ungzip
3597
3598 (See @option{--gzip}, @pxref{gzip})
3599
3600 @opsummary{unlink-first}
3601 @item --unlink-first
3602 @itemx -U
3603
3604 Directs @command{tar} to remove the corresponding file from the file
3605 system before extracting it from the archive.  @xref{Unlink First}.
3606
3607 @opsummary{unquote}
3608 @item --unquote
3609 Enable unquoting input file or member names (default).  @xref{input
3610 name quoting}.
3611
3612 @opsummary{use-compress-program}
3613 @item --use-compress-program=@var{prog}
3614 @itemx -I=@var{prog}
3615
3616 Instructs @command{tar} to access the archive through @var{prog}, which is
3617 presumed to be a compression program of some sort.  @xref{gzip}.
3618
3619 @opsummary{utc}
3620 @item --utc
3621
3622 Display file modification dates in @acronym{UTC}.  This option implies
3623 @option{--verbose}.
3624
3625 @opsummary{verbatim-files-from}
3626 @item --verbatim-files-from
3627
3628 Instructs @GNUTAR{} to treat each line read from a file list as a file
3629 name, even if it starts with a dash.
3630
3631 File lists are supplied with the @option{--files-from} (@option{-T})
3632 option.  By default, each line read from a file list is first trimmed
3633 off the leading and trailing whitespace and, if the result begins with
3634 a dash, it is treated as a @GNUTAR{} command line option.
3635
3636 Use the @option{--verbatim-files-from} option to disable this special
3637 handling.  This facilitates the use of @command{tar} with file lists
3638 created by @command{file} command.
3639
3640 This option affects all @option{--files-from} options that occur after
3641 it in the command line.  Its effect is reverted by the
3642 @option{--no-verbatim-files-from} option.
3643
3644 This option is implied by the @option{--null} option.
3645
3646 @xref{verbatim-files-from}.
3647
3648 @opsummary{verbose}
3649 @item --verbose
3650 @itemx -v
3651
3652 Specifies that @command{tar} should be more verbose about the
3653 operations it is performing.  This option can be specified multiple
3654 times for some operations to increase the amount of information displayed.
3655 @xref{verbose}.
3656
3657 @opsummary{verify}
3658 @item --verify
3659 @itemx -W
3660
3661 Verifies that the archive was correctly written when creating an
3662 archive.  @xref{verify}.
3663
3664 @opsummary{version}
3665 @item --version
3666
3667 Print information about the program's name, version, origin and legal
3668 status, all on standard output, and then exit successfully.
3669 @xref{help}.
3670
3671 @opsummary{volno-file}
3672 @item --volno-file=@var{file}
3673
3674 Used in conjunction with @option{--multi-volume}.  @command{tar} will
3675 keep track of which volume of a multi-volume archive it is working in
3676 @var{file}.  @xref{volno-file}.
3677
3678 @opsummary{warning}
3679 @item --warning=@var{keyword}
3680
3681 Enable or disable warning messages identified by @var{keyword}.  The
3682 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3683 @xref{warnings}.
3684
3685 @opsummary{wildcards}
3686 @item --wildcards
3687 Use wildcards when matching member names with patterns.
3688 @xref{controlling pattern-matching}.
3689
3690 @opsummary{wildcards-match-slash}
3691 @item --wildcards-match-slash
3692 Wildcards match @samp{/}.
3693 @xref{controlling pattern-matching}.
3694
3695 @opsummary{xattrs}
3696 @item --xattrs
3697 Enable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3698
3699 @opsummary{xattrs-exclude}
3700 @item --xattrs-exclude=@var{pattern}
3701 Specify exclude pattern for xattr keys.
3702 @xref{Extended File Attributes, xattrs-exclude}.
3703
3704 @opsummary{xattrs-include}
3705 @item --xattrs-include=@var{pattern}.
3706 Specify include pattern for xattr keys.  @var{pattern} is a POSIX
3707 regular expression, e.g. @samp{--xattrs-exclude='^user\.'} to include
3708 only attributes from the user namespace.
3709 @xref{Extended File Attributes, xattrs-include}.
3710
3711 @opsummary{xz}
3712 @item --xz
3713 @itemx -J
3714 Use @command{xz} for compressing or decompressing the archives.  @xref{gzip}.
3715
3716 @end table
3717
3718 @node Short Option Summary
3719 @subsection Short Options Cross Reference
3720
3721 Here is an alphabetized list of all of the short option forms, matching
3722 them with the equivalent long option.
3723
3724 @multitable @columnfractions 0.20 0.80
3725 @headitem Short Option  @tab Reference
3726
3727 @item -A @tab @ref{--concatenate}.
3728
3729 @item -B @tab @ref{--read-full-records}.
3730
3731 @item -C @tab @ref{--directory}.
3732
3733 @item -F @tab @ref{--info-script}.
3734
3735 @item -G @tab @ref{--incremental}.
3736
3737 @item -J @tab @ref{--xz}.
3738
3739 @item -K @tab @ref{--starting-file}.
3740
3741 @item -L @tab @ref{--tape-length}.
3742
3743 @item -M @tab @ref{--multi-volume}.
3744
3745 @item -N @tab @ref{--newer}.
3746
3747 @item -O @tab @ref{--to-stdout}.
3748
3749 @item -P @tab @ref{--absolute-names}.
3750
3751 @item -R @tab @ref{--block-number}.
3752
3753 @item -S @tab @ref{--sparse}.
3754
3755 @item -T @tab @ref{--files-from}.
3756
3757 @item -U @tab @ref{--unlink-first}.
3758
3759 @item -V @tab @ref{--label}.
3760
3761 @item -W @tab @ref{--verify}.
3762
3763 @item -X @tab @ref{--exclude-from}.
3764
3765 @item -Z @tab @ref{--compress}.
3766
3767 @item -b @tab @ref{--blocking-factor}.
3768
3769 @item -c @tab @ref{--create}.
3770
3771 @item -d @tab @ref{--compare}.
3772
3773 @item -f @tab @ref{--file}.
3774
3775 @item -g @tab @ref{--listed-incremental}.
3776
3777 @item -h @tab @ref{--dereference}.
3778
3779 @item -i @tab @ref{--ignore-zeros}.
3780
3781 @item -j @tab @ref{--bzip2}.
3782
3783 @item -k @tab @ref{--keep-old-files}.
3784
3785 @item -l @tab @ref{--check-links}.
3786
3787 @item -m @tab @ref{--touch}.
3788
3789 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3790 @ref{--portability}.
3791
3792 The latter usage is deprecated.  It is retained for compatibility with
3793 the earlier versions of @GNUTAR{}.  In future releases
3794 @option{-o} will be equivalent to @option{--no-same-owner} only.
3795
3796 @item -p @tab @ref{--preserve-permissions}.
3797
3798 @item -r @tab @ref{--append}.
3799
3800 @item -s @tab @ref{--same-order}.
3801
3802 @item -t @tab @ref{--list}.
3803
3804 @item -u @tab @ref{--update}.
3805
3806 @item -v @tab @ref{--verbose}.
3807
3808 @item -w @tab @ref{--interactive}.
3809
3810 @item -x @tab @ref{--extract}.
3811
3812 @item -z @tab @ref{--gzip}.
3813
3814 @end multitable
3815
3816 @node Position-Sensitive Options
3817 @subsection Position-Sensitive Options
3818
3819 Some @GNUTAR{} options can be used multiple times in the same
3820 invocation and affect all arguments that appear after them.  These are
3821 options that control how file names are selected and what kind of
3822 pattern matching is used.
3823
3824 The most obvious example is the @option{-C} option.  It instructs @command{tar}
3825 to change to the directory given as its argument prior to processing
3826 the rest of command line (@pxref{directory}).  Thus, in the following
3827 command:
3828
3829 @example
3830 @kbd{tar -c -f a.tar -C /etc passwd -C /var log spool}
3831 @end example
3832
3833 @noindent
3834 the file @file{passwd} will be searched in the directory @file{/etc},
3835 and files @file{log} and @file{spool} -- in @file{/var}.
3836
3837 These options can also be used in a file list supplied with the
3838 @option{--files-from} (@option{-T}) option (@pxref{files}).  In that
3839 case they affect all files (patterns) appearing in that file after
3840 them and remain in effect for any arguments processed after that file.
3841 For example, if the file @file{list.txt} contained:
3842
3843 @example
3844 README
3845 -C src
3846 main.c
3847 @end example
3848
3849 @noindent
3850 and @command{tar} were invoked as follows:
3851
3852 @example
3853 @kbd{tar -c -f a.tar -T list.txt Makefile}
3854 @end example
3855
3856 @noindent
3857 then the file @file{README} would be looked up in the current working
3858 directory, and files @file{main.c} and @file{Makefile} would be looked
3859 up in the directory @file{src}.
3860
3861 Many options can be prefixed with @option{--no-} to cancel the effect
3862 of the original option.
3863
3864 For example, the @option{--recursion} option controls whether to
3865 recurse in the subdirectories.  It's counterpart
3866 @option{--no-recursion} disables this.  Consider the command below.  It will
3867 store in the archive the directory @file{/usr} with all files and
3868 directories that are located in it as well as any files and
3869 directories in @file{/var}, without recursing into them@footnote{The @option{--recursion}
3870 option is the default and is used here for clarity.  The same example
3871 can be written as:
3872
3873 @example
3874 tar -cf a.tar /usr --no-recursion /var/*
3875 @end example
3876 }:
3877
3878 @example
3879 tar -cf a.tar --recursion /usr --no-recursion /var/*
3880 @end example
3881
3882 The following table summarizes all position-sensitive options. 
3883
3884 @table @option
3885 @item --directory=@var{dir}
3886 @itemx -C @var{dir}
3887 @xref{directory}.
3888
3889 @item --null
3890 @itemx --no-null
3891 @xref{nul}.
3892
3893 @item --unquote
3894 @itemx --no-unquote
3895 @xref{input name quoting}.
3896
3897 @item --verbatim-files-from
3898 @itemx --no-verbatim-files-from
3899 @xref{verbatim-files-from}.
3900
3901 @item --recursion 
3902 @itemx --no-recursion
3903 @xref{recurse}.
3904
3905 @item --anchored 
3906 @itemx --no-anchored 
3907 @xref{anchored patterns}.
3908
3909 @item --ignore-case 
3910 @itemx --no-ignore-case 
3911 @xref{case-insensitive matches}.
3912
3913 @item --wildcards
3914 @itemx --no-wildcards
3915 @xref{controlling pattern-matching}.
3916
3917 @item --wildcards-match-slash 
3918 @itemx --no-wildcards-match-slash 
3919 @xref{controlling pattern-matching}.
3920
3921 @item --exclude
3922 @xref{exclude}.
3923
3924 @item --exclude-from
3925 @itemx -X
3926 @itemx --exclude-caches
3927 @itemx --exclude-caches-under
3928 @itemx --exclude-caches-all
3929 @itemx --exclude-tag
3930 @itemx --exclude-ignore
3931 @itemx --exclude-ignore-recursive
3932 @itemx --exclude-tag-under
3933 @itemx --exclude-tag-all
3934 @itemx --exclude-vcs
3935 @itemx --exclude-vcs-ignores
3936 @itemx --exclude-backups
3937 @xref{exclude}.
3938 @end table
3939
3940 @node help
3941 @section @GNUTAR{} documentation
3942
3943 @cindex Getting program version number
3944 @opindex version
3945 @cindex Version of the @command{tar} program
3946 Being careful, the first thing is really checking that you are using
3947 @GNUTAR{}, indeed.  The @option{--version} option
3948 causes @command{tar} to print information about its name, version,
3949 origin and legal status, all on standard output, and then exit
3950 successfully.  For example, @w{@samp{tar --version}} might print:
3951
3952 @smallexample
3953 tar (GNU tar) @value{VERSION}
3954 Copyright (C) 2013-2016 Free Software Foundation, Inc.
3955 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3956 This is free software: you are free to change and redistribute it.
3957 There is NO WARRANTY, to the extent permitted by law.
3958
3959 Written by John Gilmore and Jay Fenlason.
3960 @end smallexample
3961
3962 @noindent
3963 The first occurrence of @samp{tar} in the result above is the program
3964 name in the package (for example, @command{rmt} is another program),
3965 while the second occurrence of @samp{tar} is the name of the package
3966 itself, containing possibly many programs.  The package is currently
3967 named @samp{tar}, after the name of the main program it
3968 contains@footnote{There are plans to merge the @command{cpio} and
3969 @command{tar} packages into a single one which would be called
3970 @code{paxutils}.  So, who knows if, one of this days, the
3971 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3972 paxutils) 3.2}}.}.
3973
3974 @cindex Obtaining help
3975 @cindex Listing all @command{tar} options
3976 @xopindex{help, introduction}
3977 Another thing you might want to do is checking the spelling or meaning
3978 of some particular @command{tar} option, without resorting to this
3979 manual, for once you have carefully read it.  @GNUTAR{}
3980 has a short help feature, triggerable through the
3981 @option{--help} option.  By using this option, @command{tar} will
3982 print a usage message listing all available options on standard
3983 output, then exit successfully, without doing anything else and
3984 ignoring all other options.  Even if this is only a brief summary, it
3985 may be several screens long.  So, if you are not using some kind of
3986 scrollable window, you might prefer to use something like:
3987
3988 @smallexample
3989 $ @kbd{tar --help | less}
3990 @end smallexample
3991
3992 @noindent
3993 presuming, here, that you like using @command{less} for a pager.  Other
3994 popular pagers are @command{more} and @command{pg}.  If you know about some
3995 @var{keyword} which interests you and do not want to read all the
3996 @option{--help} output, another common idiom is doing:
3997
3998 @smallexample
3999 tar --help | grep @var{keyword}
4000 @end smallexample
4001
4002 @noindent
4003 for getting only the pertinent lines.  Notice, however, that some
4004 @command{tar} options have long description lines and the above
4005 command will list only the first of them.
4006
4007 The exact look of the option summary displayed by @kbd{tar --help} is
4008 configurable. @xref{Configuring Help Summary}, for a detailed description.
4009
4010 @opindex usage
4011 If you only wish to check the spelling of an option, running @kbd{tar
4012 --usage} may be a better choice.  This will display a terse list of
4013 @command{tar} options without accompanying explanations.
4014
4015 The short help output is quite succinct, and you might have to get
4016 back to the full documentation for precise points.  If you are reading
4017 this paragraph, you already have the @command{tar} manual in some
4018 form.  This manual is available in a variety of forms from
4019 @url{http://www.gnu.org/software/tar/manual}.  It may be printed out of the @GNUTAR{}
4020 distribution, provided you have @TeX{} already installed somewhere,
4021 and a laser printer around.  Just configure the distribution, execute
4022 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
4023 usual way (contact your local guru to know how).  If @GNUTAR{}
4024 has been conveniently installed at your place, this
4025 manual is also available in interactive, hypertextual form as an Info
4026 file.  Just call @w{@samp{info tar}} or, if you do not have the
4027 @command{info} program handy, use the Info reader provided within
4028 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
4029
4030 There is currently no @code{man} page for @GNUTAR{}.
4031 If you observe such a @code{man} page on the system you are running,
4032 either it does not belong to @GNUTAR{}, or it has not
4033 been produced by @acronym{GNU}.  Some package maintainers convert
4034 @kbd{tar --help} output to a man page, using @command{help2man}.  In
4035 any case, please bear in mind that the authoritative source of
4036 information about @GNUTAR{} is this Texinfo documentation.
4037
4038 @node defaults
4039 @section Obtaining @GNUTAR{} default values
4040
4041 @opindex show-defaults
4042 @GNUTAR{} has some predefined defaults that are used when you do not
4043 explicitly specify another values.  To obtain a list of such
4044 defaults, use @option{--show-defaults} option.  This will output the
4045 values in the form of @command{tar} command line options:
4046
4047 @smallexample
4048 @group
4049 $ @kbd{tar --show-defaults}
4050 --format=gnu -f- -b20 --quoting-style=escape
4051 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
4052 @end group
4053 @end smallexample
4054
4055 @noindent
4056 Notice, that this option outputs only one line.  The example output above
4057 has been split to fit page boundaries.
4058
4059 @noindent
4060 The above output shows that this version of @GNUTAR{} defaults to
4061 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
4062 output as the archive, if no @option{--file} option has been given
4063 (@pxref{file tutorial}), the default blocking factor is 20
4064 (@pxref{Blocking Factor}).  It also shows the default locations where
4065 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
4066
4067 @node verbose
4068 @section Checking @command{tar} progress
4069
4070 Typically, @command{tar} performs most operations without reporting any
4071 information to the user except error messages.  When using @command{tar}
4072 with many options, particularly ones with complicated or
4073 difficult-to-predict behavior, it is possible to make serious mistakes.
4074 @command{tar} provides several options that make observing @command{tar}
4075 easier.  These options cause @command{tar} to print information as it
4076 progresses in its job, and you might want to use them just for being
4077 more careful about what is going on, or merely for entertaining
4078 yourself.  If you have encountered a problem when operating on an
4079 archive, however, you may need more information than just an error
4080 message in order to solve the problem.  The following options can be
4081 helpful diagnostic tools.
4082
4083 @cindex Verbose operation
4084 @opindex verbose
4085 Normally, the @option{--list} (@option{-t}) command to list an archive
4086 prints just the file names (one per line) and the other commands are
4087 silent. When used with most operations, the @option{--verbose}
4088 (@option{-v}) option causes @command{tar} to print the name of each
4089 file or archive member as it is processed.  This and the other options
4090 which make @command{tar} print status information can be useful in
4091 monitoring @command{tar}.
4092
4093 With @option{--create} or @option{--extract}, @option{--verbose} used
4094 once just prints the names of the files or members as they are processed.
4095 Using it twice causes @command{tar} to print a longer listing
4096 (@xref{verbose member listing}, for the description) for each member.
4097 Since @option{--list} already prints  the names of the members,
4098 @option{--verbose} used once with @option{--list} causes @command{tar}
4099 to print an @samp{ls -l} type listing of the files in the archive.
4100 The following examples both extract members with long list output:
4101
4102 @smallexample
4103 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
4104 $ @kbd{tar xvvf archive.tar}
4105 @end smallexample
4106
4107 Verbose output appears on the standard output except when an archive is
4108 being written to the standard output, as with @samp{tar --create
4109 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
4110 installer let standard output be the default archive).  In that case
4111 @command{tar} writes verbose output to the standard error stream.
4112
4113 If @option{--index-file=@var{file}} is specified, @command{tar} sends
4114 verbose output to @var{file} rather than to standard output or standard
4115 error.
4116
4117 @anchor{totals}
4118 @cindex Obtaining total status information
4119 @opindex totals
4120 The @option{--totals} option causes @command{tar} to print on the
4121 standard error the total amount of bytes transferred when processing
4122 an archive.  When creating or appending to an archive, this option
4123 prints the number of bytes written to the archive and the average
4124 speed at which they have been written, e.g.:
4125
4126 @smallexample
4127 @group
4128 $ @kbd{tar -c -f archive.tar --totals /home}
4129 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
4130 @end group
4131 @end smallexample
4132
4133 When reading an archive, this option displays the number of bytes
4134 read:
4135
4136 @smallexample
4137 @group
4138 $ @kbd{tar -x -f archive.tar --totals}
4139 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
4140 @end group
4141 @end smallexample
4142
4143 Finally, when deleting from an archive, the @option{--totals} option
4144 displays both numbers plus number of bytes removed from the archive:
4145
4146 @smallexample
4147 @group
4148 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
4149 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
4150 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
4151 Total bytes deleted: 1474048
4152 @end group
4153 @end smallexample
4154
4155 You can also obtain this information on request.  When
4156 @option{--totals} is used with an argument, this argument is
4157 interpreted as a symbolic name of a signal, upon delivery of which the
4158 statistics is to be printed:
4159
4160 @table @option
4161 @item --totals=@var{signo}
4162 Print statistics upon delivery of signal @var{signo}.  Valid arguments
4163 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4164 @code{SIGUSR2}.  Shortened names without @samp{SIG} prefix are also
4165 accepted.
4166 @end table
4167
4168 Both forms of @option{--totals} option can be used simultaneously.
4169 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
4170 extract all members from its default archive and print statistics
4171 after finishing the extraction, as well as when receiving signal
4172 @code{SIGUSR1}.
4173
4174 @anchor{Progress information}
4175 @cindex Progress information
4176 The @option{--checkpoint} option prints an occasional message
4177 as @command{tar} reads or writes the archive.  It is designed for
4178 those who don't need the more detailed (and voluminous) output of
4179 @option{--block-number} (@option{-R}), but do want visual confirmation
4180 that @command{tar} is actually making forward progress.  By default it
4181 prints a message each 10 records read or written.  This can be changed
4182 by giving it a numeric argument after an equal sign:
4183
4184 @smallexample
4185 $ @kbd{tar -c --checkpoint=1000} /var
4186 tar: Write checkpoint 1000
4187 tar: Write checkpoint 2000
4188 tar: Write checkpoint 3000
4189 @end smallexample
4190
4191 This example shows the default checkpoint message used by
4192 @command{tar}.  If you place a dot immediately after the equal
4193 sign, it will print a @samp{.} at each checkpoint@footnote{This is
4194 actually a shortcut for @option{--checkpoint=@var{n}
4195 --checkpoint-action=dot}.  @xref{checkpoints, dot}.}.  For example:
4196
4197 @smallexample
4198 $ @kbd{tar -c --checkpoint=.1000} /var
4199 ...
4200 @end smallexample
4201
4202 The @option{--checkpoint} option provides a flexible mechanism for
4203 executing arbitrary actions upon hitting checkpoints, see the next
4204 section (@pxref{checkpoints}), for more information on it.
4205
4206 @opindex show-omitted-dirs
4207 @anchor{show-omitted-dirs}
4208 The @option{--show-omitted-dirs} option, when reading an archive---with
4209 @option{--list} or @option{--extract}, for example---causes a message
4210 to be printed for each directory in the archive which is skipped.
4211 This happens regardless of the reason for skipping: the directory might
4212 not have been named on the command line (implicitly or explicitly),
4213 it might be excluded by the use of the
4214 @option{--exclude=@var{pattern}} option, or some other reason.
4215
4216 @opindex block-number
4217 @cindex Block number where error occurred
4218 @anchor{block-number}
4219 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
4220 every message it would normally produce, the block number within the
4221 archive where the message was triggered.  Also, supplementary messages
4222 are triggered when reading blocks full of NULs, or when hitting end of
4223 file on the archive.  As of now, if the archive is properly terminated
4224 with a NUL block, the reading of the file may stop before end of file
4225 is met, so the position of end of file will not usually show when
4226 @option{--block-number} (@option{-R}) is used.  Note that @GNUTAR{}
4227 drains the archive before exiting when reading the
4228 archive from a pipe.
4229
4230 @cindex Error message, block number of
4231 This option is especially useful when reading damaged archives, since
4232 it helps pinpoint the damaged sections.  It can also be used with
4233 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
4234 choose among several backup tapes when retrieving a file later, in
4235 favor of the tape where the file appears earliest (closest to the
4236 front of the tape).  @xref{backup}.
4237
4238 @node checkpoints
4239 @section Checkpoints
4240 @cindex checkpoints, defined
4241 @opindex checkpoint
4242 @opindex checkpoint-action
4243
4244 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
4245 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
4246 from the archive (a @dfn{read checkpoint}).  Checkpoints allow to
4247 periodically execute arbitrary actions.
4248
4249 The checkpoint facility is enabled using the following option:
4250
4251 @table @option
4252 @xopindex{checkpoint, defined}
4253 @item --checkpoint[=@var{n}]
4254 Schedule checkpoints before writing or reading each @var{n}th record.
4255 The default value for @var{n} is 10.
4256 @end table
4257
4258 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
4259 These actions include: pausing, displaying textual messages, and
4260 executing arbitrary external programs.  Actions are defined using
4261 the @option{--checkpoint-action} option.
4262
4263 @table @option
4264 @xopindex{checkpoint-action, defined}
4265 @item --checkpoint-action=@var{action}
4266 Execute an @var{action} at each checkpoint.
4267 @end table
4268
4269 @cindex @code{echo}, checkpoint action
4270 The simplest value of @var{action} is @samp{echo}.  It instructs
4271 @command{tar} to display the default message on the standard error
4272 stream upon arriving at each checkpoint.  The default message is (in
4273 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
4274 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
4275 Here, @var{n} represents ordinal number of the checkpoint.
4276
4277 In another locales, translated versions of this message are used.
4278
4279 This is the default action, so running:
4280
4281 @smallexample
4282 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
4283 @end smallexample
4284
4285 @noindent
4286 is equivalent to:
4287
4288 @smallexample
4289 $ @kbd{tar -c --checkpoint=1000} /var
4290 @end smallexample
4291
4292 The @samp{echo} action also allows to supply a customized message.
4293 You do so by placing an equals sign and the message right after it,
4294 e.g.:
4295
4296 @smallexample
4297 --checkpoint-action="echo=Hit %s checkpoint #%u"
4298 @end smallexample
4299
4300 The @samp{%s} and @samp{%u} in the above example are
4301 @dfn{format specifiers}.  The @samp{%s} specifier is replaced with
4302 the @dfn{type} of the checkpoint: @samp{write} or
4303 @samp{read} (or a corresponding translated version in locales other
4304 than @acronym{POSIX}).  The @samp{%u} specifier is replaced with
4305 the ordinal number of the checkpoint.  Thus, the above example could
4306 produce the following output when used with the @option{--create}
4307 option:
4308
4309 @smallexample
4310 tar: Hit write checkpoint #10
4311 tar: Hit write checkpoint #20
4312 tar: Hit write checkpoint #30
4313 @end smallexample
4314
4315 The complete list of available format specifiers follows.  Some of
4316 them can take optional arguments.  These arguments, if given, are
4317 supplied in curly braces between the percent sign and the specifier
4318 letter.
4319
4320 @table @samp
4321 @item %s
4322 Print type of the checkpoint (@samp{write} or @samp{read}).
4323
4324 @item %u
4325 Print number of the checkpoint.
4326
4327 @item %@{r,w,d@}T
4328 Print number of bytes transferred so far and approximate transfer
4329 speed.  Optional arguments supply prefixes to be used before number
4330 of bytes read, written and deleted, correspondingly.  If absent,
4331 they default to @samp{R}. @samp{W}, @samp{D}.  Any or all of them can
4332 be omitted, so, that e.g. @samp{%@{@}T} means to print corresponding
4333 statistics without any prefixes.  Any surplus arguments, if present,
4334 are silently ignored.
4335
4336 @example
4337 $ @kbd{tar --delete -f f.tar --checkpoint-action=echo="#%u: %T" main.c}
4338 tar: #1: R: 0 (0B, 0B/s),W: 0 (0B, 0B/s),D: 0
4339 tar: #2: R: 10240 (10KiB, 19MiB/s),W: 0 (0B, 0B/s),D: 10240
4340 @end example
4341
4342 @noindent
4343 See also the @samp{totals} action, described below.
4344
4345 @item %@{@var{fmt}@}t
4346 Output current local time using @var{fmt} as format for @command{strftime}
4347 (@pxref{strftime, strftime,,strftime(3), strftime(3) man page}).  The
4348 @samp{@{@var{fmt}@}} part is optional.  If not present, the default
4349 format is @samp{%c}, i.e. the preferred date and time representation
4350 for the current locale.
4351
4352 @item %@{@var{n}@}*
4353 Pad output with spaces to the @var{n}th column.  If the
4354 @samp{@{@var{n}@}} part is omitted, the current screen width
4355 is assumed.
4356
4357 @item %c
4358 This is a shortcut for @samp{%@{%Y-%m-%d %H:%M:%S@}t: %ds, %@{read,wrote@}T%*\r},
4359 intended mainly for use with @samp{ttyout} action (see below).
4360 @end table
4361
4362 Aside from format expansion, the message string is subject to
4363 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
4364 replaced with their corresponding @acronym{ASCII} characters
4365 (@pxref{escape sequences}).  E.g. the following action will produce an
4366 audible bell and the message described above at each checkpoint:
4367
4368 @smallexample
4369 --checkpoint-action='echo=\aHit %s checkpoint #%u'
4370 @end smallexample
4371
4372 @cindex @code{bell}, checkpoint action
4373 There is also a special action which produces an audible signal:
4374 @samp{bell}.  It is not equivalent to @samp{echo='\a'}, because
4375 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
4376 whereas @samp{echo='\a'} sends it to the standard error.
4377
4378 @cindex @code{ttyout}, checkpoint action
4379 The @samp{ttyout=@var{string}} action outputs @var{string} to
4380 @file{/dev/tty}, so it can be used even if the standard output is
4381 redirected elsewhere.  The @var{string} is subject to the same
4382 modifications as with @samp{echo} action.  In contrast to the latter,
4383 @samp{ttyout} does not prepend @command{tar} executable name to the
4384 string, nor does it output a newline after it.  For example, the
4385 following action will print the checkpoint message at the same screen
4386 line, overwriting any previous message:
4387
4388 @smallexample
4389 --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r"
4390 @end smallexample
4391
4392 @noindent
4393 Notice the use of @samp{%*} specifier to clear out any eventual
4394 remains of the prior output line.  As as more complex example,
4395 consider this:
4396
4397 @smallexample
4398 --checkpoint-action=ttyout='%@{%Y-%m-%d %H:%M:%S@}t (%d sec): #%u, %T%*\r'
4399 @end smallexample
4400
4401 @noindent
4402 This prints the current local time, number of seconds expired since
4403 tar was started, the checkpoint ordinal number, transferred bytes and
4404 average computed I/O speed.
4405
4406 @cindex @code{dot}, checkpoint action
4407 Another available checkpoint action is @samp{dot} (or @samp{.}).  It
4408 instructs @command{tar} to print a single dot on the standard listing
4409 stream, e.g.:
4410
4411 @smallexample
4412 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
4413 ...
4414 @end smallexample
4415
4416 For compatibility with previous @GNUTAR{} versions, this action can
4417 be abbreviated by placing a dot in front of the checkpoint frequency,
4418 as shown in the previous section.
4419
4420 @cindex @code{totals}, checkpoint action
4421 The @samp{totals} action prints the total number of bytes transferred
4422 so far.  The format of the data is the same as for the
4423 @option{--totals} option (@pxref{totals}).  See also @samp{%T} format
4424 specifier of the @samp{echo} or @samp{ttyout} action.
4425
4426 @cindex @code{sleep}, checkpoint action
4427 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4428 amount of seconds.  The following example will stop for 30 seconds at each
4429 checkpoint:
4430
4431 @smallexample
4432 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4433 @end smallexample
4434
4435 @anchor{checkpoint exec}
4436 @cindex @code{exec}, checkpoint action
4437 Finally, the @code{exec} action executes a given external command.
4438 For example:
4439
4440 @smallexample
4441 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4442 @end smallexample
4443
4444 The supplied command can be any valid command invocation, with or
4445 without additional command line arguments.  If it does contain
4446 arguments, don't forget to quote it to prevent it from being split by
4447 the shell.  @xref{external, Running External Commands}, for more detail.
4448
4449 The command gets a copy of @command{tar}'s environment plus the
4450 following variables:
4451
4452 @table @env
4453 @vrindex TAR_VERSION, checkpoint script environment
4454 @item TAR_VERSION
4455 @GNUTAR{} version number.
4456
4457 @vrindex TAR_ARCHIVE, checkpoint script environment
4458 @item TAR_ARCHIVE
4459 The name of the archive @command{tar} is processing.
4460
4461 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4462 @item TAR_BLOCKING_FACTOR
4463 Current blocking factor (@pxref{Blocking}).
4464
4465 @vrindex TAR_CHECKPOINT, checkpoint script environment
4466 @item TAR_CHECKPOINT
4467 Number of the checkpoint.
4468
4469 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4470 @item TAR_SUBCOMMAND
4471 A short option describing the operation @command{tar} is executing.
4472 @xref{Operations}, for a complete list of subcommand options.
4473
4474 @vrindex TAR_FORMAT, checkpoint script environment
4475 @item TAR_FORMAT
4476 Format of the archive being processed. @xref{Formats}, for a complete
4477 list of archive format names.
4478 @end table
4479
4480 These environment variables can also be passed as arguments to the
4481 command, provided that they are properly escaped, for example:
4482
4483 @smallexample
4484 @kbd{tar -c -f arc.tar \
4485      --checkpoint-action='exec=/sbin/cpoint $TAR_CHECKPOINT'}
4486 @end smallexample
4487
4488 @noindent
4489 Notice single quotes to prevent variable names from being expanded by
4490 the shell when invoking @command{tar}.
4491
4492 Any number of actions can be defined, by supplying several
4493 @option{--checkpoint-action} options in the command line.  For
4494 example, the command below displays two messages, pauses
4495 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4496
4497 @example
4498 @group
4499 $ @kbd{tar -c -f arc.tar \
4500        --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4501        --checkpoint-action='echo=Sleeping for 30 seconds' \
4502        --checkpoint-action='sleep=30' \
4503        --checkpoint-action='exec=/sbin/cpoint'}
4504 @end group
4505 @end example
4506
4507 This example also illustrates the fact that
4508 @option{--checkpoint-action} can be used without
4509 @option{--checkpoint}.  In this case, the default checkpoint frequency
4510 (at each 10th record) is assumed.
4511
4512 @node warnings
4513 @section Controlling Warning Messages
4514
4515 Sometimes, while performing the requested task, @GNUTAR{} notices
4516 some conditions that are not exactly errors, but which the user
4517 should be aware of.  When this happens, @command{tar} issues a
4518 @dfn{warning message} describing the condition.  Warning messages
4519 are output to the standard error and they do not affect the exit
4520 code of @command{tar} command.
4521
4522 @xopindex{warning, explained}
4523 @GNUTAR{} allows the user to suppress some or all of its warning
4524 messages:
4525
4526 @table @option
4527 @item --warning=@var{keyword}
4528 Control display of the warning messages identified by @var{keyword}.
4529 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4530 suppressed.  Otherwise, they are enabled.
4531
4532 Multiple @option{--warning} messages accumulate.
4533
4534 The tables below list allowed values for @var{keyword} along with the
4535 warning messages they control.
4536 @end table
4537
4538 @subheading Keywords controlling @command{tar} operation
4539 @table @asis
4540 @kwindex all
4541 @item all
4542 Enable all warning messages.  This is the default.
4543 @kwindex none
4544 @item none
4545 Disable all warning messages.
4546 @kwindex filename-with-nuls
4547 @cindex @samp{file name read contains nul character}, warning message
4548 @item filename-with-nuls
4549 @samp{%s: file name read contains nul character}
4550 @kwindex alone-zero-block
4551 @cindex @samp{A lone zero block at}, warning message
4552 @item alone-zero-block
4553 @samp{A lone zero block at %s}
4554 @end table
4555
4556 @subheading Keywords applicable for @command{tar --create}
4557 @table @asis
4558 @kwindex cachedir
4559 @cindex @samp{contains a cache directory tag}, warning message
4560 @item cachedir
4561 @samp{%s: contains a cache directory tag %s; %s}
4562 @kwindex file-shrank
4563 @cindex @samp{File shrank by %s bytes}, warning message
4564 @item file-shrank
4565 @samp{%s: File shrank by %s bytes; padding with zeros}
4566 @kwindex xdev
4567 @cindex @samp{file is on a different filesystem}, warning message
4568 @item xdev
4569 @samp{%s: file is on a different filesystem; not dumped}
4570 @kwindex file-ignored
4571 @cindex @samp{Unknown file type; file ignored}, warning message
4572 @cindex @samp{socket ignored}, warning message
4573 @cindex @samp{door ignored}, warning message
4574 @item file-ignored
4575 @samp{%s: Unknown file type; file ignored}
4576 @*@samp{%s: socket ignored}
4577 @*@samp{%s: door ignored}
4578 @kwindex file-unchanged
4579 @cindex @samp{file is unchanged; not dumped}, warning message
4580 @item file-unchanged
4581 @samp{%s: file is unchanged; not dumped}
4582 @kwindex ignore-archive
4583 @cindex @samp{file is the archive; not dumped}, warning message
4584 @kwindex ignore-archive
4585 @cindex @samp{file is the archive; not dumped}, warning message
4586 @item ignore-archive
4587 @samp{%s: file is the archive; not dumped}
4588 @kwindex file-removed
4589 @cindex @samp{File removed before we read it}, warning message
4590 @item file-removed
4591 @samp{%s: File removed before we read it}
4592 @kwindex file-changed
4593 @cindex @samp{file changed as we read it}, warning message
4594 @item file-changed
4595 @samp{%s: file changed as we read it}
4596 @end table
4597
4598 @subheading Keywords applicable for @command{tar --extract}
4599 @table @asis
4600 @kwindex existing-file
4601 @cindex @samp{%s: skipping existing file}, warning message
4602 @item existing-file
4603 @samp{%s: skipping existing file}
4604 @kwindex timestamp
4605 @cindex @samp{implausibly old time stamp %s}, warning message
4606 @cindex @samp{time stamp %s is %s s in the future}, warning message
4607 @item timestamp
4608 @samp{%s: implausibly old time stamp %s}
4609 @*@samp{%s: time stamp %s is %s s in the future}
4610 @kwindex contiguous-cast
4611 @cindex @samp{Extracting contiguous files as regular files}, warning message
4612 @item contiguous-cast
4613 @samp{Extracting contiguous files as regular files}
4614 @kwindex symlink-cast
4615 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4616 @item symlink-cast
4617 @samp{Attempting extraction of symbolic links as hard links}
4618 @kwindex unknown-cast
4619 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4620 @item unknown-cast
4621 @samp{%s: Unknown file type '%c', extracted as normal file}
4622 @kwindex ignore-newer
4623 @cindex @samp{Current %s is newer or same age}, warning message
4624 @item ignore-newer
4625 @samp{Current %s is newer or same age}
4626 @kwindex unknown-keyword
4627 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4628 @item unknown-keyword
4629 @samp{Ignoring unknown extended header keyword '%s'}
4630 @kwindex decompress-program
4631 @item decompress-program
4632 Controls verbose description of failures occurring when trying to run
4633 alternative decompressor programs (@pxref{alternative decompression
4634 programs}).  This warning is disabled by default (unless
4635 @option{--verbose} is used).  A common example of what you can get
4636 when using this warning is:
4637
4638 @smallexample
4639 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4640 tar (child): cannot run compress: No such file or directory
4641 tar (child): trying gzip
4642 @end smallexample
4643
4644 This means that @command{tar} first tried to decompress
4645 @file{archive.Z} using @command{compress}, and, when that
4646 failed, switched to @command{gzip}.
4647 @kwindex record-size
4648 @cindex @samp{Record size = %lu blocks}, warning message
4649 @item record-size
4650 @samp{Record size = %lu blocks}
4651 @end table
4652
4653 @subheading Keywords controlling incremental extraction:
4654 @table @asis
4655 @kwindex rename-directory
4656 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4657 @cindex @samp{%s: Directory has been renamed}, warning message
4658 @item rename-directory
4659 @samp{%s: Directory has been renamed from %s}
4660 @*@samp{%s: Directory has been renamed}
4661 @kwindex new-directory
4662 @cindex @samp{%s: Directory is new}, warning message
4663 @item new-directory
4664 @samp{%s: Directory is new}
4665 @kwindex xdev
4666 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4667 @item xdev
4668 @samp{%s: directory is on a different device: not purging}
4669 @kwindex bad-dumpdir
4670 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4671 @item bad-dumpdir
4672 @samp{Malformed dumpdir: 'X' never used}
4673 @end table
4674
4675 @node interactive
4676 @section Asking for Confirmation During Operations
4677 @cindex Interactive operation
4678
4679 Typically, @command{tar} carries out a command without stopping for
4680 further instructions.  In some situations however, you may want to
4681 exclude some files and archive members from the operation (for instance
4682 if disk or storage space is tight).  You can do this by excluding
4683 certain files automatically (@pxref{Choosing}), or by performing
4684 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4685 @command{tar} also accepts @option{--confirmation} for this option.
4686
4687 @opindex interactive
4688 When the @option{--interactive} (@option{-w}) option is specified, before
4689 reading, writing, or deleting files, @command{tar} first prints a message
4690 for each such file, telling what operation it intends to take, then asks
4691 for confirmation on the terminal.  The actions which require
4692 confirmation include adding a file to the archive, extracting a file
4693 from the archive, deleting a file from the archive, and deleting a file
4694 from disk.  To confirm the action, you must type a line of input
4695 beginning with @samp{y}.  If your input line begins with anything other
4696 than @samp{y}, @command{tar} skips that file.
4697
4698 If @command{tar} is reading the archive from the standard input,
4699 @command{tar} opens the file @file{/dev/tty} to support the interactive
4700 communications.
4701
4702 Verbose output is normally sent to standard output, separate from
4703 other error messages.  However, if the archive is produced directly
4704 on standard output, then verbose output is mixed with errors on
4705 @code{stderr}.  Producing the archive on standard output may be used
4706 as a way to avoid using disk space, when the archive is soon to be
4707 consumed by another process reading it, say.  Some people felt the need
4708 of producing an archive on stdout, still willing to segregate between
4709 verbose output and error output.  A possible approach would be using a
4710 named pipe to receive the archive, and having the consumer process to
4711 read from that named pipe.  This has the advantage of letting standard
4712 output free to receive verbose output, all separate from errors.
4713
4714 @node external
4715 @section Running External Commands
4716
4717 Certain @GNUTAR{} operations imply running external commands that you
4718 supply on the command line.  One of such operations is checkpointing,
4719 described above (@pxref{checkpoint exec}).  Another example of this
4720 feature is the @option{-I} option, which allows you to supply the
4721 program to use for compressing or decompressing the archive
4722 (@pxref{use-compress-program}).
4723
4724 Whenever such operation is requested, @command{tar} first splits the
4725 supplied command into words much like the shell does.  It then treats
4726 the first word as the name of the program or the shell script to execute
4727 and the rest of words as its command line arguments.  The program,
4728 unless given as an absolute file name, is searched in the shell's
4729 @env{PATH}.
4730
4731 Any additional information is normally supplied to external commands
4732 in environment variables, specific to each particular operation.  For
4733 example, the @option{--checkpoint-action=exec} option, defines the
4734 @env{TAR_ARCHIVE} variable to the name of the archive being worked
4735 upon.  You can, should the need be, use these variables in the
4736 command line of the external command.  For example:
4737
4738 @smallexample
4739 $ @kbd{tar -x -f archive.tar \
4740     --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
4741 @end smallexample
4742
4743 @noindent
4744 This command prints for each checkpoint its number and the name of the
4745 archive, using the same output line on the screen.
4746
4747 Notice the use of single quotes to prevent variable names from being
4748 expanded by the shell when invoking @command{tar}.
4749
4750 @node operations
4751 @chapter @GNUTAR{} Operations
4752
4753 @menu
4754 * Basic tar::
4755 * Advanced tar::
4756 * create options::
4757 * extract options::
4758 * backup::
4759 * Applications::
4760 * looking ahead::
4761 @end menu
4762
4763 @node Basic tar
4764 @section Basic @GNUTAR{} Operations
4765
4766 The basic @command{tar} operations, @option{--create} (@option{-c}),
4767 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4768 @option{-x}), are currently presented and described in the tutorial
4769 chapter of this manual.  This section provides some complementary notes
4770 for these operations.
4771
4772 @table @option
4773 @xopindex{create, complementary notes}
4774 @item --create
4775 @itemx -c
4776
4777 Creating an empty archive would have some kind of elegance.  One can
4778 initialize an empty archive and later use @option{--append}
4779 (@option{-r}) for adding all members.  Some applications would not
4780 welcome making an exception in the way of adding the first archive
4781 member.  On the other hand, many people reported that it is
4782 dangerously too easy for @command{tar} to destroy a magnetic tape with
4783 an empty archive@footnote{This is well described in @cite{Unix-haters
4784 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4785 Books, ISBN 1-56884-203-1.}.  The two most common errors are:
4786
4787 @enumerate
4788 @item
4789 Mistakingly using @code{create} instead of @code{extract}, when the
4790 intent was to extract the full contents of an archive.  This error
4791 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4792 the QWERTY keyboard.  Instead of being unpacked, the archive then
4793 gets wholly destroyed.  When users speak about @dfn{exploding} an
4794 archive, they usually mean something else :-).
4795
4796 @item
4797 Forgetting the argument to @code{file}, when the intent was to create
4798 an archive with a single file in it.  This error is likely because a
4799 tired user can easily add the @kbd{f} key to the cluster of option
4800 letters, by the mere force of habit, without realizing the full
4801 consequence of doing so.  The usual consequence is that the single
4802 file, which was meant to be saved, is rather destroyed.
4803 @end enumerate
4804
4805 So, recognizing the likelihood and the catastrophic nature of these
4806 errors, @GNUTAR{} now takes some distance from elegance, and
4807 cowardly refuses to create an archive when @option{--create} option is
4808 given, there are no arguments besides options, and
4809 @option{--files-from} (@option{-T}) option is @emph{not} used.  To get
4810 around the cautiousness of @GNUTAR{} and nevertheless create an
4811 archive with nothing in it, one may still use, as the value for the
4812 @option{--files-from} option, a file with no names in it, as shown in
4813 the following commands:
4814
4815 @smallexample
4816 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4817 @kbd{tar -cf empty-archive.tar -T /dev/null}
4818 @end smallexample
4819
4820 @xopindex{extract, complementary notes}
4821 @item --extract
4822 @itemx --get
4823 @itemx -x
4824
4825 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4826
4827 @item @option{--list} (@option{-t})
4828
4829 @GNUTAR{} now shows dates as @samp{1996-08-30},
4830 while it used to show them as @samp{Aug 30 1996}. Preferably,
4831 people should get used to ISO 8601 dates.  Local American dates should
4832 be made available again with full date localization support, once
4833 ready.  In the meantime, programs not being localizable for dates
4834 should prefer international dates, that's really the way to go.
4835
4836 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4837 are curious, it contains a detailed explanation of the ISO 8601 standard.
4838
4839 @end table
4840
4841 @node Advanced tar
4842 @section Advanced @GNUTAR{} Operations
4843
4844 Now that you have learned the basics of using @GNUTAR{}, you may want
4845 to learn about further ways in which @command{tar} can help you.
4846
4847 This chapter presents five, more advanced operations which you probably
4848 won't use on a daily basis, but which serve more specialized functions.
4849 We also explain the different styles of options and why you might want
4850 to use one or another, or a combination of them in your @command{tar}
4851 commands.  Additionally, this chapter includes options which allow you to
4852 define the output from @command{tar} more carefully, and provide help and
4853 error correction in special circumstances.
4854
4855 @FIXME{check this after the chapter is actually revised to make sure
4856 it still introduces the info in the chapter correctly : ).}
4857
4858 @menu
4859 * Operations::
4860 * append::
4861 * update::
4862 * concatenate::
4863 * delete::
4864 * compare::
4865 @end menu
4866
4867 @node Operations
4868 @subsection The Five Advanced @command{tar} Operations
4869
4870 @cindex basic operations
4871 In the last chapter, you learned about the first three operations to
4872 @command{tar}.  This chapter presents the remaining five operations to
4873 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4874 @option{--delete}, and @option{--compare}.
4875
4876 You are not likely to use these operations as frequently as those
4877 covered in the last chapter; however, since they perform specialized
4878 functions, they are quite useful when you do need to use them.  We
4879 will give examples using the same directory and files that you created
4880 in the last chapter.  As you may recall, the directory is called
4881 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4882 and the two archive files you created are
4883 @samp{collection.tar} and @samp{music.tar}.
4884
4885 We will also use the archive files @samp{afiles.tar} and
4886 @samp{bfiles.tar}.  The archive @samp{afiles.tar} contains the members @samp{apple},
4887 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4888 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4889
4890 Unless we state otherwise, all practicing you do and examples you follow
4891 in this chapter will take place in the @file{practice} directory that
4892 you created in the previous chapter; see @ref{prepare for examples}.
4893 (Below in this section, we will remind you of the state of the examples
4894 where the last chapter left them.)
4895
4896 The five operations that we will cover in this chapter are:
4897
4898 @table @option
4899 @item --append
4900 @itemx -r
4901 Add new entries to an archive that already exists.
4902 @item --update
4903 @itemx -u
4904 Add more recent copies of archive members to the end of an archive, if
4905 they exist.
4906 @item --concatenate
4907 @itemx --catenate
4908 @itemx -A
4909 Add one or more pre-existing archives to the end of another archive.
4910 @item --delete
4911 Delete items from an archive (does not work on tapes).
4912 @item --compare
4913 @itemx --diff
4914 @itemx -d
4915 Compare archive members to their counterparts in the file system.
4916 @end table
4917
4918 @node append
4919 @subsection How to Add Files to Existing Archives: @option{--append}
4920
4921 @cindex appending files to existing archive
4922 @opindex append
4923 If you want to add files to an existing archive, you don't need to
4924 create a new archive; you can use @option{--append} (@option{-r}).
4925 The archive must already exist in order to use @option{--append}.  (A
4926 related operation is the @option{--update} operation; you can use this
4927 to add newer versions of archive members to an existing archive.  To learn how to
4928 do this with @option{--update}, @pxref{update}.)
4929
4930 If you use @option{--append} to add a file that has the same name as an
4931 archive member to an archive containing that archive member, then the
4932 old member is not deleted.  What does happen, however, is somewhat
4933 complex.  @command{tar} @emph{allows} you to have infinite number of files
4934 with the same name.  Some operations treat these same-named members no
4935 differently than any other set of archive members: for example, if you
4936 view an archive with @option{--list} (@option{-t}), you will see all
4937 of those members listed, with their data modification times, owners, etc.
4938
4939 Other operations don't deal with these members as perfectly as you might
4940 prefer; if you were to use @option{--extract} to extract the archive,
4941 only the most recently added copy of a member with the same name as
4942 other members would end up in the working directory.  This is because
4943 @option{--extract} extracts an archive in the order the members appeared
4944 in the archive; the most recently archived members will be extracted
4945 last.  Additionally, an extracted member will @emph{replace} a file of
4946 the same name which existed in the directory already, and @command{tar}
4947 will not prompt you about this@footnote{Unless you give it
4948 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
4949 the disk copy is newer than the one in the archive and you invoke
4950 @command{tar} with @option{--keep-newer-files} option.}.  Thus, only
4951 the most recently archived member will end up being extracted, as it
4952 will replace the one extracted before it, and so on.
4953
4954 @cindex extracting @var{n}th copy of the file
4955 @xopindex{occurrence, described}
4956 There exists a special option that allows you to get around this
4957 behavior and extract (or list) only a particular copy of the file.
4958 This is @option{--occurrence} option.  If you run @command{tar} with
4959 this option, it will extract only the first copy of the file.  You
4960 may also give this option an argument specifying the number of
4961 copy to be extracted.  Thus, for example if the archive
4962 @file{archive.tar} contained three copies of file @file{myfile}, then
4963 the command
4964
4965 @smallexample
4966 tar --extract --file archive.tar --occurrence=2 myfile
4967 @end smallexample
4968
4969 @noindent
4970 would extract only the second copy.  @xref{Option
4971 Summary,---occurrence}, for the description of @option{--occurrence}
4972 option.
4973
4974 @FIXME{ hag -- you might want to incorporate some of the above into the
4975 MMwtSN node; not sure.  i didn't know how to make it simpler...
4976
4977 There are a few ways to get around this.  Xref to Multiple Members
4978 with the Same Name, maybe.}
4979
4980 @cindex Members, replacing with other members
4981 @cindex Replacing members with other members
4982 @xopindex{delete, using before --append}
4983 If you want to replace an archive member, use @option{--delete} to
4984 delete the member you want to remove from the archive, and then use
4985 @option{--append} to add the member you want to be in the archive.  Note
4986 that you can not change the order of the archive; the most recently
4987 added member will still appear last.  In this sense, you cannot truly
4988 ``replace'' one member with another.  (Replacing one member with another
4989 will not work on certain types of media, such as tapes; see @ref{delete}
4990 and @ref{Media}, for more information.)
4991
4992 @menu
4993 * appending files::             Appending Files to an Archive
4994 * multiple::
4995 @end menu
4996
4997 @node appending files
4998 @subsubsection Appending Files to an Archive
4999 @cindex Adding files to an Archive
5000 @cindex Appending files to an Archive
5001 @cindex Archives, Appending files to
5002 @opindex append
5003
5004 The simplest way to add a file to an already existing archive is the
5005 @option{--append} (@option{-r}) operation, which writes specified
5006 files into the archive whether or not they are already among the
5007 archived files.
5008
5009 When you use @option{--append}, you @emph{must} specify file name
5010 arguments, as there is no default.  If you specify a file that already
5011 exists in the archive, another copy of the file will be added to the
5012 end of the archive.  As with other operations, the member names of the
5013 newly added files will be exactly the same as their names given on the
5014 command line.  The @option{--verbose} (@option{-v}) option will print
5015 out the names of the files as they are written into the archive.
5016
5017 @option{--append} cannot be performed on some tape drives, unfortunately,
5018 due to deficiencies in the formats those tape drives use.  The archive
5019 must be a valid @command{tar} archive, or else the results of using this
5020 operation will be unpredictable.  @xref{Media}.
5021
5022 To demonstrate using @option{--append} to add a file to an archive,
5023 create a file called @file{rock} in the @file{practice} directory.
5024 Make sure you are in the @file{practice} directory.  Then, run the
5025 following @command{tar} command to add @file{rock} to
5026 @file{collection.tar}:
5027
5028 @smallexample
5029 $ @kbd{tar --append --file=collection.tar rock}
5030 @end smallexample
5031
5032 @noindent
5033 If you now use the @option{--list} (@option{-t}) operation, you will see that
5034 @file{rock} has been added to the archive:
5035
5036 @smallexample
5037 $ @kbd{tar --list --file=collection.tar}
5038 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5039 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5040 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5041 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5042 @end smallexample
5043
5044 @node multiple
5045 @subsubsection Multiple Members with the Same Name
5046 @cindex members, multiple
5047 @cindex multiple members
5048
5049 You can use @option{--append} (@option{-r}) to add copies of files
5050 which have been updated since the archive was created.  (However, we
5051 do not recommend doing this since there is another @command{tar}
5052 option called @option{--update}; @xref{update}, for more information.
5053 We describe this use of @option{--append} here for the sake of
5054 completeness.)  When you extract the archive, the older version will
5055 be effectively lost.  This works because files are extracted from an
5056 archive in the order in which they were archived.  Thus, when the
5057 archive is extracted, a file archived later in time will replace a
5058 file of the same name which was archived earlier, even though the
5059 older version of the file will remain in the archive unless you delete
5060 all versions of the file.
5061
5062 Supposing you change the file @file{blues} and then append the changed
5063 version to @file{collection.tar}.  As you saw above, the original
5064 @file{blues} is in the archive @file{collection.tar}.  If you change the
5065 file and append the new version of the file to the archive, there will
5066 be two copies in the archive.  When you extract the archive, the older
5067 version of the file will be extracted first, and then replaced by the
5068 newer version when it is extracted.
5069
5070 You can append the new, changed copy of the file @file{blues} to the
5071 archive in this way:
5072
5073 @smallexample
5074 $ @kbd{tar --append --verbose --file=collection.tar blues}
5075 blues
5076 @end smallexample
5077
5078 @noindent
5079 Because you specified the @option{--verbose} option, @command{tar} has
5080 printed the name of the file being appended as it was acted on.  Now
5081 list the contents of the archive:
5082
5083 @smallexample
5084 $ @kbd{tar --list --verbose --file=collection.tar}
5085 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5086 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5087 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5088 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5089 -rw-r--r-- me/user          58 1996-10-24 18:30 blues
5090 @end smallexample
5091
5092 @noindent
5093 The newest version of @file{blues} is now at the end of the archive
5094 (note the different creation dates and file sizes).  If you extract
5095 the archive, the older version of the file @file{blues} will be
5096 replaced by the newer version.  You can confirm this by extracting
5097 the archive and running @samp{ls} on the directory.
5098
5099 If you wish to extract the first occurrence of the file @file{blues}
5100 from the archive, use @option{--occurrence} option, as shown in
5101 the following example:
5102
5103 @smallexample
5104 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
5105 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5106 @end smallexample
5107
5108 @xref{Writing}, for more information on @option{--extract} and
5109 see @ref{Option Summary, --occurrence}, for a description of
5110 @option{--occurrence} option.
5111
5112 @node update
5113 @subsection Updating an Archive
5114 @cindex Updating an archive
5115 @opindex update
5116
5117 In the previous section, you learned how to use @option{--append} to
5118 add a file to an existing archive.  A related operation is
5119 @option{--update} (@option{-u}).  The @option{--update} operation
5120 updates a @command{tar} archive by comparing the date of the specified
5121 archive members against the date of the file with the same name.  If
5122 the file has been modified more recently than the archive member, then
5123 the newer version of the file is added to the archive (as with
5124 @option{--append}).
5125
5126 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
5127 The operation will fail.
5128
5129 @FIXME{other examples of media on which --update will fail?  need to ask
5130 charles and/or mib/thomas/dave shevett..}
5131
5132 Both @option{--update} and @option{--append} work by adding to the end
5133 of the archive.  When you extract a file from the archive, only the
5134 version stored last will wind up in the file system, unless you use
5135 the @option{--backup} option.  @xref{multiple}, for a detailed discussion.
5136
5137 @menu
5138 * how to update::
5139 @end menu
5140
5141 @node how to update
5142 @subsubsection How to Update an Archive Using @option{--update}
5143 @opindex update
5144
5145 You must use file name arguments with the @option{--update}
5146 (@option{-u}) operation.  If you don't specify any files,
5147 @command{tar} won't act on any files and won't tell you that it didn't
5148 do anything (which may end up confusing you).
5149
5150 @c note: the above parenthetical added because in fact, this
5151 @c behavior just confused the author. :-)
5152
5153 To see the @option{--update} option at work, create a new file,
5154 @file{classical}, in your practice directory, and some extra text to the
5155 file @file{blues}, using any text editor.  Then invoke @command{tar} with
5156 the @samp{update} operation and the @option{--verbose} (@option{-v})
5157 option specified, using the names of all the files in the @file{practice}
5158 directory as file name arguments:
5159
5160 @smallexample
5161 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
5162 blues
5163 classical
5164 $
5165 @end smallexample
5166
5167 @noindent
5168 Because we have specified verbose mode, @command{tar} prints out the names
5169 of the files it is working on, which in this case are the names of the
5170 files that needed to be updated.  If you run @samp{tar --list} and look
5171 at the archive, you will see @file{blues} and @file{classical} at its
5172 end.  There will be a total of two versions of the member @samp{blues};
5173 the one at the end will be newer and larger, since you added text before
5174 updating it.
5175
5176 The reason @command{tar} does not overwrite the older file when updating
5177 it is because writing to the middle of a section of tape is a difficult
5178 process.  Tapes are not designed to go backward.  @xref{Media}, for more
5179 information about tapes.
5180
5181 @option{--update} (@option{-u}) is not suitable for performing backups for two
5182 reasons: it does not change directory content entries, and it
5183 lengthens the archive every time it is used.  The @GNUTAR{}
5184 options intended specifically for backups are more
5185 efficient.  If you need to run backups, please consult @ref{Backups}.
5186
5187 @node concatenate
5188 @subsection Combining Archives with @option{--concatenate}
5189
5190 @cindex Adding archives to an archive
5191 @cindex Concatenating Archives
5192 @opindex concatenate
5193 @opindex catenate
5194 @c @cindex @option{-A} described
5195 Sometimes it may be convenient to add a second archive onto the end of
5196 an archive rather than adding individual files to the archive.  To add
5197 one or more archives to the end of another archive, you should use the
5198 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
5199
5200 To use @option{--concatenate}, give the first archive with
5201 @option{--file} option and name the rest of archives to be
5202 concatenated on the command line.  The members, and their member
5203 names, will be copied verbatim from those archives to the first
5204 one@footnote{This can cause multiple members to have the same name.  For
5205 information on how this affects reading the archive, see @ref{multiple}.}.
5206 The new, concatenated archive will be called by the same name as the
5207 one given with the @option{--file} option.  As usual, if you omit
5208 @option{--file}, @command{tar} will use the value of the environment
5209 variable @env{TAPE}, or, if this has not been set, the default archive name.
5210
5211 @FIXME{There is no way to specify a new name...}
5212
5213 To demonstrate how @option{--concatenate} works, create two small archives
5214 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
5215 files from @file{practice}:
5216
5217 @smallexample
5218 $ @kbd{tar -cvf bluesrock.tar blues rock}
5219 blues
5220 rock
5221 $ @kbd{tar -cvf folkjazz.tar folk jazz}
5222 folk
5223 jazz
5224 @end smallexample
5225
5226 @noindent
5227 If you like, You can run @samp{tar --list} to make sure the archives
5228 contain what they are supposed to:
5229
5230 @smallexample
5231 $ @kbd{tar -tvf bluesrock.tar}
5232 -rw-r--r-- melissa/user    105 1997-01-21 19:42 blues
5233 -rw-r--r-- melissa/user     33 1997-01-20 15:34 rock
5234 $ @kbd{tar -tvf jazzfolk.tar}
5235 -rw-r--r-- melissa/user     20 1996-09-23 16:44 folk
5236 -rw-r--r-- melissa/user     65 1997-01-30 14:15 jazz
5237 @end smallexample
5238
5239 We can concatenate these two archives with @command{tar}:
5240
5241 @smallexample
5242 $ @kbd{cd ..}
5243 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
5244 @end smallexample
5245
5246 If you now list the contents of the @file{bluesrock.tar}, you will see
5247 that now it also contains the archive members of @file{jazzfolk.tar}:
5248
5249 @smallexample
5250 $ @kbd{tar --list --file=bluesrock.tar}
5251 blues
5252 rock
5253 folk
5254 jazz
5255 @end smallexample
5256
5257 When you use @option{--concatenate}, the source and target archives must
5258 already exist and must have been created using compatible format
5259 parameters.  Notice, that @command{tar} does not check whether the
5260 archives it concatenates have compatible formats, it does not
5261 even check if the files are really tar archives.
5262
5263 Like @option{--append} (@option{-r}), this operation cannot be performed on some
5264 tape drives, due to deficiencies in the formats those tape drives use.
5265
5266 @cindex @code{concatenate} vs @command{cat}
5267 @cindex @command{cat} vs @code{concatenate}
5268 It may seem more intuitive to you to want or try to use @command{cat} to
5269 concatenate two archives instead of using the @option{--concatenate}
5270 operation; after all, @command{cat} is the utility for combining files.
5271
5272 However, @command{tar} archives incorporate an end-of-file marker which
5273 must be removed if the concatenated archives are to be read properly as
5274 one archive.  @option{--concatenate} removes the end-of-archive marker
5275 from the target archive before each new archive is appended.  If you use
5276 @command{cat} to combine the archives, the result will not be a valid
5277 @command{tar} format archive.  If you need to retrieve files from an
5278 archive that was added to using the @command{cat} utility, use the
5279 @option{--ignore-zeros} (@option{-i}) option.  @xref{Ignore Zeros}, for further
5280 information on dealing with archives improperly combined using the
5281 @command{cat} shell utility.
5282
5283 @node delete
5284 @subsection Removing Archive Members Using @option{--delete}
5285 @cindex Deleting files from an archive
5286 @cindex Removing files from an archive
5287
5288 @opindex delete
5289 You can remove members from an archive by using the @option{--delete}
5290 option.  Specify the name of the archive with @option{--file}
5291 (@option{-f}) and then specify the names of the members to be deleted;
5292 if you list no member names, nothing will be deleted.  The
5293 @option{--verbose} option will cause @command{tar} to print the names
5294 of the members as they are deleted. As with @option{--extract}, you
5295 must give the exact member names when using @samp{tar --delete}.
5296 @option{--delete} will remove all versions of the named file from the
5297 archive.  The @option{--delete} operation can run very slowly.
5298
5299 Unlike other operations, @option{--delete} has no short form.
5300
5301 @cindex Tapes, using @option{--delete} and
5302 @cindex Deleting from tape archives
5303 This operation will rewrite the archive.  You can only use
5304 @option{--delete} on an archive if the archive device allows you to
5305 write to any point on the media, such as a disk; because of this, it
5306 does not work on magnetic tapes.  Do not try to delete an archive member
5307 from a magnetic tape; the action will not succeed, and you will be
5308 likely to scramble the archive and damage your tape.  There is no safe
5309 way (except by completely re-writing the archive) to delete files from
5310 most kinds of magnetic tape.  @xref{Media}.
5311
5312 To delete all versions of the file @file{blues} from the archive
5313 @file{collection.tar} in the @file{practice} directory, make sure you
5314 are in that directory, and then,
5315
5316 @smallexample
5317 $ @kbd{tar --list --file=collection.tar}
5318 blues
5319 folk
5320 jazz
5321 rock
5322 $ @kbd{tar --delete --file=collection.tar blues}
5323 $ @kbd{tar --list --file=collection.tar}
5324 folk
5325 jazz
5326 rock
5327 @end smallexample
5328
5329 @FIXME{Check if the above listing is actually produced after running
5330 all the examples on collection.tar.}
5331
5332 The @option{--delete} option has been reported to work properly when
5333 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
5334
5335 @node compare
5336 @subsection Comparing Archive Members with the File System
5337 @cindex Verifying the currency of an archive
5338
5339 @opindex compare
5340 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
5341 specified archive members against files with the same names, and then
5342 reports differences in file size, mode, owner, modification date and
5343 contents.  You should @emph{only} specify archive member names, not file
5344 names.  If you do not name any members, then @command{tar} will compare the
5345 entire archive.  If a file is represented in the archive but does not
5346 exist in the file system, @command{tar} reports a difference.
5347
5348 You have to specify the record size of the archive when modifying an
5349 archive with a non-default record size.
5350
5351 @command{tar} ignores files in the file system that do not have
5352 corresponding members in the archive.
5353
5354 The following example compares the archive members @file{rock},
5355 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
5356 files of the same name in the file system.  (Note that there is no file,
5357 @file{funk}; @command{tar} will report an error message.)
5358
5359 @smallexample
5360 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
5361 rock
5362 blues
5363 tar: funk not found in archive
5364 @end smallexample
5365
5366 The spirit behind the @option{--compare} (@option{--diff},
5367 @option{-d}) option is to check whether the archive represents the
5368 current state of files on disk, more than validating the integrity of
5369 the archive media.  For this latter goal, see @ref{verify}.
5370
5371 @node create options
5372 @section Options Used by @option{--create}
5373
5374 @xopindex{create, additional options}
5375 The previous chapter described the basics of how to use
5376 @option{--create} (@option{-c}) to create an archive from a set of files.
5377 @xref{create}.  This section described advanced options to be used with
5378 @option{--create}.
5379
5380 @menu
5381 * override::                  Overriding File Metadata.
5382 * Extended File Attributes::
5383 * Ignore Failed Read::
5384 @end menu
5385
5386 @node override
5387 @subsection Overriding File Metadata
5388
5389 As described above, a @command{tar} archive keeps, for each member it contains,
5390 its @dfn{metadata}, such as modification time, mode and ownership of
5391 the file.  @GNUTAR{} allows to replace these data with other values
5392 when adding files to the archive.  The options described in this
5393 section affect creation of archives of any type.  For POSIX archives,
5394 see also @ref{PAX keywords}, for additional ways of controlling
5395 metadata, stored in the archive.
5396
5397 @table @option
5398 @opindex mode
5399 @item --mode=@var{permissions}
5400
5401 When adding files to an archive, @command{tar} will use
5402 @var{permissions} for the archive members, rather than the permissions
5403 from the files.  @var{permissions} can be specified either as an octal
5404 number or as symbolic permissions, like with
5405 @command{chmod} (@xref{File permissions, Permissions, File
5406 permissions, fileutils, @acronym{GNU} file utilities}.  This reference
5407 also has useful information for those not being overly familiar with
5408 the UNIX permission system).  Using latter syntax allows for
5409 more flexibility.  For example, the value @samp{a+rw} adds read and write
5410 permissions for everybody, while retaining executable bits on directories
5411 or on any other file already marked as executable:
5412
5413 @smallexample
5414 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
5415 @end smallexample
5416
5417 @item --mtime=@var{date}
5418 @opindex mtime
5419
5420 When adding files to an archive, @command{tar} will use @var{date} as
5421 the modification time of members when creating archives, instead of
5422 their actual modification times.  The argument @var{date} can be
5423 either a textual date representation in almost arbitrary format
5424 (@pxref{Date input formats}) or a name of an existing file, starting
5425 with @samp{/} or @samp{.}.  In the latter case, the modification time
5426 of that file will be used.
5427
5428 The following example will set the modification date to 00:00:00,
5429 January 1, 1970:
5430
5431 @smallexample
5432 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
5433 @end smallexample
5434
5435 @noindent
5436 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
5437 will try to convert the specified date back to its textual
5438 representation and compare it with the one given with
5439 @option{--mtime} options.  If the two dates differ, @command{tar} will
5440 print a warning saying what date it will use.  This is to help user
5441 ensure he is using the right date.
5442
5443 For example:
5444
5445 @smallexample
5446 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
5447 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
5448 13:06:29.152478
5449 @dots{}
5450 @end smallexample
5451
5452 @noindent
5453 When used with @option{--clamp-mtime} @GNUTAR{} will only set the
5454 modification date to @var{date} on files whose actual modification
5455 date is later than @var{date}.  This is to make it easy to build
5456 reproducible archives given a common timestamp for generated files
5457 while still retaining the original timestamps of untouched files.
5458
5459 @smallexample
5460 $ @kbd{tar -c -f archive.tar --clamp-mtime --mtime=@atchar{}$SOURCE_DATE_EPOCH .}
5461 @end smallexample
5462
5463 @item --owner=@var{user}
5464 @opindex owner
5465
5466 Specifies that @command{tar} should use @var{user} as the owner of members
5467 when creating archives, instead of the user associated with the source
5468 file.
5469
5470 If @var{user} contains a colon, it is taken to be of the form
5471 @var{name}:@var{id} where a nonempty @var{name} specifies the user
5472 name and a nonempty @var{id} specifies the decimal numeric user
5473 @acronym{ID}.  If @var{user} does not contain a colon, it is taken to
5474 be a user number if it is one or more decimal digits; otherwise it is
5475 taken to be a user name.
5476
5477 If a name is given but no number, the number is inferred from the
5478 current host's user database if possible, and the file's user number
5479 is used otherwise.  If a number is given but no name, the name is
5480 inferred from the number if possible, and an empty name is used
5481 otherwise.  If both name and number are given, the user database is
5482 not consulted, and the name and number need not be valid on the
5483 current host.
5484
5485 There is no value indicating a missing number, and @samp{0} usually means
5486 @code{root}.  Some people like to force @samp{0} as the value to offer in
5487 their distributions for the owner of files, because the @code{root} user is
5488 anonymous anyway, so that might as well be the owner of anonymous
5489 archives.  For example:
5490
5491 @smallexample
5492 $ @kbd{tar -c -f archive.tar --owner=0 .}
5493 @end smallexample
5494
5495 @noindent
5496 or:
5497
5498 @smallexample
5499 $ @kbd{tar -c -f archive.tar --owner=root .}
5500 @end smallexample
5501
5502 @item --group=@var{group}
5503 @opindex group
5504
5505 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5506 rather than the group from the source file.  As with @option{--owner},
5507 the argument @var{group} can be an existing group symbolic name, or a
5508 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5509 @end table
5510
5511 The @option{--owner} and @option{--group} options affect all files
5512 added to the archive.  @GNUTAR{} provides also two options that allow
5513 for more detailed control over owner translation:
5514
5515 @table @option
5516 @item --owner-map=@var{file}
5517 Read UID translation map from @var{file}.
5518
5519 When reading, empty lines are ignored.  The @samp{#} sign, unless
5520 quoted, introduces a comment, which extends to the end of the line.
5521 Each nonempty line defines mapping for a single UID.  It must consist
5522 of two fields separated by any amount of whitespace.  The first field
5523 defines original username and UID.  It can be a valid user name or
5524 a valid UID prefixed with a plus sign.  In both cases the
5525 corresponding UID or user name is inferred from the current host's
5526 user database.
5527
5528 The second field defines the UID and username to map the original one
5529 to.  Its format can be the same as described above.  Otherwise, it can
5530 have the form @var{newname}:@var{newuid}, in which case neither
5531 @var{newname} nor @var{newuid} are required to be valid as per the
5532 user database.
5533
5534 For example, consider the following file:
5535
5536 @example
5537 +10     bin
5538 smith   root:0
5539 @end example
5540
5541 @noindent
5542 Given this file, each input file that is owner by UID 10 will be
5543 stored in archive with owner name @samp{bin} and owner UID
5544 corresponding to @samp{bin}.  Each file owned by user @samp{smith}
5545 will be stored with owner name @samp{root} and owner ID 0.  Other
5546 files will remain unchanged.
5547
5548 When used together with @option{--owner-map}, the @option{--owner}
5549 option affects only files whose owner is not listed in the map file.
5550
5551 @item --group-map=@var{file}
5552 Read GID translation map from @var{file}.
5553
5554 The format of @var{file} is the same as for @option{--owner-map}
5555 option:
5556
5557 Each nonempty line defines mapping for a single GID.  It must consist
5558 of two fields separated by any amount of whitespace.  The first field
5559 defines original group name and GID.  It can be a valid group name or
5560 a valid GID prefixed with a plus sign.  In both cases the
5561 corresponding GID or user name is inferred from the current host's
5562 group database.
5563
5564 The second field defines the GID and group name to map the original one
5565 to.  Its format can be the same as described above.  Otherwise, it can
5566 have the form @var{newname}:@var{newgid}, in which case neither
5567 @var{newname} nor @var{newgid} are required to be valid as per the
5568 group database.
5569
5570 When used together with @option{--group-map}, the @option{--group}
5571 option affects only files whose owner group is not rewritten using the
5572 map file.
5573 @end table
5574
5575 @node Extended File Attributes
5576 @subsection Extended File Attributes
5577
5578 Extended file attributes are name-value pairs that can be
5579 associated with each node in a file system.  Despite the fact that 
5580 POSIX.1e draft which proposed them has been withdrawn, the extended
5581 file attributes are supported by many file systems.  @GNUTAR{} can
5582 store extended file attributes along with the files.  This feature is
5583 controlled by the following command line arguments:
5584
5585 @table @option
5586 @item --xattrs
5587 Enable extended attributes support.  When used with @option{--create},
5588 this option instructs @GNUTAR to store extended file attribute in the
5589 created archive.  This implies POSIX.1-2001 archive format
5590 (@option{--format=pax}).
5591
5592 When used with @option{--extract}, this option tells @command{tar},
5593 for each file extracted, to read stored attributes from the archive
5594 and to apply them to the file.
5595
5596 @item --no-xattrs
5597 Disable extended attributes support.  This is the default.
5598 @end table
5599
5600 Attribute names are strings prefixed by a @dfn{namespace} name and a dot.
5601 Currently, four namespaces exist: @samp{user}, @samp{trusted},
5602 @samp{security} and @samp{system}.  By default, when @option{--xattr}
5603 is used, all names are stored in the archive (or extracted, if using
5604 @option{--extract}).  This can be controlled using the following
5605 options:
5606
5607 @table @option
5608 @item --xattrs-exclude=@var{pattern}
5609 Specify exclude pattern for extended attributes.
5610
5611 @item --xattrs-include=@var{pattern}
5612 Specify include pattern for extended attributes.
5613 @end table
5614
5615 Here, the @var{pattern} is POSIX regular expression.  For example, the
5616 following command:
5617
5618 @example
5619 $ @kbd{tar --xattrs --xattrs-exclude='^user\.' -c a.tar .}
5620 @end example
5621
5622 will include in the archive @file{a.tar} all attributes, except those
5623 from the @samp{user} namespace.
5624
5625 Any number of these options can be given, thereby creating lists of
5626 include and exclude patterns.
5627
5628 When both options are used, first @option{--xattrs-inlcude} is applied
5629 to select the set of attribute names to keep, and then
5630 @option{--xattrs-exclude} is applied to the resulting set.  In other
5631 words, only those attributes will be stored, whose names match one
5632 of the regexps in @option{--xattrs-inlcude} and don't match any of
5633 the regexps from @option{--xattrs-exclude}.
5634
5635 When listing the archive, if both @option{--xattrs} and
5636 @option{--verbose} options are given, files that have extended
5637 attributes are marked with an asterisk following their permission
5638 mask.  For example:
5639
5640 @example
5641 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5642 @end example
5643
5644 When two or more @option{--verbose} options are given, a detailed
5645 listing of extended attributes is printed after each file entry.  Each
5646 attribute is listed on a separate line, which begins with two spaces
5647 and the letter @samp{x} indicating extended attribute.  It is followed
5648 by a colon, length of the attribute and its name, e.g.:
5649
5650 @example
5651 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5652   x:  7 user.mime_type
5653   x: 32 trusted.md5sum
5654 @end example
5655
5656 File access control lists (@dfn{ACL}) are another actively used feature
5657 proposed by the POSIX.1e standard.  Each ACL consists of a set of ACL
5658 entries, each of which describes the access permissions on the file for
5659 an individual user or a group of users as a combination of read, write
5660 and search/execute permissions.
5661
5662 Whether or not to use ACLs is controlled by the following two options:
5663
5664 @table @option
5665 @item --acls
5666 Enable POSIX ACLs support.  When used with @option{--create},
5667 this option instructs @GNUTAR{} to store ACLs in the
5668 created archive.  This implies POSIX.1-2001 archive format
5669 (@option{--format=pax}).
5670
5671 When used with @option{--extract}, this option tells @command{tar},
5672 to restore ACLs for each file extracted (provided they are present
5673 in the archive).
5674
5675 @item --no-acls
5676 Disable POSIX ACLs support.  This is the default.
5677 @end table
5678
5679 When listing the archive, if both @option{--acls} and
5680 @option{--verbose} options are given, files that have ACLs are marked
5681 with a plus sing following their permission mask.  For example:
5682
5683 @example
5684 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5685 @end example
5686
5687 When two or more @option{--verbose} options are given, a detailed
5688 listing of ACL is printed after each file entry:
5689
5690 @example
5691 @group
5692 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5693   a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r--
5694 @end group  
5695 @end example
5696
5697 @dfn{Security-Enhanced Linux} (@dfn{SELinux} for short) is a Linux
5698 kernel security module that provides a mechanism for supporting access
5699 control security policies, including so-called mandatory access
5700 controls (@dfn{MAC}).  Support for SELinux attributes is controlled by
5701 the following command line options:
5702
5703 @table @option
5704 @item --selinux
5705 Enable the SELinux context support.
5706
5707 @item --no-selinux
5708 Disable SELinux context support.
5709 @end table
5710
5711 @node Ignore Failed Read
5712 @subsection Ignore Fail Read
5713
5714 @table @option
5715 @item --ignore-failed-read
5716 @opindex ignore-failed-read
5717 Do not exit with nonzero on unreadable files or directories.
5718 @end table
5719
5720 @node extract options
5721 @section Options Used by @option{--extract}
5722 @cindex options for use with @option{--extract}
5723
5724 @xopindex{extract, additional options}
5725 The previous chapter showed how to use @option{--extract} to extract
5726 an archive into the file system.  Various options cause @command{tar} to
5727 extract more information than just file contents, such as the owner,
5728 the permissions, the modification date, and so forth.  This section
5729 presents options to be used with @option{--extract} when certain special
5730 considerations arise.  You may review the information presented in
5731 @ref{extract} for more basic information about the
5732 @option{--extract} operation.
5733
5734 @menu
5735 * Reading::                     Options to Help Read Archives
5736 * Writing::                     Changing How @command{tar} Writes Files
5737 * Scarce::                      Coping with Scarce Resources
5738 @end menu
5739
5740 @node Reading
5741 @subsection Options to Help Read Archives
5742 @cindex Options when reading archives
5743
5744 @cindex Reading incomplete records
5745 @cindex Records, incomplete
5746 @opindex read-full-records
5747 Normally, @command{tar} will request data in full record increments from
5748 an archive storage device.  If the device cannot return a full record,
5749 @command{tar} will report an error.  However, some devices do not always
5750 return full records, or do not require the last record of an archive to
5751 be padded out to the next record boundary.  To keep reading until you
5752 obtain a full record, or to accept an incomplete record if it contains
5753 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5754 in conjunction with the @option{--extract} or @option{--list} operations.
5755 @xref{Blocking}.
5756
5757 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5758 @command{tar} reads an archive from standard input, or from a remote
5759 machine.  This is because on @acronym{BSD} Unix systems, attempting to read a
5760 pipe returns however much happens to be in the pipe, even if it is
5761 less than was requested.  If this option were not enabled, @command{tar}
5762 would fail as soon as it read an incomplete record from the pipe.
5763
5764 If you're not sure of the blocking factor of an archive, you can
5765 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5766 @option{--blocking-factor=@var{512-size}} (@option{-b
5767 @var{512-size}}), using a blocking factor larger than what the archive
5768 uses.  This lets you avoid having to determine the blocking factor
5769 of an archive.  @xref{Blocking Factor}.
5770
5771 @menu
5772 * read full records::
5773 * Ignore Zeros::
5774 @end menu
5775
5776 @node read full records
5777 @unnumberedsubsubsec Reading Full Records
5778
5779 @FIXME{need sentence or so of intro here}
5780
5781 @table @option
5782 @opindex read-full-records
5783 @item --read-full-records
5784 @item -B
5785 Use in conjunction with @option{--extract} (@option{--get},
5786 @option{-x}) to read an archive which contains incomplete records, or
5787 one which has a blocking factor less than the one specified.
5788 @end table
5789
5790 @node Ignore Zeros
5791 @unnumberedsubsubsec Ignoring Blocks of Zeros
5792
5793 @cindex End-of-archive blocks, ignoring
5794 @cindex Ignoring end-of-archive blocks
5795 @opindex ignore-zeros
5796 Normally, @command{tar} stops reading when it encounters a block of zeros
5797 between file entries (which usually indicates the end of the archive).
5798 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5799 completely read an archive which contains a block of zeros before the
5800 end (i.e., a damaged archive, or one that was created by concatenating
5801 several archives together).
5802
5803 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5804 versions of @command{tar} write garbage after the end-of-archive entry,
5805 since that part of the media is never supposed to be read.  @GNUTAR{}
5806 does not write after the end of an archive, but seeks to
5807 maintain compatibility among archiving utilities.
5808
5809 @table @option
5810 @item --ignore-zeros
5811 @itemx -i
5812 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5813 encountered while reading an archive.  Use in conjunction with
5814 @option{--extract} or @option{--list}.
5815 @end table
5816
5817 @node Writing
5818 @subsection Changing How @command{tar} Writes Files
5819 @UNREVISED
5820
5821 @FIXME{Introductory paragraph}
5822
5823 @menu
5824 * Dealing with Old Files::
5825 * Overwrite Old Files::
5826 * Keep Old Files::
5827 * Keep Newer Files::
5828 * Unlink First::
5829 * Recursive Unlink::
5830 * Data Modification Times::
5831 * Setting Access Permissions::
5832 * Directory Modification Times and Permissions::
5833 * Writing to Standard Output::
5834 * Writing to an External Program::
5835 * remove files::
5836 @end menu
5837
5838 @node Dealing with Old Files
5839 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5840
5841 @xopindex{overwrite-dir, introduced}
5842 When extracting files, if @command{tar} discovers that the extracted
5843 file already exists, it normally replaces the file by removing it before
5844 extracting it, to prevent confusion in the presence of hard or symbolic
5845 links.  (If the existing file is a symbolic link, it is removed, not
5846 followed.)  However, if a directory cannot be removed because it is
5847 nonempty, @command{tar} normally overwrites its metadata (ownership,
5848 permission, etc.).  The @option{--overwrite-dir} option enables this
5849 default behavior.  To be more cautious and preserve the metadata of
5850 such a directory, use the @option{--no-overwrite-dir} option.
5851
5852 @cindex Overwriting old files, prevention
5853 @xopindex{keep-old-files, introduced}
5854 To be even more cautious and prevent existing files from being replaced, use
5855 the @option{--keep-old-files} (@option{-k}) option.  It causes
5856 @command{tar} to refuse to replace or update a file that already
5857 exists, i.e., a file with the same name as an archive member prevents
5858 extraction of that archive member.  Instead, it reports an error.  For
5859 example:
5860
5861 @example
5862 $ @kbd{ls}
5863 blues
5864 $ @kbd{tar -x -k -f archive.tar}
5865 tar: blues: Cannot open: File exists
5866 tar: Exiting with failure status due to previous errors
5867 @end example
5868
5869 @xopindex{skip-old-files, introduced}
5870 If you wish to preserve old files untouched, but don't want
5871 @command{tar} to treat them as errors, use the
5872 @option{--skip-old-files} option.  This option causes @command{tar} to
5873 silently skip extracting over existing files.
5874
5875 @xopindex{overwrite, introduced}
5876 To be more aggressive about altering existing files, use the
5877 @option{--overwrite} option.  It causes @command{tar} to overwrite
5878 existing files and to follow existing symbolic links when extracting.
5879
5880 @cindex Protecting old files
5881 Some people argue that @GNUTAR{} should not hesitate
5882 to overwrite files with other files when extracting.  When extracting
5883 a @command{tar} archive, they expect to see a faithful copy of the
5884 state of the file system when the archive was created.  It is debatable
5885 that this would always be a proper behavior.  For example, suppose one
5886 has an archive in which @file{usr/local} is a link to
5887 @file{usr/local2}.  Since then, maybe the site removed the link and
5888 renamed the whole hierarchy from @file{/usr/local2} to
5889 @file{/usr/local}.  Such things happen all the time.  I guess it would
5890 not be welcome at all that @GNUTAR{} removes the
5891 whole hierarchy just to make room for the link to be reinstated
5892 (unless it @emph{also} simultaneously restores the full
5893 @file{/usr/local2}, of course!)  @GNUTAR{} is indeed
5894 able to remove a whole hierarchy to reestablish a symbolic link, for
5895 example, but @emph{only if} @option{--recursive-unlink} is specified
5896 to allow this behavior.  In any case, single files are silently
5897 removed.
5898
5899 @xopindex{unlink-first, introduced}
5900 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5901 some cases by causing @command{tar} to remove files unconditionally
5902 before extracting them.
5903
5904 @node Overwrite Old Files
5905 @unnumberedsubsubsec Overwrite Old Files
5906
5907 @table @option
5908 @opindex overwrite
5909 @item --overwrite
5910 Overwrite existing files and directory metadata when extracting files
5911 from an archive.
5912
5913 This causes @command{tar} to write extracted files into the file system without
5914 regard to the files already on the system; i.e., files with the same
5915 names as archive members are overwritten when the archive is extracted.
5916 It also causes @command{tar} to extract the ownership, permissions,
5917 and time stamps onto any preexisting files or directories.
5918 If the name of a corresponding file name is a symbolic link, the file
5919 pointed to by the symbolic link will be overwritten instead of the
5920 symbolic link itself (if this is possible).  Moreover, special devices,
5921 empty directories and even symbolic links are automatically removed if
5922 they are in the way of extraction.
5923
5924 Be careful when using the @option{--overwrite} option, particularly when
5925 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5926 can change the contents, ownership or permissions of any file on your
5927 system.  Also, many systems do not take kindly to overwriting files that
5928 are currently being executed.
5929
5930 @opindex overwrite-dir
5931 @item --overwrite-dir
5932 Overwrite the metadata of directories when extracting files from an
5933 archive, but remove other files before extracting.
5934 @end table
5935
5936 @node Keep Old Files
5937 @unnumberedsubsubsec Keep Old Files
5938
5939 @GNUTAR{} provides two options to control its actions in a situation
5940 when it is about to extract a file which already exists on disk.
5941
5942 @table @option
5943 @opindex keep-old-files
5944 @item --keep-old-files
5945 @itemx -k
5946 Do not replace existing files from archive.  When such a file is
5947 encountered, @command{tar} issues an error message.  Upon end of
5948 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
5949
5950 @item --skip-old-files
5951 Do not replace existing files from archive, but do not treat that
5952 as error.  Such files are silently skipped and do not affect
5953 @command{tar} exit status.
5954
5955 Additional verbosity can be obtained using @option{--warning=existing-file}
5956 together with that option (@pxref{warnings}).
5957 @end table
5958
5959 @node Keep Newer Files
5960 @unnumberedsubsubsec Keep Newer Files
5961
5962 @table @option
5963 @opindex keep-newer-files
5964 @item --keep-newer-files
5965 Do not replace existing files that are newer than their archive
5966 copies.  This option is meaningless with @option{--list} (@option{-t}).
5967 @end table
5968
5969 @node Unlink First
5970 @unnumberedsubsubsec Unlink First
5971
5972 @table @option
5973 @opindex unlink-first
5974 @item --unlink-first
5975 @itemx -U
5976 Remove files before extracting over them.
5977 This can make @command{tar} run a bit faster if you know in advance
5978 that the extracted files all need to be removed.  Normally this option
5979 slows @command{tar} down slightly, so it is disabled by default.
5980 @end table
5981
5982 @node Recursive Unlink
5983 @unnumberedsubsubsec Recursive Unlink
5984
5985 @table @option
5986 @opindex recursive-unlink
5987 @item --recursive-unlink
5988 When this option is specified, try removing files and directory hierarchies
5989 before extracting over them.  @emph{This is a dangerous option!}
5990 @end table
5991
5992 If you specify the @option{--recursive-unlink} option,
5993 @command{tar} removes @emph{anything} that keeps you from extracting a file
5994 as far as current permissions will allow it.  This could include removal
5995 of the contents of a full directory hierarchy.
5996
5997 @node Data Modification Times
5998 @unnumberedsubsubsec Setting Data Modification Times
5999
6000 @cindex Data modification times of extracted files
6001 @cindex Modification times of extracted files
6002 Normally, @command{tar} sets the data modification times of extracted
6003 files to the corresponding times recorded for the files in the archive, but
6004 limits the permissions of extracted files by the current @code{umask}
6005 setting.
6006
6007 To set the data modification times of extracted files to the time when
6008 the files were extracted, use the @option{--touch} (@option{-m}) option in
6009 conjunction with @option{--extract} (@option{--get}, @option{-x}).
6010
6011 @table @option
6012 @opindex touch
6013 @item --touch
6014 @itemx -m
6015 Sets the data modification time of extracted archive members to the time
6016 they were extracted, not the time recorded for them in the archive.
6017 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
6018 @end table
6019
6020 @node Setting Access Permissions
6021 @unnumberedsubsubsec Setting Access Permissions
6022
6023 @cindex Permissions of extracted files
6024 @cindex Modes of extracted files
6025 To set the modes (access permissions) of extracted files to those
6026 recorded for those files in the archive, use @option{--same-permissions}
6027 in conjunction with the @option{--extract} (@option{--get},
6028 @option{-x}) operation.
6029
6030 @table @option
6031 @opindex preserve-permissions
6032 @opindex same-permissions
6033 @item --preserve-permissions
6034 @itemx --same-permissions
6035 @c @itemx --ignore-umask
6036 @itemx -p
6037 Set modes of extracted archive members to those recorded in the
6038 archive, instead of current umask settings.  Use in conjunction with
6039 @option{--extract} (@option{--get}, @option{-x}).
6040 @end table
6041
6042 @node Directory Modification Times and Permissions
6043 @unnumberedsubsubsec Directory Modification Times and Permissions
6044
6045 After successfully extracting a file member, @GNUTAR{} normally
6046 restores its permissions and modification times, as described in the
6047 previous sections.  This cannot be done for directories, because
6048 after extracting a directory @command{tar} will almost certainly
6049 extract files into that directory and this will cause the directory
6050 modification time to be updated.  Moreover, restoring that directory
6051 permissions may not permit file creation within it.  Thus, restoring
6052 directory permissions and modification times must be delayed at least
6053 until all files have been extracted into that directory.  @GNUTAR{}
6054 restores directories using the following approach.
6055
6056 The extracted directories are created with the mode specified in the
6057 archive, as modified by the umask of the user, which gives sufficient
6058 permissions to allow file creation.  The meta-information about the
6059 directory is recorded in the temporary list of directories.  When
6060 preparing to extract next archive member, @GNUTAR{} checks if the
6061 directory prefix of this file contains the remembered directory.  If
6062 it does not, the program assumes that all files have been extracted
6063 into that directory, restores its modification time and permissions
6064 and removes its entry from the internal list.  This approach allows
6065 to correctly restore directory meta-information in the majority of
6066 cases, while keeping memory requirements sufficiently small.  It is
6067 based on the fact, that most @command{tar} archives use the predefined
6068 order of members: first the directory, then all the files and
6069 subdirectories in that directory.
6070
6071 However, this is not always true.  The most important exception are
6072 incremental archives (@pxref{Incremental Dumps}).  The member order in
6073 an incremental archive is reversed: first all directory members are
6074 stored, followed by other (non-directory) members.  So, when extracting
6075 from incremental archives, @GNUTAR{} alters the above procedure.  It
6076 remembers all restored directories, and restores their meta-data
6077 only after the entire archive has been processed.  Notice, that you do
6078 not need to specify any special options for that, as @GNUTAR{}
6079 automatically detects archives in incremental format.
6080
6081 There may be cases, when such processing is required for normal archives
6082 too.  Consider the following example:
6083
6084 @smallexample
6085 @group
6086 $ @kbd{tar --no-recursion -cvf archive \
6087     foo foo/file1 bar bar/file foo/file2}
6088 foo/
6089 foo/file1
6090 bar/
6091 bar/file
6092 foo/file2
6093 @end group
6094 @end smallexample
6095
6096 During the normal operation, after encountering @file{bar}
6097 @GNUTAR{} will assume that all files from the directory @file{foo}
6098 were already extracted and will therefore restore its timestamp and
6099 permission bits.  However, after extracting @file{foo/file2} the
6100 directory timestamp will be offset again.
6101
6102 To correctly restore directory meta-information in such cases, use
6103 the @option{--delay-directory-restore} command line option:
6104
6105 @table @option
6106 @opindex delay-directory-restore
6107 @item --delay-directory-restore
6108 Delays restoring of the modification times and permissions of extracted
6109 directories until the end of extraction.  This way, correct
6110 meta-information is restored even if the archive has unusual member
6111 ordering.
6112
6113 @opindex no-delay-directory-restore
6114 @item --no-delay-directory-restore
6115 Cancel the effect of the previous @option{--delay-directory-restore}.
6116 Use this option if you have used @option{--delay-directory-restore} in
6117 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
6118 temporarily disable it.
6119 @end table
6120
6121 @node Writing to Standard Output
6122 @unnumberedsubsubsec Writing to Standard Output
6123
6124 @cindex Writing extracted files to standard output
6125 @cindex Standard output, writing extracted files to
6126 To write the extracted files to the standard output, instead of
6127 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
6128 conjunction with @option{--extract} (@option{--get}, @option{-x}).  This option is useful if you are
6129 extracting files to send them through a pipe, and do not need to
6130 preserve them in the file system.  If you extract multiple members,
6131 they appear on standard output concatenated, in the order they are
6132 found in the archive.
6133
6134 @table @option
6135 @opindex to-stdout
6136 @item --to-stdout
6137 @itemx -O
6138 Writes files to the standard output.  Use only in conjunction with
6139 @option{--extract} (@option{--get}, @option{-x}).  When this option is
6140 used, instead of creating the files specified, @command{tar} writes
6141 the contents of the files extracted to its standard output.  This may
6142 be useful if you are only extracting the files in order to send them
6143 through a pipe.  This option is meaningless with @option{--list}
6144 (@option{-t}).
6145 @end table
6146
6147 This can be useful, for example, if you have a tar archive containing
6148 a big file and don't want to store the file on disk before processing
6149 it.  You can use a command like this:
6150
6151 @smallexample
6152 tar -xOzf foo.tgz bigfile | process
6153 @end smallexample
6154
6155 or even like this if you want to process the concatenation of the files:
6156
6157 @smallexample
6158 tar -xOzf foo.tgz bigfile1 bigfile2 | process
6159 @end smallexample
6160
6161 However, @option{--to-command} may be more convenient for use with
6162 multiple files. See the next section.
6163
6164 @node Writing to an External Program
6165 @unnumberedsubsubsec Writing to an External Program
6166
6167 You can instruct @command{tar} to send the contents of each extracted
6168 file to the standard input of an external program:
6169
6170 @table @option
6171 @opindex to-command
6172 @item --to-command=@var{command}
6173 Extract files and pipe their contents to the standard input of
6174 @var{command}.  When this option is used, instead of creating the
6175 files specified, @command{tar} invokes @var{command} and pipes the
6176 contents of the files to its standard output.  The @var{command} may
6177 contain command line arguments (see @ref{external, Running External Commands},
6178 for more detail).
6179
6180 Notice, that @var{command} is executed once for each regular file
6181 extracted.  Non-regular files (directories, etc.)@: are ignored when this
6182 option is used.
6183 @end table
6184
6185 The command can obtain the information about the file it processes
6186 from the following environment variables:
6187
6188 @table @env
6189 @vrindex TAR_FILETYPE, to-command environment
6190 @item TAR_FILETYPE
6191 Type of the file. It is a single letter with the following meaning:
6192
6193 @multitable @columnfractions 0.10 0.90
6194 @item f @tab Regular file
6195 @item d @tab Directory
6196 @item l @tab Symbolic link
6197 @item h @tab Hard link
6198 @item b @tab Block device
6199 @item c @tab Character device
6200 @end multitable
6201
6202 Currently only regular files are supported.
6203
6204 @vrindex TAR_MODE, to-command environment
6205 @item TAR_MODE
6206 File mode, an octal number.
6207
6208 @vrindex TAR_FILENAME, to-command environment
6209 @item TAR_FILENAME
6210 The name of the file.
6211
6212 @vrindex TAR_REALNAME, to-command environment
6213 @item TAR_REALNAME
6214 Name of the file as stored in the archive.
6215
6216 @vrindex TAR_UNAME, to-command environment
6217 @item TAR_UNAME
6218 Name of the file owner.
6219
6220 @vrindex TAR_GNAME, to-command environment
6221 @item TAR_GNAME
6222 Name of the file owner group.
6223
6224 @vrindex TAR_ATIME, to-command environment
6225 @item TAR_ATIME
6226 Time of last access. It is a decimal number, representing seconds
6227 since the Epoch.  If the archive provides times with nanosecond
6228 precision, the nanoseconds are appended to the timestamp after a
6229 decimal point.
6230
6231 @vrindex TAR_MTIME, to-command environment
6232 @item TAR_MTIME
6233 Time of last modification.
6234
6235 @vrindex TAR_CTIME, to-command environment
6236 @item TAR_CTIME
6237 Time of last status change.
6238
6239 @vrindex TAR_SIZE, to-command environment
6240 @item TAR_SIZE
6241 Size of the file.
6242
6243 @vrindex TAR_UID, to-command environment
6244 @item TAR_UID
6245 UID of the file owner.
6246
6247 @vrindex TAR_GID, to-command environment
6248 @item TAR_GID
6249 GID of the file owner.
6250 @end table
6251
6252 Additionally, the following variables contain information about
6253 tar mode and the archive being processed:
6254
6255 @table @env
6256 @vrindex TAR_VERSION, to-command environment
6257 @item TAR_VERSION
6258 @GNUTAR{} version number.
6259
6260 @vrindex TAR_ARCHIVE, to-command environment
6261 @item TAR_ARCHIVE
6262 The name of the archive @command{tar} is processing.
6263
6264 @vrindex TAR_BLOCKING_FACTOR, to-command environment
6265 @item TAR_BLOCKING_FACTOR
6266 Current blocking factor (@pxref{Blocking}).
6267
6268 @vrindex TAR_VOLUME, to-command environment
6269 @item TAR_VOLUME
6270 Ordinal number of the volume @command{tar} is processing.
6271
6272 @vrindex TAR_FORMAT, to-command environment
6273 @item TAR_FORMAT
6274 Format of the archive being processed. @xref{Formats}, for a complete
6275 list of archive format names.
6276 @end table
6277
6278 These variables are defined prior to executing the command, so you can
6279 pass them as arguments, if you prefer.  For example, if the command
6280 @var{proc} takes the member name and size as its arguments, then you
6281 could do:
6282
6283 @smallexample
6284 $ @kbd{tar -x -f archive.tar \
6285        --to-command='proc $TAR_FILENAME $TAR_SIZE'}
6286 @end smallexample
6287
6288 @noindent
6289 Notice single quotes to prevent variable names from being expanded by
6290 the shell when invoking @command{tar}.
6291
6292 If @var{command} exits with a non-0 status, @command{tar} will print
6293 an error message similar to the following:
6294
6295 @smallexample
6296 tar: 2345: Child returned status 1
6297 @end smallexample
6298
6299 Here, @samp{2345} is the PID of the finished process.
6300
6301 If this behavior is not wanted, use @option{--ignore-command-error}:
6302
6303 @table @option
6304 @opindex ignore-command-error
6305 @item --ignore-command-error
6306 Ignore exit codes of subprocesses.  Notice that if the program
6307 exits on signal or otherwise terminates abnormally, the error message
6308 will be printed even if this option is used.
6309
6310 @opindex no-ignore-command-error
6311 @item --no-ignore-command-error
6312 Cancel the effect of any previous @option{--ignore-command-error}
6313 option. This option is useful if you have set
6314 @option{--ignore-command-error} in @env{TAR_OPTIONS}
6315 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
6316 @end table
6317
6318 @node remove files
6319 @unnumberedsubsubsec Removing Files
6320
6321 @FIXME{The section is too terse. Something more to add? An example,
6322 maybe?}
6323
6324 @table @option
6325 @opindex remove-files
6326 @item --remove-files
6327 Remove files after adding them to the archive.
6328 @end table
6329
6330 @node Scarce
6331 @subsection Coping with Scarce Resources
6332 @UNREVISED
6333
6334 @cindex Small memory
6335 @cindex Running out of space
6336
6337 @menu
6338 * Starting File::
6339 * Same Order::
6340 @end menu
6341
6342 @node Starting File
6343 @unnumberedsubsubsec Starting File
6344
6345 @table @option
6346 @opindex starting-file
6347 @item --starting-file=@var{name}
6348 @itemx -K @var{name}
6349 Starts an operation in the middle of an archive.  Use in conjunction
6350 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
6351 @end table
6352
6353 @cindex Middle of the archive, starting in the
6354 If a previous attempt to extract files failed due to lack of disk
6355 space, you can use @option{--starting-file=@var{name}} (@option{-K
6356 @var{name}}) to start extracting only after member @var{name} of the
6357 archive.  This assumes, of course, that there is now free space, or
6358 that you are now extracting into a different file system.  (You could
6359 also choose to suspend @command{tar}, remove unnecessary files from
6360 the file system, and then resume the same @command{tar} operation.
6361 In this case, @option{--starting-file} is not necessary.)  See also
6362 @ref{interactive}, and @ref{exclude}.
6363
6364 @node Same Order
6365 @unnumberedsubsubsec Same Order
6366
6367 @table @option
6368 @cindex Large lists of file names on small machines
6369 @opindex same-order
6370 @opindex preserve-order
6371 @item --same-order
6372 @itemx --preserve-order
6373 @itemx -s
6374 To process large lists of file names on machines with small amounts of
6375 memory.  Use in conjunction with @option{--compare} (@option{--diff},
6376 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
6377 (@option{--get}, @option{-x}).
6378 @end table
6379
6380 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
6381 names to be listed or extracted is sorted in the same order as the
6382 files in the archive.  This allows a large list of names to be used,
6383 even on a small machine that would not otherwise be able to hold all
6384 the names in memory at the same time.  Such a sorted list can easily be
6385 created by running @samp{tar -t} on the archive and editing its output.
6386
6387 This option is probably never needed on modern computer systems.
6388
6389 @node backup
6390 @section Backup options
6391
6392 @cindex backup options
6393
6394 @GNUTAR{} offers options for making backups of files
6395 before writing new versions.  These options control the details of
6396 these backups.  They may apply to the archive itself before it is
6397 created or rewritten, as well as individual extracted members.  Other
6398 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
6399 and @command{mv}, for example) offer similar options.
6400
6401 Backup options may prove unexpectedly useful when extracting archives
6402 containing many members having identical name, or when extracting archives
6403 on systems having file name limitations, making different members appear
6404 as having similar names through the side-effect of name truncation.
6405 @FIXME{This is true only if we have a good scheme for truncated backup names,
6406 which I'm not sure at all: I suspect work is needed in this area.}
6407 When any existing file is backed up before being overwritten by extraction,
6408 then clashing files are automatically be renamed to be unique, and the
6409 true name is kept for only the last file of a series of clashing files.
6410 By using verbose mode, users may track exactly what happens.
6411
6412 At the detail level, some decisions are still experimental, and may
6413 change in the future, we are waiting comments from our users.  So, please
6414 do not learn to depend blindly on the details of the backup features.
6415 For example, currently, directories themselves are never renamed through
6416 using these options, so, extracting a file over a directory still has
6417 good chances to fail.  Also, backup options apply to created archives,
6418 not only to extracted members.  For created archives, backups will not
6419 be attempted when the archive is a block or character device, or when it
6420 refers to a remote file.
6421
6422 For the sake of simplicity and efficiency, backups are made by renaming old
6423 files prior to creation or extraction, and not by copying.  The original
6424 name is restored if the file creation fails.  If a failure occurs after a
6425 partial extraction of a file, both the backup and the partially extracted
6426 file are kept.
6427
6428 @table @samp
6429 @item --backup[=@var{method}]
6430 @opindex backup
6431 @vindex VERSION_CONTROL
6432 @cindex backups
6433 Back up files that are about to be overwritten or removed.
6434 Without this option, the original versions are destroyed.
6435
6436 Use @var{method} to determine the type of backups made.
6437 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
6438 environment variable.  And if @env{VERSION_CONTROL} is not set,
6439 use the @samp{existing} method.
6440
6441 @vindex version-control @r{Emacs variable}
6442 This option corresponds to the Emacs variable @samp{version-control};
6443 the same values for @var{method} are accepted as in Emacs.  This option
6444 also allows more descriptive names.  The valid @var{method}s are:
6445
6446 @table @samp
6447 @item t
6448 @itemx numbered
6449 @cindex numbered @r{backup method}
6450 Always make numbered backups.
6451
6452 @item nil
6453 @itemx existing
6454 @cindex existing @r{backup method}
6455 Make numbered backups of files that already have them, simple backups
6456 of the others.
6457
6458 @item never
6459 @itemx simple
6460 @cindex simple @r{backup method}
6461 Always make simple backups.
6462
6463 @end table
6464
6465 @item --suffix=@var{suffix}
6466 @opindex suffix
6467 @cindex backup suffix
6468 @vindex SIMPLE_BACKUP_SUFFIX
6469 Append @var{suffix} to each backup file made with @option{--backup}.  If this
6470 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
6471 environment variable is used.  And if @env{SIMPLE_BACKUP_SUFFIX} is not
6472 set, the default is @samp{~}, just as in Emacs.
6473
6474 @end table
6475
6476 @node Applications
6477 @section Notable @command{tar} Usages
6478 @UNREVISED
6479
6480 @FIXME{Using Unix file linking capability to recreate directory
6481 structures---linking files into one subdirectory and then
6482 @command{tar}ring that directory.}
6483
6484 @FIXME{Nice hairy example using absolute-names, newer, etc.}
6485
6486 @findex uuencode
6487 You can easily use archive files to transport a group of files from
6488 one system to another: put all relevant files into an archive on one
6489 computer system, transfer the archive to another system, and extract
6490 the contents there.  The basic transfer medium might be magnetic tape,
6491 Internet FTP, or even electronic mail (though you must encode the
6492 archive with @command{uuencode} in order to transport it properly by
6493 mail).  Both machines do not have to use the same operating system, as
6494 long as they both support the @command{tar} program.
6495
6496 For example, here is how you might copy a directory's contents from
6497 one disk to another, while preserving the dates, modes, owners and
6498 link-structure of all the files therein.  In this case, the transfer
6499 medium is a @dfn{pipe}:
6500
6501 @smallexample
6502 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
6503 @end smallexample
6504
6505 @noindent
6506 You can avoid subshells by using @option{-C} option:
6507
6508 @smallexample
6509 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
6510 @end smallexample
6511
6512 @noindent
6513 The command also works using long option forms:
6514
6515 @smallexample
6516 @group
6517 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
6518        | (cd targetdir; tar --extract --file=-)}
6519 @end group
6520 @end smallexample
6521
6522 @noindent
6523 or
6524
6525 @smallexample
6526 @group
6527 $ @kbd{tar --directory sourcedir --create --file=- . \
6528        | tar --directory targetdir --extract --file=-}
6529 @end group
6530 @end smallexample
6531
6532 @noindent
6533 This is one of the easiest methods to transfer a @command{tar} archive.
6534
6535 @node looking ahead
6536 @section Looking Ahead: The Rest of this Manual
6537
6538 You have now seen how to use all eight of the operations available to
6539 @command{tar}, and a number of the possible options.  The next chapter
6540 explains how to choose and change file and archive names, how to use
6541 files to store names of other files which you can then call as
6542 arguments to @command{tar} (this can help you save time if you expect to
6543 archive the same list of files a number of times), and so forth.
6544 @FIXME{in case it's not obvious, i'm making this up in some sense
6545 based on my limited memory of what the next chapter *really* does.  i
6546 just wanted to flesh out this final section a little bit so i'd
6547 remember to stick it in here. :-)}
6548
6549 If there are too many files to conveniently list on the command line,
6550 you can list the names in a file, and @command{tar} will read that file.
6551 @xref{files}.
6552
6553 There are various ways of causing @command{tar} to skip over some files,
6554 and not archive them.  @xref{Choosing}.
6555
6556 @node Backups
6557 @chapter Performing Backups and Restoring Files
6558 @cindex backups
6559
6560 @GNUTAR{} is distributed along with the scripts for performing backups
6561 and restores.  Even if there is a good chance those scripts may be
6562 satisfying to you, they are not the only scripts or methods available for doing
6563 backups and restore.  You may well create your own, or use more
6564 sophisticated packages dedicated to that purpose.
6565
6566 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
6567 Automatic Network Disk Archiver), a backup system developed by James
6568 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
6569 This is free software, and it is available from @uref{http://www.amanda.org}.
6570
6571 @FIXME{
6572
6573 Here is a possible plan for a future documentation about the backuping
6574 scripts which are provided within the @GNUTAR{}
6575 distribution.
6576
6577 @itemize @bullet
6578 @item dumps
6579  @itemize @minus
6580  @item what are dumps
6581  @item different levels of dumps
6582   @itemize +
6583   @item full dump = dump everything
6584   @item level 1, level 2 dumps etc
6585         A level @var{n} dump dumps everything changed since the last level
6586         @var{n}-1 dump (?)
6587   @end itemize
6588  @item how to use scripts for dumps  (ie, the concept)
6589   @itemize +
6590   @item scripts to run after editing backup specs (details)
6591   @end itemize
6592  @item Backup Specs, what is it.
6593   @itemize +
6594   @item how to customize
6595   @item actual text of script  [/sp/dump/backup-specs]
6596   @end itemize
6597  @item Problems
6598   @itemize +
6599    @item rsh doesn't work
6600    @item rtape isn't installed
6601    @item (others?)
6602   @end itemize
6603  @item the @option{--incremental} option of tar
6604  @item tapes
6605   @itemize +
6606   @item write protection
6607   @item types of media, different sizes and types, useful for different things
6608   @item files and tape marks
6609      one tape mark between files, two at end.
6610   @item positioning the tape
6611      MT writes two at end of write,
6612      backspaces over one when writing again.
6613   @end itemize
6614  @end itemize
6615 @end itemize
6616 }
6617
6618 This chapter documents both the provided shell scripts and @command{tar}
6619 options which are more specific to usage as a backup tool.
6620
6621 To @dfn{back up} a file system means to create archives that contain
6622 all the files in that file system.  Those archives can then be used to
6623 restore any or all of those files (for instance if a disk crashes or a
6624 file is accidentally deleted).  File system @dfn{backups} are also
6625 called @dfn{dumps}.
6626
6627 @menu
6628 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
6629 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
6630 * Backup Levels::               Levels of Backups
6631 * Backup Parameters::           Setting Parameters for Backups and Restoration
6632 * Scripted Backups::            Using the Backup Scripts
6633 * Scripted Restoration::        Using the Restore Script
6634 @end menu
6635
6636 @node Full Dumps
6637 @section Using @command{tar} to Perform Full Dumps
6638 @UNREVISED
6639
6640 @cindex full dumps
6641 @cindex dumps, full
6642
6643 @cindex corrupted archives
6644 Full dumps should only be made when no other people or programs
6645 are modifying files in the file system.  If files are modified while
6646 @command{tar} is making the backup, they may not be stored properly in
6647 the archive, in which case you won't be able to restore them if you
6648 have to.  (Files not being modified are written with no trouble, and do
6649 not corrupt the entire archive.)
6650
6651 You will want to use the @option{--label=@var{archive-label}}
6652 (@option{-V @var{archive-label}}) option to give the archive a
6653 volume label, so you can tell what this archive is even if the label
6654 falls off the tape, or anything like that.
6655
6656 Unless the file system you are dumping is guaranteed to fit on
6657 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
6658 Make sure you have enough tapes on hand to complete the backup.
6659
6660 If you want to dump each file system separately you will need to use
6661 the @option{--one-file-system} option to prevent
6662 @command{tar} from crossing file system boundaries when storing
6663 (sub)directories.
6664
6665 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
6666 option is not needed, since this is a complete copy of everything in
6667 the file system, and a full restore from this backup would only be
6668 done onto a completely
6669 empty disk.
6670
6671 Unless you are in a hurry, and trust the @command{tar} program (and your
6672 tapes), it is a good idea to use the @option{--verify} (@option{-W})
6673 option, to make sure your files really made it onto the dump properly.
6674 This will also detect cases where the file was modified while (or just
6675 after) it was being archived.  Not all media (notably cartridge tapes)
6676 are capable of being verified, unfortunately.
6677
6678 @node Incremental Dumps
6679 @section Using @command{tar} to Perform Incremental Dumps
6680
6681 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
6682 stores additional metadata so that exact state of the file system
6683 can be restored when extracting the archive.
6684
6685 @GNUTAR{} currently offers two options for handling incremental
6686 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
6687 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
6688
6689 @xopindex{listed-incremental, described}
6690 The option @option{--listed-incremental} instructs tar to operate on
6691 an incremental archive with additional metadata stored in a standalone
6692 file, called a @dfn{snapshot file}.  The purpose of this file is to help
6693 determine which files have been changed, added or deleted since the
6694 last backup, so that the next incremental backup will contain only
6695 modified files.  The name of the snapshot file is given as an argument
6696 to the option:
6697
6698 @table @option
6699 @item --listed-incremental=@var{file}
6700 @itemx -g @var{file}
6701   Handle incremental backups with snapshot data in @var{file}.
6702 @end table
6703
6704 To create an incremental backup, you would use
6705 @option{--listed-incremental} together with @option{--create}
6706 (@pxref{create}).  For example:
6707
6708 @smallexample
6709 $ @kbd{tar --create \
6710            --file=archive.1.tar \
6711            --listed-incremental=/var/log/usr.snar \
6712            /usr}
6713 @end smallexample
6714
6715 This will create in @file{archive.1.tar} an incremental backup of
6716 the @file{/usr} file system, storing additional metadata in the file
6717 @file{/var/log/usr.snar}.  If this file does not exist, it will be
6718 created.  The created archive will then be a @dfn{level 0 backup};
6719 please see the next section for more on backup levels.
6720
6721 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6722 determines which files are modified.  In this case only these files will be
6723 stored in the archive.  Suppose, for example, that after running the
6724 above command, you delete file @file{/usr/doc/old} and create
6725 directory @file{/usr/local/db} with the following contents:
6726
6727 @smallexample
6728 $ @kbd{ls /usr/local/db}
6729 /usr/local/db/data
6730 /usr/local/db/index
6731 @end smallexample
6732
6733 Some time later you create another incremental backup.  You will
6734 then see:
6735
6736 @smallexample
6737 $ @kbd{tar --create \
6738            --file=archive.2.tar \
6739            --listed-incremental=/var/log/usr.snar \
6740            /usr}
6741 tar: usr/local/db: Directory is new
6742 usr/local/db/
6743 usr/local/db/data
6744 usr/local/db/index
6745 @end smallexample
6746
6747 @noindent
6748 The created archive @file{archive.2.tar} will contain only these
6749 three members.  This archive is called a @dfn{level 1 backup}.  Notice
6750 that @file{/var/log/usr.snar} will be updated with the new data, so if
6751 you plan to create more @samp{level 1} backups, it is necessary to
6752 create a working copy of the snapshot file before running
6753 @command{tar}.  The above example will then be modified as follows:
6754
6755 @smallexample
6756 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6757 $ @kbd{tar --create \
6758            --file=archive.2.tar \
6759            --listed-incremental=/var/log/usr.snar-1 \
6760            /usr}
6761 @end smallexample
6762
6763 @anchor{--level=0}
6764 @xopindex{level, described}
6765 You can force @samp{level 0} backups either by removing the snapshot
6766 file before running @command{tar}, or by supplying the
6767 @option{--level=0} option, e.g.:
6768
6769 @smallexample
6770 $ @kbd{tar --create \
6771            --file=archive.2.tar \
6772            --listed-incremental=/var/log/usr.snar-0 \
6773            --level=0 \
6774            /usr}
6775 @end smallexample
6776
6777 Incremental dumps depend crucially on time stamps, so the results are
6778 unreliable if you modify a file's time stamps during dumping (e.g.,
6779 with the @option{--atime-preserve=replace} option), or if you set the clock
6780 backwards.
6781
6782 @anchor{device numbers}
6783 @cindex Device numbers, using in incremental backups
6784 Metadata stored in snapshot files include device numbers, which,
6785 obviously are supposed to be non-volatile values.  However, it turns
6786 out that @acronym{NFS} devices have undependable values when an automounter
6787 gets in the picture.  This can lead to a great deal of spurious
6788 redumping in incremental dumps, so it is somewhat useless to compare
6789 two @acronym{NFS} devices numbers over time.  The solution implemented
6790 currently is to consider all @acronym{NFS} devices as being equal
6791 when it comes to comparing directories; this is fairly gross, but
6792 there does not seem to be a better way to go.
6793
6794 Apart from using @acronym{NFS}, there are a number of cases where
6795 relying on device numbers can cause spurious redumping of unmodified
6796 files.  For example, this occurs when archiving @acronym{LVM} snapshot
6797 volumes.  To avoid this, use @option{--no-check-device} option:
6798
6799 @table @option
6800 @xopindex{no-check-device, described}
6801 @item --no-check-device
6802 Do not rely on device numbers when preparing a list of changed files
6803 for an incremental dump.
6804
6805 @xopindex{check-device, described}
6806 @item --check-device
6807 Use device numbers when preparing a list of changed files
6808 for an incremental dump.  This is the default behavior.  The purpose
6809 of this option is to undo the effect of the @option{--no-check-device}
6810 if it was given in @env{TAR_OPTIONS} environment variable
6811 (@pxref{TAR_OPTIONS}).
6812 @end table
6813
6814 There is also another way to cope with changing device numbers.  It is
6815 described in detail in @ref{Fixing Snapshot Files}.
6816
6817 Note that incremental archives use @command{tar} extensions and may
6818 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6819
6820 @xopindex{listed-incremental, using with @option{--extract}}
6821 @xopindex{extract, using with @option{--listed-incremental}}
6822 To extract from the incremental dumps, use
6823 @option{--listed-incremental} together with @option{--extract}
6824 option (@pxref{extracting files}).  In this case, @command{tar} does
6825 not need to access snapshot file, since all the data necessary for
6826 extraction are stored in the archive itself.  So, when extracting, you
6827 can give whatever argument to @option{--listed-incremental}, the usual
6828 practice is to use @option{--listed-incremental=/dev/null}.
6829 Alternatively, you can use @option{--incremental}, which needs no
6830 arguments.  In general, @option{--incremental} (@option{-G}) can be
6831 used as a shortcut for @option{--listed-incremental} when listing or
6832 extracting incremental backups (for more information regarding this
6833 option, @pxref{incremental-op}).
6834
6835 When extracting from the incremental backup @GNUTAR{} attempts to
6836 restore the exact state the file system had when the archive was
6837 created.  In particular, it will @emph{delete} those files in the file
6838 system that did not exist in their directories when the archive was
6839 created.  If you have created several levels of incremental files,
6840 then in order to restore the exact contents the file system  had when
6841 the last level was created, you will need to restore from all backups
6842 in turn.  Continuing our example, to restore the state of @file{/usr}
6843 file system, one would do@footnote{Notice, that since both archives
6844 were created without @option{-P} option (@pxref{absolute}), these
6845 commands should be run from the root file system.}:
6846
6847 @smallexample
6848 $ @kbd{tar --extract \
6849            --listed-incremental=/dev/null \
6850            --file archive.1.tar}
6851 $ @kbd{tar --extract \
6852            --listed-incremental=/dev/null \
6853            --file archive.2.tar}
6854 @end smallexample
6855
6856 To list the contents of an incremental archive, use @option{--list}
6857 (@pxref{list}), as usual.  To obtain more information about the
6858 archive, use @option{--listed-incremental} or @option{--incremental}
6859 combined with two @option{--verbose} options@footnote{Two
6860 @option{--verbose} options were selected to avoid breaking usual
6861 verbose listing output (@option{--list --verbose}) when using in
6862 scripts.
6863
6864 @xopindex{incremental, using with @option{--list}}
6865 @xopindex{listed-incremental, using with @option{--list}}
6866 @xopindex{list, using with @option{--incremental}}
6867 @xopindex{list, using with @option{--listed-incremental}}
6868 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6869 contents of the DUMPDIR header (with terminating nulls) when
6870 @option{--incremental} or @option{--listed-incremental} option was
6871 given, no matter what the verbosity level.  This behavior, and,
6872 especially, the binary output it produced were considered inconvenient
6873 and were changed in version 1.16.}:
6874
6875 @smallexample
6876 @kbd{tar --list --incremental --verbose --verbose --file archive.tar}
6877 @end smallexample
6878
6879 This command will print, for each directory in the archive, the list
6880 of files in that directory at the time the archive was created.  This
6881 information is put out in a format which is both human-readable and
6882 unambiguous for a program: each file name is printed as
6883
6884 @smallexample
6885 @var{x} @var{file}
6886 @end smallexample
6887
6888 @noindent
6889 where @var{x} is a letter describing the status of the file: @samp{Y}
6890 if the file  is present in the archive, @samp{N} if the file is not
6891 included in the archive, or a @samp{D} if the file is a directory (and
6892 is included in the archive).  @xref{Dumpdir}, for the detailed
6893 description of dumpdirs and status codes.  Each such
6894 line is terminated by a newline character.  The last line is followed
6895 by an additional newline to indicate the end of the data.
6896
6897 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6898 gives the same behavior as @option{--listed-incremental} when used
6899 with @option{--list} and @option{--extract} options.  When used with
6900 @option{--create} option, it creates an incremental archive without
6901 creating snapshot file.  Thus, it is impossible to create several
6902 levels of incremental backups with @option{--incremental} option.
6903
6904 @node Backup Levels
6905 @section Levels of Backups
6906
6907 An archive containing all the files in the file system is called a
6908 @dfn{full backup} or @dfn{full dump}.  You could insure your data by
6909 creating a full dump every day.  This strategy, however, would waste a
6910 substantial amount of archive media and user time, as unchanged files
6911 are daily re-archived.
6912
6913 It is more efficient to do a full dump only occasionally.  To back up
6914 files between full dumps, you can use @dfn{incremental dumps}.  A @dfn{level
6915 one} dump archives all the files that have changed since the last full
6916 dump.
6917
6918 A typical dump strategy would be to perform a full dump once a week,
6919 and a level one dump once a day.  This means some versions of files
6920 will in fact be archived more than once, but this dump strategy makes
6921 it possible to restore a file system to within one day of accuracy by
6922 only extracting two archives---the last weekly (full) dump and the
6923 last daily (level one) dump.  The only information lost would be in
6924 files changed or created since the last daily backup.  (Doing dumps
6925 more than once a day is usually not worth the trouble.)
6926
6927 @GNUTAR{} comes with scripts you can use to do full
6928 and level-one (actually, even level-two and so on) dumps.  Using
6929 scripts (shell programs) to perform backups and restoration is a
6930 convenient and reliable alternative to typing out file name lists
6931 and @command{tar} commands by hand.
6932
6933 Before you use these scripts, you need to edit the file
6934 @file{backup-specs}, which specifies parameters used by the backup
6935 scripts and by the restore script.  This file is usually located
6936 in @file{/etc/backup} directory.  @xref{Backup Parameters}, for its
6937 detailed description.  Once the backup parameters are set, you can
6938 perform backups or restoration by running the appropriate script.
6939
6940 The name of the backup script is @code{backup}.  The name of the
6941 restore script is @code{restore}.  The following sections describe
6942 their use in detail.
6943
6944 @emph{Please Note:} The backup and restoration scripts are
6945 designed to be used together.  While it is possible to restore files by
6946 hand from an archive which was created using a backup script, and to create
6947 an archive by hand which could then be extracted using the restore script,
6948 it is easier to use the scripts.  @xref{Incremental Dumps}, before
6949 making such an attempt.
6950
6951 @node Backup Parameters
6952 @section Setting Parameters for Backups and Restoration
6953
6954 The file @file{backup-specs} specifies backup parameters for the
6955 backup and restoration scripts provided with @command{tar}.  You must
6956 edit @file{backup-specs} to fit your system configuration and schedule
6957 before using these scripts.
6958
6959 Syntactically, @file{backup-specs} is a shell script, containing
6960 mainly variable assignments.  However, any valid shell construct
6961 is allowed in this file.  Particularly, you may wish to define
6962 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6963 For more information about shell script syntax, please refer to
6964 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6965 g_02, the definition of the Shell Command Language}.  See also
6966 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6967
6968 The shell variables controlling behavior of @code{backup} and
6969 @code{restore} are described in the following subsections.
6970
6971 @menu
6972 * General-Purpose Variables::
6973 * Magnetic Tape Control::
6974 * User Hooks::
6975 * backup-specs example::        An Example Text of @file{Backup-specs}
6976 @end menu
6977
6978 @node General-Purpose Variables
6979 @subsection General-Purpose Variables
6980
6981 @defvr {Backup variable} ADMINISTRATOR
6982 The user name of the backup administrator.  @code{Backup} scripts
6983 sends a backup report to this address.
6984 @end defvr
6985
6986 @defvr {Backup variable} BACKUP_HOUR
6987 The hour at which the backups are done.  This can be a number from 0
6988 to 23, or the time specification in form @var{hours}:@var{minutes},
6989 or the string @samp{now}.
6990
6991 This variable is used by @code{backup}.  Its value may be overridden
6992 using @option{--time} option (@pxref{Scripted Backups}).
6993 @end defvr
6994
6995 @defvr {Backup variable} TAPE_FILE
6996
6997 The device @command{tar} writes the archive to.  If @var{TAPE_FILE}
6998 is a remote archive (@pxref{remote-dev}), backup script will suppose
6999 that your @command{mt} is able to access remote devices.  If @var{RSH}
7000 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
7001 invocations of @command{mt}.
7002 @end defvr
7003
7004 @defvr {Backup variable} BLOCKING
7005
7006 The blocking factor @command{tar} will use when writing the dump archive.
7007 @xref{Blocking Factor}.
7008 @end defvr
7009
7010 @defvr {Backup variable} BACKUP_DIRS
7011
7012 A list of file systems to be dumped (for @code{backup}), or restored
7013 (for @code{restore}).  You can include any directory
7014 name in the list --- subdirectories on that file system will be
7015 included, regardless of how they may look to other networked machines.
7016 Subdirectories on other file systems will be ignored.
7017
7018 The host name specifies which host to run @command{tar} on, and should
7019 normally be the host that actually contains the file system.  However,
7020 the host machine must have @GNUTAR{} installed, and
7021 must be able to access the directory containing the backup scripts and
7022 their support files using the same file name that is used on the
7023 machine where the scripts are run (i.e., what @command{pwd} will print
7024 when in that directory on that machine).  If the host that contains
7025 the file system does not have this capability, you can specify another
7026 host as long as it can access the file system through @acronym{NFS}.
7027
7028 If the list of file systems is very long you may wish to put it
7029 in a separate file.  This file is usually named
7030 @file{/etc/backup/dirs}, but this name may be overridden in
7031 @file{backup-specs} using @code{DIRLIST} variable.
7032 @end defvr
7033
7034 @defvr {Backup variable} DIRLIST
7035
7036 The name of the file that contains a list of file systems to backup
7037 or restore.  By default it is @file{/etc/backup/dirs}.
7038 @end defvr
7039
7040 @defvr {Backup variable} BACKUP_FILES
7041
7042 A list of individual files to be dumped (for @code{backup}), or restored
7043 (for @code{restore}).  These should be accessible from the machine on
7044 which the backup script is run.
7045
7046 If the list of individual files is very long you may wish to store it
7047 in a separate file.  This file is usually named
7048 @file{/etc/backup/files}, but this name may be overridden in
7049 @file{backup-specs} using @code{FILELIST} variable.
7050 @end defvr
7051
7052 @defvr {Backup variable} FILELIST
7053
7054 The name of the file that contains a list of individual files to backup
7055 or restore.  By default it is @file{/etc/backup/files}.
7056 @end defvr
7057
7058 @defvr {Backup variable} MT
7059
7060 Full file name of @command{mt} binary.
7061 @end defvr
7062
7063 @defvr {Backup variable} RSH
7064 @anchor{RSH}
7065 Full file name of @command{rsh} binary or its equivalent.  You may wish to
7066 set it to @code{ssh}, to improve security.  In this case you will have
7067 to use public key authentication.
7068 @end defvr
7069
7070 @defvr {Backup variable} RSH_COMMAND
7071
7072 Full file name of @command{rsh} binary on remote machines.  This will
7073 be passed via @option{--rsh-command} option to the remote invocation
7074 of @GNUTAR{}.
7075 @end defvr
7076
7077 @defvr {Backup variable} VOLNO_FILE
7078
7079 Name of temporary file to hold volume numbers.  This needs to be accessible
7080 by all the machines which have file systems to be dumped.
7081 @end defvr
7082
7083 @defvr {Backup variable} XLIST
7084
7085 Name of @dfn{exclude file list}.  An @dfn{exclude file list} is a file
7086 located on the remote machine and containing the list of files to
7087 be excluded from the backup.  Exclude file lists are searched in
7088 /etc/tar-backup directory.  A common use for exclude file lists
7089 is to exclude files containing security-sensitive information
7090 (e.g., @file{/etc/shadow} from backups).
7091
7092 This variable affects only @code{backup}.
7093 @end defvr
7094
7095 @defvr {Backup variable} SLEEP_TIME
7096
7097 Time to sleep between dumps of any two successive file systems
7098
7099 This variable affects only @code{backup}.
7100 @end defvr
7101
7102 @defvr {Backup variable} DUMP_REMIND_SCRIPT
7103
7104 Script to be run when it's time to insert a new tape in for the next
7105 volume.  Administrators may want to tailor this script for their site.
7106 If this variable isn't set, @GNUTAR{} will display its built-in
7107 prompt, and will expect confirmation from the console.  For the
7108 description of the default prompt, see @ref{change volume prompt}.
7109
7110 @end defvr
7111
7112 @defvr {Backup variable} SLEEP_MESSAGE
7113
7114 Message to display on the terminal while waiting for dump time.  Usually
7115 this will just be some literal text.
7116 @end defvr
7117
7118 @defvr {Backup variable} TAR
7119
7120 Full file name of the @GNUTAR{} executable.  If this is not set, backup
7121 scripts will search @command{tar} in the current shell path.
7122 @end defvr
7123
7124 @node Magnetic Tape Control
7125 @subsection Magnetic Tape Control
7126
7127 Backup scripts access tape device using special @dfn{hook functions}.
7128 These functions take a single argument --- the name of the tape
7129 device.  Their names are kept in the following variables:
7130
7131 @defvr {Backup variable} MT_BEGIN
7132 The name of @dfn{begin} function.  This function is called before
7133 accessing the drive.  By default it retensions the tape:
7134
7135 @smallexample
7136 MT_BEGIN=mt_begin
7137
7138 mt_begin() @{
7139     mt -f "$1" retension
7140 @}
7141 @end smallexample
7142 @end defvr
7143
7144 @defvr {Backup variable} MT_REWIND
7145 The name of @dfn{rewind} function.  The default definition is as
7146 follows:
7147
7148 @smallexample
7149 MT_REWIND=mt_rewind
7150
7151 mt_rewind() @{
7152     mt -f "$1" rewind
7153 @}
7154 @end smallexample
7155
7156 @end defvr
7157
7158 @defvr {Backup variable} MT_OFFLINE
7159 The name of the function switching the tape off line.  By default
7160 it is defined as follows:
7161
7162 @smallexample
7163 MT_OFFLINE=mt_offline
7164
7165 mt_offline() @{
7166     mt -f "$1" offl
7167 @}
7168 @end smallexample
7169 @end defvr
7170
7171 @defvr {Backup variable} MT_STATUS
7172 The name of the function used to obtain the status of the archive device,
7173 including error count.  Default definition:
7174
7175 @smallexample
7176 MT_STATUS=mt_status
7177
7178 mt_status() @{
7179     mt -f "$1" status
7180 @}
7181 @end smallexample
7182 @end defvr
7183
7184 @node User Hooks
7185 @subsection User Hooks
7186
7187 @dfn{User hooks} are shell functions executed before and after
7188 each @command{tar} invocation.  Thus, there are @dfn{backup
7189 hooks}, which are executed before and after dumping each file
7190 system, and @dfn{restore hooks}, executed before and
7191 after restoring a file system.  Each user hook is a shell function
7192 taking four arguments:
7193
7194 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
7195 Its arguments are:
7196
7197 @table @var
7198 @item level
7199 Current backup or restore level.
7200
7201 @item host
7202 Name or IP address of the host machine being dumped or restored.
7203
7204 @item fs
7205 Full file name of the file system being dumped or restored.
7206
7207 @item fsname
7208 File system name with directory separators replaced with colons.  This
7209 is useful, e.g., for creating unique files.
7210 @end table
7211 @end deffn
7212
7213 Following variables keep the names of user hook functions:
7214
7215 @defvr {Backup variable} DUMP_BEGIN
7216 Dump begin function.  It is executed before dumping the file system.
7217 @end defvr
7218
7219 @defvr {Backup variable} DUMP_END
7220 Executed after dumping the file system.
7221 @end defvr
7222
7223 @defvr {Backup variable} RESTORE_BEGIN
7224 Executed before restoring the file system.
7225 @end defvr
7226
7227 @defvr {Backup variable} RESTORE_END
7228 Executed after restoring the file system.
7229 @end defvr
7230
7231 @node backup-specs example
7232 @subsection An Example Text of @file{Backup-specs}
7233
7234 The following is an example of @file{backup-specs}:
7235
7236 @smallexample
7237 # site-specific parameters for file system backup.
7238
7239 ADMINISTRATOR=friedman
7240 BACKUP_HOUR=1
7241 TAPE_FILE=/dev/nrsmt0
7242
7243 # Use @code{ssh} instead of the less secure @code{rsh}
7244 RSH=/usr/bin/ssh
7245 RSH_COMMAND=/usr/bin/ssh
7246
7247 # Override MT_STATUS function:
7248 my_status() @{
7249       mts -t $TAPE_FILE
7250 @}
7251 MT_STATUS=my_status
7252
7253 # Disable MT_OFFLINE function
7254 MT_OFFLINE=:
7255
7256 BLOCKING=124
7257 BACKUP_DIRS="
7258         albert:/fs/fsf
7259         apple-gunkies:/gd
7260         albert:/fs/gd2
7261         albert:/fs/gp
7262         geech:/usr/jla
7263         churchy:/usr/roland
7264         albert:/
7265         albert:/usr
7266         apple-gunkies:/
7267         apple-gunkies:/usr
7268         gnu:/hack
7269         gnu:/u
7270         apple-gunkies:/com/mailer/gnu
7271         apple-gunkies:/com/archive/gnu"
7272
7273 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
7274
7275 @end smallexample
7276
7277 @node Scripted Backups
7278 @section Using the Backup Scripts
7279
7280 The syntax for running a backup script is:
7281
7282 @smallexample
7283 backup --level=@var{level} --time=@var{time}
7284 @end smallexample
7285
7286 The @option{--level} option requests the dump level.  Thus, to produce
7287 a full dump, specify @code{--level=0} (this is the default, so
7288 @option{--level} may be omitted if its value is
7289 @code{0})@footnote{For backward compatibility, the @code{backup} will also
7290 try to deduce the requested dump level from the name of the
7291 script itself.  If the name consists of a string @samp{level-}
7292 followed by a single decimal digit, that digit is taken as
7293 the dump level number.  Thus, you may create a link from @code{backup}
7294 to @code{level-1} and then run @code{level-1} whenever you need to
7295 create a level one dump.}.
7296
7297 The @option{--time} option determines when should the backup be
7298 run.  @var{Time} may take three forms:
7299
7300 @table @asis
7301 @item @var{hh}:@var{mm}
7302
7303 The dump must be run at @var{hh} hours @var{mm} minutes.
7304
7305 @item @var{hh}
7306
7307 The dump must be run at @var{hh} hours.
7308
7309 @item now
7310
7311 The dump must be run immediately.
7312 @end table
7313
7314 You should start a script with a tape or disk mounted.  Once you
7315 start a script, it prompts you for new tapes or disks as it
7316 needs them.  Media volumes don't have to correspond to archive
7317 files --- a multi-volume archive can be started in the middle of a
7318 tape that already contains the end of another multi-volume archive.
7319 The @code{restore} script prompts for media by its archive volume,
7320 so to avoid an error message you should keep track of which tape
7321 (or disk) contains which volume of the archive (@pxref{Scripted
7322 Restoration}).
7323
7324 The backup scripts write two files on the file system.  The first is a
7325 record file in @file{/etc/tar-backup/}, which is used by the scripts
7326 to store and retrieve information about which files were dumped.  This
7327 file is not meant to be read by humans, and should not be deleted by
7328 them.  @xref{Snapshot Files}, for a more detailed explanation of this
7329 file.
7330
7331 The second file is a log file containing the names of the file systems
7332 and files dumped, what time the backup was made, and any error
7333 messages that were generated, as well as how much space was left in
7334 the media volume after the last volume of the archive was written.
7335 You should check this log file after every backup.  The file name is
7336 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
7337 represents current date, and @var{n} represents current dump level number.
7338
7339 The script also prints the name of each system being dumped to the
7340 standard output.
7341
7342 Following is the full list of options accepted by @code{backup}
7343 script:
7344
7345 @table @option
7346 @item -l @var{level}
7347 @itemx --level=@var{level}
7348 Do backup level @var{level} (default 0).
7349
7350 @item -f
7351 @itemx --force
7352 Force backup even if today's log file already exists.
7353
7354 @item -v[@var{level}]
7355 @itemx --verbose[=@var{level}]
7356 Set verbosity level.  The higher the level is, the more debugging
7357 information will be output during execution.  Default @var{level}
7358 is 100, which means the highest debugging level.
7359
7360 @item -t @var{start-time}
7361 @itemx --time=@var{start-time}
7362 Wait till @var{time}, then do backup.
7363
7364 @item -h
7365 @itemx --help
7366 Display short help message and exit.
7367
7368 @item -V
7369 @itemx --version
7370 Display information about the program's name, version, origin and legal
7371 status, all on standard output, and then exit successfully.
7372 @end table
7373
7374
7375 @node Scripted Restoration
7376 @section Using the Restore Script
7377
7378 To restore files that were archived using a scripted backup, use the
7379 @code{restore} script.  Its usage is quite straightforward.  In the
7380 simplest form, invoke @code{restore --all}, it will
7381 then restore all the file systems and files specified in
7382 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
7383
7384 You may select the file systems (and/or files) to restore by
7385 giving @code{restore} a list of @dfn{patterns} in its command
7386 line.  For example, running
7387
7388 @smallexample
7389 restore 'albert:*'
7390 @end smallexample
7391
7392 @noindent
7393 will restore all file systems on the machine @samp{albert}.  A more
7394 complicated example:
7395
7396 @smallexample
7397 restore 'albert:*' '*:/var'
7398 @end smallexample
7399
7400 @noindent
7401 This command will restore all file systems on the machine @samp{albert}
7402 as well as @file{/var} file system on all machines.
7403
7404 By default @code{restore} will start restoring files from the lowest
7405 available dump level (usually zero) and will continue through
7406 all available dump levels.  There may be situations where such a
7407 thorough restore is not necessary.  For example, you may wish to
7408 restore only files from the recent level one backup.  To do so,
7409 use @option{--level} option, as shown in the example below:
7410
7411 @smallexample
7412 restore --level=1
7413 @end smallexample
7414
7415 The full list of options accepted by @code{restore} follows:
7416
7417 @table @option
7418 @item -a
7419 @itemx --all
7420 Restore all file systems and files specified in @file{backup-specs}.
7421
7422 @item -l @var{level}
7423 @itemx --level=@var{level}
7424 Start restoring from the given backup level, instead of the default 0.
7425
7426 @item -v[@var{level}]
7427 @itemx --verbose[=@var{level}]
7428 Set verbosity level.  The higher the level is, the more debugging
7429 information will be output during execution.  Default @var{level}
7430 is 100, which means the highest debugging level.
7431
7432 @item -h
7433 @itemx --help
7434 Display short help message and exit.
7435
7436 @item -V
7437 @itemx --version
7438 Display information about the program's name, version, origin and legal
7439 status, all on standard output, and then exit successfully.
7440 @end table
7441
7442 You should start the restore script with the media containing the
7443 first volume of the archive mounted.  The script will prompt for other
7444 volumes as they are needed.  If the archive is on tape, you don't need
7445 to rewind the tape to to its beginning---if the tape head is
7446 positioned past the beginning of the archive, the script will rewind
7447 the tape as needed.  @xref{Tape Positioning}, for a discussion of tape
7448 positioning.
7449
7450 @quotation
7451 @strong{Warning:} The script will delete files from the active file
7452 system if they were not in the file system when the archive was made.
7453 @end quotation
7454
7455 @xref{Incremental Dumps}, for an explanation of how the script makes
7456 that determination.
7457
7458 @node Choosing
7459 @chapter Choosing Files and Names for @command{tar}
7460
7461 Certain options to @command{tar} enable you to specify a name for your
7462 archive.  Other options let you decide which files to include or exclude
7463 from the archive, based on when or whether files were modified, whether
7464 the file names do or don't match specified patterns, or whether files
7465 are in specified directories.
7466
7467 This chapter discusses these options in detail.
7468
7469 @menu
7470 * file::                        Choosing the Archive's Name
7471 * Selecting Archive Members::
7472 * files::                       Reading Names from a File
7473 * exclude::                     Excluding Some Files
7474 * wildcards::                   Wildcards Patterns and Matching
7475 * quoting styles::              Ways of Quoting Special Characters in Names
7476 * transform::                   Modifying File and Member Names
7477 * after::                       Operating Only on New Files
7478 * recurse::                     Descending into Directories
7479 * one::                         Crossing File System Boundaries
7480 @end menu
7481
7482 @node file
7483 @section Choosing and Naming Archive Files
7484
7485 @cindex Naming an archive
7486 @cindex Archive Name
7487 @cindex Choosing an archive file
7488 @cindex Where is the archive?
7489 @opindex file
7490 By default, @command{tar} uses an archive file name that was compiled when
7491 it was built on the system; usually this name refers to some physical
7492 tape drive on the machine.  However, the person who installed @command{tar}
7493 on the system may not have set the default to a meaningful value as far as
7494 most users are concerned.  As a result, you will usually want to tell
7495 @command{tar} where to find (or create) the archive.  The
7496 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
7497 option allows you to either specify or name a file to use as the archive
7498 instead of the default archive file location.
7499
7500 @table @option
7501 @xopindex{file, short description}
7502 @item --file=@var{archive-name}
7503 @itemx -f @var{archive-name}
7504 Name the archive to create or operate on.  Use in conjunction with
7505 any operation.
7506 @end table
7507
7508 For example, in this @command{tar} command,
7509
7510 @smallexample
7511 $ @kbd{tar -cvf collection.tar blues folk jazz}
7512 @end smallexample
7513
7514 @noindent
7515 @file{collection.tar} is the name of the archive.  It must directly
7516 follow the @option{-f} option, since whatever directly follows @option{-f}
7517 @emph{will} end up naming the archive.  If you neglect to specify an
7518 archive name, you may end up overwriting a file in the working directory
7519 with the archive you create since @command{tar} will use this file's name
7520 for the archive name.
7521
7522 An archive can be saved as a file in the file system, sent through a
7523 pipe or over a network, or written to an I/O device such as a tape,
7524 floppy disk, or CD write drive.
7525
7526 @cindex Writing new archives
7527 @cindex Archive creation
7528 If you do not name the archive, @command{tar} uses the value of the
7529 environment variable @env{TAPE} as the file name for the archive.  If
7530 that is not available, @command{tar} uses a default, compiled-in archive
7531 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
7532
7533 @cindex Standard input and output
7534 @cindex tar to standard input and output
7535 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
7536 archive from standard input (when listing or extracting files), or
7537 writes it to standard output (when creating an archive).  If you use
7538 @file{-} as an @var{archive-name} when modifying an archive,
7539 @command{tar} reads the original archive from its standard input and
7540 writes the entire new archive to its standard output.
7541
7542 The following example is a convenient way of copying directory
7543 hierarchy from @file{sourcedir} to @file{targetdir}.
7544
7545 @smallexample
7546 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
7547 @end smallexample
7548
7549 The @option{-C} option allows to avoid using subshells:
7550
7551 @smallexample
7552 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
7553 @end smallexample
7554
7555 In both examples above, the leftmost @command{tar} invocation archives
7556 the contents of @file{sourcedir} to the standard output, while the
7557 rightmost one reads this archive from its standard input and
7558 extracts it.  The @option{-p} option tells it to restore permissions
7559 of the extracted files.
7560
7561 @cindex Remote devices
7562 @cindex tar to a remote device
7563 @anchor{remote-dev}
7564 To specify an archive file on a device attached to a remote machine,
7565 use the following:
7566
7567 @smallexample
7568 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
7569 @end smallexample
7570
7571 @noindent
7572 @command{tar} will set up the remote connection, if possible, and
7573 prompt you for a username and password.  If you use
7574 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
7575 will attempt to set up the remote connection using your username
7576 as the username on the remote machine.
7577
7578 @cindex Local and remote archives
7579 @anchor{local and remote archives}
7580 If the archive file name includes a colon (@samp{:}), then it is assumed
7581 to be a file on another machine.  If the archive file is
7582 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
7583 host @var{host}.  The remote host is accessed using the @command{rsh}
7584 program, with a username of @var{user}.  If the username is omitted
7585 (along with the @samp{@@} sign), then your user name will be used.
7586 (This is the normal @command{rsh} behavior.)  It is necessary for the
7587 remote machine, in addition to permitting your @command{rsh} access, to
7588 have the @file{rmt} program installed (this command is included in
7589 the @GNUTAR{} distribution and by default is installed under
7590 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
7591 installation prefix).  If you need to use a file whose name includes a
7592 colon, then the remote tape drive behavior
7593 can be inhibited by using the @option{--force-local} option.
7594
7595 When the archive is being created to @file{/dev/null}, @GNUTAR{}
7596 tries to minimize input and output operations.  The Amanda backup
7597 system, when used with @GNUTAR{}, has an initial sizing pass which
7598 uses this feature.
7599
7600 @node Selecting Archive Members
7601 @section Selecting Archive Members
7602 @cindex Specifying files to act on
7603 @cindex Specifying archive members
7604
7605 @dfn{File Name arguments} specify which files in the file system
7606 @command{tar} operates on, when creating or adding to an archive, or which
7607 archive members @command{tar} operates on, when reading or deleting from
7608 an archive.  @xref{Operations}.
7609
7610 To specify file names, you can include them as the last arguments on
7611 the command line, as follows:
7612 @smallexample
7613 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
7614 @end smallexample
7615
7616 If a file name begins with dash (@samp{-}), precede it with
7617 @option{--add-file} option to prevent it from being treated as an
7618 option.
7619
7620 @anchor{input name quoting}
7621 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
7622 name, replacing @dfn{escape sequences} according to the following
7623 table:
7624
7625 @multitable @columnfractions 0.20 0.60
7626 @headitem Escape @tab Replaced with
7627 @item \a         @tab Audible bell (@acronym{ASCII} 7)
7628 @item \b         @tab Backspace (@acronym{ASCII} 8)
7629 @item \f         @tab Form feed (@acronym{ASCII} 12)
7630 @item \n         @tab New line (@acronym{ASCII} 10)
7631 @item \r         @tab Carriage return (@acronym{ASCII} 13)
7632 @item \t         @tab Horizontal tabulation (@acronym{ASCII} 9)
7633 @item \v         @tab Vertical tabulation (@acronym{ASCII} 11)
7634 @item \?         @tab @acronym{ASCII} 127
7635 @item \@var{n}   @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
7636                  of up to 3 digits)
7637 @end multitable
7638
7639 A backslash followed by any other symbol is retained.
7640
7641 This default behavior is controlled by the following command line
7642 option:
7643
7644 @table @option
7645 @opindex unquote
7646 @item --unquote
7647 Enable unquoting input file or member names (default).
7648
7649 @opindex no-unquote
7650 @item --no-unquote
7651 Disable unquoting input file or member names.
7652 @end table
7653
7654 If you specify a directory name as a file name argument, all the files
7655 in that directory are operated on by @command{tar}.
7656
7657 If you do not specify files, @command{tar} behavior differs depending
7658 on the operation mode as described below:
7659
7660 When @command{tar} is invoked with @option{--create} (@option{-c}),
7661 @command{tar} will stop immediately, reporting the following:
7662
7663 @smallexample
7664 @group
7665 $ @kbd{tar cf a.tar}
7666 tar: Cowardly refusing to create an empty archive
7667 Try 'tar --help' or 'tar --usage' for more information.
7668 @end group
7669 @end smallexample
7670
7671 If you specify either @option{--list} (@option{-t}) or
7672 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
7673 operates on all the archive members in the archive.
7674
7675 If run with @option{--diff} option, tar will compare the archive with
7676 the contents of the current working directory.
7677
7678 If you specify any other operation, @command{tar} does nothing.
7679
7680 By default, @command{tar} takes file names from the command line.  However,
7681 there are other ways to specify file or member names, or to modify the
7682 manner in which @command{tar} selects the files or members upon which to
7683 operate.  In general, these methods work both for specifying the names
7684 of files and archive members.
7685
7686 @node files
7687 @section Reading Names from a File
7688
7689 @cindex Reading file names from a file
7690 @cindex Lists of file names
7691 @cindex File Name arguments, alternatives
7692 @cindex @command{find}, using with @command{tar}
7693 Instead of giving the names of files or archive members on the command
7694 line, you can put the names into a file, and then use the
7695 @option{--files-from=@var{file-of-names}} (@option{-T
7696 @var{file-of-names}}) option to @command{tar}.  Give the name of the
7697 file which contains the list of files to include as the argument to
7698 @option{--files-from}.  In the list, the file names should be separated by
7699 newlines.  You will frequently use this option when you have generated
7700 the list of files to archive with the @command{find} utility.
7701
7702 @table @option
7703 @opindex files-from
7704 @item --files-from=@var{file-name}
7705 @itemx -T @var{file-name}
7706 Get names to extract or create from file @var{file-name}.
7707 @end table
7708
7709 If you give a single dash as a file name for @option{--files-from}, (i.e.,
7710 you specify either @code{--files-from=-} or @code{-T -}), then the file
7711 names are read from standard input.
7712
7713 Unless you are running @command{tar} with @option{--create}, you cannot use
7714 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
7715 command.
7716
7717 Any number of @option{-T} options can be given in the command line.
7718
7719 The following example shows how to use @command{find} to generate a list of
7720 files smaller than 400K in length and put that list into a file
7721 called @file{small-files}.  You can then use the @option{-T} option to
7722 @command{tar} to specify the files from that file, @file{small-files}, to
7723 create the archive @file{little.tgz}.  (The @option{-z} option to
7724 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7725 more information.)
7726
7727 @smallexample
7728 $ @kbd{find . -size -400 -print > small-files}
7729 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7730 @end smallexample
7731
7732 @noindent
7733 By default, each line read from the file list is first stripped off
7734 any leading and trailing whitespace.  If the resulting string begins
7735 with @samp{-} character, it is considered a @command{tar} option and is
7736 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7737 recognized only @option{-C} option in file lists, and only if the
7738 option and its argument occupied two consecutive lines.}. For example,
7739 the common use of this feature is to change to another directory by
7740 specifying @option{-C} option:
7741
7742 @smallexample
7743 @group
7744 $ @kbd{cat list}
7745 -C/etc
7746 passwd
7747 hosts
7748 -C/lib
7749 libc.a
7750 $ @kbd{tar -c -f foo.tar --files-from list}
7751 @end group
7752 @end smallexample
7753
7754 @noindent
7755 In this example, @command{tar} will first switch to @file{/etc}
7756 directory and add files @file{passwd} and @file{hosts} to the
7757 archive.  Then it will change to @file{/lib} directory and will archive
7758 the file @file{libc.a}.  Thus, the resulting archive @file{foo.tar} will
7759 contain:
7760
7761 @smallexample
7762 @group
7763 $ @kbd{tar tf foo.tar}
7764 passwd
7765 hosts
7766 libc.a
7767 @end group
7768 @end smallexample
7769
7770 Note, that any options used in the file list remain in effect for the
7771 rest of the command line.  For example, using the same @file{list}
7772 file as above, the following command
7773
7774 @smallexample
7775 $ @kbd{tar -c -f foo.tar --files-from list libcurses.a}
7776 @end smallexample
7777
7778 @noindent
7779 will look for file @file{libcurses.a} in the directory @file{/lib},
7780 because it was used with the last @option{-C} option
7781 (@pxref{Position-Sensitive Options}).
7782
7783 @anchor{verbatim-files-from}
7784 @opindex verbatim-files-from
7785 If such option handling is undesirable, use the
7786 @option{--verbatim-files-from} option.  When this option is in effect,
7787 each line read from the file list is treated as a file name.  Notice,
7788 that this means, in particular, that no whitespace trimming is
7789 performed.
7790
7791 @anchor{no-verbatim-files-from}
7792 @opindex no-verbatim-files-from
7793 The @option{--verbatim-files-from} affects all @option{-T} options
7794 that follow it in the command line.  The default behavior can be
7795 restored using @option{--no-verbatim-files-from} option.
7796
7797 @opindex add-file
7798 To disable option handling for a single file name, use the
7799 @option{--add-file} option, e.g.: @code{--add-file=--my-file}.
7800
7801 You can use any @GNUTAR{} command line options in the file list file,
7802 including @option{--files-from} option itself.  This allows for
7803 including contents of a file list into another file list file.
7804 Note however, that options that control file list processing, such as
7805 @option{--verbatim-files-from} or @option{--null} won't affect the
7806 file they appear in.  They will affect next @option{--files-from}
7807 option, if there is any.
7808
7809 @menu
7810 * nul::
7811 @end menu
7812
7813 @node nul
7814 @subsection @code{NUL}-Terminated File Names
7815
7816 @cindex File names, terminated by @code{NUL}
7817 @cindex @code{NUL}-terminated file names
7818 The @option{--null} option causes
7819 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7820 to read file names terminated by a @code{NUL} instead of a newline, so
7821 files whose names contain newlines can be archived using
7822 @option{--files-from}.
7823
7824 @table @option
7825 @xopindex{null, described}
7826 @item --null
7827 Only consider @code{NUL}-terminated file names, instead of files that
7828 terminate in a newline.
7829
7830 @xopindex{no-null, described}
7831 @item --no-null
7832 Undo the effect of any previous @option{--null} option.
7833 @end table
7834
7835 The @option{--null} option is just like the one in @acronym{GNU}
7836 @command{xargs} and @command{cpio}, and is useful with the
7837 @option{-print0} predicate of @acronym{GNU} @command{find}.  In
7838 @command{tar}, @option{--null} also disables special handling for
7839 file names that begin with dash (similar to
7840 @option{--verbatim-files-from} option).
7841
7842 This example shows how to use @command{find} to generate a list of files
7843 larger than 800K in length and put that list into a file called
7844 @file{long-files}.  The @option{-print0} option to @command{find} is just
7845 like @option{-print}, except that it separates files with a @code{NUL}
7846 rather than with a newline.  You can then run @command{tar} with both the
7847 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7848 files from that file, @file{long-files}, to create the archive
7849 @file{big.tgz}.  The @option{--null} option to @command{tar} will cause
7850 @command{tar} to recognize the @code{NUL} separator between files.
7851
7852 @smallexample
7853 $ @kbd{find . -size +800 -print0 > long-files}
7854 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7855 @end smallexample
7856
7857 The @option{--no-null} option can be used if you need to read both
7858 @code{NUL}-terminated and newline-terminated files on the same command line.
7859 For example, if @file{flist} is a newline-terminated file, then the
7860 following command can be used to combine it with the above command:
7861
7862 @smallexample
7863 @group
7864 $ @kbd{find . -size +800 -print0 |
7865   tar -c -f big.tar --null -T - --no-null -T flist}
7866 @end group
7867 @end smallexample
7868
7869 This example uses short options for typographic reasons, to avoid
7870 very long lines.
7871
7872 @GNUTAR is tries to automatically detect @code{NUL}-terminated file
7873 lists, so in many cases it is safe to use them even without the
7874 @option{--null} option.  In this case @command{tar} will print a
7875 warning and continue reading such a file as if @option{--null} were
7876 actually given:
7877
7878 @smallexample
7879 @group
7880 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7881 tar: -: file name read contains nul character
7882 @end group
7883 @end smallexample
7884
7885 The null terminator, however, remains in effect only for this
7886 particular file, any following @option{-T} options will assume
7887 newline termination.  Of course, the null autodetection applies
7888 to these eventual surplus @option{-T} options as well.
7889
7890 @node exclude
7891 @section Excluding Some Files
7892
7893 @cindex File names, excluding files by
7894 @cindex Excluding files by name and pattern
7895 @cindex Excluding files by file system
7896 @opindex exclude
7897 @opindex exclude-from
7898 To avoid operating on files whose names match a particular pattern,
7899 use the @option{--exclude} or @option{--exclude-from} options.
7900
7901 @table @option
7902 @opindex exclude
7903 @item --exclude=@var{pattern}
7904 Causes @command{tar} to ignore files that match the @var{pattern}.
7905 @end table
7906
7907 @findex exclude
7908 The @option{--exclude=@var{pattern}} option prevents any file or
7909 member whose name matches the shell wildcard (@var{pattern}) from
7910 being operated on.
7911 For example, to create an archive with all the contents of the directory
7912 @file{src} except for files whose names end in @file{.o}, use the
7913 command @samp{tar -cf src.tar --exclude='*.o' src}.
7914
7915 You may give multiple @option{--exclude} options.
7916
7917 @table @option
7918 @opindex exclude-from
7919 @item --exclude-from=@var{file}
7920 @itemx -X @var{file}
7921 Causes @command{tar} to ignore files that match the patterns listed in
7922 @var{file}.
7923 @end table
7924
7925 @findex exclude-from
7926 Use the @option{--exclude-from} option to read a
7927 list of patterns, one per line, from @var{file}; @command{tar} will
7928 ignore files matching those patterns.  Thus if @command{tar} is
7929 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7930 single line @file{*.o}, no files whose names end in @file{.o} will be
7931 added to the archive.
7932
7933 Notice, that lines from @var{file} are read verbatim. One of the
7934 frequent errors is leaving some extra whitespace after a file name,
7935 which is difficult to catch using text editors.
7936
7937 However, empty lines are OK.
7938
7939 @cindex VCS, excluding patterns from ignore files
7940 @cindex VCS, ignore files
7941 @cindex CVS, ignore files
7942 @cindex Git, ignore files
7943 @cindex Bazaar, ignore files
7944 @cindex Mercurial, ignore files
7945 When archiving directories that are under some version control system (VCS),
7946 it is often convenient to read exclusion patterns from this VCS'
7947 ignore files (e.g. @file{.cvsignore}, @file{.gitignore}, etc.)  The
7948 following options provide such possibility:
7949
7950 @table @option
7951 @anchor{exclude-vcs-ignores}
7952 @opindex exclude-vcs-ignores
7953 @item --exclude-vcs-ignores
7954 Before archiving a directory, see if it contains any of the following
7955 files: @file{cvsignore}, @file{.gitignore}, @file{.bzrignore}, or
7956 @file{.hgignore}.  If so, read ignore patterns from these files.
7957
7958 The patterns are treated much as the corresponding VCS would treat
7959 them, i.e.:
7960
7961 @table @file
7962 @findex .cvsignore
7963 @item .cvsignore
7964 Contains shell-style globbing patterns that apply only to the
7965 directory where this file resides.  No comments are allowed in the
7966 file.  Empty lines are ignored.
7967
7968 @findex .gitignore
7969 @item .gitignore
7970 Contains shell-style globbing patterns.  Applies to the directory
7971 where @file{.gitfile} is located and all its subdirectories.
7972
7973 Any line beginning with a @samp{#} is a comment.  Backslash escapes
7974 the comment character.
7975
7976 @findex .bzrignore
7977 @item .bzrignore
7978 Contains shell globbing-patterns and regular expressions (if prefixed
7979 with @samp{RE:}@footnote{According to the Bazaar docs,
7980 globbing-patterns are Korn-shell style and regular expressions are
7981 perl-style.  As of @GNUTAR{} version @value{VERSION}, these are
7982 treated as shell-style globs and posix extended regexps.  This will be
7983 fixed in future releases.}.  Patterns affect the directory and all its
7984 subdirectories.
7985
7986 Any line beginning with a @samp{#} is a comment.
7987
7988 @findex .hgignore
7989 @item .hgignore
7990 Contains posix regular expressions@footnote{Support for perl-style
7991 regexps will appear in future releases.}.  The line @samp{syntax:
7992 glob} switches to shell globbing patterns.  The line @samp{syntax:
7993 regexp} switches back.  Comments begin with a @samp{#}.  Patterns
7994 affect the directory and all its subdirectories.
7995 @end table
7996
7997 @opindex exclude-ignore
7998 @item --exclude-ignore=@var{file}
7999 Before dumping a directory, @command{tar} checks if it contains
8000 @var{file}.  If so, exclusion patterns are read from this file.
8001 The patterns affect only the directory itself.
8002
8003 @opindex exclude-ignore-recursive
8004 @item --exclude-ignore-recursive=@var{file}
8005 Same as @option{--exclude-ignore}, except that the patterns read
8006 affect both the directory where @var{file} resides and all its
8007 subdirectories.
8008 @end table
8009
8010 @table @option
8011 @cindex version control system, excluding files
8012 @cindex VCS, excluding files
8013 @cindex SCCS, excluding files
8014 @cindex RCS, excluding files
8015 @cindex CVS, excluding files
8016 @cindex SVN, excluding files
8017 @cindex git, excluding files
8018 @cindex Bazaar, excluding files
8019 @cindex Arch, excluding files
8020 @cindex Mercurial, excluding files
8021 @cindex Darcs, excluding files
8022 @anchor{exclude-vcs}
8023 @opindex exclude-vcs
8024 @item --exclude-vcs
8025 Exclude files and directories used by following version control
8026 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
8027 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
8028
8029 As of version @value{VERSION}, the following files are excluded:
8030
8031 @itemize @bullet
8032 @item @file{CVS/}, and everything under it
8033 @item @file{RCS/}, and everything under it
8034 @item @file{SCCS/}, and everything under it
8035 @item @file{.git/}, and everything under it
8036 @item @file{.gitignore}
8037 @item @file{.gitmodules}
8038 @item @file{.gitattributes}
8039 @item @file{.cvsignore}
8040 @item @file{.svn/}, and everything under it
8041 @item @file{.arch-ids/}, and everything under it
8042 @item @file{@{arch@}/}, and everything under it
8043 @item @file{=RELEASE-ID}
8044 @item @file{=meta-update}
8045 @item @file{=update}
8046 @item @file{.bzr}
8047 @item @file{.bzrignore}
8048 @item @file{.bzrtags}
8049 @item @file{.hg}
8050 @item @file{.hgignore}
8051 @item @file{.hgrags}
8052 @item @file{_darcs}
8053 @end itemize
8054
8055 @opindex exclude-backups
8056 @item --exclude-backups
8057 Exclude backup and lock files.  This option causes exclusion of files
8058 that match the following shell globbing patterns:
8059
8060 @table @asis
8061 @item .#*
8062 @item *~
8063 @item #*#
8064 @end table
8065
8066 @end table
8067
8068 @findex exclude-caches
8069 When creating an archive, the @option{--exclude-caches} option family
8070 causes @command{tar} to exclude all directories that contain a @dfn{cache
8071 directory tag}. A cache directory tag is a short file with the
8072 well-known name @file{CACHEDIR.TAG} and having a standard header
8073 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
8074 Various applications write cache directory tags into directories they
8075 use to hold regenerable, non-precious data, so that such data can be
8076 more easily excluded from backups.
8077
8078 There are three @samp{exclude-caches} options, each providing a different
8079 exclusion semantics:
8080
8081 @table @option
8082 @opindex exclude-caches
8083 @item --exclude-caches
8084 Do not archive the contents of the directory, but archive the
8085 directory itself and the @file{CACHEDIR.TAG} file.
8086
8087 @opindex exclude-caches-under
8088 @item --exclude-caches-under
8089 Do not archive the contents of the directory, nor the
8090 @file{CACHEDIR.TAG} file, archive only the directory itself.
8091
8092 @opindex exclude-caches-all
8093 @item --exclude-caches-all
8094 Omit directories containing @file{CACHEDIR.TAG} file entirely.
8095 @end table
8096
8097 @findex exclude-tag
8098 Another option family, @option{--exclude-tag}, provides a generalization of
8099 this concept.  It takes a single argument, a file name to look for.
8100 Any directory that contains this file will be excluded from the dump.
8101 Similarly to @samp{exclude-caches}, there are three options in this
8102 option family:
8103
8104 @table @option
8105 @opindex exclude-tag
8106 @item --exclude-tag=@var{file}
8107 Do not dump the contents of the directory, but dump the
8108 directory itself and the @var{file}.
8109
8110 @opindex exclude-tag-under
8111 @item --exclude-tag-under=@var{file}
8112 Do not dump the contents of the directory, nor the
8113 @var{file}, archive only the directory itself.
8114
8115 @opindex exclude-tag-all
8116 @item --exclude-tag-all=@var{file}
8117 Omit directories containing @var{file} file entirely.
8118 @end table
8119
8120 Multiple @option{--exclude-tag*} options can be given.
8121
8122 For example, given this directory:
8123
8124 @smallexample
8125 @group
8126 $ @kbd{find dir}
8127 dir
8128 dir/blues
8129 dir/jazz
8130 dir/folk
8131 dir/folk/tagfile
8132 dir/folk/sanjuan
8133 dir/folk/trote
8134 @end group
8135 @end smallexample
8136
8137 The @option{--exclude-tag} will produce the following:
8138
8139 @smallexample
8140 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
8141 dir/
8142 dir/blues
8143 dir/jazz
8144 dir/folk/
8145 tar: dir/folk/: contains a cache directory tag tagfile;
8146   contents not dumped
8147 dir/folk/tagfile
8148 @end smallexample
8149
8150 Both the @file{dir/folk} directory and its tagfile are preserved in
8151 the archive, however the rest of files in this directory are not.
8152
8153 Now, using the @option{--exclude-tag-under} option will exclude
8154 @file{tagfile} from the dump, while still preserving the directory
8155 itself, as shown in this example:
8156
8157 @smallexample
8158 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
8159 dir/
8160 dir/blues
8161 dir/jazz
8162 dir/folk/
8163 ./tar: dir/folk/: contains a cache directory tag tagfile;
8164   contents not dumped
8165 @end smallexample
8166
8167 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
8168 directory entirely:
8169
8170 @smallexample
8171 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
8172 dir/
8173 dir/blues
8174 dir/jazz
8175 ./tar: dir/folk/: contains a cache directory tag tagfile;
8176   directory not dumped
8177 @end smallexample
8178
8179 @menu
8180 * problems with exclude::
8181 @end menu
8182
8183 @node problems with exclude
8184 @unnumberedsubsec Problems with Using the @code{exclude} Options
8185
8186 @xopindex{exclude, potential problems with}
8187 Some users find @samp{exclude} options confusing.  Here are some common
8188 pitfalls:
8189
8190 @itemize @bullet
8191 @item
8192 The main operating mode of @command{tar} does not act on a file name
8193 explicitly listed on the command line, if one of its file name
8194 components is excluded.  In the example above, if
8195 you create an archive and exclude files that end with @samp{*.o}, but
8196 explicitly name the file @samp{dir.o/foo} after all the options have been
8197 listed, @samp{dir.o/foo} will be excluded from the archive.
8198
8199 @item
8200 You can sometimes confuse the meanings of @option{--exclude} and
8201 @option{--exclude-from}.  Be careful: use @option{--exclude} when files
8202 to be excluded are given as a pattern on the command line.  Use
8203 @option{--exclude-from} to introduce the name of a file which contains
8204 a list of patterns, one per line; each of these patterns can exclude
8205 zero, one, or many files.
8206
8207 @item
8208 When you use @option{--exclude=@var{pattern}}, be sure to quote the
8209 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
8210 like @samp{*}.  If you do not do this, the shell might expand the
8211 @samp{*} itself using files at hand, so @command{tar} might receive a
8212 list of files instead of one pattern, or none at all, making the
8213 command somewhat illegal.  This might not correspond to what you want.
8214
8215 For example, write:
8216
8217 @smallexample
8218 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
8219 @end smallexample
8220
8221 @noindent
8222 rather than:
8223
8224 @smallexample
8225 # @emph{Wrong!}
8226 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
8227 @end smallexample
8228
8229 @item
8230 You must use use shell syntax, or globbing, rather than @code{regexp}
8231 syntax, when using exclude options in @command{tar}.  If you try to use
8232 @code{regexp} syntax to describe files to be excluded, your command
8233 might fail.
8234
8235 @item
8236 @FIXME{The change in semantics must have occurred before 1.11,
8237 so I doubt if it is worth mentioning at all. Anyway, should at
8238 least specify in which version the semantics changed.}
8239 In earlier versions of @command{tar}, what is now the
8240 @option{--exclude-from} option was called @option{--exclude} instead.
8241 Now, @option{--exclude} applies to patterns listed on the command
8242 line and @option{--exclude-from} applies to patterns listed in a
8243 file.
8244
8245 @end itemize
8246
8247 @node wildcards
8248 @section Wildcards Patterns and Matching
8249
8250 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
8251 @samp{*} or @samp{?} for example, are replaced and expanded into all
8252 existing files matching the given pattern.  @GNUTAR{} can use wildcard
8253 patterns for matching (or globbing) archive members when extracting
8254 from or listing an archive.  Wildcard patterns are also used for
8255 verifying volume labels of @command{tar} archives.  This section has the
8256 purpose of explaining wildcard syntax for @command{tar}.
8257
8258 @FIXME{the next few paragraphs need work.}
8259
8260 A @var{pattern} should be written according to shell syntax, using wildcard
8261 characters to effect globbing.  Most characters in the pattern stand
8262 for themselves in the matched string, and case is significant: @samp{a}
8263 will match only @samp{a}, and not @samp{A}.  The character @samp{?} in the
8264 pattern matches any single character in the matched string.  The character
8265 @samp{*} in the pattern matches zero, one, or more single characters in
8266 the matched string.  The character @samp{\} says to take the following
8267 character of the pattern @emph{literally}; it is useful when one needs to
8268 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
8269
8270 The character @samp{[}, up to the matching @samp{]}, introduces a character
8271 class.  A @dfn{character class} is a list of acceptable characters
8272 for the next single character of the matched string.  For example,
8273 @samp{[abcde]} would match any of the first five letters of the alphabet.
8274 Note that within a character class, all of the ``special characters''
8275 listed above other than @samp{\} lose their special meaning; for example,
8276 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
8277 @samp{[}, @samp{*}, @samp{?}, or @samp{]}.  (Due to parsing constraints,
8278 the characters @samp{-} and @samp{]} must either come @emph{first} or
8279 @emph{last} in a character class.)
8280
8281 @cindex Excluding characters from a character class
8282 @cindex Character class, excluding characters from
8283 If the first character of the class after the opening @samp{[}
8284 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
8285 Rather than listing character to match, it lists those characters which
8286 are @emph{forbidden} as the next single character of the matched string.
8287
8288 Other characters of the class stand for themselves.  The special
8289 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
8290 letters, is meant to represent all characters between @var{a} and
8291 @var{e}, inclusive.
8292
8293 @FIXME{need to add a sentence or so here to make this clear for those
8294 who don't have dan around.}
8295
8296 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
8297 special for wildcard matches.  However, if a pattern completely matches
8298 a directory prefix of a matched string, then it matches the full matched
8299 string: thus, excluding a directory also excludes all the files beneath it.
8300
8301 @menu
8302 * controlling pattern-matching::
8303 @end menu
8304
8305 @node controlling pattern-matching
8306 @unnumberedsubsec Controlling Pattern-Matching
8307
8308 For the purposes of this section, we call @dfn{exclusion members} all
8309 member names obtained while processing @option{--exclude} and
8310 @option{--exclude-from} options, and @dfn{inclusion members} those
8311 member names that were given in the command line or read from the file
8312 specified with @option{--files-from} option.
8313
8314 These two pairs of member lists are used in the following operations:
8315 @option{--diff}, @option{--extract}, @option{--list},
8316 @option{--update}.
8317
8318 There are no inclusion members in create mode (@option{--create} and
8319 @option{--append}), since in this mode the names obtained from the
8320 command line refer to @emph{files}, not archive members.
8321
8322 By default, inclusion members are compared with archive members
8323 literally @footnote{Notice that earlier @GNUTAR{} versions used
8324 globbing for inclusion members, which contradicted to UNIX98
8325 specification and was not documented. @xref{Changes}, for more
8326 information on this and other changes.} and exclusion members are
8327 treated as globbing patterns.  For example:
8328
8329 @smallexample
8330 @group
8331 $ @kbd{tar tf foo.tar}
8332 a.c
8333 b.c
8334 a.txt
8335 [remarks]
8336 # @i{Member names are used verbatim:}
8337 $ @kbd{tar -xf foo.tar -v '[remarks]'}
8338 [remarks]
8339 # @i{Exclude member names are globbed:}
8340 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
8341 a.txt
8342 [remarks]
8343 @end group
8344 @end smallexample
8345
8346 This behavior can be altered by using the following options:
8347
8348 @table @option
8349 @opindex wildcards
8350 @item --wildcards
8351 Treat all member names as wildcards.
8352
8353 @opindex no-wildcards
8354 @item --no-wildcards
8355 Treat all member names as literal strings.
8356 @end table
8357
8358 Thus, to extract files whose names end in @samp{.c}, you can use:
8359
8360 @smallexample
8361 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
8362 a.c
8363 b.c
8364 @end smallexample
8365
8366 @noindent
8367 Notice quoting of the pattern to prevent the shell from interpreting
8368 it.
8369
8370 The effect of @option{--wildcards} option is canceled by
8371 @option{--no-wildcards}.  This can be used to pass part of
8372 the command line arguments verbatim and other part as globbing
8373 patterns.  For example, the following invocation:
8374
8375 @smallexample
8376 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
8377 @end smallexample
8378
8379 @noindent
8380 instructs @command{tar} to extract from @file{foo.tar} all files whose
8381 names end in @samp{.txt} and the file named @file{[remarks]}.
8382
8383 Normally, a pattern matches a name if an initial subsequence of the
8384 name's components matches the pattern, where @samp{*}, @samp{?}, and
8385 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
8386 and wildcards can match @samp{/}.
8387
8388 Other than optionally stripping leading @samp{/} from names
8389 (@pxref{absolute}), patterns and names are used as-is.  For
8390 example, trailing @samp{/} is not trimmed from a user-specified name
8391 before deciding whether to exclude it.
8392
8393 However, this matching procedure can be altered by the options listed
8394 below.  These options accumulate.  For example:
8395
8396 @smallexample
8397 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
8398 @end smallexample
8399
8400 @noindent
8401 ignores case when excluding @samp{makefile}, but not when excluding
8402 @samp{readme}.
8403
8404 @table @option
8405 @anchor{anchored patterns}
8406 @opindex anchored
8407 @opindex no-anchored
8408 @item --anchored
8409 @itemx --no-anchored
8410 If anchored, a pattern must match an initial subsequence
8411 of the name's components.  Otherwise, the pattern can match any
8412 subsequence.  Default is @option{--no-anchored} for exclusion members
8413 and @option{--anchored} inclusion members.
8414
8415 @anchor{case-insensitive matches}
8416 @opindex ignore-case
8417 @opindex no-ignore-case
8418 @item --ignore-case
8419 @itemx --no-ignore-case
8420 When ignoring case, upper-case patterns match lower-case names and vice versa.
8421 When not ignoring case (the default), matching is case-sensitive.
8422
8423 @opindex wildcards-match-slash
8424 @opindex no-wildcards-match-slash
8425 @item --wildcards-match-slash
8426 @itemx --no-wildcards-match-slash
8427 When wildcards match slash (the default for exclusion members), a
8428 wildcard like @samp{*} in the pattern can match a @samp{/} in the
8429 name.  Otherwise, @samp{/} is matched only by @samp{/}.
8430
8431 @end table
8432
8433 The @option{--recursion} and @option{--no-recursion} options
8434 (@pxref{recurse}) also affect how member patterns are interpreted.  If
8435 recursion is in effect, a pattern matches a name if it matches any of
8436 the name's parent directories.
8437
8438 The following table summarizes pattern-matching default values:
8439
8440 @multitable @columnfractions .3 .7
8441 @headitem Members @tab Default settings
8442 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
8443 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
8444 @end multitable
8445
8446 @node quoting styles
8447 @section Quoting Member Names
8448
8449 When displaying member names, @command{tar} takes care to avoid
8450 ambiguities caused by certain characters.  This is called @dfn{name
8451 quoting}.  The characters in question are:
8452
8453 @itemize @bullet
8454 @item Non-printable control characters:
8455 @anchor{escape sequences}
8456 @multitable @columnfractions 0.20 0.10 0.60
8457 @headitem Character @tab @acronym{ASCII} @tab Character name
8458 @item \a @tab 7  @tab Audible bell
8459 @item \b @tab 8  @tab Backspace
8460 @item \f @tab 12 @tab Form feed
8461 @item \n @tab 10 @tab New line
8462 @item \r @tab 13 @tab Carriage return
8463 @item \t @tab 9  @tab Horizontal tabulation
8464 @item \v @tab 11 @tab Vertical tabulation
8465 @end multitable
8466
8467 @item Space (@acronym{ASCII} 32)
8468
8469 @item Single and double quotes (@samp{'} and @samp{"})
8470
8471 @item Backslash (@samp{\})
8472 @end itemize
8473
8474 The exact way @command{tar} uses to quote these characters depends on
8475 the @dfn{quoting style}.  The default quoting style, called
8476 @dfn{escape} (see below), uses backslash notation to represent control
8477 characters, space and backslash.  Using this quoting style, control
8478 characters are represented as listed in column @samp{Character} in the
8479 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
8480
8481 @GNUTAR{} offers seven distinct quoting styles, which can be selected
8482 using @option{--quoting-style} option:
8483
8484 @table @option
8485 @item --quoting-style=@var{style}
8486 @opindex quoting-style
8487
8488 Sets quoting style.  Valid values for @var{style} argument are:
8489 literal, shell, shell-always, c, escape, locale, clocale.
8490 @end table
8491
8492 These styles are described in detail below.  To illustrate their
8493 effect, we will use an imaginary tar archive @file{arch.tar}
8494 containing the following members:
8495
8496 @smallexample
8497 @group
8498 # 1. Contains horizontal tabulation character.
8499 a       tab
8500 # 2. Contains newline character
8501 a
8502 newline
8503 # 3. Contains a space
8504 a space
8505 # 4. Contains double quotes
8506 a"double"quote
8507 # 5. Contains single quotes
8508 a'single'quote
8509 # 6. Contains a backslash character:
8510 a\backslash
8511 @end group
8512 @end smallexample
8513
8514 Here is how usual @command{ls} command would have listed them, if they
8515 had existed in the current working directory:
8516
8517 @smallexample
8518 @group
8519 $ @kbd{ls}
8520 a\ttab
8521 a\nnewline
8522 a\ space
8523 a"double"quote
8524 a'single'quote
8525 a\\backslash
8526 @end group
8527 @end smallexample
8528
8529 Quoting styles:
8530
8531 @table @samp
8532 @item literal
8533 No quoting, display each character as is:
8534
8535 @smallexample
8536 @group
8537 $ @kbd{tar tf arch.tar --quoting-style=literal}
8538 ./
8539 ./a space
8540 ./a'single'quote
8541 ./a"double"quote
8542 ./a\backslash
8543 ./a     tab
8544 ./a
8545 newline
8546 @end group
8547 @end smallexample
8548
8549 @item shell
8550 Display characters the same way Bourne shell does:
8551 control characters, except @samp{\t} and @samp{\n}, are printed using
8552 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
8553 single quote is printed as @samp{\'}.  If a name contains any quoted
8554 characters, it is enclosed in single quotes.  In particular, if a name
8555 contains single quotes, it is printed as several single-quoted strings:
8556
8557 @smallexample
8558 @group
8559 $ @kbd{tar tf arch.tar --quoting-style=shell}
8560 ./
8561 './a space'
8562 './a'\''single'\''quote'
8563 './a"double"quote'
8564 './a\backslash'
8565 './a    tab'
8566 './a
8567 newline'
8568 @end group
8569 @end smallexample
8570
8571 @item shell-always
8572 Same as @samp{shell}, but the names are always enclosed in single
8573 quotes:
8574
8575 @smallexample
8576 @group
8577 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
8578 './'
8579 './a space'
8580 './a'\''single'\''quote'
8581 './a"double"quote'
8582 './a\backslash'
8583 './a    tab'
8584 './a
8585 newline'
8586 @end group
8587 @end smallexample
8588
8589 @item c
8590 Use the notation of the C programming language.  All names are
8591 enclosed in double quotes.  Control characters are quoted using
8592 backslash notations, double quotes are represented as @samp{\"},
8593 backslash characters are represented as @samp{\\}.  Single quotes and
8594 spaces are not quoted:
8595
8596 @smallexample
8597 @group
8598 $ @kbd{tar tf arch.tar --quoting-style=c}
8599 "./"
8600 "./a space"
8601 "./a'single'quote"
8602 "./a\"double\"quote"
8603 "./a\\backslash"
8604 "./a\ttab"
8605 "./a\nnewline"
8606 @end group
8607 @end smallexample
8608
8609 @item escape
8610 Control characters are printed using backslash notation, a space is
8611 printed as @samp{\ } and a backslash as @samp{\\}.  This is the
8612 default quoting style, unless it was changed when configured the
8613 package.
8614
8615 @smallexample
8616 @group
8617 $ @kbd{tar tf arch.tar --quoting-style=escape}
8618 ./
8619 ./a space
8620 ./a'single'quote
8621 ./a"double"quote
8622 ./a\\backslash
8623 ./a\ttab
8624 ./a\nnewline
8625 @end group
8626 @end smallexample
8627
8628 @item locale
8629 Control characters, single quote and backslash are printed using
8630 backslash notation.  All names are quoted using left and right
8631 quotation marks, appropriate to the current locale.  If it does not
8632 define quotation marks, use @samp{'} as left and as right
8633 quotation marks.  Any occurrences of the right quotation mark in a
8634 name are escaped with @samp{\}, for example:
8635
8636 For example:
8637
8638 @smallexample
8639 @group
8640 $ @kbd{tar tf arch.tar --quoting-style=locale}
8641 './'
8642 './a space'
8643 './a\'single\'quote'
8644 './a"double"quote'
8645 './a\\backslash'
8646 './a\ttab'
8647 './a\nnewline'
8648 @end group
8649 @end smallexample
8650
8651 @item clocale
8652 Same as @samp{locale}, but @samp{"} is used for both left and right
8653 quotation marks, if not provided by the currently selected locale:
8654
8655 @smallexample
8656 @group
8657 $ @kbd{tar tf arch.tar --quoting-style=clocale}
8658 "./"
8659 "./a space"
8660 "./a'single'quote"
8661 "./a\"double\"quote"
8662 "./a\\backslash"
8663 "./a\ttab"
8664 "./a\nnewline"
8665 @end group
8666 @end smallexample
8667 @end table
8668
8669 You can specify which characters should be quoted in addition to those
8670 implied by the current quoting style:
8671
8672 @table @option
8673 @item --quote-chars=@var{string}
8674 Always quote characters from @var{string}, even if the selected
8675 quoting style would not quote them.
8676 @end table
8677
8678 For example, using @samp{escape} quoting (compare with the usual
8679 escape listing above):
8680
8681 @smallexample
8682 @group
8683 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
8684 ./
8685 ./a\ space
8686 ./a'single'quote
8687 ./a\"double\"quote
8688 ./a\\backslash
8689 ./a\ttab
8690 ./a\nnewline
8691 @end group
8692 @end smallexample
8693
8694 To disable quoting of such additional characters, use the following
8695 option:
8696
8697 @table @option
8698 @item --no-quote-chars=@var{string}
8699 Remove characters listed in @var{string} from the list of quoted
8700 characters set by the previous @option{--quote-chars} option.
8701 @end table
8702
8703 This option is particularly useful if you have added
8704 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
8705 and wish to disable it for the current invocation.
8706
8707 Note, that @option{--no-quote-chars} does @emph{not} disable those
8708 characters that are quoted by default in the selected quoting style.
8709
8710 @node transform
8711 @section Modifying File and Member Names
8712
8713 @command{Tar} archives contain detailed information about files stored
8714 in them and full file names are part of that information.  When
8715 storing a file to an archive, its file name is recorded in it,
8716 along with the actual file contents.  When restoring from an archive,
8717 a file is created on disk with exactly the same name as that stored
8718 in the archive.  In the majority of cases this is the desired behavior
8719 of a file archiver.  However, there are some cases when it is not.
8720
8721 First of all, it is often unsafe to extract archive members with
8722 absolute file names or those that begin with a @file{../}.  @GNUTAR{}
8723 takes special precautions when extracting such names and provides a
8724 special option for handling them, which is described in
8725 @ref{absolute}.
8726
8727 Secondly, you may wish to extract file names without some leading
8728 directory components, or with otherwise modified names.  In other
8729 cases it is desirable to store files under differing names in the
8730 archive.
8731
8732 @GNUTAR{} provides several options for these needs.
8733
8734 @table @option
8735 @opindex strip-components
8736 @item --strip-components=@var{number}
8737 Strip given @var{number} of leading components from file names before
8738 extraction.
8739 @end table
8740
8741 For example, suppose you have archived whole @file{/usr} hierarchy to
8742 a tar archive named @file{usr.tar}.  Among other files, this archive
8743 contains @file{usr/include/stdlib.h}, which you wish to extract to
8744 the current working directory.  To do so, you type:
8745
8746 @smallexample
8747 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
8748 @end smallexample
8749
8750 The option @option{--strip=2} instructs @command{tar} to strip the
8751 two leading components (@file{usr/} and @file{include/}) off the file
8752 name.
8753
8754 If you add the @option{--verbose} (@option{-v}) option to the invocation
8755 above, you will note that the verbose listing still contains the
8756 full file name, with the two removed components still in place.  This
8757 can be inconvenient, so @command{tar} provides a special option for
8758 altering this behavior:
8759
8760 @anchor{show-transformed-names}
8761 @table @option
8762 @opindex show-transformed-names
8763 @item --show-transformed-names
8764 Display file or member names with all requested transformations
8765 applied.
8766 @end table
8767
8768 @noindent
8769 For example:
8770
8771 @smallexample
8772 @group
8773 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
8774 usr/include/stdlib.h
8775 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
8776 stdlib.h
8777 @end group
8778 @end smallexample
8779
8780 Notice that in both cases the file @file{stdlib.h} is extracted to the
8781 current working directory, @option{--show-transformed-names} affects
8782 only the way its name is displayed.
8783
8784 This option is especially useful for verifying whether the invocation
8785 will have the desired effect.  Thus, before running
8786
8787 @smallexample
8788 $ @kbd{tar -x --strip=@var{n}}
8789 @end smallexample
8790
8791 @noindent
8792 it is often advisable to run
8793
8794 @smallexample
8795 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8796 @end smallexample
8797
8798 @noindent
8799 to make sure the command will produce the intended results.
8800
8801 In case you need to apply more complex modifications to the file name,
8802 @GNUTAR{} provides a general-purpose transformation option:
8803
8804 @table @option
8805 @opindex transform
8806 @opindex xform
8807 @item --transform=@var{expression}
8808 @itemx --xform=@var{expression}
8809 Modify file names using supplied @var{expression}.
8810 @end table
8811
8812 @noindent
8813 The @var{expression} is a @command{sed}-like replace expression of the
8814 form:
8815
8816 @smallexample
8817 s/@var{regexp}/@var{replace}/[@var{flags}]
8818 @end smallexample
8819
8820 @noindent
8821 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8822 replacement for each file name part that matches @var{regexp}.  Both
8823 @var{regexp} and @var{replace} are described in detail in
8824 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8825
8826 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8827 that it be used consistently throughout the expression. For example,
8828 the following two expressions are equivalent:
8829
8830 @smallexample
8831 @group
8832 s/one/two/
8833 s,one,two,
8834 @end group
8835 @end smallexample
8836
8837 Changing delimiters is often useful when the @var{regex} contains
8838 slashes.  For example, it is more convenient to write @code{s,/,-,} than
8839 @code{s/\//-/}.
8840
8841 As in @command{sed}, you can give several replace expressions,
8842 separated by a semicolon.
8843
8844 Supported @var{flags} are:
8845
8846 @table @samp
8847 @item g
8848 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8849 just the first.
8850
8851 @item i
8852 Use case-insensitive matching.
8853
8854 @item x
8855 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8856 regexps, Extended regular expressions, Extended regular expressions,
8857 sed, GNU sed}).
8858
8859 @item @var{number}
8860 Only replace the @var{number}th match of the @var{regexp}.
8861
8862 Note: the @acronym{POSIX} standard does not specify what should happen
8863 when you mix the @samp{g} and @var{number} modifiers.  @GNUTAR{}
8864 follows the GNU @command{sed} implementation in this regard, so
8865 the interaction is defined to be: ignore matches before the
8866 @var{number}th, and then match and replace all matches from the
8867 @var{number}th on.
8868
8869 @end table
8870
8871 In addition, several @dfn{transformation scope} flags are supported,
8872 that control to what files transformations apply.  These are:
8873
8874 @table @samp
8875 @item r
8876 Apply transformation to regular archive members.
8877
8878 @item R
8879 Do not apply transformation to regular archive members.
8880
8881 @item s
8882 Apply transformation to symbolic link targets.
8883
8884 @item S
8885 Do not apply transformation to symbolic link targets.
8886
8887 @item h
8888 Apply transformation to hard link targets.
8889
8890 @item H
8891 Do not apply transformation to hard link targets.
8892 @end table
8893
8894 Default is @samp{rsh}, which means to apply transformations to both archive
8895 members and targets of symbolic and hard links.
8896
8897 Default scope flags can also be changed using @samp{flags=} statement
8898 in the transform expression.  The flags set this way remain in force
8899 until next @samp{flags=} statement or end of expression, whichever
8900 occurs first.  For example:
8901
8902 @smallexample
8903   --transform 'flags=S;s|^|/usr/local/|'
8904 @end smallexample
8905
8906 Here are several examples of @option{--transform} usage:
8907
8908 @enumerate
8909 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8910
8911 @smallexample
8912 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8913 @end smallexample
8914
8915 @item Strip two leading directory components (equivalent to
8916 @option{--strip-components=2}):
8917
8918 @smallexample
8919 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8920 @end smallexample
8921
8922 @item Convert each file name to lower case:
8923
8924 @smallexample
8925 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8926 @end smallexample
8927
8928 @item Prepend @file{/prefix/}  to each file name:
8929
8930 @smallexample
8931 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8932 @end smallexample
8933
8934 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8935 to each archive member:
8936
8937 @smallexample
8938 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8939 @end smallexample
8940 @end enumerate
8941
8942 Notice the use of flags in the last example.  The @file{/lib}
8943 directory often contains many symbolic links to files within it.
8944 It may look, for example, like this:
8945
8946 @smallexample
8947 $ @kbd{ls -l}
8948 drwxr-xr-x root/root       0 2008-07-08 16:20 /lib/
8949 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8950 lrwxrwxrwx root/root       0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8951 ...
8952 @end smallexample
8953
8954 Using the expression @samp{s,^,/usr/local/,} would mean adding
8955 @samp{/usr/local} to both regular archive members and to link
8956 targets. In this case, @file{/lib/libc.so.6} would become:
8957
8958 @smallexample
8959   /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8960 @end smallexample
8961
8962 This is definitely not desired.  To avoid this, the @samp{S} flag
8963 is used, which excludes symbolic link targets from filename
8964 transformations.  The result is:
8965
8966 @smallexample
8967 $ @kbd{tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
8968        --show-transformed /lib}
8969 drwxr-xr-x root/root       0 2008-07-08 16:20 /usr/local/lib/
8970 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8971 lrwxrwxrwx root/root       0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8972  -> libc-2.3.2.so
8973 @end smallexample
8974
8975 Unlike @option{--strip-components}, @option{--transform} can be used
8976 in any @GNUTAR{} operation mode.  For example, the following command
8977 adds files to the archive while replacing the leading @file{usr/}
8978 component with @file{var/}:
8979
8980 @smallexample
8981 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8982 @end smallexample
8983
8984 To test @option{--transform} effect we suggest using
8985 @option{--show-transformed-names} option:
8986
8987 @smallexample
8988 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8989        --verbose --show-transformed-names /}
8990 @end smallexample
8991
8992 If both @option{--strip-components} and @option{--transform} are used
8993 together, then @option{--transform} is applied first, and the required
8994 number of components is then stripped from its result.
8995
8996 You can use as many @option{--transform} options in a single command
8997 line as you want.  The specified expressions will then be applied in
8998 order of their appearance.  For example, the following two invocations
8999 are equivalent:
9000
9001 @smallexample
9002 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
9003                         --transform='s,/usr/local,/usr/,'}
9004 $ @kbd{tar -cf arch.tar \
9005                --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
9006 @end smallexample
9007
9008 @node after
9009 @section Operating Only on New Files
9010
9011 @cindex Excluding file by age
9012 @cindex Data Modification time, excluding files by
9013 @cindex Modification time, excluding files by
9014 @cindex Age, excluding files by
9015 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
9016 @option{-N @var{date}}) option causes @command{tar} to only work on
9017 files whose data modification or status change times are newer than
9018 the @var{date} given.  If @var{date} starts with @samp{/} or @samp{.},
9019 it is taken to be a file name; the data modification time of that file
9020 is used as the date. If you use this option when creating or appending
9021 to an archive, the archive will only include new files.  If you use
9022 @option{--after-date} when extracting an archive, @command{tar} will
9023 only extract files newer than the @var{date} you specify.
9024
9025 If you only want @command{tar} to make the date comparison based on
9026 modification of the file's data (rather than status
9027 changes), then use the @option{--newer-mtime=@var{date}} option.
9028
9029 @cindex --after-date and --update compared
9030 @cindex --newer-mtime and --update compared
9031 You may use these options with any operation.  Note that these options
9032 differ from the @option{--update} (@option{-u}) operation in that they
9033 allow you to specify a particular date against which @command{tar} can
9034 compare when deciding whether or not to archive the files.
9035
9036 @table @option
9037 @opindex after-date
9038 @opindex newer
9039 @item --after-date=@var{date}
9040 @itemx --newer=@var{date}
9041 @itemx -N @var{date}
9042 Only store files newer than @var{date}.
9043
9044 Acts on files only if their data modification or status change times are
9045 later than @var{date}.  Use in conjunction with any operation.
9046
9047 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
9048 name; the data modification time of that file is used as the date.
9049
9050 @opindex newer-mtime
9051 @item --newer-mtime=@var{date}
9052 Acts like @option{--after-date}, but only looks at data modification times.
9053 @end table
9054
9055 These options limit @command{tar} to operate only on files which have
9056 been modified after the date specified.  A file's status is considered to have
9057 changed if its contents have been modified, or if its owner,
9058 permissions, and so forth, have been changed.  (For more information on
9059 how to specify a date, see @ref{Date input formats}; remember that the
9060 entire date argument must be quoted if it contains any spaces.)
9061
9062 Gurus would say that @option{--after-date} tests both the data
9063 modification time (@code{mtime}, the time the contents of the file
9064 were last modified) and the status change time (@code{ctime}, the time
9065 the file's status was last changed: owner, permissions, etc.@:)
9066 fields, while @option{--newer-mtime} tests only the @code{mtime}
9067 field.
9068
9069 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
9070 @code{ctime} and processes the file if either one is more recent than
9071 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
9072 disregards @code{ctime}.  Neither does it use @code{atime} (the last time the
9073 contents of the file were looked at).
9074
9075 Date specifiers can have embedded spaces.  Because of this, you may need
9076 to quote date arguments to keep the shell from parsing them as separate
9077 arguments.  For example, the following command will add to the archive
9078 all the files modified less than two days ago:
9079
9080 @smallexample
9081 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
9082 @end smallexample
9083
9084 When any of these options is used with the option @option{--verbose}
9085 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
9086 date back to its textual representation and compare that with the
9087 one given with the option.  If the two dates differ, @command{tar} will
9088 print a warning saying what date it will use.  This is to help user
9089 ensure he is using the right date.  For example:
9090
9091 @smallexample
9092 @group
9093 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
9094 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
9095 13:19:37.232434
9096 @end group
9097 @end smallexample
9098
9099 @quotation
9100 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
9101 should not be used for incremental backups.  @xref{Incremental Dumps},
9102 for proper way of creating incremental backups.
9103 @end quotation
9104
9105 @node recurse
9106 @section Descending into Directories
9107 @cindex Avoiding recursion in directories
9108 @cindex Descending directories, avoiding
9109 @cindex Directories, avoiding recursion
9110 @cindex Recursion in directories, avoiding
9111
9112 Usually, @command{tar} will recursively explore all directories (either
9113 those given on the command line or through the @option{--files-from}
9114 option) for the various files they contain.  However, you may not always
9115 want @command{tar} to act this way.
9116
9117 @opindex no-recursion
9118 @cindex @command{find}, using with @command{tar}
9119 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
9120 into specified directories.  If you specify @option{--no-recursion}, you can
9121 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
9122 utility for hunting through levels of directories to
9123 construct a list of file names which you could then pass to @command{tar}.
9124 @command{find} allows you to be more selective when choosing which files to
9125 archive; see @ref{files}, for more information on using @command{find} with
9126 @command{tar}.
9127
9128 @table @option
9129 @item --no-recursion
9130 Prevents @command{tar} from recursively descending directories.
9131
9132 @opindex recursion
9133 @item --recursion
9134 Requires @command{tar} to recursively descend directories.
9135 This is the default.
9136 @end table
9137
9138 When you use @option{--no-recursion}, @GNUTAR{} grabs
9139 directory entries themselves, but does not descend on them
9140 recursively.  Many people use @command{find} for locating files they
9141 want to back up, and since @command{tar} @emph{usually} recursively
9142 descends on directories, they have to use the @samp{@w{-not -type d}}
9143 test in their @command{find} invocation (@pxref{Type, Type, Type test,
9144 find, Finding Files}), as they usually do not want all the files in a
9145 directory. They then use the @option{--files-from} option to archive
9146 the files located via @command{find}.
9147
9148 The problem when restoring files archived in this manner is that the
9149 directories themselves are not in the archive; so the
9150 @option{--same-permissions} (@option{--preserve-permissions},
9151 @option{-p}) option does not affect them---while users might really
9152 like it to.  Specifying @option{--no-recursion} is a way to tell
9153 @command{tar} to grab only the directory entries given to it, adding
9154 no new files on its own.  To summarize, if you use @command{find} to
9155 create a list of files to be stored in an archive, use it as follows:
9156
9157 @smallexample
9158 @group
9159 $ @kbd{find @var{dir} @var{tests} | \
9160   tar -cf @var{archive} -T - --no-recursion}
9161 @end group
9162 @end smallexample
9163
9164 The @option{--no-recursion} option also applies when extracting: it
9165 causes @command{tar} to extract only the matched directory entries, not
9166 the files under those directories.
9167
9168 The @option{--no-recursion} option also affects how globbing patterns
9169 are interpreted (@pxref{controlling pattern-matching}).
9170
9171 The @option{--no-recursion} and @option{--recursion} options apply to
9172 later options and operands, and can be overridden by later occurrences
9173 of @option{--no-recursion} and @option{--recursion}.  For example:
9174
9175 @smallexample
9176 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
9177 @end smallexample
9178
9179 @noindent
9180 creates an archive with one entry for @file{grape}, and the recursive
9181 contents of @file{grape/concord}, but no entries under @file{grape}
9182 other than @file{grape/concord}.
9183
9184 @node one
9185 @section Crossing File System Boundaries
9186 @cindex File system boundaries, not crossing
9187
9188 @command{tar} will normally automatically cross file system boundaries in
9189 order to archive files which are part of a directory tree.  You can
9190 change this behavior by running @command{tar} and specifying
9191 @option{--one-file-system}.  This option only affects files that are
9192 archived because they are in a directory that is being archived;
9193 @command{tar} will still archive files explicitly named on the command line
9194 or through @option{--files-from}, regardless of where they reside.
9195
9196 @table @option
9197 @opindex one-file-system
9198 @item --one-file-system
9199 Prevents @command{tar} from crossing file system boundaries when
9200 archiving.  Use in conjunction with any write operation.
9201 @end table
9202
9203 The @option{--one-file-system} option causes @command{tar} to modify its
9204 normal behavior in archiving the contents of directories.  If a file in
9205 a directory is not on the same file system as the directory itself, then
9206 @command{tar} will not archive that file.  If the file is a directory
9207 itself, @command{tar} will not archive anything beneath it; in other words,
9208 @command{tar} will not cross mount points.
9209
9210 This option is useful for making full or incremental archival backups of
9211 a file system.  If this option is used in conjunction with
9212 @option{--verbose} (@option{-v}), files that are excluded are
9213 mentioned by name on the standard error.
9214
9215 @menu
9216 * directory::                   Changing Directory
9217 * absolute::                    Absolute File Names
9218 @end menu
9219
9220 @node directory
9221 @subsection Changing the Working Directory
9222
9223 @FIXME{need to read over this node now for continuity; i've switched
9224 things around some.}
9225
9226 @cindex Changing directory mid-stream
9227 @cindex Directory, changing mid-stream
9228 @cindex Working directory, specifying
9229 To change the working directory in the middle of a list of file names,
9230 either on the command line or in a file specified using
9231 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
9232 This will change the working directory to the specified directory
9233 after that point in the list.
9234
9235 @table @option
9236 @opindex directory
9237 @item --directory=@var{directory}
9238 @itemx -C @var{directory}
9239 Changes the working directory in the middle of a command line.
9240 @end table
9241
9242 For example,
9243
9244 @smallexample
9245 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
9246 @end smallexample
9247
9248 @noindent
9249 will place the files @file{grape} and @file{prune} from the current
9250 directory into the archive @file{jams.tar}, followed by the file
9251 @file{cherry} from the directory @file{food}.  This option is especially
9252 useful when you have several widely separated files that you want to
9253 store in the same archive.
9254
9255 Note that the file @file{cherry} is recorded in the archive under the
9256 precise name @file{cherry}, @emph{not} @file{food/cherry}.  Thus, the
9257 archive will contain three files that all appear to have come from the
9258 same directory; if the archive is extracted with plain @samp{tar
9259 --extract}, all three files will be written in the current directory.
9260
9261 Contrast this with the command,
9262
9263 @smallexample
9264 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
9265 @end smallexample
9266
9267 @noindent
9268 which records the third file in the archive under the name
9269 @file{red/cherry} so that, if the archive is extracted using
9270 @samp{tar --extract}, the third file will be written in a subdirectory
9271 named @file{red}.
9272
9273 You can use the @option{--directory} option to make the archive
9274 independent of the original name of the directory holding the files.
9275 The following command places the files @file{/etc/passwd},
9276 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
9277 @file{foo.tar}:
9278
9279 @smallexample
9280 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
9281 @end smallexample
9282
9283 @noindent
9284 However, the names of the archive members will be exactly what they were
9285 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
9286 They will not appear to be related by file name to the original
9287 directories where those files were located.
9288
9289 Note that @option{--directory} options are interpreted consecutively.  If
9290 @option{--directory} specifies a relative file name, it is interpreted
9291 relative to the then current directory, which might not be the same as
9292 the original current working directory of @command{tar}, due to a previous
9293 @option{--directory} option.
9294
9295 When using @option{--files-from} (@pxref{files}), you can put various
9296 @command{tar} options (including @option{-C}) in the file list.  Notice,
9297 however, that in this case the option and its argument may not be
9298 separated by whitespace.  If you use short option, its argument must
9299 either follow the option letter immediately, without any intervening
9300 whitespace, or occupy the next line.  Otherwise, if you use long
9301 option, separate its argument by an equal sign.
9302
9303 For instance, the file list for the above example will be:
9304
9305 @smallexample
9306 @group
9307 -C/etc
9308 passwd
9309 hosts
9310 --directory=/lib
9311 libc.a
9312 @end group
9313 @end smallexample
9314
9315 @noindent
9316 To use it, you would invoke @command{tar} as follows:
9317
9318 @smallexample
9319 $ @kbd{tar -c -f foo.tar --files-from list}
9320 @end smallexample
9321
9322 The interpretation of options in file lists is disabled by
9323 @option{--verbatim-files-from} and @option{--null} options.
9324
9325 @node absolute
9326 @subsection Absolute File Names
9327 @cindex absolute file names
9328 @cindex file names, absolute
9329
9330 By default, @GNUTAR{} drops a leading @samp{/} on
9331 input or output, and complains about file names containing a @file{..}
9332 component.  There is an option that turns off this behavior:
9333
9334 @table @option
9335 @opindex absolute-names
9336 @item --absolute-names
9337 @itemx -P
9338 Do not strip leading slashes from file names, and permit file names
9339 containing a @file{..} file name component.
9340 @end table
9341
9342 When @command{tar} extracts archive members from an archive, it strips any
9343 leading slashes (@samp{/}) from the member name.  This causes absolute
9344 member names in the archive to be treated as relative file names.  This
9345 allows you to have such members extracted wherever you want, instead of
9346 being restricted to extracting the member in the exact directory named
9347 in the archive.  For example, if the archive member has the name
9348 @file{/etc/passwd}, @command{tar} will extract it as if the name were
9349 really @file{etc/passwd}.
9350
9351 File names containing @file{..} can cause problems when extracting, so
9352 @command{tar} normally warns you about such files when creating an
9353 archive, and rejects attempts to extracts such files.
9354
9355 Other @command{tar} programs do not do this.  As a result, if you
9356 create an archive whose member names start with a slash, they will be
9357 difficult for other people with a non-@GNUTAR{}
9358 program to use.  Therefore, @GNUTAR{} also strips
9359 leading slashes from member names when putting members into the
9360 archive.  For example, if you ask @command{tar} to add the file
9361 @file{/bin/ls} to an archive, it will do so, but the member name will
9362 be @file{bin/ls}@footnote{A side effect of this is that when
9363 @option{--create} is used with @option{--verbose} the resulting output
9364 is not, generally speaking, the same as the one you'd get running
9365 @kbd{tar --list} command.  This may be important if you use some
9366 scripts for comparing both outputs.  @xref{listing member and file names},
9367 for the information on how to handle this case.}.
9368
9369 Symbolic links containing @file{..} or leading @samp{/} can also cause
9370 problems when extracting, so @command{tar} normally extracts them last;
9371 it may create empty files as placeholders during extraction.
9372
9373 If you use the @option{--absolute-names} (@option{-P}) option,
9374 @command{tar} will do none of these transformations.
9375
9376 To archive or extract files relative to the root directory, specify
9377 the @option{--absolute-names} (@option{-P}) option.
9378
9379 Normally, @command{tar} acts on files relative to the working
9380 directory---ignoring superior directory names when archiving, and
9381 ignoring leading slashes when extracting.
9382
9383 When you specify @option{--absolute-names} (@option{-P}),
9384 @command{tar} stores file names including all superior directory
9385 names, and preserves leading slashes.  If you only invoked
9386 @command{tar} from the root directory you would never need the
9387 @option{--absolute-names} option, but using this option
9388 may be more convenient than switching to root.
9389
9390 @FIXME{Should be an example in the tutorial/wizardry section using this
9391 to transfer files between systems.}
9392
9393 @table @option
9394 @item --absolute-names
9395 Preserves full file names (including superior directory names) when
9396 archiving and extracting files.
9397
9398 @end table
9399
9400 @command{tar} prints out a message about removing the @samp{/} from
9401 file names.  This message appears once per @GNUTAR{}
9402 invocation.  It represents something which ought to be told; ignoring
9403 what it means can cause very serious surprises, later.
9404
9405 Some people, nevertheless, do not want to see this message.  Wanting to
9406 play really dangerously, one may of course redirect @command{tar} standard
9407 error to the sink.  For example, under @command{sh}:
9408
9409 @smallexample
9410 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
9411 @end smallexample
9412
9413 @noindent
9414 Another solution, both nicer and simpler, would be to change to
9415 the @file{/} directory first, and then avoid absolute notation.
9416 For example:
9417
9418 @smallexample
9419 $ @kbd{tar -c -f archive.tar -C / home}
9420 @end smallexample
9421
9422 @xref{Integrity}, for some of the security-related implications
9423 of using this option.
9424
9425 @include parse-datetime.texi
9426
9427 @node Formats
9428 @chapter Controlling the Archive Format
9429
9430 @cindex Tar archive formats
9431 Due to historical reasons, there are several formats of tar archives.
9432 All of them are based on the same principles, but have some subtle
9433 differences that often make them incompatible with each other.
9434
9435 GNU tar is able to create and handle archives in a variety of formats.
9436 The most frequently used formats are (in alphabetical order):
9437
9438 @table @asis
9439 @item gnu
9440 Format used by @GNUTAR{} versions up to 1.13.25.  This format derived
9441 from an early @acronym{POSIX} standard, adding some improvements such as
9442 sparse file handling and incremental archives.  Unfortunately these
9443 features were implemented in a way incompatible with other archive
9444 formats.
9445
9446 Archives in @samp{gnu} format are able to hold file names of unlimited
9447 length.
9448
9449 @item oldgnu
9450 Format used by @GNUTAR{} of versions prior to 1.12.
9451
9452 @item v7
9453 Archive format, compatible with the V7 implementation of tar.  This
9454 format imposes a number of limitations.  The most important of them
9455 are:
9456
9457 @enumerate
9458 @item The maximum length of a file name is limited to 99 characters.
9459 @item The maximum length of a symbolic link is limited to 99 characters.
9460 @item It is impossible to store special files (block and character
9461 devices, fifos etc.)
9462 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
9463 octal)
9464 @item V7 archives do not contain symbolic ownership information (user
9465 and group name of the file owner).
9466 @end enumerate
9467
9468 This format has traditionally been used by Automake when producing
9469 Makefiles.  This practice will change in the future, in the meantime,
9470 however this means that projects containing file names more than 99
9471 characters long will not be able to use @GNUTAR{} @value{VERSION} and
9472 Automake prior to 1.9.
9473
9474 @item ustar
9475 Archive format defined by @acronym{POSIX.1-1988} specification.  It stores
9476 symbolic ownership information.  It is also able to store
9477 special files.  However, it imposes several restrictions as well:
9478
9479 @enumerate
9480 @item The maximum length of a file name is limited to 256 characters,
9481 provided that the file name can be split at a directory separator in
9482 two parts, first of them being at most 155 bytes long.  So, in most
9483 cases the maximum file name length will be shorter than 256
9484 characters.
9485 @item The maximum length of a symbolic link name is limited to
9486 100 characters.
9487 @item Maximum size of a file the archive is able to accommodate
9488 is 8GB
9489 @item Maximum value of UID/GID is 2097151.
9490 @item Maximum number of bits in device major and minor numbers is 21.
9491 @end enumerate
9492
9493 @item star
9494 Format used by J@"org Schilling @command{star}
9495 implementation.  @GNUTAR{} is able to read @samp{star} archives but
9496 currently does not produce them.
9497
9498 @item posix
9499 Archive format defined by @acronym{POSIX.1-2001} specification.  This is the
9500 most flexible and feature-rich format.  It does not impose any
9501 restrictions on file sizes or file name lengths.  This format is quite
9502 recent, so not all tar implementations are able to handle it properly.
9503 However, this format is designed in such a way that any tar
9504 implementation able to read @samp{ustar} archives will be able to read
9505 most @samp{posix} archives as well, with the only exception that any
9506 additional information (such as long file names etc.)@: will in such
9507 case be extracted as plain text files along with the files it refers to.
9508
9509 This archive format will be the default format for future versions
9510 of @GNUTAR{}.
9511
9512 @end table
9513
9514 The following table summarizes the limitations of each of these
9515 formats:
9516
9517 @multitable @columnfractions .10 .20 .20 .20 .20
9518 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
9519 @item gnu    @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9520 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9521 @item v7     @tab 2097151 @tab 8GB @tab 99 @tab n/a
9522 @item ustar  @tab 2097151 @tab 8GB @tab 256 @tab 21
9523 @item posix  @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
9524 @end multitable
9525
9526 The default format for @GNUTAR{} is defined at compilation
9527 time.  You may check it by running @command{tar --help}, and examining
9528 the last lines of its output.  Usually, @GNUTAR{} is configured
9529 to create archives in @samp{gnu} format, however, future version will
9530 switch to @samp{posix}.
9531
9532 @menu
9533 * Compression::                 Using Less Space through Compression
9534 * Attributes::                  Handling File Attributes
9535 * Portability::                 Making @command{tar} Archives More Portable
9536 * cpio::                        Comparison of @command{tar} and @command{cpio}
9537 @end menu
9538
9539 @node Compression
9540 @section Using Less Space through Compression
9541
9542 @menu
9543 * gzip::                        Creating and Reading Compressed Archives
9544 * sparse::                      Archiving Sparse Files
9545 @end menu
9546
9547 @node gzip
9548 @subsection Creating and Reading Compressed Archives
9549 @cindex Compressed archives
9550 @cindex Storing archives in compressed format
9551
9552 @cindex gzip
9553 @cindex bzip2
9554 @cindex lzip
9555 @cindex lzma
9556 @cindex lzop
9557 @cindex compress
9558 @GNUTAR{} is able to create and read compressed archives.  It supports
9559 a wide variety of compression programs, namely: @command{gzip},
9560 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
9561 @command{xz} and traditional @command{compress}. The latter is
9562 supported mostly for backward compatibility, and we recommend
9563 against using it, because it is by far less effective than the other
9564 compression programs@footnote{It also had patent problems in the past.}.
9565
9566 Creating a compressed archive is simple: you just specify a
9567 @dfn{compression option} along with the usual archive creation
9568 commands.  The compression option is @option{-z} (@option{--gzip}) to
9569 create a @command{gzip} compressed archive, @option{-j}
9570 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
9571 @option{--lzip} to create an @asis{lzip} compressed archive,
9572 @option{-J} (@option{--xz}) to create an @asis{XZ} archive,
9573 @option{--lzma} to create an @asis{LZMA} compressed
9574 archive, @option{--lzop} to create an @asis{LSOP} archive, and
9575 @option{-Z} (@option{--compress}) to use @command{compress} program.
9576 For example:
9577
9578 @smallexample
9579 $ @kbd{tar czf archive.tar.gz .}
9580 @end smallexample
9581
9582 You can also let @GNUTAR{} select the compression program based on
9583 the suffix of the archive file name. This is done using
9584 @option{--auto-compress} (@option{-a}) command line option. For
9585 example, the following invocation will use @command{bzip2} for
9586 compression:
9587
9588 @smallexample
9589 $ @kbd{tar caf archive.tar.bz2 .}
9590 @end smallexample
9591
9592 @noindent
9593 whereas the following one will use @command{lzma}:
9594
9595 @smallexample
9596 $ @kbd{tar caf archive.tar.lzma .}
9597 @end smallexample
9598
9599 For a complete list of file name suffixes recognized by @GNUTAR{},
9600 see @ref{auto-compress}.
9601
9602 Reading compressed archive is even simpler: you don't need to specify
9603 any additional options as @GNUTAR{} recognizes its format
9604 automatically.  Thus, the following commands will list and extract the
9605 archive created in previous example:
9606
9607 @smallexample
9608 # List the compressed archive
9609 $ @kbd{tar tf archive.tar.gz}
9610 # Extract the compressed archive
9611 $ @kbd{tar xf archive.tar.gz}
9612 @end smallexample
9613
9614 The format recognition algorithm is based on @dfn{signatures}, a
9615 special byte sequences in the beginning of file, that are specific for
9616 certain compression formats.  If this approach fails, @command{tar}
9617 falls back to using archive name suffix to determine its format
9618 (@pxref{auto-compress}, for a list of recognized suffixes).
9619
9620 @anchor{alternative decompression programs}
9621 @cindex alternative decompression programs
9622 Some compression programs are able to handle different compression
9623 formats.  @GNUTAR{} uses this, if the principal decompressor for the
9624 given format is not available.  For example, if @command{compress} is
9625 not installed, @command{tar} will try to use @command{gzip}.  As of
9626 version @value{VERSION} the following alternatives are
9627 tried@footnote{To verbosely trace the decompressor selection, use the
9628 @option{--warning=decompress-program} option
9629 (@pxref{warnings,decompress-program}).}:
9630
9631 @multitable @columnfractions 0.3 0.3 0.3
9632 @headitem Format @tab Main decompressor @tab Alternatives
9633 @item compress @tab compress @tab gzip
9634 @item lzma     @tab lzma     @tab xz
9635 @item bzip2    @tab bzip2    @tab lbzip2
9636 @end multitable
9637
9638 The only case when you have to specify a decompression option while
9639 reading the archive is when reading from a pipe or from a tape drive
9640 that does not support random access.  However, in this case @GNUTAR{}
9641 will indicate which option you should use.  For example:
9642
9643 @smallexample
9644 $ @kbd{cat archive.tar.gz | tar tf -}
9645 tar: Archive is compressed.  Use -z option
9646 tar: Error is not recoverable: exiting now
9647 @end smallexample
9648
9649 If you see such diagnostics, just add the suggested option to the
9650 invocation of @GNUTAR{}:
9651
9652 @smallexample
9653 $ @kbd{cat archive.tar.gz | tar tzf -}
9654 @end smallexample
9655
9656 Notice also, that there are several restrictions on operations on
9657 compressed archives.  First of all, compressed archives cannot be
9658 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
9659 them or delete (@option{--delete}) members from them or
9660 add (@option{--append}, alias @option{-r}) members to them.  Likewise, you
9661 cannot append another @command{tar} archive to a compressed archive using
9662 @option{--concatenate} (@option{-A}).  Secondly, multi-volume
9663 archives cannot be compressed.
9664
9665 The following options allow to select a particular compressor program:
9666
9667 @table @option
9668 @opindex gzip
9669 @opindex ungzip
9670 @item -z
9671 @itemx --gzip
9672 @itemx --ungzip
9673 Filter the archive through @command{gzip}.
9674
9675 @opindex xz
9676 @item -J
9677 @itemx --xz
9678 Filter the archive through @code{xz}.
9679
9680 @item -j
9681 @itemx --bzip2
9682 Filter the archive through @code{bzip2}.
9683
9684 @opindex lzip
9685 @item --lzip
9686 Filter the archive through @command{lzip}.
9687
9688 @opindex lzma
9689 @item --lzma
9690 Filter the archive through @command{lzma}.
9691
9692 @opindex lzop
9693 @item --lzop
9694 Filter the archive through @command{lzop}.
9695
9696 @opindex compress
9697 @opindex uncompress
9698 @item -Z
9699 @itemx --compress
9700 @itemx --uncompress
9701 Filter the archive through @command{compress}.
9702 @end table
9703
9704 When any of these options is given, @GNUTAR{} searches the compressor
9705 binary in the current path and invokes it.  The name of the compressor
9706 program is specified at compilation time using a corresponding
9707 @option{--with-@var{compname}} option to @command{configure}, e.g.
9708 @option{--with-bzip2} to select a specific @command{bzip2} binary.
9709 @xref{lbzip2}, for a detailed discussion.
9710
9711 The output produced by @command{tar --help} shows the actual
9712 compressor names along with each of these options.
9713
9714 You can use any of these options on physical devices (tape drives,
9715 etc.)@: and remote files as well as on normal files; data to or from
9716 such devices or remote files is reblocked by another copy of the
9717 @command{tar} program to enforce the specified (or default) record
9718 size.  The default compression parameters are used.
9719 You can override them by using the @option{-I} option (see
9720 below), e.g.:
9721
9722 @smallexample
9723 $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
9724 @end smallexample
9725
9726 @noindent
9727 A more traditional way to do this is to use a pipe:
9728
9729 @smallexample
9730 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
9731 @end smallexample
9732
9733 @cindex corrupted archives
9734 Compressed archives are easily corrupted, because compressed files
9735 have little redundancy.  The adaptive nature of the
9736 compression scheme means that the compression tables are implicitly
9737 spread all over the archive.  If you lose a few blocks, the dynamic
9738 construction of the compression tables becomes unsynchronized, and there
9739 is little chance that you could recover later in the archive.
9740
9741 Other compression options provide better control over creating
9742 compressed archives.  These are:
9743
9744 @table @option
9745 @anchor{auto-compress}
9746 @opindex auto-compress
9747 @item --auto-compress
9748 @itemx -a
9749 Select a compression program to use by the archive file name
9750 suffix.  The following suffixes are recognized:
9751
9752 @multitable @columnfractions 0.3 0.6
9753 @headitem Suffix @tab Compression program
9754 @item @samp{.gz} @tab @command{gzip}
9755 @item @samp{.tgz} @tab @command{gzip}
9756 @item @samp{.taz} @tab @command{gzip}
9757 @item @samp{.Z} @tab @command{compress}
9758 @item @samp{.taZ} @tab @command{compress}
9759 @item @samp{.bz2} @tab @command{bzip2}
9760 @item @samp{.tz2} @tab @command{bzip2}
9761 @item @samp{.tbz2} @tab @command{bzip2}
9762 @item @samp{.tbz} @tab @command{bzip2}
9763 @item @samp{.lz} @tab @command{lzip}
9764 @item @samp{.lzma} @tab @command{lzma}
9765 @item @samp{.tlz} @tab @command{lzma}
9766 @item @samp{.lzo} @tab @command{lzop}
9767 @item @samp{.xz} @tab @command{xz}
9768 @end multitable
9769
9770 @anchor{use-compress-program}
9771 @opindex use-compress-program
9772 @item --use-compress-program=@var{command}
9773 @itemx -I=@var{command}
9774 Use external compression program @var{command}.  Use this option if you
9775 want to specify options for the compression program, or if you
9776 are not happy with the compression program associated with the suffix
9777 at compile time, or if you have a compression program that @GNUTAR{}
9778 does not support.  The @var{command} argument is a valid command
9779 invocation, as you would type it at the command line prompt, with any
9780 additional options as needed.  Enclose it in quotes if it contains
9781 white space (@pxref{external, Running External Commands}).
9782
9783 The @var{command} should follow two conventions:
9784
9785 First, when invoked without additional options, it should read data
9786 from standard input, compress it and output it on standard output.
9787
9788 Secondly, if invoked with the additional @option{-d} option, it should
9789 do exactly the opposite, i.e., read the compressed data from the
9790 standard input and produce uncompressed data on the standard output.
9791
9792 The latter requirement means that you must not use the @option{-d}
9793 option as a part of the @var{command} itself.
9794 @end table
9795
9796 @cindex gpg, using with tar
9797 @cindex gnupg, using with tar
9798 @cindex Using encrypted archives
9799 The @option{--use-compress-program} option, in particular, lets you
9800 implement your own filters, not necessarily dealing with
9801 compression/decompression.  For example, suppose you wish to implement
9802 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9803 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9804 Manual}).  The following script does that:
9805
9806 @smallexample
9807 @group
9808 #! /bin/sh
9809 case $1 in
9810 -d) gpg --decrypt - | gzip -d -c;;
9811 '') gzip -c | gpg -s;;
9812 *)  echo "Unknown option $1">&2; exit 1;;
9813 esac
9814 @end group
9815 @end smallexample
9816
9817 Suppose you name it @file{gpgz} and save it somewhere in your
9818 @env{PATH}.  Then the following command will create a compressed
9819 archive signed with your private key:
9820
9821 @smallexample
9822 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
9823 @end smallexample
9824
9825 @noindent
9826 Likewise, the command below will list its contents:
9827
9828 @smallexample
9829 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
9830 @end smallexample
9831
9832 @ignore
9833 The above is based on the following discussion:
9834
9835      I have one question, or maybe it's a suggestion if there isn't a way
9836      to do it now.  I would like to use @option{--gzip}, but I'd also like
9837      the output to be fed through a program like @acronym{GNU}
9838      @command{ecc} (actually, right now that's @samp{exactly} what I'd like
9839      to use :-)), basically adding ECC protection on top of compression.
9840      It seems as if this should be quite easy to do, but I can't work out
9841      exactly how to go about it.  Of course, I can pipe the standard output
9842      of @command{tar} through @command{ecc}, but then I lose (though I
9843      haven't started using it yet, I confess) the ability to have
9844      @command{tar} use @command{rmt} for it's I/O (I think).
9845
9846      I think the most straightforward thing would be to let me specify a
9847      general set of filters outboard of compression (preferably ordered,
9848      so the order can be automatically reversed on input operations, and
9849      with the options they require specifiable), but beggars shouldn't be
9850      choosers and anything you decide on would be fine with me.
9851
9852      By the way, I like @command{ecc} but if (as the comments say) it can't
9853      deal with loss of block sync, I'm tempted to throw some time at adding
9854      that capability.  Supposing I were to actually do such a thing and
9855      get it (apparently) working, do you accept contributed changes to
9856      utilities like that?  (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9857
9858   Isn't that exactly the role of the
9859   @option{--use-compress-prog=@var{program}} option?
9860   I never tried it myself, but I suspect you may want to write a
9861   @var{prog} script or program able to filter stdin to stdout to
9862   way you want.  It should recognize the @option{-d} option, for when
9863   extraction is needed rather than creation.
9864
9865   It has been reported that if one writes compressed data (through the
9866   @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9867   the DLT compression mode, the data will actually get bigger and one will
9868   end up with less space on the tape.
9869 @end ignore
9870
9871 @menu
9872 * lbzip2::  Using lbzip2 with @GNUTAR{}.
9873 @end menu
9874
9875 @node lbzip2
9876 @subsubsection Using lbzip2 with @GNUTAR{}.
9877 @cindex lbzip2
9878 @cindex Laszlo Ersek
9879   @command{Lbzip2} is a multithreaded utility for handling
9880 @samp{bzip2} compression, written by Laszlo Ersek.  It makes use of
9881 multiple processors to speed up its operation and in general works
9882 considerably faster than @command{bzip2}.  For a detailed description
9883 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9884 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9885 lbzip2: parallel bzip2 utility}.
9886
9887   Recent versions of @command{lbzip2} are mostly command line compatible
9888 with @command{bzip2}, which makes it possible to automatically invoke
9889 it via the @option{--bzip2} @GNUTAR{} command line option.  To do so,
9890 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9891 line option, like this:
9892
9893 @smallexample
9894 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9895 @end smallexample
9896
9897   Once configured and compiled this way, @command{tar --help} will show the
9898 following:
9899
9900 @smallexample
9901 @group
9902 $ @kbd{tar --help | grep -- --bzip2}
9903   -j, --bzip2                filter the archive through lbzip2
9904 @end group
9905 @end smallexample
9906
9907 @noindent
9908 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9909
9910 @node sparse
9911 @subsection Archiving Sparse Files
9912 @cindex Sparse Files
9913
9914 Files in the file system occasionally have @dfn{holes}.  A @dfn{hole}
9915 in a file is a section of the file's contents which was never written.
9916 The contents of a hole reads as all zeros.  On many operating systems,
9917 actual disk storage is not allocated for holes, but they are counted
9918 in the length of the file.  If you archive such a file, @command{tar}
9919 could create an archive longer than the original.  To have @command{tar}
9920 attempt to recognize the holes in a file, use @option{--sparse}
9921 (@option{-S}).  When you use this option, then, for any file using
9922 less disk space than would be expected from its length, @command{tar}
9923 searches the file for holes.  It then records in the archive for the file where
9924 the holes (consecutive stretches of zeros) are, and only archives the
9925 ``real contents'' of the file.  On extraction (using @option{--sparse} is not
9926 needed on extraction) any such files have also holes created wherever the holes
9927 were found.  Thus, if you use @option{--sparse}, @command{tar} archives won't
9928 take more space than the original.
9929
9930 @GNUTAR{} uses two methods for detecting holes in sparse files.  These
9931 methods are described later in this subsection.
9932
9933 @table @option
9934 @opindex sparse
9935 @item -S
9936 @itemx --sparse
9937 This option instructs @command{tar} to test each file for sparseness
9938 before attempting to archive it.  If the file is found to be sparse it
9939 is treated specially, thus allowing to decrease the amount of space
9940 used by its image in the archive.
9941
9942 This option is meaningful only when creating or updating archives.  It
9943 has no effect on extraction.
9944 @end table
9945
9946 Consider using @option{--sparse} when performing file system backups,
9947 to avoid archiving the expanded forms of files stored sparsely in the
9948 system.
9949
9950 Even if your system has no sparse files currently, some may be
9951 created in the future.  If you use @option{--sparse} while making file
9952 system backups as a matter of course, you can be assured the archive
9953 will never take more space on the media than the files take on disk
9954 (otherwise, archiving a disk filled with sparse files might take
9955 hundreds of tapes).  @xref{Incremental Dumps}.
9956
9957 However, be aware that @option{--sparse} option may present a serious
9958 drawback.  Namely, in order to determine the positions of holes in a file
9959 @command{tar} may have to read it before trying to archive it, so in total
9960 the file may be read @strong{twice}.  This may happen when your OS or your FS
9961 does not support @dfn{SEEK_HOLE/SEEK_DATA} feature in @dfn{lseek} (See
9962 @option{--hole-detection}, below).
9963
9964 @cindex sparse formats, defined
9965 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9966 sparse files using in three distinct ways, called @dfn{sparse
9967 formats}.  A sparse format is identified by its @dfn{number},
9968 consisting, as usual of two decimal numbers, delimited by a dot.  By
9969 default, format @samp{1.0} is used.  If, for some reason, you wish to
9970 use an earlier format, you can select it using
9971 @option{--sparse-version} option.
9972
9973 @table @option
9974 @opindex sparse-version
9975 @item --sparse-version=@var{version}
9976 Select the format to store sparse files in.  Valid @var{version} values
9977 are: @samp{0.0}, @samp{0.1} and @samp{1.0}.  @xref{Sparse Formats},
9978 for a detailed description of each format.
9979 @end table
9980
9981 Using @option{--sparse-format} option implies @option{--sparse}.
9982
9983 @table @option
9984 @opindex hole-detection
9985 @cindex hole detection
9986 @item --hole-detection=@var{method}
9987 Enforce concrete hole detection method.  Before the real contents of sparse
9988 file are stored, @command{tar} needs to gather knowledge about file
9989 sparseness.  This is because it needs to have the file's map of holes
9990 stored into tar header before it starts archiving the file contents.
9991 Currently, two methods of hole detection are implemented:
9992
9993 @itemize @bullet
9994 @item @option{--hole-detection=seek}
9995 Seeking the file for data and holes.  It uses enhancement of the @code{lseek}
9996 system call (@code{SEEK_HOLE} and @code{SEEK_DATA}) which is able to
9997 reuse file system knowledge about sparse file contents - so the
9998 detection is usually very fast.  To use this feature, your file system
9999 and operating system must support it.  At the time of this writing
10000 (2015) this feature, in spite of not being accepted by POSIX, is
10001 fairly widely supported by different operating systems.
10002
10003 @item @option{--hole-detection=raw}
10004 Reading byte-by-byte the whole sparse file before the archiving.  This
10005 method detects holes like consecutive stretches of zeroes.  Comparing to
10006 the previous method, it is usually much slower, although more
10007 portable.
10008 @end itemize
10009 @end table
10010
10011 When no @option{--hole-detection} option is given, @command{tar} uses
10012 the @samp{seek}, if supported by the operating system.
10013
10014 Using @option{--hole-detection} option implies @option{--sparse}.
10015
10016 @node Attributes
10017 @section Handling File Attributes
10018 @cindex attributes, files
10019 @cindex file attributes
10020
10021 When @command{tar} reads files, it updates their access times.  To
10022 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
10023 reset the access time retroactively or avoid changing it in the first
10024 place.
10025
10026 @table @option
10027 @opindex atime-preserve
10028 @item --atime-preserve
10029 @itemx --atime-preserve=replace
10030 @itemx --atime-preserve=system
10031 Preserve the access times of files that are read.  This works only for
10032 files that you own, unless you have superuser privileges.
10033
10034 @option{--atime-preserve=replace} works on most systems, but it also
10035 restores the data modification time and updates the status change
10036 time.  Hence it doesn't interact with incremental dumps nicely
10037 (@pxref{Incremental Dumps}), and it can set access or data modification times
10038 incorrectly if other programs access the file while @command{tar} is
10039 running.
10040
10041 @option{--atime-preserve=system} avoids changing the access time in
10042 the first place, if the operating system supports this.
10043 Unfortunately, this may or may not work on any given operating system
10044 or file system.  If @command{tar} knows for sure it won't work, it
10045 complains right away.
10046
10047 Currently @option{--atime-preserve} with no operand defaults to
10048 @option{--atime-preserve=replace}, but this is intended to change to
10049 @option{--atime-preserve=system} when the latter is better-supported.
10050
10051 @opindex touch
10052 @item -m
10053 @itemx --touch
10054 Do not extract data modification time.
10055
10056 When this option is used, @command{tar} leaves the data modification times
10057 of the files it extracts as the times when the files were extracted,
10058 instead of setting it to the times recorded in the archive.
10059
10060 This option is meaningless with @option{--list} (@option{-t}).
10061
10062 @opindex same-owner
10063 @item --same-owner
10064 Create extracted files with the same ownership they have in the
10065 archive.
10066
10067 This is the default behavior for the superuser,
10068 so this option is meaningful only for non-root users, when @command{tar}
10069 is executed on those systems able to give files away.  This is
10070 considered as a security flaw by many people, at least because it
10071 makes quite difficult to correctly account users for the disk space
10072 they occupy.  Also, the @code{suid} or @code{sgid} attributes of
10073 files are easily and silently lost when files are given away.
10074
10075 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
10076 separately.  If it can't find a user name (because the user @acronym{ID} is not
10077 in @file{/etc/passwd}), then it does not write one.  When restoring,
10078 it tries to look the name (if one was written) up in
10079 @file{/etc/passwd}.  If it fails, then it uses the user @acronym{ID} stored in
10080 the archive instead.
10081
10082 @opindex no-same-owner
10083 @item --no-same-owner
10084 @itemx -o
10085 Do not attempt to restore ownership when extracting.  This is the
10086 default behavior for ordinary users, so this option has an effect
10087 only for the superuser.
10088
10089 @opindex numeric-owner
10090 @item --numeric-owner
10091 The @option{--numeric-owner} option allows (ANSI) archives to be written
10092 without user/group name information or such information to be ignored
10093 when extracting.  It effectively disables the generation and/or use
10094 of user/group name information.  This option forces extraction using
10095 the numeric ids from the archive, ignoring the names.
10096
10097 This is useful in certain circumstances, when restoring a backup from
10098 an emergency floppy with different passwd/group files for example.
10099 It is otherwise impossible to extract files with the right ownerships
10100 if the password file in use during the extraction does not match the
10101 one belonging to the file system(s) being extracted.  This occurs,
10102 for example, if you are restoring your files after a major crash and
10103 had booted from an emergency floppy with no password file or put your
10104 disk into another machine to do the restore.
10105
10106 The numeric ids are @emph{always} saved into @command{tar} archives.
10107 The identifying names are added at create time when provided by the
10108 system, unless @option{--format=oldgnu} is used.  Numeric ids could be
10109 used when moving archives between a collection of machines using
10110 a centralized management for attribution of numeric ids to users
10111 and groups.  This is often made through using the NIS capabilities.
10112
10113 When making a @command{tar} file for distribution to other sites, it
10114 is sometimes cleaner to use a single owner for all files in the
10115 distribution, and nicer to specify the write permission bits of the
10116 files as stored in the archive independently of their actual value on
10117 the file system.  The way to prepare a clean distribution is usually
10118 to have some Makefile rule creating a directory, copying all needed
10119 files in that directory, then setting ownership and permissions as
10120 wanted (there are a lot of possible schemes), and only then making a
10121 @command{tar} archive out of this directory, before cleaning
10122 everything out.  Of course, we could add a lot of options to
10123 @GNUTAR{} for fine tuning permissions and ownership.
10124 This is not the good way, I think.  @GNUTAR{} is
10125 already crowded with options and moreover, the approach just explained
10126 gives you a great deal of control already.
10127
10128 @xopindex{same-permissions, short description}
10129 @xopindex{preserve-permissions, short description}
10130 @item -p
10131 @itemx --same-permissions
10132 @itemx --preserve-permissions
10133 Extract all protection information.
10134
10135 This option causes @command{tar} to set the modes (access permissions) of
10136 extracted files exactly as recorded in the archive.  If this option
10137 is not used, the current @code{umask} setting limits the permissions
10138 on extracted files.  This option is by default enabled when
10139 @command{tar} is executed by a superuser.
10140
10141
10142 This option is meaningless with @option{--list} (@option{-t}).
10143 @end table
10144
10145 @node Portability
10146 @section Making @command{tar} Archives More Portable
10147
10148 Creating a @command{tar} archive on a particular system that is meant to be
10149 useful later on many other machines and with other versions of @command{tar}
10150 is more challenging than you might think.  @command{tar} archive formats
10151 have been evolving since the first versions of Unix.  Many such formats
10152 are around, and are not always compatible with each other.  This section
10153 discusses a few problems, and gives some advice about making @command{tar}
10154 archives more portable.
10155
10156 One golden rule is simplicity.  For example, limit your @command{tar}
10157 archives to contain only regular files and directories, avoiding
10158 other kind of special files.  Do not attempt to save sparse files or
10159 contiguous files as such.  Let's discuss a few more problems, in turn.
10160
10161 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
10162 archives and archive labels) in GNU and PAX formats.}
10163
10164 @menu
10165 * Portable Names::              Portable Names
10166 * dereference::                 Symbolic Links
10167 * hard links::                  Hard Links
10168 * old::                         Old V7 Archives
10169 * ustar::                       Ustar Archives
10170 * gnu::                         GNU and old GNU format archives.
10171 * posix::                       @acronym{POSIX} archives
10172 * Checksumming::                Checksumming Problems
10173 * Large or Negative Values::    Large files, negative time stamps, etc.
10174 * Other Tars::                  How to Extract GNU-Specific Data Using
10175                                 Other @command{tar} Implementations
10176 @end menu
10177
10178 @node Portable Names
10179 @subsection Portable Names
10180
10181 Use portable file and member names.  A name is portable if it contains
10182 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
10183 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
10184 contain @samp{/-}.  Avoid deep directory nesting.  For portability to
10185 old Unix hosts, limit your file name components to 14 characters or
10186 less.
10187
10188 If you intend to have your @command{tar} archives to be read under
10189 MSDOS, you should not rely on case distinction for file names, and you
10190 might use the @acronym{GNU} @command{doschk} program for helping you
10191 further diagnosing illegal MSDOS names, which are even more limited
10192 than System V's.
10193
10194 @node dereference
10195 @subsection Symbolic Links
10196 @cindex File names, using symbolic links
10197 @cindex Symbolic link as file name
10198
10199 @opindex dereference
10200 Normally, when @command{tar} archives a symbolic link, it writes a
10201 block to the archive naming the target of the link.  In that way, the
10202 @command{tar} archive is a faithful record of the file system contents.
10203 When @option{--dereference} (@option{-h}) is used with
10204 @option{--create} (@option{-c}), @command{tar} archives the files
10205 symbolic links point to, instead of
10206 the links themselves.
10207
10208 When creating portable archives, use @option{--dereference}
10209 (@option{-h}): some systems do not support
10210 symbolic links, and moreover, your distribution might be unusable if
10211 it contains unresolved symbolic links.
10212
10213 When reading from an archive, the @option{--dereference} (@option{-h})
10214 option causes @command{tar} to follow an already-existing symbolic
10215 link when @command{tar} writes or reads a file named in the archive.
10216 Ordinarily, @command{tar} does not follow such a link, though it may
10217 remove the link before writing a new file.  @xref{Dealing with Old
10218 Files}.
10219
10220 The @option{--dereference} option is unsafe if an untrusted user can
10221 modify directories while @command{tar} is running.  @xref{Security}.
10222
10223 @node hard links
10224 @subsection Hard Links
10225 @cindex File names, using hard links
10226 @cindex hard links, dereferencing
10227 @cindex dereferencing hard links
10228
10229 Normally, when @command{tar} archives a hard link, it writes a
10230 block to the archive naming the target of the link (a @samp{1} type
10231 block).  In that way, the actual file contents is stored in file only
10232 once.  For example, consider the following two files:
10233
10234 @smallexample
10235 @group
10236 $ ls -l
10237 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
10238 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
10239 @end group
10240 @end smallexample
10241
10242 Here, @file{jeden} is a link to @file{one}.  When archiving this
10243 directory with a verbose level 2, you will get an output similar to
10244 the following:
10245
10246 @smallexample
10247 $ tar cvvf ../archive.tar .
10248 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10249 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10250 hrw-r--r-- gray/staff        0 2007-10-30 15:11 ./one link to ./jeden
10251 @end smallexample
10252
10253 The last line shows that, instead of storing two copies of the file,
10254 @command{tar} stored it only once, under the name @file{jeden}, and
10255 stored file @file{one} as a hard link to this file.
10256
10257 It may be important to know that all hard links to the given file are
10258 stored in the archive.  For example, this may be necessary for exact
10259 reproduction of the file system.  The following option does that:
10260
10261 @table @option
10262 @xopindex{check-links, described}
10263 @item --check-links
10264 @itemx -l
10265 Check the number of links dumped for each processed file.  If this
10266 number does not match the total number of hard links for the file, print
10267 a warning message.
10268 @end table
10269
10270 For example, trying to archive only file @file{jeden} with this option
10271 produces the following diagnostics:
10272
10273 @smallexample
10274 $ tar -c -f ../archive.tar -l jeden
10275 tar: Missing links to 'jeden'.
10276 @end smallexample
10277
10278 Although creating special records for hard links helps keep a faithful
10279 record of the file system contents and makes archives more compact, it
10280 may present some difficulties when extracting individual members from
10281 the archive.  For example, trying to extract file @file{one} from the
10282 archive created in previous examples produces, in the absence of file
10283 @file{jeden}:
10284
10285 @smallexample
10286 $ tar xf archive.tar ./one
10287 tar: ./one: Cannot hard link to './jeden': No such file or directory
10288 tar: Error exit delayed from previous errors
10289 @end smallexample
10290
10291 The reason for this behavior is that @command{tar} cannot seek back in
10292 the archive to the previous member (in this case, @file{one}), to
10293 extract it@footnote{There are plans to fix this in future releases.}.
10294 If you wish to avoid such problems at the cost of a bigger archive,
10295 use the following option:
10296
10297 @table @option
10298 @xopindex{hard-dereference, described}
10299 @item --hard-dereference
10300 Dereference hard links and store the files they refer to.
10301 @end table
10302
10303 For example, trying this option on our two sample files, we get two
10304 copies in the archive, each of which can then be extracted
10305 independently of the other:
10306
10307 @smallexample
10308 @group
10309 $ tar -c -vv -f ../archive.tar --hard-dereference .
10310 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10311 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10312 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./one
10313 @end group
10314 @end smallexample
10315
10316 @node old
10317 @subsection Old V7 Archives
10318 @cindex Format, old style
10319 @cindex Old style format
10320 @cindex Old style archives
10321 @cindex v7 archive format
10322
10323 Certain old versions of @command{tar} cannot handle additional
10324 information recorded by newer @command{tar} programs.  To create an
10325 archive in V7 format (not ANSI), which can be read by these old
10326 versions, specify the @option{--format=v7} option in
10327 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
10328 accepts @option{--portability} or @option{--old-archive} for this
10329 option).  When you specify it,
10330 @command{tar} leaves out information about directories, pipes, fifos,
10331 contiguous files, and device files, and specifies file ownership by
10332 group and user IDs instead of group and user names.
10333
10334 When updating an archive, do not use @option{--format=v7}
10335 unless the archive was created using this option.
10336
10337 In most cases, a @emph{new} format archive can be read by an @emph{old}
10338 @command{tar} program without serious trouble, so this option should
10339 seldom be needed.  On the other hand, most modern @command{tar}s are
10340 able to read old format archives, so it might be safer for you to
10341 always use @option{--format=v7} for your distributions.  Notice,
10342 however, that @samp{ustar} format is a better alternative, as it is
10343 free from many of @samp{v7}'s drawbacks.
10344
10345 @node ustar
10346 @subsection Ustar Archive Format
10347
10348 @cindex ustar archive format
10349 The archive format defined by the @acronym{POSIX}.1-1988 specification is
10350 called @code{ustar}.  Although it is more flexible than the V7 format, it
10351 still has many restrictions (@pxref{Formats,ustar}, for the detailed
10352 description of @code{ustar} format).  Along with V7 format,
10353 @code{ustar} format is a good choice for archives intended to be read
10354 with other implementations of @command{tar}.
10355
10356 To create an archive in @code{ustar} format, use the @option{--format=ustar}
10357 option in conjunction with @option{--create} (@option{-c}).
10358
10359 @node gnu
10360 @subsection @acronym{GNU} and old @GNUTAR{} format
10361
10362 @cindex GNU archive format
10363 @cindex Old GNU archive format
10364 @GNUTAR{} was based on an early draft of the
10365 @acronym{POSIX} 1003.1 @code{ustar} standard.  @acronym{GNU} extensions to
10366 @command{tar}, such as the support for file names longer than 100
10367 characters, use portions of the @command{tar} header record which were
10368 specified in that @acronym{POSIX} draft as unused.  Subsequent changes in
10369 @acronym{POSIX} have allocated the same parts of the header record for
10370 other purposes.  As a result, @GNUTAR{} format is
10371 incompatible with the current @acronym{POSIX} specification, and with
10372 @command{tar} programs that follow it.
10373
10374 In the majority of cases, @command{tar} will be configured to create
10375 this format by default.  This will change in future releases, since
10376 we plan to make @samp{POSIX} format the default.
10377
10378 To force creation a @GNUTAR{} archive, use option
10379 @option{--format=gnu}.
10380
10381 @node posix
10382 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
10383
10384 @cindex POSIX archive format
10385 @cindex PAX archive format
10386 Starting from version 1.14 @GNUTAR{} features full support for
10387 @acronym{POSIX.1-2001} archives.
10388
10389 A @acronym{POSIX} conformant archive will be created if @command{tar}
10390 was given @option{--format=posix} (@option{--format=pax}) option.  No
10391 special option is required to read and extract from a @acronym{POSIX}
10392 archive.
10393
10394 @menu
10395 * PAX keywords:: Controlling Extended Header Keywords.
10396 @end menu
10397
10398 @node PAX keywords
10399 @subsubsection Controlling Extended Header Keywords
10400
10401 @table @option
10402 @opindex pax-option
10403 @item --pax-option=@var{keyword-list}
10404 Handle keywords in @acronym{PAX} extended headers.  This option is
10405 equivalent to @option{-o} option of the @command{pax} utility.
10406 @end table
10407
10408 @var{Keyword-list} is a comma-separated
10409 list of keyword options, each keyword option taking one of
10410 the following forms:
10411
10412 @table @code
10413 @item delete=@var{pattern}
10414 When used with one of archive-creation commands,
10415 this option instructs @command{tar} to omit from extended header records
10416 that it produces any keywords matching the string @var{pattern}.
10417
10418 When used in extract or list mode, this option instructs tar
10419 to ignore any keywords matching the given @var{pattern} in the extended
10420 header records.  In both cases, matching is performed using the pattern
10421 matching notation described in @acronym{POSIX 1003.2}, 3.13
10422 (@pxref{wildcards}).  For example:
10423
10424 @smallexample
10425 --pax-option delete=security.*
10426 @end smallexample
10427
10428 would suppress security-related information.
10429
10430 @item exthdr.name=@var{string}
10431
10432 This keyword allows user control over the name that is written into the
10433 ustar header blocks for the extended headers.  The name is obtained
10434 from @var{string} after making the following substitutions:
10435
10436 @multitable @columnfractions .25 .55
10437 @headitem Meta-character @tab Replaced By
10438 @item %d @tab  The directory name of the file, equivalent to the
10439 result of the @command{dirname} utility on the translated file name.
10440 @item %f @tab  The name of the file with the directory information
10441 stripped, equivalent to the result of the @command{basename} utility
10442 on the translated file name.
10443 @item %p @tab  The process @acronym{ID} of the @command{tar} process.
10444 @item %% @tab  A @samp{%} character.
10445 @end multitable
10446
10447 Any other @samp{%} characters in @var{string} produce undefined
10448 results.
10449
10450 If no option @samp{exthdr.name=string} is specified, @command{tar}
10451 will use the following default value:
10452
10453 @smallexample
10454 %d/PaxHeaders.%p/%f
10455 @end smallexample
10456
10457 @item exthdr.mtime=@var{value}
10458
10459 This keyword defines the value of the @samp{mtime} field that
10460 is written into the ustar header blocks for the extended headers.
10461 By default, the @samp{mtime} field is set to the modification time
10462 of the archive member described by that extended header (or to the
10463 value of the @option{--mtime} option, if supplied).
10464
10465 @item globexthdr.name=@var{string}
10466 This keyword allows user control over the name that is written into
10467 the ustar header blocks for global extended header records.  The name
10468 is obtained from the contents of @var{string}, after making
10469 the following substitutions:
10470
10471 @multitable @columnfractions .25 .55
10472 @headitem Meta-character @tab Replaced By
10473 @item %n @tab An integer that represents the
10474 sequence number of the global extended header record in the archive,
10475 starting at 1.
10476 @item %p @tab The process @acronym{ID} of the @command{tar} process.
10477 @item %% @tab A @samp{%} character.
10478 @end multitable
10479
10480 Any other @samp{%} characters in @var{string} produce undefined results.
10481
10482 If no option @samp{globexthdr.name=string} is specified, @command{tar}
10483 will use the following default value:
10484
10485 @smallexample
10486 $TMPDIR/GlobalHead.%p.%n
10487 @end smallexample
10488
10489 @noindent
10490 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
10491 environment variable.  If @var{TMPDIR} is not set, @command{tar}
10492 uses @samp{/tmp}.
10493
10494 @item globexthdr.mtime=@var{value}
10495
10496 This keyword defines the value of the @samp{mtime} field that
10497 is written into the ustar header blocks for the global extended headers.
10498 By default, the @samp{mtime} field is set to the time when
10499 @command{tar} was invoked.
10500
10501 @item @var{keyword}=@var{value}
10502 When used with one of archive-creation commands, these keyword/value pairs
10503 will be included at the beginning of the archive in a global extended
10504 header record.  When used with one of archive-reading commands,
10505 @command{tar} will behave as if it has encountered these keyword/value
10506 pairs at the beginning of the archive in a global extended header
10507 record.
10508
10509 @item @var{keyword}:=@var{value}
10510 When used with one of archive-creation commands, these keyword/value pairs
10511 will be included as records at the beginning of an extended header for
10512 each file.  This is effectively equivalent to @var{keyword}=@var{value}
10513 form except that it creates no global extended header records.
10514
10515 When used with one of archive-reading commands, @command{tar} will
10516 behave as if these keyword/value pairs were included as records at the
10517 end of each extended header; thus, they will override any global or
10518 file-specific extended header record keywords of the same names.
10519 For example, in the command:
10520
10521 @smallexample
10522 tar --format=posix --create \
10523     --file archive --pax-option gname:=user .
10524 @end smallexample
10525
10526 the group name will be forced to a new value for all files
10527 stored in the archive.
10528 @end table
10529
10530 In any of the forms described above, the @var{value} may be
10531 a string enclosed in curly braces.  In that case, the string
10532 between the braces is understood either as a textual time
10533 representation, as described in @ref{Date input formats}, or a name of
10534 the existing file, starting with @samp{/} or @samp{.}.  In the latter
10535 case, the modification time of that file is used.
10536
10537 For example, to set all modification times to the current date, you
10538 use the following option:
10539
10540 @smallexample
10541 --pax-option='mtime:=@{now@}'
10542 @end smallexample
10543
10544 Note quoting of the option's argument.
10545
10546 @cindex archives, binary equivalent
10547 @cindex binary equivalent archives, creating
10548 As another example, here is the option that ensures that any two
10549 archives created using it, will be binary equivalent if they have the
10550 same contents:
10551
10552 @smallexample
10553 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0
10554 @end smallexample
10555
10556 @noindent
10557 If you extract files from such an archive and recreate the archive
10558 from them, you will also need to eliminate changes due to ctime, as
10559 shown in examples below:
10560
10561 @smallexample
10562 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0,ctime:=0
10563 @end smallexample
10564
10565 @noindent
10566 or
10567
10568 @smallexample
10569 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0,delete=ctime
10570 @end smallexample
10571
10572 @node Checksumming
10573 @subsection Checksumming Problems
10574
10575 SunOS and HP-UX @command{tar} fail to accept archives created using
10576 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
10577 is, file names having characters with the eighth bit set, because they
10578 use signed checksums, while @GNUTAR{} uses unsigned
10579 checksums while creating archives, as per @acronym{POSIX} standards.  On
10580 reading, @GNUTAR{} computes both checksums and accepts either of them.
10581 It is somewhat worrying that a lot of people may go
10582 around doing backup of their files using faulty (or at least
10583 non-standard) software, not learning about it until it's time to
10584 restore their missing files with an incompatible file extractor, or
10585 vice versa.
10586
10587 @GNUTAR{} computes checksums both ways, and accepts either of them
10588 on read, so @acronym{GNU} tar can read Sun tapes even with their
10589 wrong checksums.  @GNUTAR{} produces the standard
10590 checksum, however, raising incompatibilities with Sun.  That is to
10591 say, @GNUTAR{} has not been modified to
10592 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
10593 I've been told that more recent Sun @command{tar} now read standard
10594 archives, so maybe Sun did a similar patch, after all?
10595
10596 The story seems to be that when Sun first imported @command{tar}
10597 sources on their system, they recompiled it without realizing that
10598 the checksums were computed differently, because of a change in
10599 the default signing of @code{char}'s in their compiler.  So they
10600 started computing checksums wrongly.  When they later realized their
10601 mistake, they merely decided to stay compatible with it, and with
10602 themselves afterwards.  Presumably, but I do not really know, HP-UX
10603 has chosen their @command{tar} archives to be compatible with Sun's.
10604 The current standards do not favor Sun @command{tar} format.  In any
10605 case, it now falls on the shoulders of SunOS and HP-UX users to get
10606 a @command{tar} able to read the good archives they receive.
10607
10608 @node Large or Negative Values
10609 @subsection Large or Negative Values
10610 @cindex large values
10611 @cindex future time stamps
10612 @cindex negative time stamps
10613 @UNREVISED
10614
10615 The above sections suggest to use @samp{oldest possible} archive
10616 format if in doubt.  However, sometimes it is not possible.  If you
10617 attempt to archive a file whose metadata cannot be represented using
10618 required format, @GNUTAR{} will print error message and ignore such a
10619 file.  You will than have to switch to a format that is able to
10620 handle such values.  The format summary table (@pxref{Formats}) will
10621 help you to do so.
10622
10623 In particular, when trying to archive files larger than 8GB or with
10624 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
10625 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
10626 @acronym{POSIX} archive formats.  When considering which format to
10627 choose, bear in mind that the @acronym{GNU} format uses
10628 two's-complement base-256 notation to store values that do not fit
10629 into standard @acronym{ustar} range.  Such archives can generally be
10630 read only by a @GNUTAR{} implementation.  Moreover, they sometimes
10631 cannot be correctly restored on another hosts even by @GNUTAR{}.  For
10632 example, using two's complement representation for negative time
10633 stamps that assumes a signed 32-bit @code{time_t} generates archives
10634 that are not portable to hosts with differing @code{time_t}
10635 representations.
10636
10637 On the other hand, @acronym{POSIX} archives, generally speaking, can
10638 be extracted by any tar implementation that understands older
10639 @acronym{ustar} format.  The only exception are files larger than 8GB.
10640
10641 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
10642 POSIX-aware tars.}
10643
10644 @node Other Tars
10645 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
10646
10647 In previous sections you became acquainted with various quirks
10648 necessary to make your archives portable.  Sometimes you may need to
10649 extract archives containing GNU-specific members using some
10650 third-party @command{tar} implementation or an older version of
10651 @GNUTAR{}.  Of course your best bet is to have @GNUTAR{} installed,
10652 but if it is for some reason impossible, this section will explain
10653 how to cope without it.
10654
10655 When we speak about @dfn{GNU-specific} members we mean two classes of
10656 them: members split between the volumes of a multi-volume archive and
10657 sparse members.  You will be able to always recover such members if
10658 the archive is in PAX format.  In addition split members can be
10659 recovered from archives in old GNU format.  The following subsections
10660 describe the required procedures in detail.
10661
10662 @menu
10663 * Split Recovery::       Members Split Between Volumes
10664 * Sparse Recovery::      Sparse Members
10665 @end menu
10666
10667 @node Split Recovery
10668 @subsubsection Extracting Members Split Between Volumes
10669
10670 @cindex Multi-volume archives, extracting using non-GNU tars
10671 If a member is split between several volumes of an old GNU format archive
10672 most third party @command{tar} implementation will fail to extract
10673 it.  To extract it, use @command{tarcat} program (@pxref{Tarcat}).
10674 This program is available from
10675 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
10676 home page}.  It concatenates several archive volumes into a single
10677 valid archive.  For example, if you have three volumes named from
10678 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
10679 extract them using a third-party @command{tar}:
10680
10681 @smallexample
10682 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
10683 @end smallexample
10684
10685 @cindex Multi-volume archives in PAX format, extracting using non-GNU tars
10686 You could use this approach for most (although not all) PAX
10687 format archives as well.  However, extracting split members from a PAX
10688 archive is a much easier task, because PAX volumes are constructed in
10689 such a way that each part of a split member is extracted to a
10690 different file by @command{tar} implementations that are not aware of
10691 GNU extensions.  More specifically, the very first part retains its
10692 original name, and all subsequent parts are named using the pattern:
10693
10694 @smallexample
10695 %d/GNUFileParts.%p/%f.%n
10696 @end smallexample
10697
10698 @noindent
10699 where symbols preceded by @samp{%} are @dfn{macro characters} that
10700 have the following meaning:
10701
10702 @multitable @columnfractions .25 .55
10703 @headitem Meta-character @tab Replaced By
10704 @item %d @tab  The directory name of the file, equivalent to the
10705 result of the @command{dirname} utility on its full name.
10706 @item %f @tab  The file name of the file, equivalent to the result
10707 of the @command{basename} utility on its full name.
10708 @item %p @tab  The process @acronym{ID} of the @command{tar} process that
10709 created the archive.
10710 @item %n @tab  Ordinal number of this particular part.
10711 @end multitable
10712
10713 For example, if the file @file{var/longfile} was split during archive
10714 creation between three volumes, and the creator @command{tar} process
10715 had process @acronym{ID} @samp{27962}, then the member names will be:
10716
10717 @smallexample
10718 var/longfile
10719 var/GNUFileParts.27962/longfile.1
10720 var/GNUFileParts.27962/longfile.2
10721 @end smallexample
10722
10723 When you extract your archive using a third-party @command{tar}, these
10724 files will be created on your disk, and the only thing you will need
10725 to do to restore your file in its original form is concatenate them in
10726 the proper order, for example:
10727
10728 @smallexample
10729 @group
10730 $ @kbd{cd var}
10731 $ @kbd{cat GNUFileParts.27962/longfile.1 \
10732   GNUFileParts.27962/longfile.2 >> longfile}
10733 $ rm -f GNUFileParts.27962
10734 @end group
10735 @end smallexample
10736
10737 Notice, that if the @command{tar} implementation you use supports PAX
10738 format archives, it will probably emit warnings about unknown keywords
10739 during extraction.  They will look like this:
10740
10741 @smallexample
10742 @group
10743 Tar file too small
10744 Unknown extended header keyword 'GNU.volume.filename' ignored.
10745 Unknown extended header keyword 'GNU.volume.size' ignored.
10746 Unknown extended header keyword 'GNU.volume.offset' ignored.
10747 @end group
10748 @end smallexample
10749
10750 @noindent
10751 You can safely ignore these warnings.
10752
10753 If your @command{tar} implementation is not PAX-aware, you will get
10754 more warnings and more files generated on your disk, e.g.:
10755
10756 @smallexample
10757 @group
10758 $ @kbd{tar xf vol-1.tar}
10759 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
10760 normal file
10761 Unexpected EOF in archive
10762 $ @kbd{tar xf vol-2.tar}
10763 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
10764 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
10765 'x', extracted as normal file
10766 @end group
10767 @end smallexample
10768
10769 Ignore these warnings.  The @file{PaxHeaders.*} directories created
10770 will contain files with @dfn{extended header keywords} describing the
10771 extracted files.  You can delete them, unless they describe sparse
10772 members.  Read further to learn more about them.
10773
10774 @node Sparse Recovery
10775 @subsubsection Extracting Sparse Members
10776
10777 @cindex sparse files, extracting with non-GNU tars
10778 Any @command{tar} implementation will be able to extract sparse members from a
10779 PAX archive.  However, the extracted files will be @dfn{condensed},
10780 i.e., any zero blocks will be removed from them.  When we restore such
10781 a condensed file to its original form, by adding zero blocks (or
10782 @dfn{holes}) back to their original locations, we call this process
10783 @dfn{expanding} a compressed sparse file.
10784
10785 @pindex xsparse
10786 To expand a file, you will need a simple auxiliary program called
10787 @command{xsparse}.  It is available in source form from
10788 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
10789 home page}.
10790
10791 @cindex sparse files v.1.0, extracting with non-GNU tars
10792 Let's begin with archive members in @dfn{sparse format
10793 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
10794 The condensed file will contain both file map and file data, so no
10795 additional data will be needed to restore it.  If the original file
10796 name was @file{@var{dir}/@var{name}}, then the condensed file will be
10797 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
10798 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
10799 @dfn{process @acronym{ID}} of the @command{tar} process which created the
10800 archive (@pxref{PAX keywords}).}.
10801
10802 To expand a version 1.0 file, run @command{xsparse} as follows:
10803
10804 @smallexample
10805 $ @kbd{xsparse @file{cond-file}}
10806 @end smallexample
10807
10808 @noindent
10809 where @file{cond-file} is the name of the condensed file.  The utility
10810 will deduce the name for the resulting expanded file using the
10811 following algorithm:
10812
10813 @enumerate 1
10814 @item If @file{cond-file} does not contain any directories,
10815 @file{../cond-file} will be used;
10816
10817 @item If @file{cond-file} has the form
10818 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
10819 are simple names, with no @samp{/} characters in them, the output file
10820 name will be @file{@var{dir}/@var{name}}.
10821
10822 @item Otherwise, if @file{cond-file} has the form
10823 @file{@var{dir}/@var{name}}, the output file name will be
10824 @file{@var{name}}.
10825 @end enumerate
10826
10827 In the unlikely case when this algorithm does not suit your needs,
10828 you can explicitly specify output file name as a second argument to
10829 the command:
10830
10831 @smallexample
10832 $ @kbd{xsparse @file{cond-file} @file{out-file}}
10833 @end smallexample
10834
10835 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
10836 first.  In this mode, the command does not actually expand the file,
10837 but verbosely lists all actions it would be taking to do so.  The dry
10838 run mode is enabled by @option{-n} command line argument:
10839
10840 @smallexample
10841 @group
10842 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
10843 Reading v.1.0 sparse map
10844 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10845 '/home/gray/sparsefile'
10846 Finished dry run
10847 @end group
10848 @end smallexample
10849
10850 To actually expand the file, you would run:
10851
10852 @smallexample
10853 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
10854 @end smallexample
10855
10856 @noindent
10857 The program behaves the same way all UNIX utilities do: it will keep
10858 quiet unless it has something important to tell you (e.g. an error
10859 condition or something).  If you wish it to produce verbose output,
10860 similar to that from the dry run mode, use @option{-v} option:
10861
10862 @smallexample
10863 @group
10864 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10865 Reading v.1.0 sparse map
10866 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10867 '/home/gray/sparsefile'
10868 Done
10869 @end group
10870 @end smallexample
10871
10872 Additionally, if your @command{tar} implementation has extracted the
10873 @dfn{extended headers} for this file, you can instruct @command{xstar}
10874 to use them in order to verify the integrity of the expanded file.
10875 The option @option{-x} sets the name of the extended header file to
10876 use.  Continuing our example:
10877
10878 @smallexample
10879 @group
10880 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
10881   /home/gray/GNUSparseFile.6058/sparsefile}
10882 Reading extended header file
10883 Found variable GNU.sparse.major = 1
10884 Found variable GNU.sparse.minor = 0
10885 Found variable GNU.sparse.name = sparsefile
10886 Found variable GNU.sparse.realsize = 217481216
10887 Reading v.1.0 sparse map
10888 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10889 '/home/gray/sparsefile'
10890 Done
10891 @end group
10892 @end smallexample
10893
10894 @anchor{extracting sparse v.0.x}
10895 @cindex sparse files v.0.1, extracting with non-GNU tars
10896 @cindex sparse files v.0.0, extracting with non-GNU tars
10897 An @dfn{extended header} is a special @command{tar} archive header
10898 that precedes an archive member and contains a set of
10899 @dfn{variables}, describing the member properties that cannot be
10900 stored in the standard @code{ustar} header.  While optional for
10901 expanding sparse version 1.0 members, the use of extended headers is
10902 mandatory when expanding sparse members in older sparse formats: v.0.0
10903 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10904 Formats}.)  So, for these formats, the question is: how to obtain
10905 extended headers from the archive?
10906
10907 If you use a @command{tar} implementation that does not support PAX
10908 format, extended headers for each member will be extracted as a
10909 separate file.  If we represent the member name as
10910 @file{@var{dir}/@var{name}}, then the extended header file will be
10911 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
10912 @var{n} is an integer number.
10913
10914 Things become more difficult if your @command{tar} implementation
10915 does support PAX headers, because in this case you will have to
10916 manually extract the headers.  We recommend the following algorithm:
10917
10918 @enumerate 1
10919 @item
10920 Consult the documentation of your @command{tar} implementation for an
10921 option that prints @dfn{block numbers} along with the archive
10922 listing (analogous to @GNUTAR{}'s @option{-R} option).  For example,
10923 @command{star} has @option{-block-number}.
10924
10925 @item
10926 Obtain verbose listing using the @samp{block number} option, and
10927 find block numbers of the sparse member in question and the member
10928 immediately following it.  For example, running @command{star} on our
10929 archive we obtain:
10930
10931 @smallexample
10932 @group
10933 $ @kbd{star -t -v -block-number -f arc.tar}
10934 @dots{}
10935 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10936 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10937 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10938 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10939 block        56:  425984 -rw-r--r--  gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10940 block       897:   65391 -rw-r--r--  gray/users Jun 24 20:06 2006 README
10941 @dots{}
10942 @end group
10943 @end smallexample
10944
10945 @noindent
10946 (as usual, ignore the warnings about unknown keywords.)
10947
10948 @item
10949 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10950 and @var{Bn} be the block number of the next member.
10951 Compute:
10952
10953 @smallexample
10954 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10955 @end smallexample
10956
10957 @noindent
10958 This number gives the size of the extended header part in tar @dfn{blocks}.
10959 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10960 = 7}.
10961
10962 @item
10963 Use @command{dd} to extract the headers:
10964
10965 @smallexample
10966 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10967 @end smallexample
10968
10969 @noindent
10970 where @var{archive} is the archive name, @var{hname} is a name of the
10971 file to store the extended header in, @var{Bs} and @var{N} are
10972 computed in previous steps.
10973
10974 In our example, this command will be
10975
10976 @smallexample
10977 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
10978 @end smallexample
10979 @end enumerate
10980
10981 Finally, you can expand the condensed file, using the obtained header:
10982
10983 @smallexample
10984 @group
10985 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
10986 Reading extended header file
10987 Found variable GNU.sparse.size = 217481216
10988 Found variable GNU.sparse.numblocks = 208
10989 Found variable GNU.sparse.name = sparsefile
10990 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
10991 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
10992 Done
10993 @end group
10994 @end smallexample
10995
10996 @node cpio
10997 @section Comparison of @command{tar} and @command{cpio}
10998 @UNREVISED
10999
11000 @FIXME{Reorganize the following material}
11001
11002 The @command{cpio} archive formats, like @command{tar}, do have maximum
11003 file name lengths.  The binary and old @acronym{ASCII} formats have a maximum file
11004 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
11005 file length of 1024.  @acronym{GNU} @command{cpio} can read and write archives
11006 with arbitrary file name lengths, but other @command{cpio} implementations
11007 may crash unexplainedly trying to read them.
11008
11009 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
11010 @command{cpio} doesn't handle symbolic links in the form in which it comes
11011 in System V prior to SVR4, and some vendors may have added symlinks
11012 to their system without enhancing @command{cpio} to know about them.
11013 Others may have enhanced it in a way other than the way I did it
11014 at Sun, and which was adopted by AT&T (and which is, I think, also
11015 present in the @command{cpio} that Berkeley picked up from AT&T and put
11016 into a later @acronym{BSD} release---I think I gave them my changes).
11017
11018 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
11019 can handle @command{tar} format input, and write it on output, and it
11020 probably handles symbolic links.  They may not have bothered doing
11021 anything to enhance @command{tar} as a result.)
11022
11023 @command{cpio} handles special files; traditional @command{tar} doesn't.
11024
11025 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
11026 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
11027 (4.3-tahoe and later).
11028
11029 @command{tar}'s way of handling multiple hard links to a file can handle
11030 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
11031 @command{cpio}s way requires you to play some games (in its ``binary''
11032 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
11033 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
11034 field of the header to make sure that the file system @acronym{ID}/i-number pairs
11035 of different files were always different), and I don't know which
11036 @command{cpio}s, if any, play those games.  Those that don't might get
11037 confused and think two files are the same file when they're not, and
11038 make hard links between them.
11039
11040 @command{tar}s way of handling multiple hard links to a file places only
11041 one copy of the link on the tape, but the name attached to that copy
11042 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
11043 way puts one copy for every link, but you can retrieve it using any
11044 of the names.
11045
11046 @quotation
11047 What type of check sum (if any) is used, and how is this calculated.
11048 @end quotation
11049
11050 See the attached manual pages for @command{tar} and @command{cpio} format.
11051 @command{tar} uses a checksum which is the sum of all the bytes in the
11052 @command{tar} header for a file; @command{cpio} uses no checksum.
11053
11054 @quotation
11055 If anyone knows why @command{cpio} was made when @command{tar} was present
11056 at the unix scene,
11057 @end quotation
11058
11059 It wasn't.  @command{cpio} first showed up in PWB/UNIX 1.0; no
11060 generally-available version of UNIX had @command{tar} at the time.  I don't
11061 know whether any version that was generally available @emph{within AT&T}
11062 had @command{tar}, or, if so, whether the people within AT&T who did
11063 @command{cpio} knew about it.
11064
11065 On restore, if there is a corruption on a tape @command{tar} will stop at
11066 that point, while @command{cpio} will skip over it and try to restore the
11067 rest of the files.
11068
11069 The main difference is just in the command syntax and header format.
11070
11071 @command{tar} is a little more tape-oriented in that everything is blocked
11072 to start on a record boundary.
11073
11074 @quotation
11075 Is there any differences between the ability to recover crashed
11076 archives between the two of them.  (Is there any chance of recovering
11077 crashed archives at all.)
11078 @end quotation
11079
11080 Theoretically it should be easier under @command{tar} since the blocking
11081 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
11082 However, modern @command{cpio}'s and variations have an option to just
11083 search for the next file header after an error with a reasonable chance
11084 of resyncing.  However, lots of tape driver software won't allow you to
11085 continue past a media error which should be the only reason for getting
11086 out of sync unless a file changed sizes while you were writing the
11087 archive.
11088
11089 @quotation
11090 If anyone knows why @command{cpio} was made when @command{tar} was present
11091 at the unix scene, please tell me about this too.
11092 @end quotation
11093
11094 Probably because it is more media efficient (by not blocking everything
11095 and using only the space needed for the headers where @command{tar}
11096 always uses 512 bytes per file header) and it knows how to archive
11097 special files.
11098
11099 You might want to look at the freely available alternatives.  The
11100 major ones are @command{afio}, @GNUTAR{}, and
11101 @command{pax}, each of which have their own extensions with some
11102 backwards compatibility.
11103
11104 Sparse files were @command{tar}red as sparse files (which you can
11105 easily test, because the resulting archive gets smaller, and
11106 @acronym{GNU} @command{cpio} can no longer read it).
11107
11108 @node Media
11109 @chapter Tapes and Other Archive Media
11110 @UNREVISED
11111
11112 A few special cases about tape handling warrant more detailed
11113 description.  These special cases are discussed below.
11114
11115 Many complexities surround the use of @command{tar} on tape drives.  Since
11116 the creation and manipulation of archives located on magnetic tape was
11117 the original purpose of @command{tar}, it contains many features making
11118 such manipulation easier.
11119
11120 Archives are usually written on dismountable media---tape cartridges,
11121 mag tapes, or floppy disks.
11122
11123 The amount of data a tape or disk holds depends not only on its size,
11124 but also on how it is formatted.  A 2400 foot long reel of mag tape
11125 holds 40 megabytes of data when formatted at 1600 bits per inch.  The
11126 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
11127
11128 Magnetic media are re-usable---once the archive on a tape is no longer
11129 needed, the archive can be erased and the tape or disk used over.
11130 Media quality does deteriorate with use, however.  Most tapes or disks
11131 should be discarded when they begin to produce data errors.  EXABYTE
11132 tape cartridges should be discarded when they generate an @dfn{error
11133 count} (number of non-usable bits) of more than 10k.
11134
11135 Magnetic media are written and erased using magnetic fields, and
11136 should be protected from such fields to avoid damage to stored data.
11137 Sticking a floppy disk to a filing cabinet using a magnet is probably
11138 not a good idea.
11139
11140 @menu
11141 * Device::                      Device selection and switching
11142 * Remote Tape Server::
11143 * Common Problems and Solutions::
11144 * Blocking::                    Blocking
11145 * Many::                        Many archives on one tape
11146 * Using Multiple Tapes::        Using Multiple Tapes
11147 * label::                       Including a Label in the Archive
11148 * verify::
11149 * Write Protection::
11150 @end menu
11151
11152 @node Device
11153 @section Device Selection and Switching
11154 @UNREVISED
11155
11156 @table @option
11157 @item -f [@var{hostname}:]@var{file}
11158 @itemx --file=[@var{hostname}:]@var{file}
11159 Use archive file or device @var{file} on @var{hostname}.
11160 @end table
11161
11162 This option is used to specify the file name of the archive @command{tar}
11163 works on.
11164
11165 If the file name is @samp{-}, @command{tar} reads the archive from standard
11166 input (when listing or extracting), or writes it to standard output
11167 (when creating).  If the @samp{-} file name is given when updating an
11168 archive, @command{tar} will read the original archive from its standard
11169 input, and will write the entire new archive to its standard output.
11170
11171 If the file name contains a @samp{:}, it is interpreted as
11172 @samp{hostname:file name}.  If the @var{hostname} contains an @dfn{at}
11173 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}.  In
11174 either case, @command{tar} will invoke the command @command{rsh} (or
11175 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
11176 machine.  If you give an alternate login name, it will be given to the
11177 @command{rsh}.
11178 Naturally, the remote machine must have an executable
11179 @command{/usr/libexec/rmt}.  This program is free software from the
11180 University of California, and a copy of the source code can be found
11181 with the sources for @command{tar}; it's compiled and installed by default.
11182 The exact path to this utility is determined when configuring the package.
11183 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
11184 your installation prefix.  This location may also be overridden at
11185 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
11186 ---rmt-command}, for detailed description of this option.  @xref{Remote
11187 Tape Server}, for the description of @command{rmt} command).
11188
11189 If this option is not given, but the environment variable @env{TAPE}
11190 is set, its value is used; otherwise, old versions of @command{tar}
11191 used a default archive name (which was picked when @command{tar} was
11192 compiled).  The default is normally set up to be the @dfn{first} tape
11193 drive or other transportable I/O medium on the system.
11194
11195 Starting with version 1.11.5, @GNUTAR{} uses
11196 standard input and standard output as the default device, and I will
11197 not try anymore supporting automatic device detection at installation
11198 time.  This was failing really in too many cases, it was hopeless.
11199 This is now completely left to the installer to override standard
11200 input and standard output for default device, if this seems
11201 preferable.  Further, I think @emph{most} actual usages of
11202 @command{tar} are done with pipes or disks, not really tapes,
11203 cartridges or diskettes.
11204
11205 Some users think that using standard input and output is running
11206 after trouble.  This could lead to a nasty surprise on your screen if
11207 you forget to specify an output file name---especially if you are going
11208 through a network or terminal server capable of buffering large amounts
11209 of output.  We had so many bug reports in that area of configuring
11210 default tapes automatically, and so many contradicting requests, that
11211 we finally consider the problem to be portably intractable.  We could
11212 of course use something like @samp{/dev/tape} as a default, but this
11213 is @emph{also} running after various kind of trouble, going from hung
11214 processes to accidental destruction of real tapes.  After having seen
11215 all this mess, using standard input and output as a default really
11216 sounds like the only clean choice left, and a very useful one too.
11217
11218 @GNUTAR{} reads and writes archive in records, I
11219 suspect this is the main reason why block devices are preferred over
11220 character devices.  Most probably, block devices are more efficient
11221 too.  The installer could also check for @samp{DEFTAPE} in
11222 @file{<sys/mtio.h>}.
11223
11224 @table @option
11225 @xopindex{force-local, short description}
11226 @item --force-local
11227 Archive file is local even if it contains a colon.
11228
11229 @opindex rsh-command
11230 @item --rsh-command=@var{command}
11231 Use remote @var{command} instead of @command{rsh}.  This option exists
11232 so that people who use something other than the standard @command{rsh}
11233 (e.g., a Kerberized @command{rsh}) can access a remote device.
11234
11235 When this command is not used, the shell command found when
11236 the @command{tar} program was installed is used instead.  This is
11237 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
11238 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
11239 The installer may have overridden this by defining the environment
11240 variable @env{RSH} @emph{at installation time}.
11241
11242 @item -[0-7][lmh]
11243 Specify drive and density.
11244
11245 @xopindex{multi-volume, short description}
11246 @item -M
11247 @itemx --multi-volume
11248 Create/list/extract multi-volume archive.
11249
11250 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
11251 that may be larger than will fit on the medium used to hold it.
11252 @xref{Multi-Volume Archives}.
11253
11254 @xopindex{tape-length, short description}
11255 @item -L @var{num}
11256 @itemx --tape-length=@var{size}[@var{suf}]
11257 Change tape after writing @var{size} units of data.  Unless @var{suf} is
11258 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
11259 1024} bytes.  The following suffixes alter this behavior:
11260
11261 @float Table, size-suffixes
11262 @caption{Size Suffixes}
11263 @multitable @columnfractions 0.2 0.3 0.3
11264 @headitem Suffix @tab Units            @tab Byte Equivalent
11265 @item b          @tab Blocks           @tab @var{size} x 512
11266 @item B          @tab Kilobytes        @tab @var{size} x 1024
11267 @item c          @tab Bytes            @tab @var{size}
11268 @item G          @tab Gigabytes        @tab @var{size} x 1024^3
11269 @item K          @tab Kilobytes        @tab @var{size} x 1024
11270 @item k          @tab Kilobytes        @tab @var{size} x 1024
11271 @item M          @tab Megabytes        @tab @var{size} x 1024^2
11272 @item P          @tab Petabytes        @tab @var{size} x 1024^5
11273 @item T          @tab Terabytes        @tab @var{size} x 1024^4
11274 @item w          @tab Words            @tab @var{size} x 2
11275 @end multitable
11276 @end float
11277
11278 This option might be useful when your tape drivers do not properly
11279 detect end of physical tapes.  By being slightly conservative on the
11280 maximum tape length, you might avoid the problem entirely.
11281
11282 @xopindex{info-script, short description}
11283 @xopindex{new-volume-script, short description}
11284 @item -F @var{command}
11285 @itemx --info-script=@var{command}
11286 @itemx --new-volume-script=@var{command}
11287 Execute @var{command} at end of each tape.  This implies
11288 @option{--multi-volume} (@option{-M}).  @xref{info-script}, for a detailed
11289 description of this option.
11290 @end table
11291
11292 @node Remote Tape Server
11293 @section Remote Tape Server
11294
11295 @cindex remote tape drive
11296 @pindex rmt
11297 In order to access the tape drive on a remote machine, @command{tar}
11298 uses the remote tape server written at the University of California at
11299 Berkeley.  The remote tape server must be installed as
11300 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
11301 want to use.  @command{tar} calls @command{rmt} by running an
11302 @command{rsh} or @command{remsh} to the remote machine, optionally
11303 using a different login name if one is supplied.
11304
11305 A copy of the source for the remote tape server is provided.  Its
11306 source code can be freely distributed.  It is compiled and
11307 installed by default.
11308
11309 @cindex absolute file names
11310 Unless you use the @option{--absolute-names} (@option{-P}) option,
11311 @GNUTAR{} will not allow you to create an archive that contains
11312 absolute file names (a file name beginning with @samp{/}).  If you try,
11313 @command{tar} will automatically remove the leading @samp{/} from the
11314 file names it stores in the archive.  It will also type a warning
11315 message telling you what it is doing.
11316
11317 When reading an archive that was created with a different
11318 @command{tar} program, @GNUTAR{} automatically
11319 extracts entries in the archive which have absolute file names as if
11320 the file names were not absolute.  This is an important feature.  A
11321 visitor here once gave a @command{tar} tape to an operator to restore;
11322 the operator used Sun @command{tar} instead of @GNUTAR{},
11323 and the result was that it replaced large portions of
11324 our @file{/bin} and friends with versions from the tape; needless to
11325 say, we were unhappy about having to recover the file system from
11326 backup tapes.
11327
11328 For example, if the archive contained a file @file{/usr/bin/computoy},
11329 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
11330 relative to the current directory.  If you want to extract the files in
11331 an archive to the same absolute names that they had when the archive
11332 was created, you should do a @samp{cd /} before extracting the files
11333 from the archive, or you should either use the @option{--absolute-names}
11334 option, or use the command @samp{tar -C / @dots{}}.
11335
11336 @cindex Ultrix 3.1 and write failure
11337 Some versions of Unix (Ultrix 3.1 is known to have this problem),
11338 can claim that a short write near the end of a tape succeeded,
11339 when it actually failed.  This will result in the -M option not
11340 working correctly.  The best workaround at the moment is to use a
11341 significantly larger blocking factor than the default 20.
11342
11343 In order to update an archive, @command{tar} must be able to backspace the
11344 archive in order to reread or rewrite a record that was just read (or
11345 written).  This is currently possible only on two kinds of files: normal
11346 disk files (or any other file that can be backspaced with @samp{lseek}),
11347 and industry-standard 9-track magnetic tape (or any other kind of tape
11348 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
11349
11350 This means that the @option{--append}, @option{--concatenate}, and
11351 @option{--delete} commands will not work on any other kind of file.
11352 Some media simply cannot be backspaced, which means these commands and
11353 options will never be able to work on them.  These non-backspacing
11354 media include pipes and cartridge tape drives.
11355
11356 Some other media can be backspaced, and @command{tar} will work on them
11357 once @command{tar} is modified to do so.
11358
11359 Archives created with the @option{--multi-volume}, @option{--label}, and
11360 @option{--incremental} (@option{-G}) options may not be readable by other version
11361 of @command{tar}.  In particular, restoring a file that was split over
11362 a volume boundary will require some careful work with @command{dd}, if
11363 it can be done at all.  Other versions of @command{tar} may also create
11364 an empty file whose name is that of the volume header.  Some versions
11365 of @command{tar} may create normal files instead of directories archived
11366 with the @option{--incremental} (@option{-G}) option.
11367
11368 @node Common Problems and Solutions
11369 @section Some Common Problems and their Solutions
11370
11371 @ifclear PUBLISH
11372
11373 @format
11374 errors from system:
11375 permission denied
11376 no such file or directory
11377 not owner
11378
11379 errors from @command{tar}:
11380 directory checksum error
11381 header format error
11382
11383 errors from media/system:
11384 i/o error
11385 device busy
11386 @end format
11387
11388 @end ifclear
11389
11390 @node Blocking
11391 @section Blocking
11392 @cindex block
11393 @cindex record
11394
11395 @dfn{Block} and @dfn{record} terminology is rather confused, and it
11396 is also confusing to the expert reader.  On the other hand, readers
11397 who are new to the field have a fresh mind, and they may safely skip
11398 the next two paragraphs, as the remainder of this manual uses those
11399 two terms in a quite consistent way.
11400
11401 John Gilmore, the writer of the public domain @command{tar} from which
11402 @GNUTAR{} was originally derived, wrote (June 1995):
11403
11404 @quotation
11405 The nomenclature of tape drives comes from IBM, where I believe
11406 they were invented for the IBM 650 or so.  On IBM mainframes, what
11407 is recorded on tape are tape blocks.  The logical organization of
11408 data is into records.  There are various ways of putting records into
11409 blocks, including @code{F} (fixed sized records), @code{V} (variable
11410 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
11411 to a block), @code{VB} (variable size records, @var{n} to a block),
11412 @code{VSB} (variable spanned blocked: variable sized records that can
11413 occupy more than one block), etc.  The @code{JCL} @samp{DD RECFORM=}
11414 parameter specified this to the operating system.
11415
11416 The Unix man page on @command{tar} was totally confused about this.
11417 When I wrote @code{PD TAR}, I used the historically correct terminology
11418 (@command{tar} writes data records, which are grouped into blocks).
11419 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
11420 here), and now Fran@,{c}ois has migrated that terminology back
11421 into the source code too.
11422 @end quotation
11423
11424 The term @dfn{physical block} means the basic transfer chunk from or
11425 to a device, after which reading or writing may stop without anything
11426 being lost.  In this manual, the term @dfn{block} usually refers to
11427 a disk physical block, @emph{assuming} that each disk block is 512
11428 bytes in length.  It is true that some disk devices have different
11429 physical blocks, but @command{tar} ignore these differences in its own
11430 format, which is meant to be portable, so a @command{tar} block is always
11431 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
11432 The term @dfn{logical block} often represents the basic chunk of
11433 allocation of many disk blocks as a single entity, which the operating
11434 system treats somewhat atomically; this concept is only barely used
11435 in @GNUTAR{}.
11436
11437 The term @dfn{physical record} is another way to speak of a physical
11438 block, those two terms are somewhat interchangeable.  In this manual,
11439 the term @dfn{record} usually refers to a tape physical block,
11440 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
11441 It is true that archives may be put on disk or used with pipes,
11442 but nevertheless, @command{tar} tries to read and write the archive one
11443 @dfn{record} at a time, whatever the medium in use.  One record is made
11444 up of an integral number of blocks, and this operation of putting many
11445 disk blocks into a single tape block is called @dfn{reblocking}, or
11446 more simply, @dfn{blocking}.  The term @dfn{logical record} refers to
11447 the logical organization of many characters into something meaningful
11448 to the application.  The term @dfn{unit record} describes a small set
11449 of characters which are transmitted whole to or by the application,
11450 and often refers to a line of text.  Those two last terms are unrelated
11451 to what we call a @dfn{record} in @GNUTAR{}.
11452
11453 When writing to tapes, @command{tar} writes the contents of the archive
11454 in chunks known as @dfn{records}.  To change the default blocking
11455 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
11456 @var{512-size}}) option.  Each record will then be composed of
11457 @var{512-size} blocks.  (Each @command{tar} block is 512 bytes.
11458 @xref{Standard}.)  Each file written to the archive uses at least one
11459 full record.  As a result, using a larger record size can result in
11460 more wasted space for small files.  On the other hand, a larger record
11461 size can often be read and written much more efficiently.
11462
11463 Further complicating the problem is that some tape drives ignore the
11464 blocking entirely.  For these, a larger record size can still improve
11465 performance (because the software layers above the tape drive still
11466 honor the blocking), but not as dramatically as on tape drives that
11467 honor blocking.
11468
11469 When reading an archive, @command{tar} can usually figure out the
11470 record size on itself.  When this is the case, and a non-standard
11471 record size was used when the archive was created, @command{tar} will
11472 print a message about a non-standard blocking factor, and then operate
11473 normally@footnote{If this message is not needed, you can turn it off
11474 using the @option{--warning=no-record-size} option.}.  On some tape
11475 devices, however, @command{tar} cannot figure out the record size
11476 itself.  On most of those, you can specify a blocking factor (with
11477 @option{--blocking-factor}) larger than the actual blocking factor,
11478 and then use the @option{--read-full-records} (@option{-B}) option.
11479 (If you specify a blocking factor with @option{--blocking-factor} and
11480 don't use the @option{--read-full-records} option, then @command{tar}
11481 will not attempt to figure out the recording size itself.)  On some
11482 devices, you must always specify the record size exactly with
11483 @option{--blocking-factor} when reading, because @command{tar} cannot
11484 figure it out.  In any case, use @option{--list} (@option{-t}) before
11485 doing any extractions to see whether @command{tar} is reading the archive
11486 correctly.
11487
11488 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
11489 putting them into records is to put a whole number of them (one or
11490 more) into each record.  @command{tar} records are all the same size;
11491 at the end of the file there's a block containing all zeros, which
11492 is how you tell that the remainder of the last record(s) are garbage.
11493
11494 In a standard @command{tar} file (no options), the block size is 512
11495 and the record size is 10240, for a blocking factor of 20.  What the
11496 @option{--blocking-factor} option does is sets the blocking factor,
11497 changing the record size while leaving the block size at 512 bytes.
11498 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
11499 most tape drives these days prefer much bigger records in order to
11500 stream and not waste tape.  When writing tapes for myself, some tend
11501 to use a factor of the order of 2048, say, giving a record size of
11502 around one megabyte.
11503
11504 If you use a blocking factor larger than 20, older @command{tar}
11505 programs might not be able to read the archive, so we recommend this
11506 as a limit to use in practice.  @GNUTAR{}, however,
11507 will support arbitrarily large record sizes, limited only by the
11508 amount of virtual memory or the physical characteristics of the tape
11509 device.
11510
11511 @menu
11512 * Format Variations::           Format Variations
11513 * Blocking Factor::             The Blocking Factor of an Archive
11514 @end menu
11515
11516 @node Format Variations
11517 @subsection Format Variations
11518 @cindex Format Parameters
11519 @cindex Format Options
11520 @cindex Options, archive format specifying
11521 @cindex Options, format specifying
11522 @UNREVISED
11523
11524 Format parameters specify how an archive is written on the archive
11525 media.  The best choice of format parameters will vary depending on
11526 the type and number of files being archived, and on the media used to
11527 store the archive.
11528
11529 To specify format parameters when accessing or creating an archive,
11530 you can use the options described in the following sections.
11531 If you do not specify any format parameters, @command{tar} uses
11532 default parameters.  You cannot modify a compressed archive.
11533 If you create an archive with the @option{--blocking-factor} option
11534 specified (@pxref{Blocking Factor}), you must specify that
11535 blocking-factor when operating on the archive.  @xref{Formats}, for other
11536 examples of format parameter considerations.
11537
11538 @node Blocking Factor
11539 @subsection The Blocking Factor of an Archive
11540 @cindex Blocking Factor
11541 @cindex Record Size
11542 @cindex Number of blocks per record
11543 @cindex Number of bytes per record
11544 @cindex Bytes per record
11545 @cindex Blocks per record
11546 @UNREVISED
11547
11548 @opindex blocking-factor
11549 The data in an archive is grouped into blocks, which are 512 bytes.
11550 Blocks are read and written in whole number multiples called
11551 @dfn{records}.  The number of blocks in a record (i.e., the size of a
11552 record in units of 512 bytes) is called the @dfn{blocking factor}.
11553 The @option{--blocking-factor=@var{512-size}} (@option{-b
11554 @var{512-size}}) option specifies the blocking factor of an archive.
11555 The default blocking factor is typically 20 (i.e., 10240 bytes), but
11556 can be specified at installation.  To find out the blocking factor of
11557 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
11558 This may not work on some devices.
11559
11560 Records are separated by gaps, which waste space on the archive media.
11561 If you are archiving on magnetic tape, using a larger blocking factor
11562 (and therefore larger records) provides faster throughput and allows you
11563 to fit more data on a tape (because there are fewer gaps).  If you are
11564 archiving on cartridge, a very large blocking factor (say 126 or more)
11565 greatly increases performance.  A smaller blocking factor, on the other
11566 hand, may be useful when archiving small files, to avoid archiving lots
11567 of nulls as @command{tar} fills out the archive to the end of the record.
11568 In general, the ideal record size depends on the size of the
11569 inter-record gaps on the tape you are using, and the average size of the
11570 files you are archiving.  @xref{create}, for information on
11571 writing archives.
11572
11573 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
11574
11575 Archives with blocking factors larger than 20 cannot be read
11576 by very old versions of @command{tar}, or by some newer versions
11577 of @command{tar} running on old machines with small address spaces.
11578 With @GNUTAR{}, the blocking factor of an archive is limited
11579 only by the maximum record size of the device containing the archive,
11580 or by the amount of available virtual memory.
11581
11582 Also, on some systems, not using adequate blocking factors, as sometimes
11583 imposed by the device drivers, may yield unexpected diagnostics.  For
11584 example, this has been reported:
11585
11586 @smallexample
11587 Cannot write to /dev/dlt: Invalid argument
11588 @end smallexample
11589
11590 @noindent
11591 In such cases, it sometimes happen that the @command{tar} bundled by
11592 the system is aware of block size idiosyncrasies, while @GNUTAR{}
11593 requires an explicit specification for the block size,
11594 which it cannot guess.  This yields some people to consider
11595 @GNUTAR{} is misbehaving, because by comparison,
11596 @cite{the bundle @command{tar} works OK}.  Adding @w{@kbd{-b 256}},
11597 for example, might resolve the problem.
11598
11599 If you use a non-default blocking factor when you create an archive, you
11600 must specify the same blocking factor when you modify that archive.  Some
11601 archive devices will also require you to specify the blocking factor when
11602 reading that archive, however this is not typically the case.  Usually, you
11603 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
11604 reports a non-default record size and then lists the archive members as
11605 it would normally.  To extract files from an archive with a non-standard
11606 blocking factor (particularly if you're not sure what the blocking factor
11607 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
11608 specifying a blocking factor larger then the blocking factor of the archive
11609 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
11610 @xref{list}, for more information on the @option{--list} (@option{-t})
11611 operation.  @xref{Reading}, for a more detailed explanation of that option.
11612
11613 @table @option
11614 @item --blocking-factor=@var{number}
11615 @itemx -b @var{number}
11616 Specifies the blocking factor of an archive.  Can be used with any
11617 operation, but is usually not necessary with @option{--list} (@option{-t}).
11618 @end table
11619
11620 Device blocking
11621
11622 @table @option
11623 @item -b @var{blocks}
11624 @itemx --blocking-factor=@var{blocks}
11625 Set record size to @math{@var{blocks}*512} bytes.
11626
11627 This option is used to specify a @dfn{blocking factor} for the archive.
11628 When reading or writing the archive, @command{tar}, will do reads and writes
11629 of the archive in records of @math{@var{block}*512} bytes.  This is true
11630 even when the archive is compressed.  Some devices requires that all
11631 write operations be a multiple of a certain size, and so, @command{tar}
11632 pads the archive out to the next record boundary.
11633
11634 The default blocking factor is set when @command{tar} is compiled, and is
11635 typically 20.  Blocking factors larger than 20 cannot be read by very
11636 old versions of @command{tar}, or by some newer versions of @command{tar}
11637 running on old machines with small address spaces.
11638
11639 With a magnetic tape, larger records give faster throughput and fit
11640 more data on a tape (because there are fewer inter-record gaps).
11641 If the archive is in a disk file or a pipe, you may want to specify
11642 a smaller blocking factor, since a large one will result in a large
11643 number of null bytes at the end of the archive.
11644
11645 When writing cartridge or other streaming tapes, a much larger
11646 blocking factor (say 126 or more) will greatly increase performance.
11647 However, you must specify the same blocking factor when reading or
11648 updating the archive.
11649
11650 Apparently, Exabyte drives have a physical block size of 8K bytes.
11651 If we choose our blocksize as a multiple of 8k bytes, then the problem
11652 seems to disappear.  Id est, we are using block size of 112 right
11653 now, and we haven't had the problem since we switched@dots{}
11654
11655 With @GNUTAR{} the blocking factor is limited only
11656 by the maximum record size of the device containing the archive, or by
11657 the amount of available virtual memory.
11658
11659 However, deblocking or reblocking is virtually avoided in a special
11660 case which often occurs in practice, but which requires all the
11661 following conditions to be simultaneously true:
11662 @itemize @bullet
11663 @item
11664 the archive is subject to a compression option,
11665 @item
11666 the archive is not handled through standard input or output, nor
11667 redirected nor piped,
11668 @item
11669 the archive is directly handled to a local disk, instead of any special
11670 device,
11671 @item
11672 @option{--blocking-factor} is not explicitly specified on the @command{tar}
11673 invocation.
11674 @end itemize
11675
11676 If the output goes directly to a local disk, and not through
11677 stdout, then the last write is not extended to a full record size.
11678 Otherwise, reblocking occurs.  Here are a few other remarks on this
11679 topic:
11680
11681 @itemize @bullet
11682
11683 @item
11684 @command{gzip} will complain about trailing garbage if asked to
11685 uncompress a compressed archive on tape, there is an option to turn
11686 the message off, but it breaks the regularity of simply having to use
11687 @samp{@var{prog} -d} for decompression.  It would be nice if gzip was
11688 silently ignoring any number of trailing zeros.  I'll ask Jean-loup
11689 Gailly, by sending a copy of this message to him.
11690
11691 @item
11692 @command{compress} does not show this problem, but as Jean-loup pointed
11693 out to Michael, @samp{compress -d} silently adds garbage after
11694 the result of decompression, which tar ignores because it already
11695 recognized its end-of-file indicator.  So this bug may be safely
11696 ignored.
11697
11698 @item
11699 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
11700 but will still return an exit status of 2 which tar reports in turn.
11701 @command{tar} might ignore the exit status returned, but I hate doing
11702 that, as it weakens the protection @command{tar} offers users against
11703 other possible problems at decompression time.  If @command{gzip} was
11704 silently skipping trailing zeros @emph{and} also avoiding setting the
11705 exit status in this innocuous case, that would solve this situation.
11706
11707 @item
11708 @command{tar} should become more solid at not stopping to read a pipe at
11709 the first null block encountered.  This inelegantly breaks the pipe.
11710 @command{tar} should rather drain the pipe out before exiting itself.
11711 @end itemize
11712
11713 @xopindex{ignore-zeros, short description}
11714 @item -i
11715 @itemx --ignore-zeros
11716 Ignore blocks of zeros in archive (means EOF).
11717
11718 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
11719 of zeros in the archive.  Normally a block of zeros indicates the
11720 end of the archive, but when reading a damaged archive, or one which
11721 was created by concatenating several archives together, this option
11722 allows @command{tar} to read the entire archive.  This option is not on
11723 by default because many versions of @command{tar} write garbage after
11724 the zeroed blocks.
11725
11726 Note that this option causes @command{tar} to read to the end of the
11727 archive file, which may sometimes avoid problems when multiple files
11728 are stored on a single physical tape.
11729
11730 @xopindex{read-full-records, short description}
11731 @item -B
11732 @itemx --read-full-records
11733 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
11734
11735 If @option{--read-full-records} is used, @command{tar}
11736 will not panic if an attempt to read a record from the archive does
11737 not return a full record.  Instead, @command{tar} will keep reading
11738 until it has obtained a full
11739 record.
11740
11741 This option is turned on by default when @command{tar} is reading
11742 an archive from standard input, or from a remote machine.  This is
11743 because on @acronym{BSD} Unix systems, a read of a pipe will return however
11744 much happens to be in the pipe, even if it is less than @command{tar}
11745 requested.  If this option was not used, @command{tar} would fail as
11746 soon as it read an incomplete record from the pipe.
11747
11748 This option is also useful with the commands for updating an archive.
11749
11750 @end table
11751
11752 Tape blocking
11753
11754 @FIXME{Appropriate options should be moved here from elsewhere.}
11755
11756 @cindex blocking factor
11757 @cindex tape blocking
11758
11759 When handling various tapes or cartridges, you have to take care of
11760 selecting a proper blocking, that is, the number of disk blocks you
11761 put together as a single tape block on the tape, without intervening
11762 tape gaps.  A @dfn{tape gap} is a small landing area on the tape
11763 with no information on it, used for decelerating the tape to a
11764 full stop, and for later regaining the reading or writing speed.
11765 When the tape driver starts reading a record, the record has to
11766 be read whole without stopping, as a tape gap is needed to stop the
11767 tape motion without losing information.
11768
11769 @cindex Exabyte blocking
11770 @cindex DAT blocking
11771 Using higher blocking (putting more disk blocks per tape block) will use
11772 the tape more efficiently as there will be less tape gaps.  But reading
11773 such tapes may be more difficult for the system, as more memory will be
11774 required to receive at once the whole record.  Further, if there is a
11775 reading error on a huge record, this is less likely that the system will
11776 succeed in recovering the information.  So, blocking should not be too
11777 low, nor it should be too high.  @command{tar} uses by default a blocking of
11778 20 for historical reasons, and it does not really matter when reading or
11779 writing to disk.  Current tape technology would easily accommodate higher
11780 blockings.  Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
11781 We were told that for some DLT drives, the blocking should be a multiple
11782 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
11783 Other manufacturers may use different recommendations for the same tapes.
11784 This might also depends of the buffering techniques used inside modern
11785 tape controllers.  Some imposes a minimum blocking, or a maximum blocking.
11786 Others request blocking to be some exponent of two.
11787
11788 So, there is no fixed rule for blocking.  But blocking at read time
11789 should ideally be the same as blocking used at write time.  At one place
11790 I know, with a wide variety of equipment, they found it best to use a
11791 blocking of 32 to guarantee that their tapes are fully interchangeable.
11792
11793 I was also told that, for recycled tapes, prior erasure (by the same
11794 drive unit that will be used to create the archives) sometimes lowers
11795 the error rates observed at rewriting time.
11796
11797 I might also use @option{--number-blocks} instead of
11798 @option{--block-number}, so @option{--block} will then expand to
11799 @option{--blocking-factor} unambiguously.
11800
11801 @node Many
11802 @section Many Archives on One Tape
11803
11804 @FIXME{Appropriate options should be moved here from elsewhere.}
11805
11806 @findex ntape @r{device}
11807 Most tape devices have two entries in the @file{/dev} directory, or
11808 entries that come in pairs, which differ only in the minor number for
11809 this device.  Let's take for example @file{/dev/tape}, which often
11810 points to the only or usual tape device of a given system.  There might
11811 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}.  The simpler
11812 name is the @emph{rewinding} version of the device, while the name
11813 having @samp{nr} in it is the @emph{no rewinding} version of the same
11814 device.
11815
11816 A rewinding tape device will bring back the tape to its beginning point
11817 automatically when this device is opened or closed.  Since @command{tar}
11818 opens the archive file before using it and closes it afterwards, this
11819 means that a simple:
11820
11821 @smallexample
11822 $ @kbd{tar cf /dev/tape @var{directory}}
11823 @end smallexample
11824
11825 @noindent
11826 will reposition the tape to its beginning both prior and after saving
11827 @var{directory} contents to it, thus erasing prior tape contents and
11828 making it so that any subsequent write operation will destroy what has
11829 just been saved.
11830
11831 @cindex tape positioning
11832 So, a rewinding device is normally meant to hold one and only one file.
11833 If you want to put more than one @command{tar} archive on a given tape, you
11834 will need to avoid using the rewinding version of the tape device.  You
11835 will also have to pay special attention to tape positioning.  Errors in
11836 positioning may overwrite the valuable data already on your tape.  Many
11837 people, burnt by past experiences, will only use rewinding devices and
11838 limit themselves to one file per tape, precisely to avoid the risk of
11839 such errors.  Be fully aware that writing at the wrong position on a
11840 tape loses all information past this point and most probably until the
11841 end of the tape, and this destroyed information @emph{cannot} be
11842 recovered.
11843
11844 To save @var{directory-1} as a first archive at the beginning of a
11845 tape, and leave that tape ready for a second archive, you should use:
11846
11847 @smallexample
11848 $ @kbd{mt -f /dev/nrtape rewind}
11849 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
11850 @end smallexample
11851
11852 @cindex tape marks
11853 @dfn{Tape marks} are special magnetic patterns written on the tape
11854 media, which are later recognizable by the reading hardware.  These
11855 marks are used after each file, when there are many on a single tape.
11856 An empty file (that is to say, two tape marks in a row) signal the
11857 logical end of the tape, after which no file exist.  Usually,
11858 non-rewinding tape device drivers will react to the close request issued
11859 by @command{tar} by first writing two tape marks after your archive, and by
11860 backspacing over one of these.  So, if you remove the tape at that time
11861 from the tape drive, it is properly terminated.  But if you write
11862 another file at the current position, the second tape mark will be
11863 erased by the new information, leaving only one tape mark between files.
11864
11865 So, you may now save @var{directory-2} as a second archive after the
11866 first on the same tape by issuing the command:
11867
11868 @smallexample
11869 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11870 @end smallexample
11871
11872 @noindent
11873 and so on for all the archives you want to put on the same tape.
11874
11875 Another usual case is that you do not write all the archives the same
11876 day, and you need to remove and store the tape between two archive
11877 sessions.  In general, you must remember how many files are already
11878 saved on your tape.  Suppose your tape already has 16 files on it, and
11879 that you are ready to write the 17th.  You have to take care of skipping
11880 the first 16 tape marks before saving @var{directory-17}, say, by using
11881 these commands:
11882
11883 @smallexample
11884 $ @kbd{mt -f /dev/nrtape rewind}
11885 $ @kbd{mt -f /dev/nrtape fsf 16}
11886 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11887 @end smallexample
11888
11889 In all the previous examples, we put aside blocking considerations, but
11890 you should do the proper things for that as well.  @xref{Blocking}.
11891
11892 @menu
11893 * Tape Positioning::            Tape Positions and Tape Marks
11894 * mt::                          The @command{mt} Utility
11895 @end menu
11896
11897 @node Tape Positioning
11898 @subsection Tape Positions and Tape Marks
11899 @UNREVISED
11900
11901 Just as archives can store more than one file from the file system,
11902 tapes can store more than one archive file.  To keep track of where
11903 archive files (or any other type of file stored on tape) begin and
11904 end, tape archive devices write magnetic @dfn{tape marks} on the
11905 archive media.  Tape drives write one tape mark between files,
11906 two at the end of all the file entries.
11907
11908 If you think of data as a series of records "rrrr"'s, and tape marks as
11909 "*"'s, a tape might look like the following:
11910
11911 @smallexample
11912 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11913 @end smallexample
11914
11915 Tape devices read and write tapes using a read/write @dfn{tape
11916 head}---a physical part of the device which can only access one
11917 point on the tape at a time.  When you use @command{tar} to read or
11918 write archive data from a tape device, the device will begin reading
11919 or writing from wherever on the tape the tape head happens to be,
11920 regardless of which archive or what part of the archive the tape
11921 head is on.  Before writing an archive, you should make sure that no
11922 data on the tape will be overwritten (unless it is no longer needed).
11923 Before reading an archive, you should make sure the tape head is at
11924 the beginning of the archive you want to read.  You can do it manually
11925 via @code{mt} utility (@pxref{mt}).  The @code{restore} script does
11926 that automatically (@pxref{Scripted Restoration}).
11927
11928 If you want to add new archive file entries to a tape, you should
11929 advance the tape to the end of the existing file entries, backspace
11930 over the last tape mark, and write the new archive file.  If you were
11931 to add two archives to the example above, the tape might look like the
11932 following:
11933
11934 @smallexample
11935 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11936 @end smallexample
11937
11938 @node mt
11939 @subsection The @command{mt} Utility
11940 @UNREVISED
11941
11942 @FIXME{Is it true that this only works on non-block devices?
11943 should explain the difference, (fixed or variable).}
11944 @xref{Blocking Factor}.
11945
11946 You can use the @command{mt} utility to advance or rewind a tape past a
11947 specified number of archive files on the tape.  This will allow you
11948 to move to the beginning of an archive before extracting or reading
11949 it, or to the end of all the archives before writing a new one.
11950 @FIXME{Why isn't there an "advance 'til you find two tape marks
11951 together"?}
11952
11953 The syntax of the @command{mt} command is:
11954
11955 @smallexample
11956 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11957 @end smallexample
11958
11959 where @var{tapename} is the name of the tape device, @var{number} is
11960 the number of times an operation is performed (with a default of one),
11961 and @var{operation} is one of the following:
11962
11963 @FIXME{is there any use for record operations?}
11964
11965 @table @option
11966 @item eof
11967 @itemx weof
11968 Writes @var{number} tape marks at the current position on the tape.
11969
11970 @item fsf
11971 Moves tape position forward @var{number} files.
11972
11973 @item bsf
11974 Moves tape position back @var{number} files.
11975
11976 @item rewind
11977 Rewinds the tape.  (Ignores @var{number}.)
11978
11979 @item offline
11980 @itemx rewoff1
11981 Rewinds the tape and takes the tape device off-line.  (Ignores @var{number}.)
11982
11983 @item status
11984 Prints status information about the tape unit.
11985
11986 @end table
11987
11988 If you don't specify a @var{tapename}, @command{mt} uses the environment
11989 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
11990 the default device specified in your @file{sys/mtio.h} file
11991 (@code{DEFTAPE} variable).  If this is not defined, the program will
11992 display a descriptive error message and exit with code 1.
11993
11994 @command{mt} returns a 0 exit status when the operation(s) were
11995 successful, 1 if the command was unrecognized, and 2 if an operation
11996 failed.
11997
11998 @node Using Multiple Tapes
11999 @section Using Multiple Tapes
12000
12001 Often you might want to write a large archive, one larger than will fit
12002 on the actual tape you are using.  In such a case, you can run multiple
12003 @command{tar} commands, but this can be inconvenient, particularly if you
12004 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
12005 Therefore, @command{tar} provides a special mode for creating
12006 multi-volume archives.
12007
12008 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
12009 on several media volumes of fixed size.  Although in this section we will
12010 often call @samp{volume} a @dfn{tape}, there is absolutely no
12011 requirement for multi-volume archives to be stored on tapes.  Instead,
12012 they can use whatever media type the user finds convenient, they can
12013 even be located on files.
12014
12015 When creating a multi-volume archive, @GNUTAR{} continues to fill
12016 current volume until it runs out of space, then it switches to
12017 next volume (usually the operator is queried to replace the tape on
12018 this point), and continues working on the new volume.  This operation
12019 continues until all requested files are dumped.  If @GNUTAR{} detects
12020 end of media while dumping a file, such a file is archived in split
12021 form.  Some very big files can even be split across several volumes.
12022
12023 Each volume is itself a valid @GNUTAR{} archive, so it can be read
12024 without any special options.  Consequently any file member residing
12025 entirely on one volume can be extracted or otherwise operated upon
12026 without needing the other volume.  Sure enough, to extract a split
12027 member you would need all volumes its parts reside on.
12028
12029 Multi-volume archives suffer from several limitations.  In particular,
12030 they cannot be compressed.
12031
12032 @GNUTAR{} is able to create multi-volume archives of two formats
12033 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
12034
12035 @menu
12036 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
12037 * Tape Files::                  Tape Files
12038 * Tarcat::                      Concatenate Volumes into a Single Archive
12039
12040 @end menu
12041
12042 @node Multi-Volume Archives
12043 @subsection Archives Longer than One Tape or Disk
12044 @cindex Multi-volume archives
12045
12046 @opindex multi-volume
12047 To create an archive that is larger than will fit on a single unit of
12048 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
12049 the @option{--create} option (@pxref{create}).  A @dfn{multi-volume}
12050 archive can be manipulated like any other archive (provided the
12051 @option{--multi-volume} option is specified), but is stored on more
12052 than one tape or file.
12053
12054 When you specify @option{--multi-volume}, @command{tar} does not report an
12055 error when it comes to the end of an archive volume (when reading), or
12056 the end of the media (when writing).  Instead, it prompts you to load
12057 a new storage volume.  If the archive is on a magnetic tape, you
12058 should change tapes when you see the prompt; if the archive is on a
12059 floppy disk, you should change disks; etc.
12060
12061 @table @option
12062 @item --multi-volume
12063 @itemx -M
12064 Creates a multi-volume archive, when used in conjunction with
12065 @option{--create} (@option{-c}).  To perform any other operation on a multi-volume
12066 archive, specify @option{--multi-volume} in conjunction with that
12067 operation.
12068 For example:
12069
12070 @smallexample
12071 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
12072 @end smallexample
12073 @end table
12074
12075 The method @command{tar} uses to detect end of tape is not perfect, and
12076 fails on some operating systems or on some devices.  If @command{tar}
12077 cannot detect the end of the tape itself, you can use
12078 @option{--tape-length} option to inform it about the capacity of the
12079 tape:
12080
12081 @anchor{tape-length}
12082 @table @option
12083 @opindex tape-length
12084 @item --tape-length=@var{size}[@var{suf}]
12085 @itemx -L @var{size}[@var{suf}]
12086 Set maximum length of a volume.  The @var{suf}, if given, specifies
12087 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
12088 megabytes (@pxref{size-suffixes}, for a list of allowed size
12089 suffixes).  Without @var{suf}, units of 1024 bytes (kilobyte) are
12090 assumed.
12091
12092 This option selects @option{--multi-volume} automatically.  For example:
12093
12094 @smallexample
12095 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
12096 @end smallexample
12097
12098 @noindent
12099 or, which is equivalent:
12100
12101 @smallexample
12102 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
12103 @end smallexample
12104 @end table
12105
12106 @anchor{change volume prompt}
12107 When @GNUTAR{} comes to the end of a storage media, it asks you to
12108 change the volume.  The built-in prompt for POSIX locale
12109 is@footnote{If you run @GNUTAR{} under a different locale, the
12110 translation to the locale's language will be used.}:
12111
12112 @smallexample
12113 Prepare volume #@var{n} for '@var{archive}' and hit return:
12114 @end smallexample
12115
12116 @noindent
12117 where @var{n} is the ordinal number of the volume to be created and
12118 @var{archive} is archive file or device name.
12119
12120 When prompting for a new tape, @command{tar} accepts any of the following
12121 responses:
12122
12123 @table @kbd
12124 @item ?
12125 Request @command{tar} to explain possible responses.
12126 @item q
12127 Request @command{tar} to exit immediately.
12128 @item n @var{file-name}
12129 Request @command{tar} to write the next volume on the file @var{file-name}.
12130 @item !
12131 Request @command{tar} to run a subshell.  This option can be disabled
12132 by giving @option{--restrict} command line option to
12133 @command{tar}@footnote{@xref{--restrict}, for more information about
12134 this option.}.
12135 @item y
12136 Request @command{tar} to begin writing the next volume.
12137 @end table
12138
12139 (You should only type @samp{y} after you have changed the tape;
12140 otherwise @command{tar} will write over the volume it just finished.)
12141
12142 @cindex Volume number file
12143 @cindex volno file
12144 @anchor{volno-file}
12145 @opindex volno-file
12146 The volume number used by @command{tar} in its tape-changing prompt
12147 can be changed; if you give the
12148 @option{--volno-file=@var{file-of-number}} option, then
12149 @var{file-of-number} should be an non-existing file to be created, or
12150 else, a file already containing a decimal number.  That number will be
12151 used as the volume number of the first volume written.  When
12152 @command{tar} is finished, it will rewrite the file with the
12153 now-current volume number. (This does not change the volume number
12154 written on a tape label, as per @ref{label}, it @emph{only} affects
12155 the number used in the prompt.)
12156
12157 @cindex End-of-archive info script
12158 @cindex Info script
12159 @anchor{info-script}
12160 @opindex info-script
12161 @opindex new-volume-script
12162 If you want more elaborate behavior than this, you can write a special
12163 @dfn{new volume script}, that will be responsible for changing the
12164 volume, and instruct @command{tar} to use it instead of its normal
12165 prompting procedure:
12166
12167 @table @option
12168 @item --info-script=@var{command}
12169 @itemx --new-volume-script=@var{command}
12170 @itemx -F @var{command}
12171 Specify the command to invoke when switching volumes.  The @var{command}
12172 can be used to eject cassettes, or to broadcast messages such as
12173 @samp{Someone please come change my tape} when performing unattended
12174 backups.
12175 @end table
12176
12177 The @var{command} can contain additional options, if such are needed.
12178 @xref{external, Running External Commands}, for a detailed discussion
12179 of the way @GNUTAR{} runs external commands.  It inherits
12180 @command{tar}'s shell environment.  Additional data is passed to it
12181 via the following environment variables:
12182
12183 @table @env
12184 @vrindex TAR_VERSION, info script environment variable
12185 @item TAR_VERSION
12186 @GNUTAR{} version number.
12187
12188 @vrindex TAR_ARCHIVE, info script environment variable
12189 @item TAR_ARCHIVE
12190 The name of the archive @command{tar} is processing.
12191
12192 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
12193 @item TAR_BLOCKING_FACTOR
12194 Current blocking factor (@pxref{Blocking}).
12195
12196 @vrindex TAR_VOLUME, info script environment variable
12197 @item TAR_VOLUME
12198 Ordinal number of the volume @command{tar} is about to start.
12199
12200 @vrindex TAR_SUBCOMMAND, info script environment variable
12201 @item TAR_SUBCOMMAND
12202 A short option describing the operation @command{tar} is executing.
12203 @xref{Operations}, for a complete list of subcommand options.
12204
12205 @vrindex TAR_FORMAT, info script environment variable
12206 @item TAR_FORMAT
12207 Format of the archive being processed. @xref{Formats}, for a complete
12208 list of archive format names.
12209
12210 @vrindex TAR_FD, info script environment variable
12211 @item TAR_FD
12212 File descriptor which can be used to communicate the new volume
12213 name to @command{tar}.
12214 @end table
12215
12216 These variables can be used in the @var{command} itself, provided that
12217 they are properly quoted to prevent them from being expanded by the
12218 shell that invokes @command{tar}.
12219
12220 The volume script can instruct @command{tar} to use new archive name,
12221 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
12222
12223 If the info script fails, @command{tar} exits; otherwise, it begins
12224 writing the next volume.
12225
12226 If you want @command{tar} to cycle through a series of files or tape
12227 drives, there are three approaches to choose from.  First of all, you
12228 can give @command{tar} multiple @option{--file} options.  In this case
12229 the specified files will be used, in sequence, as the successive
12230 volumes of the archive.  Only when the first one in the sequence needs
12231 to be used again will @command{tar} prompt for a tape change (or run
12232 the info script).  For example, suppose someone has two tape drives on
12233 a system named @file{/dev/tape0} and @file{/dev/tape1}.  For having
12234 @GNUTAR{} to switch to the second drive when it needs to write the
12235 second tape, and then back to the first tape, etc., just do either of:
12236
12237 @smallexample
12238 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
12239 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
12240 @end smallexample
12241
12242 The second method is to use the @samp{n} response to the tape-change
12243 prompt.
12244
12245 Finally, the most flexible approach is to use a volume script, that
12246 writes new archive name to the file descriptor @env{$TAR_FD}.  For example, the
12247 following volume script will create a series of archive files, named
12248 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
12249 archive being created (as given by @option{--file} option) and
12250 @var{vol} is the ordinal number of the archive being created:
12251
12252 @smallexample
12253 @group
12254 #! /bin/bash
12255 # For this script it's advisable to use a shell, such as Bash,
12256 # that supports a TAR_FD value greater than 9.
12257
12258 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
12259
12260 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
12261 case $TAR_SUBCOMMAND in
12262 -c)       ;;
12263 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
12264           ;;
12265 *)        exit 1
12266 esac
12267
12268 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
12269 @end group
12270 @end smallexample
12271
12272 The same script can be used while listing, comparing or extracting
12273 from the created archive.  For example:
12274
12275 @smallexample
12276 @group
12277 # @r{Create a multi-volume archive:}
12278 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
12279 # @r{Extract from the created archive:}
12280 $ @kbd{tar -x -f archive.tar -F new-volume .}
12281 @end group
12282 @end smallexample
12283
12284 @noindent
12285 Notice, that the first command had to use @option{-L} option, since
12286 otherwise @GNUTAR{} will end up writing everything to file
12287 @file{archive.tar}.
12288
12289 You can read each individual volume of a multi-volume archive as if it
12290 were an archive by itself.  For example, to list the contents of one
12291 volume, use @option{--list}, without @option{--multi-volume} specified.
12292 To extract an archive member from one volume (assuming it is described
12293 that volume), use @option{--extract}, again without
12294 @option{--multi-volume}.
12295
12296 If an archive member is split across volumes (i.e., its entry begins on
12297 one volume of the media and ends on another), you need to specify
12298 @option{--multi-volume} to extract it successfully.  In this case, you
12299 should load the volume where the archive member starts, and use
12300 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
12301 volumes as it needs them.  @xref{extracting archives}, for more
12302 information about extracting archives.
12303
12304 Multi-volume archives can be modified like any other archive.  To add
12305 files to a multi-volume archive, you need to only mount the last
12306 volume of the archive media (and new volumes, if needed).  For all
12307 other operations, you need to use the entire archive.
12308
12309 If a multi-volume archive was labeled using
12310 @option{--label=@var{archive-label}} (@pxref{label}) when it was
12311 created, @command{tar} will not automatically label volumes which are
12312 added later.  To label subsequent volumes, specify
12313 @option{--label=@var{archive-label}} again in conjunction with the
12314 @option{--append}, @option{--update} or @option{--concatenate} operation.
12315
12316 Notice that multi-volume support is a GNU extension and the archives
12317 created in this mode should be read only using @GNUTAR{}.  If you
12318 absolutely have to process such archives using a third-party @command{tar}
12319 implementation, read @ref{Split Recovery}.
12320
12321 @node Tape Files
12322 @subsection Tape Files
12323 @cindex labeling archives
12324 @opindex label
12325 @UNREVISED
12326
12327 To give the archive a name which will be recorded in it, use the
12328 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
12329 option.  This will write a special block identifying
12330 @var{volume-label} as the name of the archive to the front of the
12331 archive which will be displayed when the archive is listed with
12332 @option{--list}.  If you are creating a multi-volume archive with
12333 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
12334 volume label will have @samp{Volume @var{nnn}} appended to the name
12335 you give, where @var{nnn} is the number of the volume of the archive.
12336 If you use the @option{--label=@var{volume-label}} option when
12337 reading an archive, it checks to make sure the label on the tape
12338 matches the one you gave.  @xref{label}.
12339
12340 When @command{tar} writes an archive to tape, it creates a single
12341 tape file.  If multiple archives are written to the same tape, one
12342 after the other, they each get written as separate tape files.  When
12343 extracting, it is necessary to position the tape at the right place
12344 before running @command{tar}.  To do this, use the @command{mt} command.
12345 For more information on the @command{mt} command and on the organization
12346 of tapes into a sequence of tape files, see @ref{mt}.
12347
12348 People seem to often do:
12349
12350 @smallexample
12351 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
12352 @end smallexample
12353
12354 or such, for pushing a common date in all volumes or an archive set.
12355
12356 @node Tarcat
12357 @subsection Concatenate Volumes into a Single Archive
12358
12359 @pindex tarcat
12360   Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
12361 archive to a single @command{tar} archive.  Simply concatenating all
12362 volumes into one will not work, since each volume carries an additional
12363 information at the beginning.  @GNUTAR{} is shipped with the shell
12364 script @command{tarcat} designed for this purpose.
12365
12366   The script takes a list of files comprising a multi-volume archive
12367 and creates the resulting archive at the standard output.  For example:
12368
12369 @smallexample
12370 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
12371 @end smallexample
12372
12373   The script implements a simple heuristics to determine the format of
12374 the first volume file and to decide how to process the rest of the
12375 files.  However, it makes no attempt to verify whether the files are
12376 given in order or even if they are valid @command{tar} archives.
12377 It uses @command{dd} and does not filter its standard error, so you
12378 will usually see lots of spurious messages.
12379
12380 @FIXME{The script is not installed.  Should we install it?}
12381
12382 @node label
12383 @section Including a Label in the Archive
12384 @cindex Labeling an archive
12385 @cindex Labels on the archive media
12386 @cindex Labeling multi-volume archives
12387
12388 @opindex label
12389   To avoid problems caused by misplaced paper labels on the archive
12390 media, you can include a @dfn{label} entry --- an archive member which
12391 contains the name of the archive --- in the archive itself.  Use the
12392 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12393 option@footnote{Until version 1.10, that option was called
12394 @option{--volume}, but is not available under that name anymore.} in
12395 conjunction with the @option{--create} operation to include a label
12396 entry in the archive as it is being created.
12397
12398 @table @option
12399 @item --label=@var{archive-label}
12400 @itemx -V @var{archive-label}
12401 Includes an @dfn{archive-label} at the beginning of the archive when
12402 the archive is being created, when used in conjunction with the
12403 @option{--create} operation.  Checks to make sure the archive label
12404 matches the one specified (when used in conjunction with any other
12405 operation).
12406 @end table
12407
12408   If you create an archive using both
12409 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12410 and @option{--multi-volume} (@option{-M}), each volume of the archive
12411 will have an archive label of the form @samp{@var{archive-label}
12412 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
12413 next, and so on. @xref{Using Multiple Tapes}, for information on
12414 creating multiple volume archives.
12415
12416 @cindex Volume label, listing
12417 @cindex Listing volume label
12418   The volume label will be displayed by @option{--list} along with
12419 the file contents.  If verbose display is requested, it will also be
12420 explicitly marked as in the example below:
12421
12422 @smallexample
12423 @group
12424 $ @kbd{tar --verbose --list --file=iamanarchive}
12425 V--------- 0/0               0 1992-03-07 12:01 iamalabel--Volume Header--
12426 -rw-r--r-- ringo/user       40 1990-05-21 13:30 iamafilename
12427 @end group
12428 @end smallexample
12429
12430 @opindex test-label
12431 @anchor{--test-label option}
12432   However, @option{--list} option will cause listing entire
12433 contents of the archive, which may be undesirable (for example, if the
12434 archive is stored on a tape).  You can request checking only the volume
12435 label by specifying @option{--test-label} option.  This option reads only the
12436 first block of an archive, so it can be used with slow storage
12437 devices.  For example:
12438
12439 @smallexample
12440 @group
12441 $ @kbd{tar --test-label --file=iamanarchive}
12442 iamalabel
12443 @end group
12444 @end smallexample
12445
12446   If @option{--test-label} is used with one or more command line
12447 arguments, @command{tar} compares the volume label with each
12448 argument.  It exits with code 0 if a match is found, and with code 1
12449 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
12450 mismatch with an exit code 2 and printed a spurious diagnostics on
12451 stderr.}.  No output is displayed, unless you also used the
12452 @option{--verbose} option.  For example:
12453
12454 @smallexample
12455 @group
12456 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
12457 @result{} 0
12458 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
12459 @result{} 1
12460 @end group
12461 @end smallexample
12462
12463   When used with the @option{--verbose} option, @command{tar}
12464 prints the actual volume label (if any), and a verbose diagnostics in
12465 case of a mismatch:
12466
12467 @smallexample
12468 @group
12469 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
12470 iamalabel
12471 @result{} 0
12472 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
12473 iamalabel
12474 tar: Archive label mismatch
12475 @result{} 1
12476 @end group
12477 @end smallexample
12478
12479   If you request any operation, other than @option{--create}, along
12480 with using @option{--label} option, @command{tar} will first check if
12481 the archive label matches the one specified and will refuse to proceed
12482 if it does not.  Use this as a safety precaution to avoid accidentally
12483 overwriting existing archives.  For example, if you wish to add files
12484 to @file{archive}, presumably labeled with string @samp{My volume},
12485 you will get:
12486
12487 @smallexample
12488 @group
12489 $ @kbd{tar -rf archive --label 'My volume' .}
12490 tar: Archive not labeled to match 'My volume'
12491 @end group
12492 @end smallexample
12493
12494 @noindent
12495 in case its label does not match.  This will work even if
12496 @file{archive} is not labeled at all.
12497
12498   Similarly, @command{tar} will refuse to list or extract the
12499 archive if its label doesn't match the @var{archive-label}
12500 specified.  In those cases, @var{archive-label} argument is interpreted
12501 as a globbing-style pattern which must match the actual magnetic
12502 volume label.  @xref{exclude}, for a precise description of how match
12503 is attempted@footnote{Previous versions of @command{tar} used full
12504 regular expression matching, or before that, only exact string
12505 matching, instead of wildcard matchers.  We decided for the sake of
12506 simplicity to use a uniform matching device through
12507 @command{tar}.}.  If the switch @option{--multi-volume} (@option{-M}) is being used,
12508 the volume label matcher will also suffix @var{archive-label} by
12509 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
12510 up.  Since the volume numbering is automatically added in labels at
12511 creation time, it sounded logical to equally help the user taking care
12512 of it when the archive is being read.
12513
12514   You can also use @option{--label} to get a common information on
12515 all tapes of a series.  For having this information different in each
12516 series created through a single script used on a regular basis, just
12517 manage to get some date string as part of the label.  For example:
12518
12519 @smallexample
12520 @group
12521 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
12522 $ @kbd{tar --create --file=/dev/tape --multi-volume \
12523      --label="Daily backup for `date +%Y-%m-%d`"}
12524 @end group
12525 @end smallexample
12526
12527   Some more notes about volume labels:
12528
12529 @itemize @bullet
12530 @item Each label has its own date and time, which corresponds
12531 to the time when @GNUTAR{} initially attempted to write it,
12532 often soon after the operator launches @command{tar} or types the
12533 carriage return telling that the next tape is ready.
12534
12535 @item Comparing date labels to get an idea of tape throughput is
12536 unreliable.  It gives correct results only if the delays for rewinding
12537 tapes and the operator switching them were negligible, which is
12538 usually not the case.
12539 @end itemize
12540
12541 @node verify
12542 @section Verifying Data as It is Stored
12543 @cindex Verifying a write operation
12544 @cindex Double-checking a write operation
12545
12546 @table @option
12547 @item -W
12548 @itemx --verify
12549 @opindex verify, short description
12550 Attempt to verify the archive after writing.
12551 @end table
12552
12553 This option causes @command{tar} to verify the archive after writing it.
12554 Each volume is checked after it is written, and any discrepancies
12555 are recorded on the standard error output.
12556
12557 Verification requires that the archive be on a back-space-able medium.
12558 This means pipes, some cartridge tape drives, and some other devices
12559 cannot be verified.
12560
12561 You can insure the accuracy of an archive by comparing files in the
12562 system with archive members.  @command{tar} can compare an archive to the
12563 file system as the archive is being written, to verify a write
12564 operation, or can compare a previously written archive, to insure that
12565 it is up to date.
12566
12567 @xopindex{verify, using with @option{--create}}
12568 @xopindex{create, using with @option{--verify}}
12569 To check for discrepancies in an archive immediately after it is
12570 written, use the @option{--verify} (@option{-W}) option in conjunction with
12571 the @option{--create} operation.  When this option is
12572 specified, @command{tar} checks archive members against their counterparts
12573 in the file system, and reports discrepancies on the standard error.
12574
12575 To verify an archive, you must be able to read it from before the end
12576 of the last written entry.  This option is useful for detecting data
12577 errors on some tapes.  Archives written to pipes, some cartridge tape
12578 drives, and some other devices cannot be verified.
12579
12580 One can explicitly compare an already made archive with the file
12581 system by using the @option{--compare} (@option{--diff}, @option{-d})
12582 option, instead of using the more automatic @option{--verify} option.
12583 @xref{compare}.
12584
12585 Note that these two options have a slightly different intent.  The
12586 @option{--compare} option checks how identical are the logical contents of some
12587 archive with what is on your disks, while the @option{--verify} option is
12588 really for checking if the physical contents agree and if the recording
12589 media itself is of dependable quality.  So, for the @option{--verify}
12590 operation, @command{tar} tries to defeat all in-memory cache pertaining to
12591 the archive, while it lets the speed optimization undisturbed for the
12592 @option{--compare} option.  If you nevertheless use @option{--compare} for
12593 media verification, you may have to defeat the in-memory cache yourself,
12594 maybe by opening and reclosing the door latch of your recording unit,
12595 forcing some doubt in your operating system about the fact this is really
12596 the same volume as the one just written or read.
12597
12598 The @option{--verify} option would not be necessary if drivers were indeed
12599 able to detect dependably all write failures.  This sometimes require many
12600 magnetic heads, some able to read after the writes occurred.  One would
12601 not say that drivers unable to detect all cases are necessarily flawed,
12602 as long as programming is concerned.
12603
12604 The @option{--verify} (@option{-W}) option will not work in
12605 conjunction with the @option{--multi-volume} (@option{-M}) option or
12606 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
12607 and @option{--delete} operations.  @xref{Operations}, for more
12608 information on these operations.
12609
12610 Also, since @command{tar} normally strips leading @samp{/} from file
12611 names (@pxref{absolute}), a command like @samp{tar --verify -cf
12612 /tmp/foo.tar /etc} will work as desired only if the working directory is
12613 @file{/}, as @command{tar} uses the archive's relative member names
12614 (e.g., @file{etc/motd}) when verifying the archive.
12615
12616 @node Write Protection
12617 @section Write Protection
12618
12619 Almost all tapes and diskettes, and in a few rare cases, even disks can
12620 be @dfn{write protected}, to protect data on them from being changed.
12621 Once an archive is written, you should write protect the media to prevent
12622 the archive from being accidentally overwritten or deleted.  (This will
12623 protect the archive from being changed with a tape or floppy drive---it
12624 will not protect it from magnet fields or other physical hazards.)
12625
12626 The write protection device itself is usually an integral part of the
12627 physical media, and can be a two position (write enabled/write
12628 disabled) switch, a notch which can be popped out or covered, a ring
12629 which can be removed from the center of a tape reel, or some other
12630 changeable feature.
12631
12632 @node Reliability and security
12633 @chapter Reliability and Security
12634
12635 The @command{tar} command reads and writes files as any other
12636 application does, and is subject to the usual caveats about
12637 reliability and security.  This section contains some commonsense
12638 advice on the topic.
12639
12640 @menu
12641 * Reliability::
12642 * Security::
12643 @end menu
12644
12645 @node Reliability
12646 @section Reliability
12647
12648 Ideally, when @command{tar} is creating an archive, it reads from a
12649 file system that is not being modified, and encounters no errors or
12650 inconsistencies while reading and writing.  If this is the case, the
12651 archive should faithfully reflect what was read.  Similarly, when
12652 extracting from an archive, ideally @command{tar} ideally encounters
12653 no errors and the extracted files faithfully reflect what was in the
12654 archive.
12655
12656 However, when reading or writing real-world file systems, several
12657 things can go wrong; these include permissions problems, corruption of
12658 data, and race conditions.
12659
12660 @menu
12661 * Permissions problems::
12662 * Data corruption and repair::
12663 * Race conditions::
12664 @end menu
12665
12666 @node Permissions problems
12667 @subsection Permissions Problems
12668
12669 If @command{tar} encounters errors while reading or writing files, it
12670 normally reports an error and exits with nonzero status.  The work it
12671 does may therefore be incomplete.  For example, when creating an
12672 archive, if @command{tar} cannot read a file then it cannot copy the
12673 file into the archive.
12674
12675 @node Data corruption and repair
12676 @subsection Data Corruption and Repair
12677
12678 If an archive becomes corrupted by an I/O error, this may corrupt the
12679 data in an extracted file.  Worse, it may corrupt the file's metadata,
12680 which may cause later parts of the archive to become misinterpreted.
12681 An tar-format archive contains a checksum that most likely will detect
12682 errors in the metadata, but it will not detect errors in the data.
12683
12684 If data corruption is a concern, you can compute and check your own
12685 checksums of an archive by using other programs, such as
12686 @command{cksum}.
12687
12688 When attempting to recover from a read error or data corruption in an
12689 archive, you may need to skip past the questionable data and read the
12690 rest of the archive.  This requires some expertise in the archive
12691 format and in other software tools.
12692
12693 @node Race conditions
12694 @subsection Race conditions
12695
12696 If some other process is modifying the file system while @command{tar}
12697 is reading or writing files, the result may well be inconsistent due
12698 to race conditions.  For example, if another process creates some
12699 files in a directory while @command{tar} is creating an archive
12700 containing the directory's files, @command{tar} may see some of the
12701 files but not others, or it may see a file that is in the process of
12702 being created.  The resulting archive may not be a snapshot of the
12703 file system at any point in time.  If an application such as a
12704 database system depends on an accurate snapshot, restoring from the
12705 @command{tar} archive of a live file system may therefore break that
12706 consistency and may break the application.  The simplest way to avoid
12707 the consistency issues is to avoid making other changes to the file
12708 system while tar is reading it or writing it.
12709
12710 When creating an archive, several options are available to avoid race
12711 conditions.  Some hosts have a way of snapshotting a file system, or
12712 of temporarily suspending all changes to a file system, by (say)
12713 suspending the only virtual machine that can modify a file system; if
12714 you use these facilities and have @command{tar -c} read from a
12715 snapshot when creating an archive, you can avoid inconsistency
12716 problems.  More drastically, before starting @command{tar} you could
12717 suspend or shut down all processes other than @command{tar} that have
12718 access to the file system, or you could unmount the file system and
12719 then mount it read-only.
12720
12721 When extracting from an archive, one approach to avoid race conditions
12722 is to create a directory that no other process can write to, and
12723 extract into that.
12724
12725 @node Security
12726 @section Security
12727
12728 In some cases @command{tar} may be used in an adversarial situation,
12729 where an untrusted user is attempting to gain information about or
12730 modify otherwise-inaccessible files.  Dealing with untrusted data
12731 (that is, data generated by an untrusted user) typically requires
12732 extra care, because even the smallest mistake in the use of
12733 @command{tar} is more likely to be exploited by an adversary than by a
12734 race condition.
12735
12736 @menu
12737 * Privacy::
12738 * Integrity::
12739 * Live untrusted data::
12740 * Security rules of thumb::
12741 @end menu
12742
12743 @node Privacy
12744 @subsection Privacy
12745
12746 Standard privacy concerns apply when using @command{tar}.  For
12747 example, suppose you are archiving your home directory into a file
12748 @file{/archive/myhome.tar}.  Any secret information in your home
12749 directory, such as your SSH secret keys, are copied faithfully into
12750 the archive.  Therefore, if your home directory contains any file that
12751 should not be read by some other user, the archive itself should be
12752 not be readable by that user.  And even if the archive's data are
12753 inaccessible to untrusted users, its metadata (such as size or
12754 last-modified date) may reveal some information about your home
12755 directory; if the metadata are intended to be private, the archive's
12756 parent directory should also be inaccessible to untrusted users.
12757
12758 One precaution is to create @file{/archive} so that it is not
12759 accessible to any user, unless that user also has permission to access
12760 all the files in your home directory.
12761
12762 Similarly, when extracting from an archive, take care that the
12763 permissions of the extracted files are not more generous than what you
12764 want.  Even if the archive itself is readable only to you, files
12765 extracted from it have their own permissions that may differ.
12766
12767 @node Integrity
12768 @subsection Integrity
12769
12770 When creating archives, take care that they are not writable by a
12771 untrusted user; otherwise, that user could modify the archive, and
12772 when you later extract from the archive you will get incorrect data.
12773
12774 When @command{tar} extracts from an archive, by default it writes into
12775 files relative to the working directory.  If the archive was generated
12776 by an untrusted user, that user therefore can write into any file
12777 under the working directory.  If the working directory contains a
12778 symbolic link to another directory, the untrusted user can also write
12779 into any file under the referenced directory.  When extracting from an
12780 untrusted archive, it is therefore good practice to create an empty
12781 directory and run @command{tar} in that directory.
12782
12783 When extracting from two or more untrusted archives, each one should
12784 be extracted independently, into different empty directories.
12785 Otherwise, the first archive could create a symbolic link into an area
12786 outside the working directory, and the second one could follow the
12787 link and overwrite data that is not under the working directory.  For
12788 example, when restoring from a series of incremental dumps, the
12789 archives should have been created by a trusted process, as otherwise
12790 the incremental restores might alter data outside the working
12791 directory.
12792
12793 If you use the @option{--absolute-names} (@option{-P}) option when
12794 extracting, @command{tar} respects any file names in the archive, even
12795 file names that begin with @file{/} or contain @file{..}.  As this
12796 lets the archive overwrite any file in your system that you can write,
12797 the @option{--absolute-names} (@option{-P}) option should be used only
12798 for trusted archives.
12799
12800 Conversely, with the @option{--keep-old-files} (@option{-k}) and
12801 @option{--skip-old-files} options, @command{tar} refuses to replace
12802 existing files when extracting.  The difference between the two
12803 options is that the former treats existing files as errors whereas the
12804 latter just silently ignores them.
12805
12806 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
12807 refuses to replace the permissions or ownership of already-existing
12808 directories.  These options may help when extracting from untrusted
12809 archives.
12810
12811 @node Live untrusted data
12812 @subsection Dealing with Live Untrusted Data
12813
12814 Extra care is required when creating from or extracting into a file
12815 system that is accessible to untrusted users.  For example, superusers
12816 who invoke @command{tar} must be wary about its actions being hijacked
12817 by an adversary who is reading or writing the file system at the same
12818 time that @command{tar} is operating.
12819
12820 When creating an archive from a live file system, @command{tar} is
12821 vulnerable to denial-of-service attacks.  For example, an adversarial
12822 user could create the illusion of an indefinitely-deep directory
12823 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
12824 @command{tar}, or the illusion of an indefinitely-long file by
12825 creating a sparse file but arranging for blocks to be allocated just
12826 before @command{tar} reads them.  There is no easy way for
12827 @command{tar} to distinguish these scenarios from legitimate uses, so
12828 you may need to monitor @command{tar}, just as you'd need to monitor
12829 any other system service, to detect such attacks.
12830
12831 While a superuser is extracting from an archive into a live file
12832 system, an untrusted user might replace a directory with a symbolic
12833 link, in hopes that @command{tar} will follow the symbolic link and
12834 extract data into files that the untrusted user does not have access
12835 to.  Even if the archive was generated by the superuser, it may
12836 contain a file such as @file{d/etc/passwd} that the untrusted user
12837 earlier created in order to break in; if the untrusted user replaces
12838 the directory @file{d/etc} with a symbolic link to @file{/etc} while
12839 @command{tar} is running, @command{tar} will overwrite
12840 @file{/etc/passwd}.  This attack can be prevented by extracting into a
12841 directory that is inaccessible to untrusted users.
12842
12843 Similar attacks via symbolic links are also possible when creating an
12844 archive, if the untrusted user can modify an ancestor of a top-level
12845 argument of @command{tar}.  For example, an untrusted user that can
12846 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
12847 - /home/eve/Documents/yesterday} by replacing
12848 @file{/home/eve/Documents} with a symbolic link to some other
12849 location.  Attacks like these can be prevented by making sure that
12850 untrusted users cannot modify any files that are top-level arguments
12851 to @command{tar}, or any ancestor directories of these files.
12852
12853 @node Security rules of thumb
12854 @subsection Security Rules of Thumb
12855
12856 This section briefly summarizes rules of thumb for avoiding security
12857 pitfalls.
12858
12859 @itemize @bullet
12860
12861 @item
12862 Protect archives at least as much as you protect any of the files
12863 being archived.
12864
12865 @item
12866 Extract from an untrusted archive only into an otherwise-empty
12867 directory.  This directory and its parent should be accessible only to
12868 trusted users.  For example:
12869
12870 @example
12871 @group
12872 $ @kbd{chmod go-rwx .}
12873 $ @kbd{mkdir -m go-rwx dir}
12874 $ @kbd{cd dir}
12875 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12876 @end group
12877 @end example
12878
12879 As a corollary, do not do an incremental restore from an untrusted archive.
12880
12881 @item
12882 Do not let untrusted users access files extracted from untrusted
12883 archives without checking first for problems such as setuid programs.
12884
12885 @item
12886 Do not let untrusted users modify directories that are ancestors of
12887 top-level arguments of @command{tar}.  For example, while you are
12888 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12889 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12890
12891 @item
12892 Pay attention to the diagnostics and exit status of @command{tar}.
12893
12894 @item
12895 When archiving live file systems, monitor running instances of
12896 @command{tar} to detect denial-of-service attacks.
12897
12898 @item
12899 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12900 @option{--dereference} (@option{-h}), @option{--overwrite},
12901 @option{--recursive-unlink}, and @option{--remove-files} unless you
12902 understand their security implications.
12903
12904 @end itemize
12905
12906 @node Changes
12907 @appendix Changes
12908
12909 This appendix lists some important user-visible changes between
12910 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
12911 version of this document is available at
12912 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12913 @GNUTAR{} documentation page}.
12914
12915 @table @asis
12916 @item Use of globbing patterns when listing and extracting.
12917
12918 Previous versions of GNU tar assumed shell-style globbing when
12919 extracting from or listing an archive.  For example:
12920
12921 @smallexample
12922 $ @kbd{tar xf foo.tar '*.c'}
12923 @end smallexample
12924
12925 would extract all files whose names end in @samp{.c}.  This behavior
12926 was not documented and was incompatible with traditional tar
12927 implementations.  Therefore, starting from version 1.15.91, GNU tar
12928 no longer uses globbing by default.  For example, the above invocation
12929 is now interpreted as a request to extract from the archive the file
12930 named @file{*.c}.
12931
12932 To facilitate transition to the new behavior for those users who got
12933 used to the previous incorrect one, @command{tar} will print a warning
12934 if it finds out that a requested member was not found in the archive
12935 and its name looks like a globbing pattern.  For example:
12936
12937 @smallexample
12938 $ @kbd{tar xf foo.tar  '*.c'}
12939 tar: Pattern matching characters used in file names. Please,
12940 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12941 tar: suppress this warning.
12942 tar: *.c: Not found in archive
12943 tar: Error exit delayed from previous errors
12944 @end smallexample
12945
12946 To treat member names as globbing patterns, use the @option{--wildcards} option.
12947 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12948 add this option to your @env{TAR_OPTIONS} variable.
12949
12950 @xref{wildcards}, for the detailed discussion of the use of globbing
12951 patterns by @GNUTAR{}.
12952
12953 @item Use of short option @option{-o}.
12954
12955 Earlier versions of @GNUTAR{} understood @option{-o} command line
12956 option as a synonym for @option{--old-archive}.
12957
12958 @GNUTAR{} starting from version 1.13.90 understands this option as
12959 a synonym for @option{--no-same-owner}.  This is compatible with
12960 UNIX98 @command{tar} implementations.
12961
12962 However, to facilitate transition, @option{-o} option retains its
12963 old semantics when it is used with one of archive-creation commands.
12964 Users are encouraged to use @option{--format=oldgnu} instead.
12965
12966 It is especially important, since versions of @acronym{GNU} Automake
12967 up to and including 1.8.4 invoke tar with this option to produce
12968 distribution tarballs.  @xref{Formats,v7}, for the detailed discussion
12969 of this issue and its implications.
12970
12971 @xref{Options, tar-formats, Changing Automake's Behavior,
12972 automake, GNU Automake}, for a description on how to use various
12973 archive formats with @command{automake}.
12974
12975 Future versions of @GNUTAR{} will understand @option{-o} only as a
12976 synonym for @option{--no-same-owner}.
12977
12978 @item Use of short option @option{-l}
12979
12980 Earlier versions of @GNUTAR{} understood @option{-l} option as a
12981 synonym for @option{--one-file-system}.  Since such usage contradicted
12982 to UNIX98 specification and harmed compatibility with other
12983 implementations, it was declared deprecated in version 1.14.  However,
12984 to facilitate transition to its new semantics, it was supported by
12985 versions 1.15 and 1.15.90.  The present use of @option{-l} as a short
12986 variant of @option{--check-links} was introduced in version 1.15.91.
12987
12988 @item Use of options @option{--portability} and @option{--old-archive}
12989
12990 These options are deprecated.  Please use @option{--format=v7} instead.
12991
12992 @item Use of option @option{--posix}
12993
12994 This option is deprecated.  Please use @option{--format=posix} instead.
12995 @end table
12996
12997 @node Configuring Help Summary
12998 @appendix Configuring Help Summary
12999
13000 Running @kbd{tar --help} displays the short @command{tar} option
13001 summary (@pxref{help}). This summary is organized by @dfn{groups} of
13002 semantically close options. The options within each group are printed
13003 in the following order: a short option, eventually followed by a list
13004 of corresponding long option names, followed by a short description of
13005 the option. For example, here is an excerpt from the actual @kbd{tar
13006 --help} output:
13007
13008 @verbatim
13009  Main operation mode:
13010
13011   -A, --catenate, --concatenate   append tar files to an archive
13012   -c, --create               create a new archive
13013   -d, --diff, --compare      find differences between archive and
13014                              file system
13015       --delete               delete from the archive
13016 @end verbatim
13017
13018 @vrindex ARGP_HELP_FMT, environment variable
13019 The exact visual representation of the help output is configurable via
13020 @env{ARGP_HELP_FMT} environment variable. The value of this variable
13021 is a comma-separated list of @dfn{format variable} assignments. There
13022 are two kinds of format variables. An @dfn{offset variable} keeps the
13023 offset of some part of help output text from the leftmost column on
13024 the screen. A @dfn{boolean} variable is a flag that toggles some
13025 output feature on or off. Depending on the type of the corresponding
13026 variable, there are two kinds of assignments:
13027
13028 @table @asis
13029 @item Offset assignment
13030
13031 The assignment to an offset variable has the following syntax:
13032
13033 @smallexample
13034 @var{variable}=@var{value}
13035 @end smallexample
13036
13037 @noindent
13038 where @var{variable} is the variable name, and @var{value} is a
13039 numeric value to be assigned to the variable.
13040
13041 @item Boolean assignment
13042
13043 To assign @code{true} value to a variable, simply put this variable name. To
13044 assign @code{false} value, prefix the variable name with @samp{no-}. For
13045 example:
13046
13047 @smallexample
13048 @group
13049 # Assign @code{true} value:
13050 dup-args
13051 # Assign @code{false} value:
13052 no-dup-args
13053 @end group
13054 @end smallexample
13055 @end table
13056
13057 Following variables are declared:
13058
13059 @deftypevr {Help Output} boolean dup-args
13060 If true, arguments for an option are shown with both short and long
13061 options, even when a given option has both forms, for example:
13062
13063 @smallexample
13064   -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
13065 @end smallexample
13066
13067 If false, then if an option has both short and long forms, the
13068 argument is only shown with the long one, for example:
13069
13070 @smallexample
13071   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13072 @end smallexample
13073
13074 @noindent
13075 and a message indicating that the argument is applicable to both
13076 forms is printed below the options. This message can be disabled
13077 using @code{dup-args-note} (see below).
13078
13079 The default is false.
13080 @end deftypevr
13081
13082 @deftypevr {Help Output} boolean dup-args-note
13083 If this variable is true, which is the default, the following notice
13084 is displayed at the end of the help output:
13085
13086 @quotation
13087 Mandatory or optional arguments to long options are also mandatory or
13088 optional for any corresponding short options.
13089 @end quotation
13090
13091 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
13092 variables @code{dup-args} or @code{dup-args-note} should be set.
13093 @end deftypevr
13094
13095 @deftypevr {Help Output} offset short-opt-col
13096 Column in which short options start. Default is 2.
13097
13098 @smallexample
13099 @group
13100 $ @kbd{tar --help|grep ARCHIVE}
13101   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13102 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
13103       -f, --file=ARCHIVE   use archive file or device ARCHIVE
13104 @end group
13105 @end smallexample
13106 @end deftypevr
13107
13108 @deftypevr {Help Output} offset long-opt-col
13109 Column in which long options start. Default is 6. For example:
13110
13111 @smallexample
13112 @group
13113 $ @kbd{tar --help|grep ARCHIVE}
13114   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13115 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
13116   -f,           --file=ARCHIVE   use archive file or device ARCHIVE
13117 @end group
13118 @end smallexample
13119 @end deftypevr
13120
13121 @deftypevr {Help Output} offset doc-opt-col
13122 Column in which @dfn{doc options} start.  A doc option isn't actually
13123 an option, but rather an arbitrary piece of documentation that is
13124 displayed in much the same manner as the options.  For example, in
13125 the description of @option{--format} option:
13126
13127 @smallexample
13128 @group
13129   -H, --format=FORMAT        create archive of the given format.
13130
13131  FORMAT is one of the following:
13132
13133     gnu                      GNU tar 1.13.x format
13134     oldgnu                   GNU format as per tar <= 1.12
13135     pax                      POSIX 1003.1-2001 (pax) format
13136     posix                    same as pax
13137     ustar                    POSIX 1003.1-1988 (ustar) format
13138     v7                       old V7 tar format
13139 @end group
13140 @end smallexample
13141
13142 @noindent
13143 the format names are doc options. Thus, if you set
13144 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
13145 will look as follows:
13146
13147 @smallexample
13148 @group
13149   -H, --format=FORMAT        create archive of the given format.
13150
13151  FORMAT is one of the following:
13152
13153         gnu                      GNU tar 1.13.x format
13154         oldgnu                   GNU format as per tar <= 1.12
13155         pax                      POSIX 1003.1-2001 (pax) format
13156         posix                    same as pax
13157         ustar                    POSIX 1003.1-1988 (ustar) format
13158         v7                       old V7 tar format
13159 @end group
13160 @end smallexample
13161 @end deftypevr
13162
13163 @deftypevr {Help Output} offset opt-doc-col
13164 Column in which option description starts. Default is 29.
13165
13166 @smallexample
13167 @group
13168 $ @kbd{tar --help|grep ARCHIVE}
13169   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13170 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
13171   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13172 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
13173   -f, --file=ARCHIVE
13174            use archive file or device ARCHIVE
13175 @end group
13176 @end smallexample
13177
13178 @noindent
13179 Notice, that the description starts on a separate line if
13180 @code{opt-doc-col} value is too small.
13181 @end deftypevr
13182
13183 @deftypevr {Help Output} offset header-col
13184 Column in which @dfn{group headers} are printed.  A group header is a
13185 descriptive text preceding an option group.  For example, in the
13186 following text:
13187
13188 @verbatim
13189  Main operation mode:
13190
13191   -A, --catenate, --concatenate   append tar files to
13192                              an archive
13193   -c, --create               create a new archive
13194 @end verbatim
13195 @noindent
13196 @samp{Main operation mode:} is the group header.
13197
13198 The default value is 1.
13199 @end deftypevr
13200
13201 @deftypevr {Help Output} offset usage-indent
13202 Indentation of wrapped usage lines. Affects @option{--usage}
13203 output. Default is 12.
13204 @end deftypevr
13205
13206 @deftypevr {Help Output} offset rmargin
13207 Right margin of the text output. Used for wrapping.
13208 @end deftypevr
13209
13210 @node Fixing Snapshot Files
13211 @appendix Fixing Snapshot Files
13212 @include tar-snapshot-edit.texi
13213
13214 @node Tar Internals
13215 @appendix Tar Internals
13216 @include intern.texi
13217
13218 @node Genfile
13219 @appendix Genfile
13220 @include genfile.texi
13221
13222 @node Free Software Needs Free Documentation
13223 @appendix Free Software Needs Free Documentation
13224 @include freemanuals.texi
13225
13226 @node GNU Free Documentation License
13227 @appendix GNU Free Documentation License
13228
13229 @include fdl.texi
13230
13231 @node Index of Command Line Options
13232 @appendix Index of Command Line Options
13233
13234 This appendix contains an index of all @GNUTAR{} long command line
13235 options. The options are listed without the preceding double-dash.
13236 For a cross-reference of short command line options, see
13237 @ref{Short Option Summary}.
13238
13239 @printindex op
13240
13241 @node Index
13242 @appendix Index
13243
13244 @printindex cp
13245
13246 @summarycontents
13247 @contents
13248 @bye
13249
13250 @c Local variables:
13251 @c texinfo-column-for-description: 32
13252 @c End: